Splint fiddles.
[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 rpmop_s op;          /*!< Scriptlet operation timestamp; */
43     rpmtime_t ms_scriptlets;    /*!< Accumulated script duration (msecs). */
44     int reaper;                 /*!< Register SIGCHLD handler? */
45     int pipes[2];               /*!< Parent/child interlock. */
46 /*@shared@*/
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         /*@globals systemState @*/
73         /*@modifies elem, prev, systemState @*/;
74 /*@=exportlocal@*/
75
76 /**
77  * Remove node from queue.
78  * @param elem          node to link
79  * @return              0 on success
80  */
81 /*@-exportlocal@*/
82 int rpmsqRemove(/*@null@*/ void * elem)
83         /*@globals fileSystem, internalState @*/
84         /*@modifies elem, fileSystem, internalState @*/;
85 /*@=exportlocal@*/
86
87 /**
88  * Default signal handler.
89  * @param signum        signal number
90  * @param info          (siginfo_t) signal info
91  * @param context       signal context
92  */
93 /*@-exportlocal@*/
94 void rpmsqAction(int signum, void * info, void * context)
95         /*@globals rpmsqCaught, rpmsqQueue, errno, fileSystem @*/
96         /*@modifies rpmsqCaught, rpmsqQueue, errno, fileSystem @*/;
97 /*@=exportlocal@*/
98
99 /**
100  * Enable or disable a signal handler.
101  * @param signum        signal to enable (or disable if negative)
102  * @param handler       sa_sigaction handler (or NULL to use rpmsqHandler())
103  * @return              no. of refs, -1 on error
104  */
105 int rpmsqEnable(int signum, /*@null@*/ rpmsqAction_t handler)
106         /*@globals rpmsqCaught, rpmsqQueue, fileSystem, internalState @*/
107         /*@modifies rpmsqCaught, rpmsqQueue, fileSystem, internalState @*/;
108
109 /**
110  * Fork a child process.
111  * @param sq            scriptlet queue element
112  * @return              fork(2) pid
113  */
114 pid_t rpmsqFork(rpmsq sq)
115         /*@globals fileSystem, internalState @*/
116         /*@modifies sq, fileSystem, internalState @*/;
117
118 /**
119  * Wait for child process to be reaped.
120  * @param sq            scriptlet queue element
121  * @return              reaped child pid
122  */
123 pid_t rpmsqWait(rpmsq sq)
124         /*@globals fileSystem, internalState @*/
125         /*@modifies sq, fileSystem, internalState @*/;
126
127 /**
128  * Call a function in a thread.
129  * @param start         function
130  * @param arg           function argument
131  * @return              thread pointer (NULL on error)
132  */
133 void * rpmsqThread(void * (*start) (void * arg), void * arg)
134         /*@globals internalState @*/
135         /*@modifies internalState @*/;
136
137 /**
138  * Wait for thread to terminate.
139  * @param thread        thread
140  * @return              0 on success
141  */
142 int rpmsqJoin(/*@null@*/ void * thread)
143         /*@globals internalState @*/
144         /*@modifies internalState @*/;
145
146 /**
147  * Compare thread with current thread.
148  * @param thread        thread
149  * @return              0 if not equal
150  */
151 int rpmsqThreadEqual(/*@null@*/ void * thread)
152         /*@globals internalState @*/
153         /*@modifies internalState @*/;
154
155 /**
156  * Execute a command, returning its status.
157  */
158 int rpmsqExecve (const char ** argv)
159         /*@globals fileSystem, internalState @*/
160         /*@modifies fileSystem, internalState @*/;
161
162 #ifdef __cplusplus
163 }
164 #endif
165
166 #endif  /* H_RPMSQ */