summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2008-11-24 06:25:52 +0200
committerGuillem Jover <guillem@debian.org>2008-12-05 09:21:16 +0200
commitf29e54ab5ccf99376dfb3a9ac824ea795c260e10 (patch)
tree21537b270b8570600d105b3ed47fc4bbee42fbc9
parentac3a40d18a1f4dfbfa35fc92774a81cdf0aa1991 (diff)
downloaddpkg-f29e54ab5ccf99376dfb3a9ac824ea795c260e10.tar.gz
libdpkg: Move subprocess related functions from mlib.c to subproc.c
-rw-r--r--ChangeLog7
-rw-r--r--lib/mlib.c40
-rw-r--r--lib/subproc.c57
3 files changed, 64 insertions, 40 deletions
diff --git a/ChangeLog b/ChangeLog
index b7414a741..722b63a43 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
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
and PROCPIPE.
diff --git a/lib/mlib.c b/lib/mlib.c
index b315e7011..ac5436ffa 100644
--- a/lib/mlib.c
+++ b/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;
diff --git a/lib/subproc.c b/lib/subproc.c
index 009b9f26b..3b855ec04 100644
--- a/lib/subproc.c
+++ b/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);
+}
+