Splint clean.
[platform/upstream/rpm.git] / rpmio / rpmsq.h
1 #ifndef H_RPMSQ
2 #define H_RPMSQ
3
4 /** \ingroup rpmio
5  * \file rpmio/rpmsq.h
6  *
7  */
8
9 #include <rpmsw.h>
10
11 /**
12  */
13 typedef struct rpmsig_s * rpmsig;
14
15 /**
16  */
17 typedef struct rpmsqElem * rpmsq;
18
19 /**
20  * Default signal handler prototype.
21  * @param signum        signal number
22  * @param info          (siginfo_t) signal info
23  * @param context       signal context
24  */
25 typedef void (*rpmsqAction_t) (int signum, void * info, void * context)
26         /*@*/;
27
28 /*@-redecl@*/
29 /*@unchecked@*/
30 extern int _rpmsq_debug;
31 /*@=redecl@*/
32
33 /**
34  * SIGCHLD queue element.
35  */
36 struct rpmsqElem {
37     struct rpmsqElem * q_forw;  /*!< for use by insque(3)/remque(3). */
38     struct rpmsqElem * q_back;
39     pid_t child;                /*!< Currently running child. */
40     volatile pid_t reaped;      /*!< Reaped waitpid(3) return. */
41     volatile int status;        /*!< Reaped waitpid(3) status. */
42     struct rpmsw_s begin;       /*!< Start time. */
43     rpmtime_t msecs;            /*!< Instance duration (msecs). */
44     rpmtime_t script_msecs;     /*!< Accumulated script duration (msecs). */
45     int reaper;                 /*!< Register SIGCHLD handler? */
46     int pipes[2];               /*!< Parent/child interlock. */
47     void * id;                  /*!< Blocking thread id (pthread_t). */
48     pthread_mutex_t mutex;      /*!< Signal delivery to thread condvar. */
49     pthread_cond_t cond;
50 };
51
52 /*@-exportlocal@*/
53 /*@unchecked@*/
54 extern rpmsq rpmsqQueue;
55 /*@=exportlocal@*/
56
57 /*@unchecked@*/
58 extern sigset_t rpmsqCaught;
59
60 #ifdef __cplusplus
61 {
62 #endif
63
64 /**
65  * Insert node into from queue.
66  * @param elem          node to link
67  * @param prev          previous node from queue
68  * @return              0 on success
69  */
70 /*@-exportlocal@*/
71 int rpmsqInsert(/*@null@*/ void * elem, /*@null@*/ void * prev)
72         /*@modifies elem @*/;
73 /*@=exportlocal@*/
74
75 /**
76  * Remove node from queue.
77  * @param elem          node to link
78  * @return              0 on success
79  */
80 /*@-exportlocal@*/
81 int rpmsqRemove(/*@null@*/ void * elem)
82         /*@globals fileSystem, internalState @*/
83         /*@modifies elem, fileSystem, internalState @*/;
84 /*@=exportlocal@*/
85
86 /**
87  * Default signal handler.
88  * @param signum        signal number
89  * @param info          (siginfo_t) signal info
90  * @param context       signal context
91  */
92 /*@-exportlocal@*/
93 void rpmsqAction(int signum, void * info, void * context)
94         /*@globals rpmsqCaught, errno, fileSystem @*/
95         /*@modifies rpmsqCaught, errno, fileSystem @*/;
96 /*@=exportlocal@*/
97
98 /**
99  * Enable or disable a signal handler.
100  * @param signum        signal to enable (or disable if negative)
101  * @param handler       sa_sigaction handler (or NULL to use rpmsqHandler())
102  * @return              no. of refs, -1 on error
103  */
104 int rpmsqEnable(int signum, /*@null@*/ rpmsqAction_t handler)
105         /*@globals rpmsqCaught, fileSystem, internalState @*/
106         /*@modifies rpmsqCaught, fileSystem, internalState @*/;
107
108 /**
109  * Fork a child process.
110  * @param sq            scriptlet queue element
111  * @return              fork(2) pid
112  */
113 pid_t rpmsqFork(rpmsq sq)
114         /*@globals fileSystem, internalState @*/
115         /*@modifies sq, fileSystem, internalState @*/;
116
117 /**
118  * Wait for child process to be reaped.
119  * @param sq            scriptlet queue element
120  * @return              reaped child pid
121  */
122 pid_t rpmsqWait(rpmsq sq)
123         /*@globals fileSystem, internalState @*/
124         /*@modifies sq, fileSystem, internalState @*/;
125
126 /**
127  * Call a function in a thread synchronously.
128  * @param start         function
129  * @param arg           function argument
130  * @return              0 on success
131  */
132 int rpmsqThread(void * (*start) (void * arg), void * arg)
133         /*@globals internalState @*/
134         /*@modifies internalState @*/;
135
136 /**
137  * Execute a command, returning its status.
138  */
139 int rpmsqExecve (const char ** argv)
140         /*@globals fileSystem, internalState @*/
141         /*@modifies fileSystem, internalState @*/;
142
143 #ifdef __cplusplus
144 }
145 #endif
146
147 #endif  /* H_RPMSQ */