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
monitor.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 __MONITOR_H__
20 #define __MONITOR_H__
21 
22 #include <stdlib.h>
23 #include <pthread.h>
24 #include <limits.h>
25 
26 #include "common.h"
27 #include "evloop.h"
28 
29 struct monitor;
30 struct monitor_msg;
31 
32 typedef enum {
33  /*
34  * This type of monitored object can run in a thread.
35  */
37  /*
38  * This type of monitored object runs in a separate process.
39  */
42 
43 typedef enum {
45  /*
46  * This flag means that we need to setup bidirectional communication
47  * between the monitor and the child.
48  */
51 
52 typedef int monitor_flags_t;
53 
54 typedef enum {
61 
62 typedef enum {
65 
66 /*
67  * If we fork a binary, before we exec the binary, we dup2()
68  * some file descriptors so the monitor and child can communicate.
69  * These are the environment var names. To be a monitored child, at
70  * least MONITOR_CHILD_RECV_FD must be set; MONITOR_CHILD_SEND_FD may
71  * also be set if the monitor is listening for replies.
72  *
73  * We also set an object id so that the parent and child can refer to
74  * the same object.
75  */
76 
77 #define MONITOR_CHILD_RECV_FD_ENVVAR "MONITOR_CHILD_RECV_FD"
78 #define MONITOR_CHILD_SEND_FD_ENVVAR "MONITOR_CHILD_SEND_FD"
79 #define MONITOR_OBJID_ENVVAR "MONITOR_OBJID"
80 #define MONITOR_OBJTYPE_ENVVAR "MONITOR_OBJTYPE"
81 
82 typedef int (*monitor_stdio_callback_t)(int fd,char *buf,int len,void *state);
83 
84 /*
85  * Object type-specific functions.
86  */
88  /*
89  * When the monitor is created, and the evloop is built, we call
90  * this function to allow @obj to add any of the FDs it needs to our
91  * @evloop.
92  */
93  int (*evloop_attach)(struct evloop *evloop,void *obj);
94  /*
95  * When the monitor is freed, and the evloop is built, we call
96  * this function to allow @obj to add any of the FDs it needs to our
97  * @evloop.
98  */
99  int (*evloop_detach)(struct evloop *evloop,void *obj);
100  /*
101  * When the monitor is shutdown, or an object is finalized, we call
102  * this function to disconnect from the object and possibly terminate it.
103  *
104  * @sig is currently set to 1 if close should terminate the obj; 0
105  * if not (i.e., hard close vs soft close). Later we'll maybe need
106  * to define more semantics.
107  */
108  int (*close)(struct monitor *monitor,void *obj,void *objstate,
109  int kill,int kill_sig);
110  /*
111  * When the monitor is shutdown, or an object is finalized, we call
112  * this function to allow the object to remove *all* its state. The
113  * object will have already been closed. This is only to ensure
114  * that the object's non-running state is gone -- like results or logs.
115  */
116  int (*fini)(struct monitor *monitor,void *obj,void *objstate);
117  /*
118  * If @evloop is already attached to @obj, this function should
119  * return 1; if not, 0; if error, < 0.
120  */
121  int (*evloop_is_attached)(struct evloop *evloop,void *obj);
122  /*
123  * For ease of use, we allow library users to specify callbacks to
124  * receive just the msgs without having to specify an evloop handler
125  * (above). Our built-in handlers call these callbacks by default;
126  * as noted above, if the user overrides our handlers via the above
127  * two fields, these callbacks will only be called if the
128  * user-supplied ones call them.
129  *
130  * (Note: these functions must clone the msg if they need its
131  * contents to persist after the handler returns.)
132  */
133  int (*child_recv_msg)(struct monitor *monitor,struct monitor_msg *msg);
134  int (*recv_msg)(struct monitor *monitor,struct monitor_msg *msg);
135 
136  /*
137  * Callbacks for state changes, in the monitor, or as a result of a
138  * per-FD evloop handler. This allows the monitor user to respond
139  * to events in the monitored objects, and allows the monitored
140  * objects not have to be aware that they are being monitored by
141  * something like an XML SOAP server.
142  */
145  int (*event)(struct monitor *monitor,monitor_event_t event,
146  int objid,void *obj);
147  /*
148  * Each time the monitor's evloop handles something, give the
149  * objtype to see if something changed on any of its objects. This
150  * solution pretty much stinks, but since monitored objects are
151  * given an evloop to directly attach to, we do not know which
152  * evloop FDs correspond to which objects. So we just iterate
153  * through each object and give it a chance to check its state.
154  * Yes, this stinks.
155  */
156  int (*notify)(void *obj);
157 };
158 
159 /*
160  * Each monitored object we launch is paired with a monitor struct in
161  * the server thread that created it; we launch the child object from a
162  * thread that becomes the monitor thread. That thread is the owner of
163  * this structure.
164  *
165  * If the monitored object requires a process, the monitor thread
166  * watches the forked process, exchanges msgs with it, logs/buffers its
167  * stdio.
168  *
169  * If the monitored object requires a thread, that thread is itself the
170  * monitor thread for the object, and both interacts with the object and
171  * replies to requests.
172  */
173 struct monitor {
174  /* Either of MONITOR_TYPE_(THREAD|PROCESS). */
176 
178 
179  /* The thread monitoring this object. */
180  pthread_t mtid;
181 
182  /*
183  * Used to ensure safe writes to the FDs, or the thread queue. The
184  * child CANNOT take this lock!
185  */
186  pthread_mutex_t mutex;
187 
188  /*
189  * At last check in monitor_run, number of live children.
190  */
192 
193  /*
194  * At last check in monitor_run, number of live objects.
195  */
197 
198  /*
199  * Total number of objects.
200  */
201  int objs;
202 
203  /*
204  * Each sent monitor message can be associated with an object.
205  * These are stored in this hashtable. It is up to the user of the
206  * monitor to remove these when finished with them.
207  *
208  * (The intended use for us is that each split request (transmitted
209  * as a monitor_msg) is associated with a real, live soap request.
210  * For thread-based target objects, the monitor thread can pull the
211  * object out from this table when it is ready to process the
212  * request, and respond directly on the soap struct. For
213  * process-based analysis objects, the monitor thread call leave the
214  * object in this table until the process replies with the response,
215  * then reply on the soap object in this table.)
216  *
217  * Thus, for threads, the parent/child must agree on the
218  * locking/freeing behavior of this table, and the objects contained
219  * in it; objects are not locked per object.
220  */
221  GHashTable *msg_obj_tab;
222 
223  /*
224  * Used to assure serialized access to @msg_obj_tab. The only way
225  * the server should take this lock is before taking the @mutex lock
226  * above; and it had better release this lock before sending a
227  * message! Otherwise if the child is notified and reads the
228  * message first, it might try to grab this lock and block; we don't
229  * want that.
230  */
231  pthread_mutex_t msg_obj_tab_mutex;
232 
233  /*
234  * Auto-assign msg ids if caller of monitor_msg_create does not
235  * assign one.
236  */
238 
239  /*
240  * The primary object we are monitoring. Either a target or analysis, for
241  * now.
242  */
243  int objid;
244  void *obj;
245 
246  /*
247  * Our internal evloop. Each monitor runs an evloop, which is how
248  * it monitors its monitored object, and how it monitors
249  * communication on its file descriptors for monitor/child
250  * communication.
251  *
252  * Thus, users should call monitor_run() after creating a monitor,
253  * its monitored object, and linking the monitored object to this
254  * evloop. XXX: is there a way we can abstract this?
255  */
256  struct evloop *evloop;
257 
258  /*
259  * If non-negative, the monitored thread/process will be listening
260  * on @child_request_recv_fd for new msgs from the parent. The
261  * parent sends via @handler_request_send_fd.
262  *
263  * For threads, the monitor_msg sent has no payload. For processes,
264  * the monitor_msg has a variable-length payload.
265  */
266  int monitor_send_fd; /* open with F_CLOEXEC */
267  int child_recv_fd; /* close in parent after fork */
268 
269  /*
270  * These reply descriptors are only created if this is a
271  * MONITOR_TYPE_PROCESS.
272  *
273  * The request-handling thread will have buffered the request,
274  * authenticated it and checked its permissions, demuxed it to the
275  * right child, and passed it to the child via
276  * @parent_request_send_fd, and must wait for a response on
277  * @parent_reply_recv_fd, assuming the child will respond on
278  * @child_reply_send_fd .
279  *
280  * We have to do it this way because all the connection state is in
281  * the parent, but all the ability to interact with the target is in
282  * the child (i.e., ptrace).
283  */
284  int child_send_fd; /* close in parent after fork */
285  int monitor_recv_fd; /* open with F_CLOEXEC */
286 
287  /*
288  * Process-specific monitor state. There is no thread-specific
289  * state because the monitor thread is the same as the object thread
290  * -- they both share the thread. Only objects that expose an
291  * evloop interface can be used in those threads anyway.
292  */
293  struct {
294  int pid;
295  int status;
297 
298  /*
299  * Input/output buffers for the monitored process.
300  */
301  int stdin_m_fd; /* open with F_CLOEXEC */
302  int stdin_c_fd; /* close in parent after fork */
303  char *stdin_buf;
306 
307  int stdout_m_fd; /* open with F_CLOEXEC */
308  int stdout_c_fd; /* close in parent after fork */
309  /* struct cbuf *stdout_buf; */
314 
315  int stderr_m_fd; /* open with F_CLOEXEC */
316  int stderr_c_fd; /* close in parent after fork */
317  /* struct cbuf *stderr_buf; */
322  } p;
323 
326 };
327 
328 #define SEQNO_MAX SHRT_MAX
329 
330 struct monitor_msg {
331  /*
332  * @objid is the monitored object ID; demuxes the message to the
333  * right monitored object.
334  */
335  int objid;
336 
337  /*
338  * User-defined fields. The idea is to support a generic
339  * communication protocol to the monitored @objid/@objtype, and to
340  * associate a state object with each msg. The state object might
341  * persist across several messages. @id is intended to serve as a
342  * msg ID; it uniquely binds one or more messages to a state object.
343  * @cmd is a command ID, or something; @seqno is intended to serve
344  * as a sequence number for a command, so that commands can be
345  * ordered and multi-message.
346  */
347  int id;
348 
349  short cmd;
350  short seqno;
351  int len;
352  char *msg;
353 
354  /*
355  * This field is not transmitted; it's just convenience for the msg
356  * handler. Corresponds to @objid above.
357  */
358  void *obj;
359 
360  /*
361  * This field is not transmitted; this is the state object for
362  * stateful commands.
363  */
364  void *msg_obj;
365 };
366 
367 /*
368  * Lib init/fini.
369  */
370 void monitor_init(void);
371 void monitor_fini(void);
372 
373 /*
374  * Allows us to have dynamic object types, associated with handler
375  * functions. If @objtype is -1, its value is assigned automatically,
376  * and the caller should save it for future use (i.e., passing to
377  * monitor_create/monitor_attach).
378  */
379 int monitor_register_objtype(int objtype,struct monitor_objtype_ops *ops,
380  pthread_mutex_t *objtype_mutex);
381 /*
382  * Sometimes we need to lock/unlock the per-objtype lock.
383  */
384 int monitor_lock_objtype(int objtype);
385 int monitor_unlock_objtype(int objtype);
386 /*
387  * Most times we unlock an objtype mutex, we don't really need to hold
388  * the global monitor mutex to do so. This could only get us in trouble
389  * if we call it when the monitor lib is being uninitialized, I think.
390  */
391 int monitor_unlock_objtype_unsafe(int objtype);
392 /*
393  * Sometimes we need to atomically lock the per-objtype mutex when we
394  * lookup an object, but not lock the object's monitor's lock.
395  */
396 int monitor_lookup_objid_lock_objtype(int objid,int objtype,
397  void **obj,struct monitor **monitor);
398 /*
399  * Sometimes we need to atomically lock the per-objtype mutex AND the
400  * object's monitor's lock when we lookup an object.
401  */
402 int monitor_lookup_objid_lock_objtype_and_monitor(int objid,int objtype,
403  void **obj,
404  struct monitor **monitor);
405 
406 /*
407  * Returns an array_list of all the monitored objects of @objtype. Some
408  * objects may be NULL if they are instantiated in a child process that
409  * is monitored.
410  *
411  * The user is basically responsible for ensuring no object on the list
412  * is used, by making sure that any such accesses to those objects only
413  * happen when the objtype lock is held -- we do not leave the primary
414  * monitor mutex locked when we return from this call. BUT,
415  * monitor_add_obj and monitor_del_obj are both supposed be called only
416  * with the objtype lock held.
417  *
418  * The monitor code cannot try to lock the objtype lock except when
419  * instructed to do so by the user.
420  */
422  int include_null);
423 
425  int include_null);
426 
427 /*
428  * Get a new ID for a monitored object; we want these things to be
429  * globally unique, even amongst different monitored object types.
430  * Makes life much easier.
431  */
432 int monitor_get_unique_objid(void);
433 
434 /*
435  * Creates a monitor of @type, for a valid @objtype.
436  */
438  int objid,int objtype,void *obj,void *objstate);
439 
440 /*
441  * Creates a monitor of @type, for a (possibly unknown) @objtype.
442  *
443  * If @custom_child_recv_evh is specified, it replaces the built-in
444  * handler for the child read end of the monitor pipe (i.e., the child
445  * reading from the monitor parent thread). This function should
446  * support the monitor's builtin objid/objtype demultiplexing, but it
447  * could elect not to. If not specified, the built-in handler calls the
448  * objtype msg callback functions for that objid, if they were
449  * specified. Same for @custom_recv_evh, except that it receives from
450  * the child (the monitor parent reading from the child).
451  */
453  int objid,int objtype,void *obj,void *objstate,
454  evloop_handler_t custom_recv_evh,
455  evloop_handler_t custom_child_recv_evh);
456 
457 /*
458  * If you created a monitor without an @obj, you MUST call this function
459  * before the monitored obj will be installed into the main monitor
460  * hashtables.
461  *
462  * (Users might call this when they need the monitor created before the
463  * object is created; i.e., the target library might want the
464  * monitor-created evloop as it is creating the target object.)
465  *
466  * Users must call this with the objtype lock held!
467  */
469  int objid,int objtype,void *obj,void *objstate);
470 int monitor_add_obj(struct monitor *monitor,int objid,int objtype,void *obj,
471  void *objstate);
472 
473 
474 int monitor_close_obj(struct monitor *monitor,void *obj,
475  int kill,int kill_sig);
476 int monitor_close_objid(struct monitor *monitor,int objid,
477  int kill,int kill_sig);
478 int monitor_del_obj(struct monitor *monitor,void *obj);
479 int monitor_del_objid(struct monitor *monitor,int objid);
480 
481 /*
482  * Looks up a monitor based on monitored object id. Useful for server
483  * threads who have to find the monitor for a request for an object,
484  * perhaps.
485  */
487  int *objtype,void **obj,
488  struct monitor **monitor);
489 
490 /*
491  * Checks for at least one of the two env vars that specify file
492  * descriptors for communication with a monitor
493  */
494 int monitor_can_attach(void);
495 
496 /*
497  * Return 1 if the caller is a monitored child with both recv/send
498  * comms to the monitor; else 0.
499  */
500 int monitor_can_attach_bidi(void);
501 
502 /*
503  * "Attaches" to a monitor via pipes. This should only be called from
504  * monitored processes.
505  */
507  int objtype,void *obj,void *objstate,
508  evloop_handler_t custom_child_recv_evh,
510  void *callback_state);
511 
512 /*
513  * Call if the target spec or analysis spec dictates I/O behavior -- and
514  * if we're forking the child. Can't do this for threaded children,
515  * obviously.
516  *
517  * NB: the *_callback functions will always return a NULL-terminated
518  * buffer, and their length argument will *not* include that NULL char.
519  * This helps callbacks that want to use their buf argument as a string,
520  * even if it's not really one.
521  */
523  char *stdin_buf,int stdin_buflen);
525  int maxbufsiz,char *stdout_logfile,
527  void *callback_state);
529  int maxbufsiz,char *stderr_logfile,
531  void *callback_state);
532 
533 /*
534  * Should be called from the control thread to fork() and exec() a new
535  * process to run either a target or analysis in. This basically calls
536  * putenv() in the child to set the child MONITOR_CHILD_SEND_FD and
537  * MONITOR_CHILD_RECV_FD variables; closes FDs in the child that should
538  * not be open (and cleans up other state); and sets up the child's
539  * standard FDs as dictated by monitor_setup_*().
540  *
541  * We cannot provide a generic fork() function due to our use of
542  * pthreads, of course (see pthread_atfork() for detailed discussion).
543  * This means that if we want to run a specific target in a separate
544  * address space (i.e., for greater stability of the server), we have to
545  * have a wrapper program that spawns the target in a paused state, but
546  * knows how to expose it to the XML RPC server(s). Very doable.
547  *
548  * For now, just be careful to mark any mmap()s you don't want with
549  * MADV_DONTFORK, and any file descriptors that cannot be inherited,
550  * with CLOEXEC. That should pretty much do it.
551  */
552 int monitor_spawn(struct monitor *monitor,char *filename,
553  char *const argv[],char *const envp[],char *dir);
554 
555 /*
556  * Runs the monitor (basically just runs its internal evloop).
557  *
558  * If the monitor has no more live children nor live objs, returns 0.
559  *
560  * If the monitor thread is gone, returns -1 and ESRCH.
561  *
562  * If the monitor thread is live and another thread tries to call this,
563  * returns -1 and EPERM.
564  *
565  * If the monitor has live children or live objs, but its evloop has no
566  * descriptors, returns -1 and EINVAL.
567  *
568  * If the evloop failed badly internally (probably a bug), we remove all
569  * its monitored objects, set the monitor to a "done" state (its
570  * done_status set to RESULT_ERROR), and return -11 and errno is
571  * whatever evloop_handleone set.
572  */
573 int monitor_run(struct monitor *monitor);
574 
575 /*
576  * A process monitor is done if the child has finished and the objects
577  * are not live.
578  */
579 int monitor_is_done(struct monitor *monitor);
580 
581 /*
582  * Returns the number of objects the monitor has.
583  */
584 int monitor_objects(struct monitor *monitor);
585 
586 /*
587  * Returns the number of live objects the monitor has.
588  */
590 
591 /*
592  * Returns the number of live children the monitor is monitoring.
593  */
595 
596 /*
597  * Shuts down a monitor, closes all objects, and destroys the evloop.
598  * Only the monitor thread can call this function!
599  */
600 int monitor_shutdown(struct monitor *monitor);
601 
602 /*
603  * Cleans up and frees a monitor, and all its objects. Only the monitor
604  * thread can call this function, unless that thread has exited. This
605  * use case is perfectly appropriate; oftentimes the monitor thread is
606  * only needed as long as the objects are live; when they are not live
607  * and require no further monitoring, but their state is around for
608  * inspection, it makes no sense to leave the monitor thread running.
609  */
610 int monitor_destroy(struct monitor *monitor);
611 
612 /*
613  * Free @msg, and its buffer (if non-NULL).
614  *
615  * Also, if the msg is associated with a msg_obj, remove it!
616  */
617 void monitor_msg_free(struct monitor_msg *msg);
618 
619 /* Free @msg, but not its buffer. */
620 void monitor_msg_free_save_buffer(struct monitor_msg *msg);
621 
622 /*
623  * Returns a monitor_msg consisting of the argument values. Caller must
624  * specify @monitor and @objid; @monitor provides the default
625  * objid/objtype (which are used if objid == -1); but this also allows
626  * the caller to specify a secondary monitored object, if/when they exist.
627  */
629  int id,short cmd,short seqno,
630  int buflen,char *buf,
631  void *msg_obj);
632 
633 /*
634  * Send @msg to the monitored child associated with @msg->objid, storing
635  * @msg->id/@msg->msg_obj in our internal table if @msg->msg_obj exists.
636  *
637  * (The point of associating @msg_obj with a message id is so that if
638  * the monitor user wants to associate a custom request handler (with a
639  * thread-based monitor child), or a custom request handler for a
640  * monitor_child and a custom reply handler for the monitor (with a
641  * process-based monitor), the handlers will have a stateful object that
642  * they can work on, if necessary.)
643  */
644 int monitor_send(struct monitor_msg *msg);
645 
646 /*
647  * Receive a msg from @monitor (blocking). Retrieves a msg_obj if one
648  * was stored for this msg's id
649  */
650 struct monitor_msg *monitor_recv(struct monitor *monitor);
651 
652 /*
653  * A monitored child must call this to send a message to its parent
654  * (blocking).
655  *
656  * Sometimes, we might delete the objid we are responding to! That
657  * means that lookup in the monitor data structures will fail. So, if
658  * we can't look it up, we send it on @monitor.
659  */
660 int monitor_child_send(struct monitor_msg *msg,struct monitor *monitor);
661 
662 /*
663  * A monitored child must call this to read a message from its parent
664  * (blocking).
665  */
667 
668 #endif /* __MONITOR_H__ */
monitor_type_t
Definition: monitor.h:32
int monitor_del_objid(struct monitor *monitor, int objid)
Definition: monitor.c:788
int stdout_log_fd
Definition: monitor.h:310
void monitor_msg_free_save_buffer(struct monitor_msg *msg)
Definition: monitor.c:2521
int(* monitor_stdio_callback_t)(int fd, char *buf, int len, void *state)
Definition: monitor.h:82
int monitor_lookup_objid_lock_objtype_and_monitor(int objid, int objtype, void **obj, struct monitor **monitor)
Definition: monitor.c:372
int live_children
Definition: monitor.h:191
int monitor_objects(struct monitor *monitor)
Definition: monitor.c:2251
int monitor_add_primary_obj(struct monitor *monitor, int objid, int objtype, void *obj, void *objstate)
Definition: monitor.c:1576
char * stderr_logfile
Definition: monitor.h:319
void * obj
Definition: monitor.h:244
int monitor_lookup_objid_lock_objtype(int objid, int objtype, void **obj, struct monitor **monitor)
Definition: monitor.c:350
int pid
Definition: monitor.h:294
int(* close)(struct monitor *monitor, void *obj, void *objstate, int kill, int kill_sig)
Definition: monitor.h:108
int stdin_c_fd
Definition: monitor.h:302
int monitor_send_fd
Definition: monitor.h:266
int monitor_can_attach_bidi(void)
Definition: monitor.c:1609
void * obj
Definition: monitor.h:358
int monitor_register_objtype(int objtype, struct monitor_objtype_ops *ops, pthread_mutex_t *objtype_mutex)
Definition: monitor.c:1052
struct monitor_msg * monitor_msg_create(int objid, int id, short cmd, short seqno, int buflen, char *buf, void *msg_obj)
Definition: monitor.c:2525
GHashTable * msg_obj_tab
Definition: monitor.h:221
int monitor_is_done(struct monitor *monitor)
Definition: monitor.c:2224
int monitor_get_unique_objid(void)
Definition: monitor.c:161
void * stdout_callback_state
Definition: monitor.h:313
int objid
Definition: monitor.h:335
struct monitor * monitor
char * msg
Definition: monitor.h:352
void * stdin_callback_state
Definition: monitor.h:325
int monitor_add_obj(struct monitor *monitor, int objid, int objtype, void *obj, void *objstate)
Definition: monitor.c:554
int stdout_m_fd
Definition: monitor.h:307
int(* evloop_is_attached)(struct evloop *evloop, void *obj)
Definition: monitor.h:121
struct monitor * monitor_create_custom(monitor_type_t type, monitor_flags_t flags, int objid, int objtype, void *obj, void *objstate, evloop_handler_t custom_recv_evh, evloop_handler_t custom_child_recv_evh)
Definition: monitor.c:1411
int monitor_setup_stderr(struct monitor *monitor, int maxbufsiz, char *stderr_logfile, monitor_stdio_callback_t stderr_callback, void *callback_state)
Definition: monitor.c:1897
int(* fatal_error)(monitor_error_t error, void *obj)
Definition: monitor.h:144
int stdin_left
Definition: monitor.h:304
struct evloop * evloop
Definition: monitor.h:256
int monitor_send(struct monitor_msg *msg)
Definition: monitor.c:2607
int monitor_live_children(struct monitor *monitor)
Definition: monitor.c:2231
monitor_type_t type
Definition: monitor.h:175
int monitor_flags_t
Definition: monitor.h:52
int(* event)(struct monitor *monitor, monitor_event_t event, int objid, void *obj)
Definition: monitor.h:145
struct monitor_msg * monitor_recv(struct monitor *monitor)
Definition: monitor.c:2719
int(* evloop_detach)(struct evloop *evloop, void *obj)
Definition: monitor.h:99
monitor_flag_t
Definition: monitor.h:43
int stdin_bufsiz
Definition: monitor.h:305
int stdin_m_fd
Definition: monitor.h:301
int objid
Definition: monitor.h:243
Definition: evloop.h:66
int(* fini)(struct monitor *monitor, void *obj, void *objstate)
Definition: monitor.h:116
int monitor_lock_objtype(int objtype)
Definition: monitor.c:243
struct monitor * monitor_attach(monitor_type_t type, monitor_flags_t flags, int objtype, void *obj, void *objstate, evloop_handler_t custom_child_recv_evh, monitor_stdio_callback_t stdin_callback, void *callback_state)
Definition: monitor.c:1616
monitor_event_t
Definition: monitor.h:62
int monitor_child_send(struct monitor_msg *msg, struct monitor *monitor)
Definition: monitor.c:2798
int stderr_m_fd
Definition: monitor.h:315
short cmd
Definition: monitor.h:349
int(* child_recv_msg)(struct monitor *monitor, struct monitor_msg *msg)
Definition: monitor.h:133
int monitor_close_obj(struct monitor *monitor, void *obj, int kill, int kill_sig)
Definition: monitor.c:622
int monitor_del_obj(struct monitor *monitor, void *obj)
Definition: monitor.c:763
int monitor_unlock_objtype_unsafe(int objtype)
Definition: monitor.c:275
monitor_stdio_callback_t stderr_callback
Definition: monitor.h:320
pthread_mutex_t mutex
Definition: monitor.h:186
void monitor_fini(void)
Definition: monitor.c:127
int stderr_log_fd
Definition: monitor.h:318
int child_recv_fd
Definition: monitor.h:267
pthread_mutex_t msg_obj_tab_mutex
Definition: monitor.h:231
int monitor_recv_fd
Definition: monitor.h:285
int len
Definition: dumptarget.c:52
pthread_t mtid
Definition: monitor.h:180
int monitor_setup_stdin(struct monitor *monitor, char *stdin_buf, int stdin_buflen)
Definition: monitor.c:1817
int objs
Definition: monitor.h:201
int monitor_live_objects(struct monitor *monitor)
Definition: monitor.c:2241
int monitor_close_objid(struct monitor *monitor, int objid, int kill, int kill_sig)
Definition: monitor.c:648
int live_objs
Definition: monitor.h:196
int child_send_fd
Definition: monitor.h:284
int(* recv_msg)(struct monitor *monitor, struct monitor_msg *msg)
Definition: monitor.h:134
void monitor_msg_free(struct monitor_msg *msg)
Definition: monitor.c:2515
short seqno
Definition: monitor.h:350
char * stdout_logfile
Definition: monitor.h:311
struct monitor::@11 p
struct array_list * monitor_list_objids_by_objtype_lock_objtype(int objtype, int include_null)
Definition: monitor.c:279
struct array_list * monitor_list_objs_by_objtype_lock_objtype(int objtype, int include_null)
Definition: monitor.c:315
int monitor_setup_stdout(struct monitor *monitor, int maxbufsiz, char *stdout_logfile, monitor_stdio_callback_t stdout_callback, void *callback_state)
Definition: monitor.c:1847
monitor_stdio_callback_t stdout_callback
Definition: monitor.h:312
int pid_waitpipe_fd
Definition: monitor.h:296
int monitor_shutdown(struct monitor *monitor)
Definition: monitor.c:947
struct monitor_msg * monitor_child_recv(struct monitor *monitor)
Definition: monitor.c:2914
monitor_flags_t flags
Definition: monitor.h:177
int monitor_can_attach(void)
Definition: monitor.c:1603
int msg_obj_id_counter
Definition: monitor.h:237
int(* evloop_attach)(struct evloop *evloop, void *obj)
Definition: monitor.h:93
int status
Definition: monitor.h:295
int monitor_unlock_objtype(int objtype)
Definition: monitor.c:265
int monitor_lookup_objid(int objid, int *objtype, void **obj, struct monitor **monitor)
Definition: monitor.c:219
void monitor_init(void)
Definition: monitor.c:93
void * stderr_callback_state
Definition: monitor.h:321
int stdout_c_fd
Definition: monitor.h:308
char * stdin_buf
Definition: monitor.h:303
int(* notify)(void *obj)
Definition: monitor.h:156
int(* error)(monitor_error_t error, void *obj)
Definition: monitor.h:143
int monitor_destroy(struct monitor *monitor)
Definition: monitor.c:1039
int stderr_c_fd
Definition: monitor.h:316
int monitor_spawn(struct monitor *monitor, char *filename, char *const argv[], char *const envp[], char *dir)
Definition: monitor.c:2002
int monitor_run(struct monitor *monitor)
Definition: monitor.c:2274
monitor_stdio_callback_t stdin_callback
Definition: monitor.h:324
int(* evloop_handler_t)(int fd, int fdtype, void *state)
Definition: evloop.h:62
struct monitor * monitor_create(monitor_type_t type, monitor_flags_t flags, int objid, int objtype, void *obj, void *objstate)
Definition: monitor.c:1594
void * msg_obj
Definition: monitor.h:364
monitor_error_t
Definition: monitor.h:54