diff --git a/rpmio/rpmsq.c b/rpmio/rpmsq.c index bfd4db004c..8515a0ebd5 100644 --- a/rpmio/rpmsq.c +++ b/rpmio/rpmsq.c @@ -16,6 +16,7 @@ #include "debug.h" +static int disableInterruptSafety; static sigset_t rpmsqCaught; typedef struct rpmsig_s * rpmsig; @@ -70,6 +71,9 @@ int rpmsqEnable(int signum, rpmsqAction_t handler) rpmsig tbl; int ret = -1; + if (disableInterruptSafety) + return 0; + for (tbl = rpmsigTbl; tbl->signum >= 0; tbl++) { if (tblsignum != tbl->signum) continue; @@ -112,3 +116,25 @@ int rpmsqEnable(int signum, rpmsqAction_t handler) return ret; } + +/** \ingroup rpmio + * + * By default, librpm will trap various unix signals such as SIGINT and SIGTERM, + * in order to avoid process exit while locks are held or a transaction is being + * performed. However, there exist tools that operate on non-running roots (traditionally + * build systems such as mock), as well as deployment tools such as rpm-ostree. + * + * These tools are more robust against interruption - typically they + * will just throw away the partially constructed root. This function + * is designed for use by those tools, so an operator can happily + * press Control-C. + * + * It's recommended to call this once only at process startup if this + * behavior is desired (and to then avoid using librpm against "live" + * databases), because currently signal handlers will not be retroactively + * applied if a database is open. + */ +void rpmsqSetInterruptSafety(int on) +{ + disableInterruptSafety = !on; +} diff --git a/rpmio/rpmsq.h b/rpmio/rpmsq.h index 00a1a72cfa..22bfcc564a 100644 --- a/rpmio/rpmsq.h +++ b/rpmio/rpmsq.h @@ -52,6 +52,8 @@ void rpmsqAction(int signum); */ int rpmsqEnable(int signum, rpmsqAction_t handler); +void rpmsqSetInterruptSafety(int on); + #ifdef __cplusplus } #endif