# rpmio/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

## Defines

#define | DO_LOCK() (0)
#define | DO_UNLOCK() (0)
#define | INIT_LOCK() ((void)0)
#define | ADD_REF(__tbl) /*@-noeffect@*/ (0)
#define | SUB_REF(__tbl) /*@-noeffect@*/ (0)
#define | CLEANUP_HANDLER(__handler, __arg, __oldtypeptr) ((void)0)
#define | CLEANUP_RESET(__execute, __oldtype) ((void)0)
#define | SAME_THREAD(_a, _b) (42)
#define | ME() __pid2vp(getpid())
#define | _RPMSQ_INTERNAL
#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

static void * | __pid2vp (pid_t pid)
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.
int | rpmsqExecve (const char **argv)
| SIGCHLD cancellation handler.

## Variables

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 272 of file rpmsq.c.

#define _RPMSQ_INTERNAL

Definition at line 267 of file rpmsq.c.

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

Definition at line 248 of file rpmsq.c.

Referenced by rpmsqEnable(), and rpmsqExecve().

#define CLEANUP_HANDLER | ( | __handler,
|  | __arg,
|  | __oldtypeptr |  | ) | ((void)0)

Definition at line 250 of file rpmsq.c.

Referenced by rpmsqExecve().

#define CLEANUP_RESET | ( | __execute,
|  | __oldtype |  | ) | ((void)0)

Definition at line 251 of file rpmsq.c.

Referenced by rpmsqExecve().

#define DO_LOCK | ( |  | ) | (0)

Definition at line 245 of file rpmsq.c.

Referenced by rpmsqEnable(), and rpmsqExecve().

#define DO_UNLOCK | ( |  | ) | (0)

Definition at line 246 of file rpmsq.c.

Referenced by rpmsqEnable(), and rpmsqExecve().

#define INIT_LOCK | ( |  | ) | ((void)0)

Definition at line 247 of file rpmsq.c.

Referenced by rpmsqExecve().

#define ME | ( |  | ) | __pid2vp(getpid())

Definition at line 255 of file rpmsq.c.

Referenced by rpmsqEnable(), rpmsqFork(), rpmsqInsert(), rpmsqRemove(), rpmsqWait(), and rpmsqWaitUnregister().

#define rpmsigTbl_sigchld (&rpmsigTbl[2])

Referenced by rpmsqExecve().

#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 253 of file rpmsq.c.

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

Definition at line 249 of file rpmsq.c.

Referenced by rpmsqEnable(), and rpmsqExecve().

## Function Documentation

static void* __pid2vp | ( | pid_t | pid | ) | `[static]`

Definition at line 257 of file rpmsq.c.

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 371 of file rpmsq.c.

References errno, rpmsigTbl, save(), and rpmsig_s::signum.

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 420 of file rpmsq.c.

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

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

int rpmsqExecve | ( | const char ** | argv | ) |

SIGCHLD cancellation handler.

Execute a command, returning its status.

Execute a command, returning its status.

Definition at line 703 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(), and SUB_REF.

pid_t rpmsqFork | ( | rpmsq | sq | ) |

Fork a child process.

Parameters:

  | sq | scriptlet queue element

Returns:
  fork(2) pid

Definition at line 475 of file rpmsq.c.

References ME, 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 284 of file rpmsq.c.

References ME.

Referenced by rpmsqFork().

int rpmsqJoin | ( | void * | thread | ) |

Wait for thread to terminate.

Parameters:

  | thread | thread

Returns:
  0 on success

Definition at line 649 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 313 of file rpmsq.c.

References ME.

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 636 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 661 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 604 of file rpmsq.c.

References ME, and rpmsqWaitUnregister().

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 537 of file rpmsq.c.

References ME, rpmsqEnable(), rpmsqRemove(), rpmswEnter(), and rpmswExit().

Referenced by rpmsqWait().

## Variable Documentation

int _rpmsq_debug = 0

Definition at line 274 of file rpmsq.c.

struct rpmsig_s rpmsigTbl[]`[static]`

Referenced by rpmsqAction(), and rpmsqEnable().

sigset_t rpmsqCaught

Definition at line 345 of file rpmsq.c.

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

rpmsq rpmsqQueue = &rpmsqRock

Definition at line 281 of file rpmsq.c.

struct rpmsqElem rpmsqRock `[static]`

Definition at line 277 of file rpmsq.c.