diff options
author | Guillem Jover <guillem@debian.org> | 2018-01-13 02:37:02 +0100 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2018-08-30 03:14:08 +0200 |
commit | c7c948d8b9ed774163d35c573f25029d69e45348 (patch) | |
tree | 54cefcd327dfbddc3b4db537378aa1b3e5fe02e7 /lib | |
parent | ae6a3ddd2a774ee1cedc5ee0c87ab8c66ae5f786 (diff) | |
download | dpkg-c7c948d8b9ed774163d35c573f25029d69e45348.tar.gz |
libdpkg: Split push_cleanup() into push_cleanup_fallback()
We separate the function in one that takes one callback, and another
that takes two. This simplifies most of the call sites which only need
one callback.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dpkg/atomic-file.c | 2 | ||||
-rw-r--r-- | lib/dpkg/db-ctrl-access.c | 2 | ||||
-rw-r--r-- | lib/dpkg/db-ctrl-upgrade.c | 4 | ||||
-rw-r--r-- | lib/dpkg/db-fsys-files.c | 2 | ||||
-rw-r--r-- | lib/dpkg/ehandle.c | 32 | ||||
-rw-r--r-- | lib/dpkg/ehandle.h | 6 | ||||
-rw-r--r-- | lib/dpkg/file.c | 2 | ||||
-rw-r--r-- | lib/dpkg/libdpkg.map | 1 | ||||
-rw-r--r-- | lib/dpkg/parse.c | 2 | ||||
-rw-r--r-- | lib/dpkg/subproc.c | 2 | ||||
-rw-r--r-- | lib/dpkg/t/t-ehandle.c | 2 | ||||
-rw-r--r-- | lib/dpkg/triglib.c | 4 |
12 files changed, 45 insertions, 16 deletions
diff --git a/lib/dpkg/atomic-file.c b/lib/dpkg/atomic-file.c index b49a47b9b..20b1fb37e 100644 --- a/lib/dpkg/atomic-file.c +++ b/lib/dpkg/atomic-file.c @@ -58,7 +58,7 @@ atomic_file_open(struct atomic_file *file) file->name_new); fchmod(fileno(file->fp), 0644); - push_cleanup(cu_closestream, ~ehflag_normaltidy, NULL, 0, 1, file->fp); + push_cleanup(cu_closestream, ~ehflag_normaltidy, 1, file->fp); } void diff --git a/lib/dpkg/db-ctrl-access.c b/lib/dpkg/db-ctrl-access.c index bd98d1409..d31f5466f 100644 --- a/lib/dpkg/db-ctrl-access.c +++ b/lib/dpkg/db-ctrl-access.c @@ -81,7 +81,7 @@ pkg_infodb_foreach(struct pkginfo *pkg, struct pkgbin *pkgbin, if (!db_dir) ohshite(_("cannot read info directory")); - push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)db_dir); + push_cleanup(cu_closedir, ~0, 1, (void *)db_dir); while ((db_de = readdir(db_dir)) != NULL) { const char *filename, *filetype, *dot; diff --git a/lib/dpkg/db-ctrl-upgrade.c b/lib/dpkg/db-ctrl-upgrade.c index fc88bd4d0..1770ecaeb 100644 --- a/lib/dpkg/db-ctrl-upgrade.c +++ b/lib/dpkg/db-ctrl-upgrade.c @@ -91,7 +91,7 @@ pkg_infodb_link_multiarch_files(void) if (!db_dir) ohshite(_("cannot read info directory")); - push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)db_dir); + push_cleanup(cu_closedir, ~0, 1, (void *)db_dir); while ((db_de = readdir(db_dir)) != NULL) { const char *filetype, *dot; struct pkginfo *pkg; @@ -213,7 +213,7 @@ pkg_infodb_upgrade_to_multiarch(void) db_file = atomic_file_new(db_format_file, 0); atomic_file_open(db_file); - push_cleanup(cu_abort_db_upgrade, ehflag_bombout, NULL, 0, 1, db_file); + push_cleanup(cu_abort_db_upgrade, ehflag_bombout, 1, db_file); pkg_infodb_link_multiarch_files(); pkg_infodb_write_format(db_file, 1); diff --git a/lib/dpkg/db-fsys-files.c b/lib/dpkg/db-fsys-files.c index bfc2ccbe6..ff2ee7063 100644 --- a/lib/dpkg/db-fsys-files.c +++ b/lib/dpkg/db-fsys-files.c @@ -117,7 +117,7 @@ ensure_packagefiles_available(struct pkginfo *pkg) return; } - push_cleanup(cu_closefd, ehflag_bombout, NULL, 0, 1, &fd); + push_cleanup(cu_closefd, ehflag_bombout, 1, &fd); if (fstat(fd, &stat_buf)) ohshite(_("unable to stat files list file for package '%.250s'"), diff --git a/lib/dpkg/ehandle.c b/lib/dpkg/ehandle.c index f21fb07e9..ae3b46aad 100644 --- a/lib/dpkg/ehandle.c +++ b/lib/dpkg/ehandle.c @@ -324,9 +324,11 @@ void push_checkpoint(int mask, int value) { econtext->cleanups= cep; } -void push_cleanup(void (*call1)(int argc, void **argv), int mask1, +static void +cleanup_entry_new(void (*call1)(int argc, void **argv), int mask1, void (*call2)(int argc, void **argv), int mask2, - unsigned int nargs, ...) { + unsigned int nargs, va_list vargs) +{ struct cleanup_entry *cep; void **argv; int e = 0; @@ -343,7 +345,8 @@ void push_cleanup(void (*call1)(int argc, void **argv), int mask1, cep->calls[0].call= call1; cep->calls[0].mask= mask1; cep->calls[1].call= call2; cep->calls[1].mask= mask2; cep->cpmask=~0; cep->cpvalue=0; cep->argc= nargs; - va_start(args, nargs); + + va_copy(args, vargs); argv = cep->argv; while (nargs-- > 0) *argv++ = va_arg(args, void *); @@ -359,6 +362,29 @@ void push_cleanup(void (*call1)(int argc, void **argv), int mask1, onerr_abort--; } +void +push_cleanup(void (*call)(int argc, void **argv), int mask, + unsigned int nargs, ...) +{ + va_list args; + + va_start(args, nargs); + cleanup_entry_new(call, mask, NULL, 0, nargs, args); + va_end(args); +} + +void +push_cleanup_fallback(void (*call1)(int argc, void **argv), int mask1, + void (*call2)(int argc, void **argv), int mask2, + unsigned int nargs, ...) +{ + va_list args; + + va_start(args, nargs); + cleanup_entry_new(call1, mask1, call2, mask2, nargs, args); + va_end(args); +} + void pop_cleanup(int flagset) { struct cleanup_entry *cep; int i; diff --git a/lib/dpkg/ehandle.h b/lib/dpkg/ehandle.h index 370614812..36059048a 100644 --- a/lib/dpkg/ehandle.h +++ b/lib/dpkg/ehandle.h @@ -59,8 +59,10 @@ void push_error_context_func(error_handler_func *handler, void push_error_context(void); void pop_error_context(int flagset); -void push_cleanup(void (*f1)(int argc, void **argv), int flagmask1, - void (*f2)(int argc, void **argv), int flagmask2, +void push_cleanup_fallback(void (*f1)(int argc, void **argv), int flagmask1, + void (*f2)(int argc, void **argv), int flagmask2, + unsigned int nargs, ...); +void push_cleanup(void (*call)(int argc, void **argv), int flagmask, unsigned int nargs, ...); void push_checkpoint(int mask, int value); void pop_cleanup(int flagset); diff --git a/lib/dpkg/file.c b/lib/dpkg/file.c index cd261222c..364f8aed6 100644 --- a/lib/dpkg/file.c +++ b/lib/dpkg/file.c @@ -150,7 +150,7 @@ file_lock(int *lockfd, enum file_lock_flags flags, const char *filename, ohshite(_("unable to lock %s"), desc); } - push_cleanup(file_unlock_cleanup, ~0, NULL, 0, 2, lockfd, desc); + push_cleanup(file_unlock_cleanup, ~0, 2, lockfd, desc); } void diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map index cf176d6c9..cd0bd255d 100644 --- a/lib/dpkg/libdpkg.map +++ b/lib/dpkg/libdpkg.map @@ -46,6 +46,7 @@ LIBDPKG_PRIVATE { catch_fatal_error; push_checkpoint; push_cleanup; + push_cleanup_fallback; pop_cleanup; onerr_abort; # XXX variable, do not export ohshitv; diff --git a/lib/dpkg/parse.c b/lib/dpkg/parse.c index d9daa112c..158e4d11e 100644 --- a/lib/dpkg/parse.c +++ b/lib/dpkg/parse.c @@ -557,7 +557,7 @@ parsedb_open(const char *filename, enum parsedbflags flags) ps = parsedb_new(filename, fd, flags | pdb_close_fd); - push_cleanup(cu_closefd, ~ehflag_normaltidy, NULL, 0, 1, &ps->fd); + push_cleanup(cu_closefd, ~ehflag_normaltidy, 1, &ps->fd); return ps; } diff --git a/lib/dpkg/subproc.c b/lib/dpkg/subproc.c index b2f36ec2e..7b3fb9906 100644 --- a/lib/dpkg/subproc.c +++ b/lib/dpkg/subproc.c @@ -73,7 +73,7 @@ subproc_signals_ignore(const char *name) for (i = 0; i < array_count(signo_ignores); i++) subproc_set_signal(signo_ignores[i], &sa, &sa_save[i], name); - push_cleanup(subproc_signals_cleanup, ~0, NULL, 0, 0); + push_cleanup(subproc_signals_cleanup, ~0, 0); onerr_abort--; } diff --git a/lib/dpkg/t/t-ehandle.c b/lib/dpkg/t/t-ehandle.c index 5904bfae1..7a20887af 100644 --- a/lib/dpkg/t/t-ehandle.c +++ b/lib/dpkg/t/t-ehandle.c @@ -100,7 +100,7 @@ test_cleanup_error(void) pass = false; push_error_context_jump(&handler_jump, printer_empty, "test cleanup"); - push_cleanup(cleanup_error, ~ehflag_normaltidy, NULL, 0, 0); + push_cleanup(cleanup_error, ~ehflag_normaltidy, 0); pop_error_context(ehflag_bombout); /* We should have recovered from the cleanup handler failing, diff --git a/lib/dpkg/triglib.c b/lib/dpkg/triglib.c index 395601359..f7488ee61 100644 --- a/lib/dpkg/triglib.c +++ b/lib/dpkg/triglib.c @@ -507,7 +507,7 @@ trig_file_interests_ensure(void) triggersfilefile); } - push_cleanup(cu_closestream, ~0, NULL, 0, 1, f); + push_cleanup(cu_closestream, ~0, 1, f); while (fgets_checked(linebuf, sizeof(linebuf), f, triggersfilefile) >= 0) { struct dpkg_error err; char *slash; @@ -694,7 +694,7 @@ trig_parse_ci(const char *file, trig_parse_cicb *interest, return; /* No file is just like an empty one. */ ohshite(_("unable to open triggers ci file '%.250s'"), file); } - push_cleanup(cu_closestream, ~0, NULL, 0, 1, f); + push_cleanup(cu_closestream, ~0, 1, f); while ((l = fgets_checked(linebuf, sizeof(linebuf), f, file)) >= 0) { for (cmd = linebuf; c_iswhite(*cmd); cmd++) ; |