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 /lib | |
parent | cece29526d506b89b54cc80a6c400f9f58f36286 (diff) | |
download | dpkg-b8a6ab4c5c88463bfe8ff1e13cddbf397c950c61.tar.gz |
libdpkg: Namespace and reword subproc flags
Diffstat (limited to 'lib')
-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 |
5 files changed, 31 insertions, 22 deletions
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); } |