summaryrefslogtreecommitdiff
path: root/rpmio/rpmsq.h
blob: 9e3960ebcf8e74b4dcba02ca29057d7e3e9acff5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef	H_RPMSQ
#define	H_RPMSQ

/** \ingroup rpmio
 * \file rpmio/rpmsq.h
 *
 */

#include <pthread.h>
#include <signal.h>
#include <sys/signal.h>
#include <search.h>		/* XXX insque(3)/remque(3) protos. */

typedef struct rpmsig_s * rpmsig;

typedef struct rpmsqElem * rpmsq;

/*@-redecl@*/
/*@unchecked@*/
extern int _rpmsq_debug;
/*@=redecl@*/

/**
 * SIGCHLD queue element.
 */
struct rpmsqElem {
    struct rpmsqElem * q_forw;	/*!< for use by insque(3)/remque(3). */
    struct rpmsqElem * q_back;
    pid_t child;		/*!< Currently running child. */
    volatile pid_t reaped;	/*!< Reaped waitpid(3) return. */
    volatile int status;	/*!< Reaped waitpid(3) status. */
    int reaper;			/*!< Register SIGCHLD handler? */
    void * id;			/*!< Blocking thread id (pthread_t). */
    pthread_mutex_t mutex;
    pthread_cond_t cond;
};

/*@unchecked@*/
extern rpmsq rpmsqQueue;

/*@unchecked@*/
extern sigset_t rpmsqCaught;

#ifdef __cplusplus
{
#endif

/**
 */
int rpmsqInsert(/*@null@*/ void * elem, /*@null@*/ void * prev)
	/*@globals rpmsqQueue @*/
	/*@modifies elem, rpmsqQueue @*/;

/**
 */
int rpmsqRemove(/*@null@*/ void * elem)
	/*@modifies elem @*/;

/**
 */
void rpmsqHandler(int signum)
	/*@globals rpmsqCaught, fileSystem @*/
	/*@modifies rpmsqCaught, fileSystem @*/;

/**
 * Enable or disable a signal handler.
 * @param signum	signal to enable (or disable if negative)
 * @param handler	signal handler (or NULL to use rpmsqHandler())
 * @return		no. of refs, -1 on error
 */
int rpmsqEnable(int signum, /*@null@*/ sighandler_t handler)
	/*@globals rpmsqCaught, fileSystem, internalState @*/
	/*@modifies rpmsqCaught, fileSystem, internalState @*/;

/**
 * Fork a child process.
 * @param sq		scriptlet queue element
 * @return		fork(2) pid
 */
pid_t rpmsqFork(rpmsq sq)
	/*@globals fileSystem, internalState @*/
	/*@modifies sq, fileSystem, internalState @*/;

/**
 * Wait for child process to be reaped.
 * @param sq		scriptlet queue element
 * @return		reaped child pid
 */
pid_t rpmsqWait(rpmsq sq)
	/*@globals fileSystem, internalState @*/
	/*@modifies sq, fileSystem, internalState @*/;

/**
 * Execute a command, returning its status.
 */
int rpmsqExecve (const char ** argv)
	/*@*/;

#ifdef __cplusplus
}
#endif

#endif	/* H_RPMSQ */