diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2016-12-14 13:09:39 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2016-12-14 13:09:39 +0200 |
commit | afbb9713ce5cd857ea2c4f7634836956a5cfb53d (patch) | |
tree | 0e463602966d973d117fd0d6ecddc28b04057c13 | |
parent | 4639f4b2ba346b715d5aeb3d50a0c3a59a23c7ea (diff) | |
download | rpm-afbb9713ce5cd857ea2c4f7634836956a5cfb53d.tar.gz |
Simplify rpmsq activate signals tracking
There's little better way of tracking set of signals than a sigset_t
with its associated APIs. For one, this way we dont for example need to
loop through the table to see if a signal is active or not.
Note that This drops the "fancy" reference counting: calling rpmsqEnable()
with different handlers would increase the refcount but not actually change
the behavior, so the refcount means exactly what? The refcounting also
hasn't been used by rpm at all/in a long time, because whether its
active or not is tracked by the rpmdb code which is the only place
really knowing if its needed or not.
-rw-r--r-- | rpmio/rpmsq.c | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/rpmio/rpmsq.c b/rpmio/rpmsq.c index 83c21b276..fd9af1f82 100644 --- a/rpmio/rpmsq.c +++ b/rpmio/rpmsq.c @@ -10,22 +10,19 @@ #include <stdio.h> #include <stdlib.h> -#define ADD_REF(__tbl) (__tbl)->active++ -#define SUB_REF(__tbl) --(__tbl)->active - #include <rpm/rpmsq.h> #include "debug.h" static int disableInterruptSafety; static sigset_t rpmsqCaught; +static sigset_t rpmsqActive; typedef struct rpmsig_s * rpmsig; static struct rpmsig_s { int signum; rpmsqAction_t handler; - int active; struct sigaction oact; } rpmsigTbl[] = { { SIGINT, rpmsqAction }, @@ -48,15 +45,10 @@ void rpmsqAction(int signum) #endif { int save = errno; - rpmsig tbl; - - for (tbl = rpmsigTbl; tbl->signum >= 0; tbl++) { - if (tbl->signum != signum) - continue; + if (sigismember(&rpmsqActive, signum)) (void) sigaddset(&rpmsqCaught, signum); - break; - } + errno = save; } @@ -75,7 +67,7 @@ int rpmsqEnable(int signum, rpmsqAction_t handler) continue; if (signum >= 0) { /* Enable. */ - if (ADD_REF(tbl) <= 0) { + if (!sigismember(&rpmsqActive, tblsignum)) { (void) sigdelset(&rpmsqCaught, tbl->signum); /* XXX Don't set a signal handler if already SIG_IGN */ @@ -90,23 +82,21 @@ int rpmsqEnable(int signum, rpmsqAction_t handler) sa.sa_flags = 0; #endif sa.sa_sigaction = (handler != NULL ? handler : tbl->handler); - if (sigaction(tbl->signum, &sa, &tbl->oact) < 0) { - SUB_REF(tbl); + if (sigaction(tbl->signum, &sa, &tbl->oact) < 0) break; - } - tbl->active = 1; /* XXX just in case */ + sigaddset(&rpmsqActive, tblsignum); if (handler != NULL) tbl->handler = handler; } } else { /* Disable. */ - if (SUB_REF(tbl) <= 0) { + if (sigismember(&rpmsqActive, tblsignum)) { if (sigaction(tbl->signum, &tbl->oact, NULL) < 0) break; - tbl->active = 0; /* XXX just in case */ + sigdelset(&rpmsqActive, tblsignum); tbl->handler = (handler != NULL ? handler : rpmsqAction); } } - ret = tbl->active; + ret = sigismember(&rpmsqActive, tblsignum); break; } return ret; |