Browse Source

Use subproc_wait instead of directly calling waitpid

Guillem Jover 16 years ago
parent
commit
a720b6aec5
3 changed files with 8 additions and 27 deletions
  1. 2 5
      dselect/method.cc
  2. 3 19
      src/configure.c
  3. 3 3
      src/processarc.c

+ 2 - 5
dselect/method.cc

@@ -138,7 +138,7 @@ static enum urqresult lockmethod(void) {
 
 urqresult falliblesubprocess(const char *exepath, const char *name,
                              const char *const *args) {
-  pid_t c1, cr;
+  pid_t c1;
   int status, i, c;
   
   cursesoff();
@@ -151,10 +151,7 @@ urqresult falliblesubprocess(const char *exepath, const char *name,
     ohshite(_("unable to run %.250s process `%.250s'"),name,exepath);
   }
 
-  while ((cr= waitpid(c1,&status,0)) == -1)
-    if (errno != EINTR) ohshite(_("unable to wait for %.250s"),name);
-  if (cr != c1)
-    ohshit(_("got wrong child's status - asked for %ld, got %ld"),(long)c1,(long)cr);
+  status = subproc_wait(c1, name);
 
   pop_cleanup(ehflag_normaltidy);
 

+ 3 - 19
src/configure.c

@@ -46,6 +46,7 @@
 #include <dpkg/dpkg-db.h>
 #include <dpkg/buffer.h>
 #include <dpkg/file.h>
+#include <dpkg/subproc.h>
 
 #include "filesdb.h"
 #include "main.h"
@@ -489,8 +490,6 @@ static void
 showdiff(const char *old, const char *new)
 {
 	int pid;
-	int r;
-	int status;
 
 	pid = m_fork();
 	if (!pid) {
@@ -514,13 +513,7 @@ showdiff(const char *old, const char *new)
 	}
 
 	/* Parent process. */
-	while (((r = waitpid(pid, &status, 0)) == -1) && (errno == EINTR))
-		;
-
-	if (r != pid) {
-		onerr_abort++;
-		ohshite(_("wait for shell failed"));
-	}
+	subproc_wait(pid, "shell");
 }
 
 /**
@@ -540,9 +533,6 @@ suspend(void)
 		/* Do not job control to suspend but fork and start a new
 		 * shell instead. */
 
-		int status;	/* waitpid status */
-		int r;		/* waitpid result */
-
 		fputs(_("Type `exit' when you're done.\n"), stderr);
 
 		pid = m_fork();
@@ -557,13 +547,7 @@ suspend(void)
 		}
 
 		/* Parent process. */
-		while (((r = waitpid(pid, &status, 0)) == -1) && (errno == EINTR))
-			;
-
-		if (r != pid) {
-			onerr_abort++;
-			ohshite(_("wait for shell failed"));
-		}
+		subproc_wait(pid, "shell");
 	} else {
 		fputs(_("Don't forget to foreground (`fg') this "
 		        "process when you're done !\n"), stderr);

+ 3 - 3
src/processarc.c

@@ -127,8 +127,7 @@ void process_archive(const char *filename) {
       execlp(SPLITTER, SPLITTER, "-Qao", reasmbuf, filename, NULL);
       ohshite(_("failed to exec dpkg-split to see if it's part of a multiparter"));
     }
-    while ((r= waitpid(c1,&status,0)) == -1 && errno == EINTR);
-    if (r != c1) { onerr_abort++; ohshite(_("wait for dpkg-split failed")); }
+    status = subproc_wait(c1, SPLITTER);
     switch (WIFEXITED(status) ? WEXITSTATUS(status) : -1) {
     case 0:
       /* It was a part - is it complete ? */
@@ -157,7 +156,8 @@ void process_archive(const char *filename) {
       ohshite(_("failed to execl debsig-verify"));
     } else {
       int status;
-      waitpid(c1, &status, 0);
+
+      status = subproc_wait(c1, "debsig-verify");
       if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) {
 	if (! fc_badverify) {
 	  ohshit(_("Verification on package %s failed!"), filename);