Просмотр исходного кода

libdpkg: Move subprocess related functions from mlib.c to subproc.c

Guillem Jover лет назад: 17
Родитель
Сommit
f29e54ab5c
3 измененных файлов с 64 добавлено и 40 удалено
  1. 7 0
      ChangeLog
  2. 0 40
      lib/mlib.c
  3. 57 0
      lib/subproc.c

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2008-12-05  Guillem Jover  <guillem@debian.org>
+
+	* lib/mlib.c: Remove <sys/wait.h> include.
+	(checksubprocerr, waitsubproc): Move to ...
+	* lib/subproc.c (checksubprocerr, waitsubproc): ... here.
+	Include <sys/types.h> and <sys/wait.h>.
+
 2008-12-05  Guillem Jover  <guillem@debian.org>
 
 	* lib/mlib.c (checksubprocerr): Split unrelated conditionals for n

+ 0 - 40
lib/mlib.c

@@ -32,7 +32,6 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <sys/wait.h>
 #include <sys/types.h>
 
 #include <dpkg.h>
@@ -118,45 +117,6 @@ void m_pipe(int *fds) {
   ohshite(_("failed to create pipe"));
 }
 
-int checksubprocerr(int status, const char *description, int flags) {
-  int n;
-  if (WIFEXITED(status)) {
-    n = WEXITSTATUS(status);
-    if (!n)
-      return 0;
-    if (flags & PROCNOERR)
-      return -1;
-    if (flags & PROCWARN)
-      warning(_("%s returned error exit status %d"), description, n);
-    else
-      ohshit(_("subprocess %s returned error exit status %d"), description, n);
-  } else if (WIFSIGNALED(status)) {
-    n = WTERMSIG(status);
-    if (!n)
-      return 0;
-    if ((flags & PROCPIPE) && n == SIGPIPE)
-      return 0;
-    if (flags & PROCWARN)
-      warning(_("%s killed by signal (%s)%s"),
-              description, strsignal(n), WCOREDUMP(status) ? _(", core dumped") : "");
-    else
-      ohshit(_("subprocess %s killed by signal (%s)%s"),
-	     description, strsignal(n), WCOREDUMP(status) ? _(", core dumped") : "");
-  } else {
-    ohshit(_("subprocess %s failed with wait status code %d"),description,status);
-  }
-  return -1;
-}
-
-int waitsubproc(pid_t pid, const char *description, int flags) {
-  pid_t r;
-  int status;
-
-  while ((r= waitpid(pid,&status,0)) == -1 && errno == EINTR);
-  if (r != pid) { onerr_abort++; ohshite(_("wait for %s failed"),description); }
-  return checksubprocerr(status,description,flags);
-}
-
 void setcloexec(int fd, const char* fn) {
   int f;
 

+ 57 - 0
lib/subproc.c

@@ -24,6 +24,8 @@
 
 #include <dpkg-i18n.h>
 
+#include <sys/types.h>
+#include <sys/wait.h>
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
@@ -68,3 +70,58 @@ cu_subproc_signals(int argc, void **argv)
 	}
 }
 
+int
+checksubprocerr(int status, const char *description, int flags)
+{
+	int n;
+
+	if (WIFEXITED(status)) {
+		n = WEXITSTATUS(status);
+		if (!n)
+			return 0;
+		if (flags & PROCNOERR)
+			return -1;
+		if (flags & PROCWARN)
+			warning(_("%s returned error exit status %d"),
+			        description, n);
+		else
+			ohshit(_("subprocess %s returned error exit status %d"),
+			       description, n);
+	} else if (WIFSIGNALED(status)) {
+		n = WTERMSIG(status);
+		if (!n)
+			return 0;
+		if ((flags & PROCPIPE) && n == SIGPIPE)
+			return 0;
+		if (flags & PROCWARN)
+			warning(_("%s killed by signal (%s)%s"),
+			        description, strsignal(n),
+			        WCOREDUMP(status) ? _(", core dumped") : "");
+		else
+			ohshit(_("subprocess %s killed by signal (%s)%s"),
+			       description, strsignal(n),
+			       WCOREDUMP(status) ? _(", core dumped") : "");
+	} else {
+		ohshit(_("subprocess %s failed with wait status code %d"),
+		       description, status);
+	}
+
+	return -1;
+}
+
+int
+waitsubproc(pid_t pid, const char *description, int flags)
+{
+	pid_t r;
+	int status;
+
+	while ((r = waitpid(pid, &status, 0)) == -1 && errno == EINTR) ;
+
+	if (r != pid) {
+		onerr_abort++;
+		ohshite(_("wait for %s failed"), description);
+	}
+
+	return checksubprocerr(status, description, flags);
+}
+