Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
waitpipe.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, 2013 The University of Utah
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef __WAITPIPE_H__
20 #define __WAITPIPE_H__
21 
22 #include <signal.h>
23 #include <glib.h>
24 
25 /*
26  * The idea is to turn SIGCHLD into select()able events.
27  *
28  * The only restriction on this little library is that it cannot handle
29  * pid 0; only pids > 0 are allowed. No problem for us, since 0 cannot
30  * be any process's child.
31  */
32 
33 /* @return 1 if the waitpipe is initialized; 0 otherwise. */
34 int waitpipe_is_initialized(void);
35 
36 /*
37  * Initialize the waitpipe, but do not install a SIGCHLD handler via
38  * sigaction. We expect to be notified via waitpipe_notify() by some
39  * external signal handler.
40  */
41 int waitpipe_init_ext(void (*alt_handler)(int,siginfo_t *,void *));
42 
43 /*
44  * Initialize the waitpipe and install a SIGCHLD handler via sigaction.
45  */
46 int waitpipe_init_auto(void (*alt_handler)(int,siginfo_t *,void *));
47 
48 /*
49  * External SIGCHLD handlers should call this, if the waitpipe was
50  * initialized via waitpipe_init_ext() above.
51  */
52 void waitpipe_notify(int signo,siginfo_t *siginfo);
53 
54 int waitpipe_fini(void);
55 
56 /*
57  * Returns half of a pipe -- the end that will receive the write when a
58  * SIGCHLD comes in for one of our pids.
59  */
60 int waitpipe_add(int pid);
61 /*
62  * Removes the pipe for @pid and closes its halves.
63  */
64 int waitpipe_remove(int pid);
65 /*
66  * Returns how many bytes were available to read() from the read half of
67  * the pipe for @pid. Returns 0 if none; -1 on error; or a positive
68  * integer which corresponds to the number of signals (and this number
69  * may cap out at the max pipe size if the pipe got full due to too many
70  * signals).
71  */
72 int waitpipe_drain(int pid);
73 
74 /*
75  * Returns the readfd associated with this pid, if one already exists.
76  */
77 int waitpipe_get(int readfd);
78 
79 /*
80  * Returns the pid associated with this read half of the pipe.
81  *
82  * This is useful so that the library user doesn't have to keep their
83  * own lookup structure at all.
84  */
85 int waitpipe_get_pid(int readfd);
86 
87 #endif /* __WAITPIPE_H__ */
int waitpipe_add(int pid)
Definition: waitpipe.c:184
int waitpipe_init_auto(void(*alt_handler)(int, siginfo_t *, void *))
Definition: waitpipe.c:140
int waitpipe_get(int readfd)
Definition: waitpipe.c:310
int waitpipe_is_initialized(void)
Definition: waitpipe.c:117
int waitpipe_fini(void)
Definition: waitpipe.c:166
int waitpipe_get_pid(int readfd)
Definition: waitpipe.c:330
void waitpipe_notify(int signo, siginfo_t *siginfo)
Definition: waitpipe.c:49
int waitpipe_remove(int pid)
Definition: waitpipe.c:284
int waitpipe_drain(int pid)
Definition: waitpipe.c:350
int waitpipe_init_ext(void(*alt_handler)(int, siginfo_t *, void *))
Definition: waitpipe.c:124