Unexpose signal queue and direct manipulation functions
[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 <rpm/rpmsw.h>
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 /** \ingroup rpmsq
16  */
17 typedef struct rpmsig_s * rpmsig;
18
19 /** \ingroup rpmsq
20  */
21 typedef struct rpmsqElem * rpmsq;
22
23 /** \ingroup rpmsq
24  * Default signal handler prototype.
25  * @param signum        signal number
26  * @param info          (siginfo_t) signal info
27  * @param context       signal context
28  */
29 typedef void (*rpmsqAction_t) (int signum, void * info, void * context);
30
31 extern int _rpmsq_debug;
32
33 /* XXX make this fully opaque? */
34 #if defined(_RPMSQ_INTERNAL)
35 /**
36  * SIGCHLD queue element.
37  */
38 struct rpmsqElem {
39     struct rpmsqElem * q_forw;  /*!< for use by insque(3)/remque(3). */
40     struct rpmsqElem * q_back;
41     pid_t child;                /*!< Currently running child. */
42     volatile pid_t reaped;      /*!< Reaped waitpid(3) return. */
43     volatile int status;        /*!< Reaped waitpid(3) status. */
44     struct rpmop_s op;          /*!< Scriptlet operation timestamp; */
45     rpmtime_t ms_scriptlets;    /*!< Accumulated script duration (msecs). */
46     int reaper;                 /*!< Register SIGCHLD handler? */
47     int pipes[2];               /*!< Parent/child interlock. */
48     void * id;                  /*!< Blocking thread id (pthread_t). */
49     pthread_mutex_t mutex;      /*!< Signal delivery to thread condvar. */
50     pthread_cond_t cond;
51 };
52 #endif /* _RPMSQ_INTERNAL */
53
54 extern sigset_t rpmsqCaught;
55
56 /** \ingroup rpmsq
57  * Default signal handler.
58  * @param signum        signal number
59  * @param info          (siginfo_t) signal info
60  * @param context       signal context
61  */
62 void rpmsqAction(int signum, void * info, void * context);
63
64 /** \ingroup rpmsq
65  * Enable or disable a signal handler.
66  * @param signum        signal to enable (or disable if negative)
67  * @param handler       sa_sigaction handler (or NULL to use rpmsqHandler())
68  * @return              no. of refs, -1 on error
69  */
70 int rpmsqEnable(int signum, rpmsqAction_t handler);
71
72 /** \ingroup rpmsq
73  * Fork a child process.
74  * @param sq            scriptlet queue element
75  * @return              fork(2) pid
76  */
77 pid_t rpmsqFork(rpmsq sq);
78
79 /** \ingroup rpmsq
80  * Wait for child process to be reaped.
81  * @param sq            scriptlet queue element
82  * @return              reaped child pid
83  */
84 pid_t rpmsqWait(rpmsq sq);
85
86 /** \ingroup rpmsq
87  * Call a function in a thread.
88  * @param start         function
89  * @param arg           function argument
90  * @return              thread pointer (NULL on error)
91  */
92 void * rpmsqThread(void * (*start) (void * arg), void * arg);
93
94 /** \ingroup rpmsq
95  * Wait for thread to terminate.
96  * @param thread        thread
97  * @return              0 on success
98  */
99 int rpmsqJoin(void * thread);
100
101 /** \ingroup rpmsq
102  * Compare thread with current thread.
103  * @param thread        thread
104  * @return              0 if not equal
105  */
106 int rpmsqThreadEqual(void * thread);
107
108 /** \ingroup rpmsq
109  * Execute a command, returning its status.
110  */
111 int rpmsqExecve (const char ** argv);
112
113 #ifdef __cplusplus
114 }
115 #endif
116
117 #endif  /* H_RPMSQ */