PIPS
|
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Go to the source code of this file.
Macros | |
#define | SIZE 1024 /**buffer size */ |
UNIX headers. More... | |
#define | SIGNAL_TAG "# jpips send signal to tpips " |
#define | CHECKPOINT "CHECKPOINT" |
available tags More... | |
#define | INTERRUPT "INTERRUPT" |
#define | KILLNOW "EXIT" |
#define | ABORTIT "ABORT" |
#define | WRAPPER "[tpips_wrapper] " |
#define | starts_with(s1, s2) (strncmp(s1, s2, strlen(s2))==0) /**a la java */ |
#define | tpw_check(what, comment) tpw_log(comment), tpw_check_perror(what, comment) |
#define | KILL(pid, sig) if (pid!=0) { tpw_check(kill(pid,sig),"kill()"); } |
Typedefs | |
typedef void(* | sig_handler_t) (int) |
Functions | |
static void | tpw_log (__attribute__((__unused__)) char *message) |
Enable log with -DLOG for debug. More... | |
static void | tpw_fatal_error (char *message) |
static void | tpw_check_perror (int en, char *message) |
checks returned value for most system commands (-1 and errno set). More... | |
static void | tpw_sig_handler (int sn) |
signal handler for tpips_wrapper. More... | |
static void | tpw_set_sig_handlers (void) |
special handlers for tpips wrapper. More... | |
static pid_t | tpw_fork_inout (void) |
fork, with stdout-stdin link kept More... | |
static char * | tpw_read_line (FILE *in) |
static void | tpw_send_string_to_tpips (char *line) |
send line to tpips. More... | |
void | tpips_wrapper (void) |
fork a tpips to goes on, while the current process acts as a wrapper, which forwards orders, and perform some special signal handling. More... | |
Variables | |
static pid_t | tpips_pid = 0 |
global because needed in tpw_fatal_error. More... | |
static FILE * | in_from_wrapper = NULL |
static FILE * | out_to_tpips = NULL |
#define SIZE 1024 /**buffer size */ |
#define tpw_check | ( | what, | |
comment | |||
) | tpw_log(comment), tpw_check_perror(what, comment) |
void tpips_wrapper | ( | void | ) |
fork a tpips to goes on, while the current process acts as a wrapper, which forwards orders, and perform some special signal handling.
the child is a new tpips, it keeps on executing... the parent just acts as a wrapper, it never returns from here.
CHILD is tpips and returns.
code for the WRAPPER starts here. the PARENT.
special handlers.
forward to tpips. how to ensure that tpips is alive? SIGCHLD and SIGPIPE are caught.
handle signals.
stop tpips on EOF.
wrapper mission done.
Definition at line 270 of file wrapper.c.
References ABORTIT, CHECKPOINT, exit, INTERRUPT, KILL, KILLNOW, line, SIGNAL_TAG, starts_with, tpips_pid, tpw_fatal_error(), tpw_fork_inout(), tpw_log(), tpw_read_line(), tpw_send_string_to_tpips(), and tpw_set_sig_handlers().
Referenced by parse_arguments().
|
static |
checks returned value for most system commands (-1 and errno set).
Definition at line 107 of file wrapper.c.
References tpw_fatal_error().
|
static |
Definition at line 97 of file wrapper.c.
References exit, fprintf(), tpips_pid, and WRAPPER.
Referenced by tpips_wrapper(), tpw_check_perror(), tpw_send_string_to_tpips(), and tpw_sig_handler().
|
static |
fork, with stdout-stdin link kept
create pipe.
fork
CHILD
stdin = in_from_wrapper;
PARENT
the output might be interleaved with tpips output... maybe I should lock stderr.
Definition at line 190 of file wrapper.c.
References fprintf(), in_from_wrapper, out_to_tpips, tpw_check, tpw_log(), and WRAPPER.
Referenced by tpips_wrapper().
|
static |
Enable log with -DLOG for debug.
Definition at line 85 of file wrapper.c.
References fprintf(), and WRAPPER.
Referenced by tpips_wrapper(), and tpw_fork_inout().
|
static |
Definition at line 238 of file wrapper.c.
Referenced by tpips_wrapper().
|
static |
send line to tpips.
could send a signal to tpips to warn about the incoming command. it would be read from in_from_wrapper only.
Definition at line 254 of file wrapper.c.
References line, out_to_tpips, and tpw_fatal_error().
Referenced by tpips_wrapper().
|
static |
special handlers for tpips wrapper.
Definition at line 166 of file wrapper.c.
References tpw_sig_handler().
Referenced by tpips_wrapper().
|
static |
signal handler for tpips_wrapper.
basically forwards signals to tpips. tries to stop tpips before exiting. stops if tpips is stopped.
these signals are traced.
forward signals to tpips.
tpips stopped.
idem?
reset signal handler.
sn | signal number |
Definition at line 127 of file wrapper.c.
References exit, fprintf(), KILL, tpips_pid, tpw_fatal_error(), and WRAPPER.
Referenced by tpw_set_sig_handlers().
|
static |
Definition at line 181 of file wrapper.c.
Referenced by tpw_fork_inout().
|
static |
Definition at line 182 of file wrapper.c.
Referenced by tpw_fork_inout(), and tpw_send_string_to_tpips().
|
static |
global because needed in tpw_fatal_error.
Definition at line 81 of file wrapper.c.
Referenced by tpips_wrapper(), tpw_fatal_error(), and tpw_sig_handler().