3ad5eb182d975147aa0eae3e53b2e800ef1a91db
[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     void * id;                  /*!< Blocking thread id (pthread_t). */
47     pthread_mutex_t mutex;      /*!< Signal delivery to thread condvar. */
48     pthread_cond_t cond;
49 };
50
51 /*@-exportlocal@*/
52 /*@unchecked@*/
53 extern rpmsq rpmsqQueue;
54 /*@=exportlocal@*/
55
56 /*@unchecked@*/
57 extern sigset_t rpmsqCaught;
58
59 #ifdef __cplusplus
60 {
61 #endif
62
63 /**
64  * Insert node into from queue.
65  * @param elem          node to link
66  * @param prev          previous node from queue
67  * @return              0 on success
68  */
69 /*@-exportlocal@*/
70 int rpmsqInsert(/*@null@*/ void * elem, /*@null@*/ void * prev)
71         /*@modifies elem @*/;
72 /*@=exportlocal@*/
73
74 /**
75  * Remove node from queue.
76  * @param elem          node to link
77  * @return              0 on success
78  */
79 /*@-exportlocal@*/
80 int rpmsqRemove(/*@null@*/ void * elem)
81         /*@globals fileSystem, internalState @*/
82         /*@modifies elem, fileSystem, internalState @*/;
83 /*@=exportlocal@*/
84
85 /**
86  * Default signal handler.
87  * @param signum        signal number
88  * @param info          (siginfo_t) signal info
89  * @param context       signal context
90  */
91 /*@-exportlocal@*/
92 void rpmsqAction(int signum, void * info, void * context)
93         /*@globals rpmsqCaught, errno, fileSystem @*/
94         /*@modifies rpmsqCaught, errno, fileSystem @*/;
95 /*@=exportlocal@*/
96
97 /**
98  * Enable or disable a signal handler.
99  * @param signum        signal to enable (or disable if negative)
100  * @param handler       sa_sigaction handler (or NULL to use rpmsqHandler())
101  * @return              no. of refs, -1 on error
102  */
103 int rpmsqEnable(int signum, /*@null@*/ rpmsqAction_t handler)
104         /*@globals rpmsqCaught, fileSystem, internalState @*/
105         /*@modifies rpmsqCaught, fileSystem, internalState @*/;
106
107 /**
108  * Fork a child process.
109  * @param sq            scriptlet queue element
110  * @return              fork(2) pid
111  */
112 pid_t rpmsqFork(rpmsq sq)
113         /*@globals fileSystem, internalState @*/
114         /*@modifies sq, fileSystem, internalState @*/;
115
116 /**
117  * Wait for child process to be reaped.
118  * @param sq            scriptlet queue element
119  * @return              reaped child pid
120  */
121 pid_t rpmsqWait(rpmsq sq)
122         /*@globals fileSystem, internalState @*/
123         /*@modifies sq, fileSystem, internalState @*/;
124
125 /**
126  * Call a function in a thread.
127  * @param start         function
128  * @param arg           function argument
129  * @return              thread pointer (NULL on error)
130  */
131 void * rpmsqThread(void * (*start) (void * arg), void * arg)
132         /*@globals internalState @*/
133         /*@modifies internalState @*/;
134
135 /**
136  * Wait for thread to terminate.
137  * @param thread        thread
138  * @return              0 on success
139  */
140 int rpmsqJoin(/*@null@*/ void * thread)
141         /*@globals internalState @*/
142         /*@modifies internalState @*/;
143
144 /**
145  * Compare thread with current thread.
146  * @param thread        thread
147  * @return              0 if not equal
148  */
149 int rpmsqThreadEqual(/*@null@*/ void * thread)
150         /*@globals internalState @*/
151         /*@modifies internalState @*/;
152
153 /**
154  * Execute a command, returning its status.
155  */
156 int rpmsqExecve (const char ** argv)
157         /*@globals fileSystem, internalState @*/
158         /*@modifies fileSystem, internalState @*/;
159
160 #ifdef __cplusplus
161 }
162 #endif
163
164 #endif  /* H_RPMSQ */