rpmio/rpmsq.c File Reference

#include "system.h"
#include <signal.h>
#include <sys/signal.h>
#include <sys/wait.h>
#include <search.h>
#include <pthread.h>
#include <rpmsq.h>
#include "debug.h"

Go to the source code of this file.

Data Structures

struct  rpmsig_s

Defines

#define DO_LOCK()   pthread_mutex_lock(&rpmsigTbl_lock);
#define DO_UNLOCK()   pthread_mutex_unlock(&rpmsigTbl_lock);
#define INIT_LOCK()
#define ADD_REF(__tbl)   (__tbl)->active++
#define SUB_REF(__tbl)   --(__tbl)->active
#define CLEANUP_HANDLER(__handler, __arg, __oldtypeptr)
#define CLEANUP_RESET(__execute, __oldtype)
#define SAME_THREAD(_a, _b)   pthread_equal(((pthread_t)_a), ((pthread_t)_b))
#define ME()   ((void *)pthread_self())
#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.
int rpmsqRemove (void *elem)
 Remove node from queue.
void rpmsqAction (int signum, void *info, void *context)
 Default signal handler.
int rpmsqEnable (int signum, rpmsqAction_t handler)
 Enable or disable a signal handler.
pid_t rpmsqFork (rpmsq sq)
 Fork a child process.
static int rpmsqWaitUnregister (rpmsq sq)
 Wait for child process to be reaped, and unregister SIGCHLD handler.
pid_t rpmsqWait (rpmsq sq)
 Wait for child process to be reaped.
void * rpmsqThread (void *(*start)(void *arg), void *arg)
 Call a function in a thread.
int rpmsqJoin (void *thread)
 Wait for thread to terminate.
int rpmsqThreadEqual (void *thread)
 Compare thread with current thread.
static void sigchld_cancel (void *arg)
 SIGCHLD cancellation handler.
int rpmsqExecve (const char **argv)
 Execute a command, returning its status.

Variables

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

Detailed Description

Definition in file rpmsq.c.


Define Documentation

#define _RPMSQ_DEBUG   0

Definition at line 187 of file rpmsq.c.

#define ADD_REF ( __tbl   )     (__tbl)->active++

Definition at line 154 of file rpmsq.c.

Referenced by rpmsqEnable(), and rpmsqExecve().

#define CLEANUP_HANDLER ( __handler,
__arg,
__oldtypeptr   ) 
Value:
(void) pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, (__oldtypeptr));\
        pthread_cleanup_push((__handler), (__arg));

Definition at line 156 of file rpmsq.c.

Referenced by rpmsqExecve().

#define CLEANUP_RESET ( __execute,
__oldtype   ) 
Value:
pthread_cleanup_pop(__execute); \
    (void) pthread_setcanceltype ((__oldtype), &(__oldtype));

Definition at line 159 of file rpmsq.c.

Referenced by rpmsqExecve().

 
#define DO_LOCK (  )     pthread_mutex_lock(&rpmsigTbl_lock);

Definition at line 144 of file rpmsq.c.

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

 
#define DO_UNLOCK (  )     pthread_mutex_unlock(&rpmsigTbl_lock);

Definition at line 145 of file rpmsq.c.

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

 
#define INIT_LOCK (  ) 
Value:
{       pthread_mutexattr_t attr; \
        (void) pthread_mutexattr_init(&attr); \
        (void) pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); \
        (void) pthread_mutex_init (&rpmsigTbl_lock, &attr); \
        (void) pthread_mutexattr_destroy(&attr); \
        rpmsigTbl_sigchld->active = 0; \
    }

Definition at line 146 of file rpmsq.c.

Referenced by rpmsqExecve().

 
#define ME (  )     ((void *)pthread_self())
#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   )     pthread_equal(((pthread_t)_a), ((pthread_t)_b))

Definition at line 163 of file rpmsq.c.

#define SUB_REF ( __tbl   )     --(__tbl)->active

Definition at line 155 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:
signum signal number
info (siginfo_t) signal info
context signal context

Definition at line 292 of file rpmsq.c.

References rpmsqElem::child, errno, rpmsqElem::mutex, 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:
signum signal to enable (or disable if negative)
handler sa_sigaction handler (or NULL to use rpmsqHandler())
Returns:
no. of refs, -1 on error

Definition at line 346 of file rpmsq.c.

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

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

int rpmsqExecve ( const char **  argv  ) 

Execute a command, returning its status.

Definition at line 636 of file rpmsq.c.

References ADD_REF, CLEANUP_HANDLER, CLEANUP_RESET, DO_LOCK, DO_UNLOCK, environ, 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:
sq scriptlet queue element
Returns:
fork(2) pid

Definition at line 401 of file rpmsq.c.

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

Referenced by runScript().

int rpmsqInsert ( void *  elem,
void *  prev 
)

Insert node into from queue.

Parameters:
elem node to link
prev previous node from queue
Returns:
0 on success

Definition at line 199 of file rpmsq.c.

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

Referenced by rpmsqFork().

int rpmsqJoin ( void *  thread  ) 

Wait for thread to terminate.

Parameters:
thread thread
Returns:
0 on success

Definition at line 592 of file rpmsq.c.

Referenced by fsmNext(), and rpmpsmNext().

int rpmsqRemove ( void *  elem  ) 

Remove node from queue.

Parameters:
elem node to link
Returns:
0 on success

Definition at line 228 of file rpmsq.c.

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

Referenced by rpmsqWaitUnregister().

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

Call a function in a thread.

Parameters:
start function
arg function argument
Returns:
thread pointer (NULL on error)

Definition at line 583 of file rpmsq.c.

Referenced by fsmNext(), and rpmpsmNext().

int rpmsqThreadEqual ( void *  thread  ) 

Compare thread with current thread.

Parameters:
thread thread
Returns:
0 if not equal

Definition at line 600 of file rpmsq.c.

pid_t rpmsqWait ( rpmsq  sq  ) 

Wait for child process to be reaped.

Parameters:
sq scriptlet queue element
Returns:
reaped child pid

Definition at line 551 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:
sq scriptlet queue element
Returns:
0 on success

Definition at line 485 of file rpmsq.c.

References rpmsqElem::child, ME, rpmsqElem::ms_scriptlets, rpmsqElem::mutex, 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 611 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]

Referenced by rpmsqAction(), and rpmsqEnable().

pthread_mutex_t rpmsigTbl_lock = PTHREAD_MUTEX_INITIALIZER [static]

Definition at line 136 of file rpmsq.c.

sigset_t rpmsqCaught

Definition at line 266 of file rpmsq.c.

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

Definition at line 196 of file rpmsq.c.

struct rpmsqElem rpmsqRock [static]

Definition at line 192 of file rpmsq.c.


Generated on 8 Jun 2012 for rpm by  doxygen 1.6.1