rpm  4.5
Data Structures | Macros | Functions | Variables
rpmsq.c File Reference
#include "system.h"
#include <signal.h>
#include <sys/signal.h>
#include <sys/wait.h>
#include <search.h>
#include <rpmsq.h>
#include "debug.h"
Include dependency graph for rpmsq.c:

Go to the source code of this file.

Data Structures

struct  rpmsig_s
 

Macros

#define DO_LOCK()
 
#define DO_UNLOCK()
 
#define INIT_LOCK()
 
#define ADD_REF(__tbl)   /*@-noeffect@*/ (0) /*@=noeffect@*/
 
#define SUB_REF(__tbl)   /*@-noeffect@*/ (0) /*@=noeffect@*/
 
#define CLEANUP_HANDLER(__handler, __arg, __oldtypeptr)
 
#define CLEANUP_RESET(__execute, __oldtype)
 
#define SAME_THREAD(_a, _b)   (42)
 
#define ME()   (((void *)getpid()))
 
#define _RPMSQ_DEBUG   0
 
#define rpmsigTbl_sigint   (&rpmsigTbl[0])
 
#define rpmsigTbl_sigquit   (&rpmsigTbl[1])
 
#define rpmsigTbl_sigchld   (&rpmsigTbl[2])
 
#define rpmsigTbl_sighup   (&rpmsigTbl[3])
 
#define rpmsigTbl_sigterm   (&rpmsigTbl[4])
 
#define rpmsigTbl_sigpipe   (&rpmsigTbl[5])
 

Functions

int rpmsqInsert (void *elem, void *prev)
 Insert node into from queue. More...
 
int rpmsqRemove (void *elem)
 Remove node from queue. More...
 
void rpmsqAction (int signum, void *info, void *context)
 Default signal handler. More...
 
int rpmsqEnable (int signum, rpmsqAction_t handler)
 Enable or disable a signal handler. More...
 
pid_t rpmsqFork (rpmsq sq)
 Fork a child process. More...
 
static int rpmsqWaitUnregister (rpmsq sq)
 Wait for child process to be reaped, and unregister SIGCHLD handler. More...
 
pid_t rpmsqWait (rpmsq sq)
 Wait for child process to be reaped. More...
 
void * rpmsqThread (void *(*start)(void *arg), void *arg)
 Call a function in a thread. More...
 
int rpmsqJoin (void *thread)
 Wait for thread to terminate. More...
 
int rpmsqThreadEqual (void *thread)
 Compare thread with current thread. More...
 
static void sigchld_cancel (void *arg)
 SIGCHLD cancellation handler. More...
 
int rpmsqExecve (const char **argv)
 Execute a command, returning its status. More...
 

Variables

int _rpmsq_debug = 0
 
static struct rpmsqElem rpmsqRock
 
rpmsq rpmsqQueue = &rpmsqRock
 
sigset_t rpmsqCaught
 
static struct rpmsig_s rpmsigTbl []
 

Macro Definition Documentation

#define _RPMSQ_DEBUG   0

Definition at line 187 of file rpmsq.c.

#define ADD_REF (   __tbl)    /*@-noeffect@*/ (0) /*@=noeffect@*/

Definition at line 172 of file rpmsq.c.

Referenced by rpmsqEnable(), and rpmsqExecve().

#define CLEANUP_HANDLER (   __handler,
  __arg,
  __oldtypeptr 
)

Definition at line 174 of file rpmsq.c.

Referenced by rpmsqExecve().

#define CLEANUP_RESET (   __execute,
  __oldtype 
)

Definition at line 175 of file rpmsq.c.

Referenced by rpmsqExecve().

#define DO_LOCK ( )

Definition at line 169 of file rpmsq.c.

Referenced by rpmsqEnable(), rpmsqExecve(), and sigchld_cancel().

#define DO_UNLOCK ( )

Definition at line 170 of file rpmsq.c.

Referenced by rpmsqEnable(), rpmsqExecve(), and sigchld_cancel().

#define INIT_LOCK ( )

Definition at line 171 of file rpmsq.c.

Referenced by rpmsqExecve().

#define ME ( )    (((void *)getpid()))
#define rpmsigTbl_sigchld   (&rpmsigTbl[2])

Referenced by rpmsqExecve(), and sigchld_cancel().

#define rpmsigTbl_sighup   (&rpmsigTbl[3])
#define rpmsigTbl_sigint   (&rpmsigTbl[0])

Referenced by rpmsqExecve().

#define rpmsigTbl_sigpipe   (&rpmsigTbl[5])
#define rpmsigTbl_sigquit   (&rpmsigTbl[1])

Referenced by rpmsqExecve().

#define rpmsigTbl_sigterm   (&rpmsigTbl[4])
#define SAME_THREAD (   _a,
  _b 
)    (42)

Definition at line 177 of file rpmsq.c.

#define SUB_REF (   __tbl)    /*@-noeffect@*/ (0) /*@=noeffect@*/

Definition at line 173 of file rpmsq.c.

Referenced by rpmsqEnable(), rpmsqExecve(), and sigchld_cancel().

Function Documentation

void rpmsqAction ( int  signum,
void *  info,
void *  context 
)

Default signal handler.

Parameters
signumsignal number
info(siginfo_t) signal info
contextsignal context

Definition at line 286 of file rpmsq.c.

References rpmsqElem::child, errno, rpmsqElem::pipes, rpmsqElem::q_forw, rpmsqElem::reaped, rpmsigTbl, save, rpmsig_s::signum, and rpmsqElem::status.

Referenced by rpmsqEnable().

int rpmsqEnable ( int  signum,
rpmsqAction_t  handler 
)

Enable or disable a signal handler.

Parameters
signumsignal to enable (or disable if negative)
handlersa_sigaction handler (or NULL to use rpmsqHandler())
Returns
no. of refs, -1 on error

Definition at line 335 of file rpmsq.c.

References ADD_REF, DO_LOCK, DO_UNLOCK, rpmsqElem::id, ME, rpmsigTbl, rpmsqAction(), rpmsig_s::signum, and SUB_REF.

Referenced by rpmdbClose(), rpmdbOpenDatabase(), rpmsqExecve(), rpmsqFork(), rpmsqWaitUnregister(), and sigchld_cancel().

int rpmsqExecve ( const char **  argv)

Execute a command, returning its status.

Definition at line 609 of file rpmsq.c.

References ADD_REF, alloca(), CLEANUP_HANDLER, CLEANUP_RESET, DO_LOCK, DO_UNLOCK, errno, INIT_LOCK, rpmsigTbl_sigchld, rpmsigTbl_sigint, rpmsigTbl_sigquit, rpmsqEnable(), sigchld_cancel(), and SUB_REF.

pid_t rpmsqFork ( rpmsq  sq)

Fork a child process.

Parameters
sqscriptlet queue element
Returns
fork(2) pid

Definition at line 390 of file rpmsq.c.

References rpmsqElem::child, ME, rpmsqElem::pipes, rpmsqElem::reaper, rpmsqEnable(), and rpmsqInsert().

Referenced by runScript().

int rpmsqInsert ( void *  elem,
void *  prev 
)

Insert node into from queue.

Parameters
elemnode to link
prevprevious node from queue
Returns
0 on success

Definition at line 199 of file rpmsq.c.

References rpmsqElem::child, rpmsqElem::id, ME, rpmsqElem::pipes, rpmsqElem::reaped, rpmsqElem::reaper, and rpmsqElem::status.

Referenced by rpmsqFork().

int rpmsqJoin ( void *  thread)

Wait for thread to terminate.

Parameters
threadthread
Returns
0 on success

Definition at line 565 of file rpmsq.c.

Referenced by fsmNext(), and rpmpsmNext().

int rpmsqRemove ( void *  elem)

Remove node from queue.

Parameters
elemnode to link
Returns
0 on success

Definition at line 228 of file rpmsq.c.

References rpmsqElem::child, rpmsqElem::id, ME, rpmsqElem::pipes, rpmsqElem::reaped, and rpmsqElem::status.

Referenced by rpmsqWaitUnregister().

void* rpmsqThread ( void *(*)(void *arg)  start,
void *  arg 
)

Call a function in a thread.

Parameters
startfunction
argfunction argument
Returns
thread pointer (NULL on error)

Definition at line 556 of file rpmsq.c.

Referenced by fsmNext(), and rpmpsmNext().

int rpmsqThreadEqual ( void *  thread)

Compare thread with current thread.

Parameters
threadthread
Returns
0 if not equal

Definition at line 573 of file rpmsq.c.

pid_t rpmsqWait ( rpmsq  sq)

Wait for child process to be reaped.

Parameters
sqscriptlet queue element
Returns
reaped child pid

Definition at line 524 of file rpmsq.c.

References rpmsqElem::child, ME, rpmsqElem::reaped, rpmsqElem::reaper, rpmsqWaitUnregister(), and rpmsqElem::status.

Referenced by psmWait().

static int rpmsqWaitUnregister ( rpmsq  sq)
static

Wait for child process to be reaped, and unregister SIGCHLD handler.

Todo:
Rewrite to use waitpid on helper thread.
Parameters
sqscriptlet queue element
Returns
0 on success

Definition at line 455 of file rpmsq.c.

References rpmsqElem::child, ME, rpmsqElem::ms_scriptlets, rpmsqElem::op, rpmsqElem::pipes, rpmsqElem::reaped, rpmsqElem::reaper, rpmsqEnable(), rpmsqRemove(), rpmswEnter(), and rpmswExit().

Referenced by rpmsqWait().

static void sigchld_cancel ( void *  arg)
static

SIGCHLD cancellation handler.

Definition at line 584 of file rpmsq.c.

References DO_LOCK, DO_UNLOCK, errno, rpmsigTbl_sigchld, rpmsqEnable(), and SUB_REF.

Referenced by rpmsqExecve().

Variable Documentation

int _rpmsq_debug = 0

Definition at line 189 of file rpmsq.c.

struct rpmsig_s rpmsigTbl[]
static
Initial value:
= {
{ SIGINT, rpmsqAction },
#define rpmsigTbl_sigint
{ SIGQUIT, rpmsqAction },
#define rpmsigTbl_sigquit
{ SIGCHLD, rpmsqAction },
#define rpmsigTbl_sigchld
{ SIGHUP, rpmsqAction },
#define rpmsigTbl_sighup
{ SIGTERM, rpmsqAction },
#define rpmsigTbl_sigterm
{ SIGPIPE, rpmsqAction },
#define rpmsigTbl_sigpipe
{ -1, NULL },
}

Referenced by rpmsqAction(), and rpmsqEnable().

sigset_t rpmsqCaught

Definition at line 260 of file rpmsq.c.

Referenced by rpmdbCheckSignals(), rpmdbCheckTerminate(), and signalsCaught().

rpmsq rpmsqQueue = &rpmsqRock

Definition at line 196 of file rpmsq.c.

struct rpmsqElem rpmsqRock
static

Definition at line 192 of file rpmsq.c.