summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2011-01-20 18:21:38 +0100
committerGuillem Jover <guillem@debian.org>2011-01-31 06:01:37 +0100
commite61824e3e7d37d0b4fcf1e2128b709292a0867cb (patch)
treeb6aeccf97293de4a30ef20554777363271387004 /lib
parent5f2e95ef39658991aade7b2357978c713bad7cae (diff)
downloaddpkg-e61824e3e7d37d0b4fcf1e2128b709292a0867cb.tar.gz
libdpkg: Refactor error output into a function variable in subproc_check()
This deduplicates two sets of identical strings.
Diffstat (limited to 'lib')
-rw-r--r--lib/dpkg/subproc.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/lib/dpkg/subproc.c b/lib/dpkg/subproc.c
index b82248e27..b4d565874 100644
--- a/lib/dpkg/subproc.c
+++ b/lib/dpkg/subproc.c
@@ -100,34 +100,31 @@ subproc_fork(void)
int
subproc_check(int status, const char *desc, int flags)
{
+ void (*out)(const char *fmt, ...) DPKG_ATTR_PRINTF(1);
int n;
+ if (flags & PROCWARN)
+ out = warning;
+ else
+ out = ohshit;
+
if (WIFEXITED(status)) {
n = WEXITSTATUS(status);
if (!n)
return 0;
if (flags & PROCNOERR)
return n;
- if (flags & PROCWARN)
- warning(_("subprocess %s returned error exit status %d"),
- desc, n);
- else
- ohshit(_("subprocess %s returned error exit status %d"),
- desc, n);
+
+ out(_("subprocess %s returned error exit status %d"), desc, n);
} else if (WIFSIGNALED(status)) {
n = WTERMSIG(status);
if (!n)
return 0;
if ((flags & PROCPIPE) && n == SIGPIPE)
return 0;
- if (flags & PROCWARN)
- warning(_("subprocess %s killed by signal (%s)%s"),
- desc, strsignal(n),
- WCOREDUMP(status) ? _(", core dumped") : "");
- else
- ohshit(_("subprocess %s killed by signal (%s)%s"),
- desc, strsignal(n),
- WCOREDUMP(status) ? _(", core dumped") : "");
+
+ out(_("subprocess %s killed by signal (%s)%s"), desc,
+ strsignal(n), WCOREDUMP(status) ? _(", core dumped") : "");
} else {
ohshit(_("subprocess %s failed with wait status code %d"),
desc, status);