diff options
author | Guillem Jover <guillem@debian.org> | 2014-10-01 19:56:11 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2014-10-06 00:48:13 +0200 |
commit | b8a6ab4c5c88463bfe8ff1e13cddbf397c950c61 (patch) | |
tree | 74792e7965175a1cb47927127acb52f5391fe490 | |
parent | cece29526d506b89b54cc80a6c400f9f58f36286 (diff) | |
download | dpkg-b8a6ab4c5c88463bfe8ff1e13cddbf397c950c61.tar.gz |
libdpkg: Namespace and reword subproc flags
-rw-r--r-- | dpkg-deb/extract.c | 2 | ||||
-rw-r--r-- | dpkg-split/split.c | 2 | ||||
-rw-r--r-- | dselect/method.cc | 2 | ||||
-rw-r--r-- | lib/dpkg/file.c | 2 | ||||
-rw-r--r-- | lib/dpkg/subproc.c | 14 | ||||
-rw-r--r-- | lib/dpkg/subproc.h | 22 | ||||
-rw-r--r-- | lib/dpkg/test/t-command.c | 2 | ||||
-rw-r--r-- | lib/dpkg/test/t-subproc.c | 13 | ||||
-rw-r--r-- | src/archives.c | 2 | ||||
-rw-r--r-- | src/configure.c | 4 | ||||
-rw-r--r-- | src/script.c | 2 | ||||
-rw-r--r-- | src/unpack.c | 6 |
12 files changed, 41 insertions, 32 deletions
diff --git a/dpkg-deb/extract.c b/dpkg-deb/extract.c index b0b165297..2c929407a 100644 --- a/dpkg-deb/extract.c +++ b/dpkg-deb/extract.c @@ -359,7 +359,7 @@ extracthalf(const char *debar, const char *dir, subproc_reap(c3, "tar", 0); } - subproc_reap(c2, _("<decompress>"), PROCPIPE); + subproc_reap(c2, _("<decompress>"), SUBPROC_NOPIPE); if (c1 != -1) subproc_reap(c1, _("paste"), 0); if (version.major == 0 && admininfo) { diff --git a/dpkg-split/split.c b/dpkg-split/split.c index 677db0372..fe4b60e2e 100644 --- a/dpkg-split/split.c +++ b/dpkg-split/split.c @@ -82,7 +82,7 @@ deb_field(const char *filename, const char *field) close(p[0]); - subproc_reap(pid, _("package field value extraction"), PROCPIPE); + subproc_reap(pid, _("package field value extraction"), SUBPROC_NOPIPE); /* Trim down trailing junk. */ for (end = buf.buf + strlen(buf.buf) - 1; end - buf.buf >= 1; end--) diff --git a/dselect/method.cc b/dselect/method.cc index 8da2e82dc..a62f236db 100644 --- a/dselect/method.cc +++ b/dselect/method.cc @@ -150,7 +150,7 @@ falliblesubprocess(struct command *cmd) fprintf(stderr, "\n"); - i = subproc_reap(pid, cmd->name, PROCWARN); + i = subproc_reap(pid, cmd->name, SUBPROC_WARN); subproc_signals_restore(); diff --git a/lib/dpkg/file.c b/lib/dpkg/file.c index bf674a17b..75252644e 100644 --- a/lib/dpkg/file.c +++ b/lib/dpkg/file.c @@ -173,5 +173,5 @@ file_show(const char *filename) command_add_arg(&cmd, filename); command_exec(&cmd); } - subproc_reap(pid, _("showing file on pager"), PROCNOCHECK); + subproc_reap(pid, _("showing file on pager"), SUBPROC_NOCHECK); } diff --git a/lib/dpkg/subproc.c b/lib/dpkg/subproc.c index 8e7a1d7f8..19227ac46 100644 --- a/lib/dpkg/subproc.c +++ b/lib/dpkg/subproc.c @@ -3,7 +3,7 @@ * subproc.c - subprocess helper routines * * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk> - * Copyright © 2008-2012 Guillem Jover <guillem@debian.org> + * Copyright © 2008-2014 Guillem Jover <guillem@debian.org> * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -119,12 +119,12 @@ subproc_fork(void) } static int -subproc_check(int status, const char *desc, int flags) +subproc_check(int status, const char *desc, enum subproc_flags flags) { void (*out)(const char *fmt, ...) DPKG_ATTR_PRINTF(1); int n; - if (flags & PROCWARN) + if (flags & SUBPROC_WARN) out = warning; else out = ohshit; @@ -133,7 +133,7 @@ subproc_check(int status, const char *desc, int flags) n = WEXITSTATUS(status); if (!n) return 0; - if (flags & PROCNOERR) + if (flags & SUBPROC_RETERROR) return n; out(_("subprocess %s returned error exit status %d"), desc, n); @@ -141,7 +141,7 @@ subproc_check(int status, const char *desc, int flags) n = WTERMSIG(status); if (!n) return 0; - if ((flags & PROCPIPE) && n == SIGPIPE) + if ((flags & SUBPROC_NOPIPE) && n == SIGPIPE) return 0; if (n == SIGINT) @@ -175,13 +175,13 @@ subproc_wait(pid_t pid, const char *desc) } int -subproc_reap(pid_t pid, const char *desc, int flags) +subproc_reap(pid_t pid, const char *desc, enum subproc_flags flags) { int status, rc; status = subproc_wait(pid, desc); - if (flags & PROCNOCHECK) + if (flags & SUBPROC_NOCHECK) rc = status; else rc = subproc_check(status, desc, flags); diff --git a/lib/dpkg/subproc.h b/lib/dpkg/subproc.h index 8cbab442e..38b068255 100644 --- a/lib/dpkg/subproc.h +++ b/lib/dpkg/subproc.h @@ -2,7 +2,7 @@ * libdpkg - Debian packaging suite library routines * subproc.h - sub-process handling routines * - * Copyright © 2008 Guillem Jover <guillem@debian.org> + * Copyright © 2008-2014 Guillem Jover <guillem@debian.org> * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,17 +33,25 @@ DPKG_BEGIN_DECLS * @{ */ +enum subproc_flags { + /** Default subprocess flags. */ + SUBPROC_NORMAL = 0, + /** Emit a warning instead of an error. */ + SUBPROC_WARN = DPKG_BIT(0), + /** Ignore SIGPIPE, and make it return 0. */ + SUBPROC_NOPIPE = DPKG_BIT(1), + /** Do not check the subprocess status. */ + SUBPROC_NOCHECK = DPKG_BIT(2), + /** Do not emit errors, just return the exit status. */ + SUBPROC_RETERROR = DPKG_BIT(3), +}; + void subproc_signals_ignore(const char *name); void subproc_signals_cleanup(int argc, void **argv); void subproc_signals_restore(void); -#define PROCPIPE 1 -#define PROCWARN 2 -#define PROCNOERR 4 -#define PROCNOCHECK 8 - pid_t subproc_fork(void); -int subproc_reap(pid_t pid, const char *desc, int flags); +int subproc_reap(pid_t pid, const char *desc, enum subproc_flags flags); /** @} */ diff --git a/lib/dpkg/test/t-command.c b/lib/dpkg/test/t-command.c index 4dc88174a..ebf2ab177 100644 --- a/lib/dpkg/test/t-command.c +++ b/lib/dpkg/test/t-command.c @@ -197,7 +197,7 @@ test_command_shell(void) pid = subproc_fork(); if (pid == 0) command_shell("false", "command shell fail test"); - ret = subproc_reap(pid, "command shell fail test", PROCNOERR); + ret = subproc_reap(pid, "command shell fail test", SUBPROC_RETERROR); test_fail(ret == 0); unsetenv("SHELL"); diff --git a/lib/dpkg/test/t-subproc.c b/lib/dpkg/test/t-subproc.c index e1337b5af..4b928e20e 100644 --- a/lib/dpkg/test/t-subproc.c +++ b/lib/dpkg/test/t-subproc.c @@ -41,38 +41,39 @@ test_subproc_fork(void) pid = subproc_fork(); if (pid == 0) exit(0); - ret = subproc_reap(pid, "subproc exit pass", PROCNOERR); + ret = subproc_reap(pid, "subproc exit pass", SUBPROC_RETERROR); test_pass(ret == 0); pid = subproc_fork(); if (pid == 0) exit(128); - ret = subproc_reap(pid, "subproc exit fail", PROCNOERR); + ret = subproc_reap(pid, "subproc exit fail", SUBPROC_RETERROR); test_pass(ret == 128); /* Test signals. */ pid = subproc_fork(); if (pid == 0) raise(SIGINT); - ret = subproc_reap(pid, "subproc signal", PROCWARN); + ret = subproc_reap(pid, "subproc signal", SUBPROC_WARN); test_pass(ret == -1); pid = subproc_fork(); if (pid == 0) raise(SIGTERM); - ret = subproc_reap(pid, "subproc signal", PROCWARN); + ret = subproc_reap(pid, "subproc signal", SUBPROC_WARN); test_pass(ret == -1); pid = subproc_fork(); if (pid == 0) raise(SIGPIPE); - ret = subproc_reap(pid, "subproc SIGPIPE", PROCWARN | PROCPIPE); + ret = subproc_reap(pid, "subproc SIGPIPE", + SUBPROC_WARN | SUBPROC_NOPIPE); test_pass(ret == 0); pid = subproc_fork(); if (pid == 0) raise(SIGPIPE); - ret = subproc_reap(pid, "subproc SIGPIPE", PROCWARN); + ret = subproc_reap(pid, "subproc SIGPIPE", SUBPROC_WARN); test_pass(ret == -1); } diff --git a/src/archives.c b/src/archives.c index c4286a551..b8554d1a1 100644 --- a/src/archives.c +++ b/src/archives.c @@ -1616,7 +1616,7 @@ archivefiles(const char *const *argv) } if (ferror(pf)) ohshite(_("error reading find's pipe")); if (fclose(pf)) ohshite(_("error closing find's pipe")); - rc = subproc_reap(pid, "find", PROCNOERR); + rc = subproc_reap(pid, "find", SUBPROC_RETERROR); if (rc != 0) ohshit(_("find for --recursive returned unhandled error %i"), rc); diff --git a/src/configure.c b/src/configure.c index fce3e251d..28094d8a0 100644 --- a/src/configure.c +++ b/src/configure.c @@ -212,7 +212,7 @@ show_diff(const char *old, const char *new) } /* Parent process. */ - subproc_reap(pid, _("conffile difference visualizer"), PROCNOCHECK); + subproc_reap(pid, _("conffile difference visualizer"), SUBPROC_NOCHECK); } /** @@ -242,7 +242,7 @@ spawn_shell(const char *confold, const char *confnew) } /* Parent process. */ - subproc_reap(pid, _("conffile shell"), PROCNOCHECK); + subproc_reap(pid, _("conffile shell"), SUBPROC_NOCHECK); } /** diff --git a/src/script.c b/src/script.c index f678b70d6..2f5ae86f9 100644 --- a/src/script.c +++ b/src/script.c @@ -328,7 +328,7 @@ maintscript_fallback(struct pkginfo *pkg, warning(_("unable to stat %s '%.250s': %s"), cmd.name, oldscriptpath, strerror(errno)); } else { - if (!maintscript_exec(pkg, &pkg->installed, &cmd, &stab, PROCWARN)) { + if (!maintscript_exec(pkg, &pkg->installed, &cmd, &stab, SUBPROC_WARN)) { command_destroy(&cmd); post_script_tasks(); return 1; diff --git a/src/unpack.c b/src/unpack.c index 2f3a6e2b5..b98510a46 100644 --- a/src/unpack.c +++ b/src/unpack.c @@ -103,7 +103,7 @@ deb_reassemble(const char **filename, const char **pfilename) ohshite(_("unable to execute %s (%s)"), _("split package reassembly"), SPLITTER); } - status = subproc_reap(pid, SPLITTER, PROCNOERR); + status = subproc_reap(pid, SPLITTER, SUBPROC_RETERROR); switch (status) { case 0: /* It was a part - is it complete? */ @@ -145,7 +145,7 @@ deb_verify(const char *filename) } else { int status; - status = subproc_reap(pid, "debsig-verify", PROCNOCHECK); + status = subproc_reap(pid, "debsig-verify", SUBPROC_NOCHECK); if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) { if (!fc_badverify) ohshit(_("verification on package %s failed!"), filename); @@ -978,7 +978,7 @@ void process_archive(const char *filename) { ohshit(_("cannot zap possible trailing zeros from dpkg-deb: %s"), err.str); close(p1[0]); p1[0] = -1; - subproc_reap(pid, BACKEND " --fsys-tarfile", PROCPIPE); + subproc_reap(pid, BACKEND " --fsys-tarfile", SUBPROC_NOPIPE); tar_deferred_extract(newfileslist, pkg); |