[Initng-svn] r4330 - in initng/trunk: plugins/logfile plugins/reload src
svn at initng.thinktux.net
svn at initng.thinktux.net
Thu Jun 1 12:49:45 CEST 2006
Author: jimmy
Date: Thu Jun 1 12:49:43 2006
New Revision: 4330
Modified:
initng/trunk/plugins/debug_commands/initng_debug_commands.c
initng/trunk/plugins/debug_commands/print_service.c
initng/trunk/plugins/logfile/initng_logfile.c
initng/trunk/plugins/reload/initng_reload.c
initng/trunk/src/initng_fd.c
initng/trunk/src/initng_fd.h
initng/trunk/src/initng_fork.c
initng/trunk/src/initng_kill_handler.c
initng/trunk/src/initng_process_db.c
initng/trunk/src/initng_process_db.h
Log:
This commit will probably make initng more unstable again, so a soon release is probably a bar ida.
This is the first steps of defining process pipes dynamilcy in initng, this is far from complete but my system boots fine anyway.
Modified: initng/trunk/plugins/debug_commands/initng_debug_commands.c
==============================================================================
--- initng/trunk/plugins/debug_commands/initng_debug_commands.c (original)
+++ initng/trunk/plugins/debug_commands/initng_debug_commands.c Thu Jun 1 12:49:43 2006
@@ -105,6 +105,7 @@
active_db_h *currentA;
s_call *currentC;
process_h *currentP;
+ pipe_h * current_pipe;
int i;
for (i = 0; i < 1024; i++)
@@ -128,12 +129,15 @@
currentP = NULL;
while_processes(currentP, currentA)
{
- if (currentP->out_pipe[0] != i)
- continue;
-
- mprintf(&string, " %i: Used service: %s, process: %s\n", i,
- currentA->name, currentP->pt->name);
- break;
+ current_pipe = NULL;
+ while_pipes(current_pipe, currentP)
+ {
+ if(current_pipe->pipe[0] == i || current_pipe->pipe[1] == i)
+ {
+ mprintf(&string, " %i: Used service: %s, process: %s\n", i,
+ currentA->name, currentP->pt->name);
+ }
+ }
}
}
Modified: initng/trunk/plugins/debug_commands/print_service.c
==============================================================================
--- initng/trunk/plugins/debug_commands/print_service.c (original)
+++ initng/trunk/plugins/debug_commands/print_service.c Thu Jun 1 12:49:43 2006
@@ -193,6 +193,7 @@
static void active_db_print_process(process_h * p, char **string)
{
+ pipe_h * current_pipe = NULL;
assert(p);
if (p->pst == P_FREE)
mprintf(string, "\tOLD Process: type %s\n", p->pt->name);
@@ -221,16 +222,39 @@
#endif
WIFSTOPPED(p->r_code), WSTOPSIG(p->r_code));
- if (p->out_pipe[0] > 0 || p->out_pipe[1] > 0)
- mprintf(string, "\t\tFds read: %i, write: %i\n", p->out_pipe[0],
- p->out_pipe[1]);
-
- if (p->buffer && p->buffer_allocated > 0)
+ while_pipes(current_pipe, p)
{
- mprintf(string,
+ int i;
+ switch(current_pipe->dir)
+ {
+ case IN_PIPE:
+ mprintf(string, "\t\tINPUT_PIPE read: %i, write: %i remote:", current_pipe->pipe[0],
+ current_pipe->pipe[1]);
+ break;
+ case OUT_PIPE:
+ mprintf(string, "\t\tOUTPUT_PIPE read: %i, write: %i remote:", current_pipe->pipe[1],
+ current_pipe->pipe[0]);
+ break;
+ case BUFFERED_OUT_PIPE:
+ mprintf(string, "\t\tBUFFERED_OUTPUT_PIPE read: %i, write: %i remote:", current_pipe->pipe[1],
+ current_pipe->pipe[0]);
+ break;
+ default:
+ continue;
+ }
+
+ for(i=0;current_pipe->targets[i] > 0 && i<10;i++)
+ mprintf(string, " %i", current_pipe->targets[i]);
+
+ mprintf(string, "\n");
+ if (current_pipe->buffer && current_pipe->buffer_allocated > 0)
+ {
+ mprintf(string,
"\t\tBuffer (%i): \n########## BUFFER ##########\n%s\n##############################\n",
- p->buffer_allocated, p->buffer);
+ current_pipe->buffer_allocated, current_pipe->buffer);
+ }
}
+
}
Modified: initng/trunk/plugins/logfile/initng_logfile.c
==============================================================================
--- initng/trunk/plugins/logfile/initng_logfile.c (original)
+++ initng/trunk/plugins/logfile/initng_logfile.c Thu Jun 1 12:49:43 2006
@@ -50,8 +50,8 @@
assert(service->name);
assert(x);
- D_("%s process fd: # %i, %i, service %s, have something to say\n",
- x->pt->name, x->out_pipe[0], x->out_pipe[1], service->name);
+ /*D_("%s process fd: # %i, %i, service %s, have something to say\n",
+ x->pt->name, x->out_pipe[0], x->out_pipe[1], service->name);*/
/* get the filename */
filename = get_string(&LOGFILE, service);
Modified: initng/trunk/plugins/reload/initng_reload.c
==============================================================================
--- initng/trunk/plugins/reload/initng_reload.c (original)
+++ initng/trunk/plugins/reload/initng_reload.c Thu Jun 1 12:49:43 2006
@@ -72,14 +72,24 @@
while_active_db(service)
{
process_h *process = NULL;
-
+
while_processes(process, service)
{
- if (process->out_pipe[0] == fd)
+ pipe_h * current_pipe = NULL;
+ while_pipes(current_pipe, process)
{
- W_("Wont close fd %i, used by service \"%s\"\n", fd,
- service->name);
- return (TRUE);
+ if((current_pipe->dir == OUT_PIPE || current_pipe->dir == BUFFERED_OUT_PIPE) && current_pipe->pipe[0] == fd)
+ {
+ W_("Wont close output_pipe fd %i, used by service \"%s\"\n", fd,
+ service->name);
+ return (TRUE);
+ }
+ else if (current_pipe->dir == IN_PIPE && current_pipe->pipe[1] == fd)
+ {
+ W_("Wont close input_pipe fd %i, used by service \"%s\"\n", fd,
+ service->name);
+ return (TRUE);
+ }
}
}
}
@@ -208,13 +218,25 @@
/* fill the data */
process->pid = entry.process[pnr].pid;
- process->out_pipe[0] = entry.process[pnr].stdout1;
- process->out_pipe[1] = entry.process[pnr].stdout2;
+
+ {
+ pipe_h *op = i_calloc(1, sizeof(pipe_h));
+ if(!op)
+ {
+ free(process);
+ continue;
+ }
+
+ op->pipe[0] = entry.process[pnr].stdout1;
+ op->pipe[1] = entry.process[pnr].stdout2;
+ op->dir = BUFFERED_OUT_PIPE;
+ op->pipet = PIPE_STDOUT;
+ op->targets[0]=1;
+ op->targets[1]=2;
+ add_pipe(op, process);
+ }
process->r_code = entry.process[pnr].rcode;
- /* allocate a new output buffer for this process */
- process->buffer = NULL;
-
/* add this process to the list */
list_add(&process->list, &new_entry->processes.list);
@@ -290,6 +312,7 @@
active_db_h *current, *q = NULL;
data_save_struct entry;
process_h *process = NULL;
+ pipe_h *current_pipe = NULL;
int i;
int pnr = 0;
s_data *c_d = NULL;
@@ -334,8 +357,17 @@
strncpy(entry.process[pnr].ptype, process->pt->name,
MAX_PTYPE_STRING_LEN);
entry.process[pnr].pid = process->pid;
- entry.process[pnr].stdout1 = process->out_pipe[0];
- entry.process[pnr].stdout2 = process->out_pipe[1];
+
+ current_pipe=NULL;
+ while_pipes(current_pipe, process)
+ {
+ entry.process[pnr].stdout1 = current_pipe->pipe[0];
+ entry.process[pnr].stdout2 = current_pipe->pipe[1];
+
+ /* TODO, add them all! */
+ break;
+ }
+
entry.process[pnr].rcode = process->r_code;
pnr++;
if (pnr >= MAX_PROCESSES)
Modified: initng/trunk/src/initng_fd.c
==============================================================================
--- initng/trunk/src/initng_fd.c (original)
+++ initng/trunk/src/initng_fd.c Thu Jun 1 12:49:43 2006
@@ -93,16 +93,16 @@
* This function is called when data is polled below,
* or when a process is freed ( with flush_buffer set)
*/
-void initng_fd_process_read_input(active_db_h * service, process_h * p)
+void initng_fd_process_read_input(active_db_h * service, process_h * p, pipe_h * pi)
{
- int old_content_offset = p->buffer_len;
+ int old_content_offset = pi->buffer_len;
int read_ret = 0;
char *tmp;
D_("\ninitng_fd_process_read_input(%s, %s, %i);\n", service->name,
p->pt->name);
- if (p->out_pipe[0] <= 0)
+ if (pi->pipe[0] <= 0)
{
F_("FIFO, can't be read! NOT OPEN!\n");
return;
@@ -112,13 +112,13 @@
* if this are not set to out_pipe, if there is nothing to read. read() will block.
* initng and sit down waiting for input.
*/
- if (!p->buffer)
+ if (!pi->buffer)
{
/* initziate buffer fnctl */
int fd_flags;
- fd_flags = fcntl(p->out_pipe[0], F_GETFL, 0);
- fcntl(p->out_pipe[0], F_SETFL, fd_flags | O_NONBLOCK);
+ fd_flags = fcntl(pi->pipe[0], F_GETFL, 0);
+ fcntl(pi->pipe[0], F_SETFL, fd_flags | O_NONBLOCK);
}
/* read data from process, and continue again after a interrupt */
@@ -129,27 +129,27 @@
/* OBSERVE, i_realloc may change the path to the data, so dont set buffer_pos to early */
/* Make sure there is room for 100 more chars */
- D_("left: %i > %i\n", p->buffer_len + 100, p->buffer_allocated);
- if (p->buffer_len + 100 >= p->buffer_allocated)
+ D_("left: %i > %i\n", pi->buffer_len + 100, pi->buffer_allocated);
+ if (pi->buffer_len + 100 >= pi->buffer_allocated)
{
/* do a realloc */
- D_("Changing size of buffer %p to: %i\n", p->buffer,
- p->buffer_allocated + 100 + 1);
- tmp = i_realloc(p->buffer,
- (p->buffer_allocated + 100 + 1) * sizeof(char));
+ D_("Changing size of buffer %p to: %i\n", pi->buffer,
+ pi->buffer_allocated + 100 + 1);
+ tmp = i_realloc(pi->buffer,
+ (pi->buffer_allocated + 100 + 1) * sizeof(char));
/* make sure realloc suceeded */
if (tmp)
{
- D_("p->buffer changes from %p to %p.\n", p->buffer, tmp);
- p->buffer = tmp;
- p->buffer_allocated += 100;
+ D_("pi->buffer changes from %p to %p.\n", pi->buffer, tmp);
+ pi->buffer = tmp;
+ pi->buffer_allocated += 100;
/*
* make sure it nulls, specially when i_realloc is run for the verry first time
* and maby there is nothing to get by read
*/
- p->buffer[p->buffer_len] = '\0';
+ pi->buffer[pi->buffer_len] = '\0';
}
else
{
@@ -160,7 +160,7 @@
/* read the data */
D_("Reading 100 chars.\n");
- read_ret = read(p->out_pipe[0], &p->buffer[p->buffer_len], 100);
+ read_ret = read(pi->pipe[0], &pi->buffer[pi->buffer_len], 100);
/*printf("read_ret = %i : \"%.100s\"\n", read_ret, read_pos); */
/* make sure read does not return -1 */
@@ -168,10 +168,10 @@
break;
/* increase buffer_len */
- p->buffer_len += read_ret;
+ pi->buffer_len += read_ret;
/* make sure its nulled at end */
- p->buffer[p->buffer_len] = '\0';
+ pi->buffer[pi->buffer_len] = '\0';
}
/* if read_ret == 100, it migit be more to read, or it got interrupted. */
while (read_ret >= 100 || errno == EINTR);
@@ -179,19 +179,19 @@
/* make sure there is any */
- if (p->buffer_len > old_content_offset)
+ if (pi->buffer_len > old_content_offset)
{
/* let all plugin take part of data */
- initng_fd_plugin_readpipe(service, p, p->buffer + old_content_offset);
+ initng_fd_plugin_readpipe(service, p, pi->buffer + old_content_offset);
}
/*if empty, dont waist memory */
- if (p->buffer_len == 0 && p->buffer)
+ if (pi->buffer_len == 0 && pi->buffer)
{
- free(p->buffer);
- p->buffer = NULL;
- p->buffer_allocated = 0;
- p->buffer_len = 0;
+ free(pi->buffer);
+ pi->buffer = NULL;
+ pi->buffer_allocated = 0;
+ pi->buffer_len = 0;
}
@@ -202,40 +202,40 @@
if (read_ret == 0)
{
D_("Closing fifos for %s.\n", service->name);
- if (p->out_pipe[0] > 0)
- close(p->out_pipe[0]);
- if (p->out_pipe[1] > 0)
- close(p->out_pipe[1]);
- p->out_pipe[0] = -1;
- p->out_pipe[1] = -1;
+ if (pi->pipe[0] > 0)
+ close(pi->pipe[0]);
+ if (pi->pipe[1] > 0)
+ close(pi->pipe[1]);
+ pi->pipe[0] = -1;
+ pi->pipe[1] = -1;
/* else, realloc to exact size */
- if (p->buffer && p->buffer_allocated > (p->buffer_len + 1))
+ if (pi->buffer && pi->buffer_allocated > (pi->buffer_len + 1))
{
- tmp = i_realloc(p->buffer, (p->buffer_len + 1) * sizeof(char));
+ tmp = i_realloc(pi->buffer, (pi->buffer_len + 1) * sizeof(char));
if (tmp)
{
- p->buffer = tmp;
- p->buffer_allocated = p->buffer_len;
+ pi->buffer = tmp;
+ pi->buffer_allocated = pi->buffer_len;
}
}
return;
}
/* if buffer reached 10000 chars */
- if (p->buffer_len > 10000)
+ if (pi->buffer_len > 10000)
{
/* copy the last 9000 chars to start */
- memmove(p->buffer, &p->buffer[p->buffer_len - 9000],
+ memmove(pi->buffer, &pi->buffer[pi->buffer_len - 9000],
9000 * sizeof(char));
/* rezise the buffer - leave some expansion space! */
- tmp = i_realloc(p->buffer, 9501 * sizeof(char));
+ tmp = i_realloc(pi->buffer, 9501 * sizeof(char));
/* make sure realloc suceeded */
if (tmp)
{
- p->buffer = tmp;
- p->buffer_allocated = 9500;
+ pi->buffer = tmp;
+ pi->buffer_allocated = 9500;
}
else
{
@@ -244,8 +244,8 @@
/* Even if realloc failed, the buffer is still valid
and we've still reduced the length of its contents */
- p->buffer_len = 9000; /* shortened by 1000 chars */
- p->buffer[9000] = '\0'; /* shortened by 1000 chars */
+ pi->buffer_len = 9000; /* shortened by 1000 chars */
+ pi->buffer[9000] = '\0'; /* shortened by 1000 chars */
}
}
@@ -277,6 +277,7 @@
active_db_h *currentA, *qA;
s_call *currentC, *qC;
process_h *currentP, *qP;
+ pipe_h * current_pipe;
/* initialization */
S_;
@@ -321,10 +322,16 @@
currentP = NULL;
while_processes(currentP, currentA)
{
- if (currentP->out_pipe[0] > 2)
+ current_pipe = NULL;
+ while_pipes(current_pipe, currentP)
{
- FD_SET(currentP->out_pipe[0], &readset);
- added++;
+ if ((current_pipe->dir == OUT_PIPE ||
+ current_pipe->dir == BUFFERED_OUT_PIPE) &&
+ current_pipe->pipe[0] > 2)
+ {
+ FD_SET(current_pipe->pipe[0], &readset);
+ added++;
+ }
}
}
}
@@ -416,18 +423,27 @@
/* and all the processes */
while_processes_safe(currentP, qP, currentA)
{
- /* if matching */
- if (currentP->out_pipe[0] > 2
- && FD_ISSET(currentP->out_pipe[0], &readset))
+ current_pipe = NULL;
+
+ /* check if this fd is a pipe bound to a process */
+ while_pipes(current_pipe, currentP)
{
- D_("Will read from %s->start_process on fd #%i\n",
- currentA->name, currentP->out_pipe[0]);
- /* Do the actual read from pipe */
- initng_fd_process_read_input(currentA, currentP);
- /* Found match, that means we need to look for one less, if we've found all we should then return */
- retval--;
- if (retval == 0)
- return;
+ /* if this pipe is a process output pipe, and the pipe are opend, and if
+ * there is data on it */
+ if((current_pipe->dir == OUT_PIPE || current_pipe->dir == BUFFERED_OUT_PIPE)&& current_pipe->pipe[0] > 2 &&
+ FD_ISSET(current_pipe->pipe[0], &readset))
+ {
+ D_("Will read from %s->start_process on fd #%i\n",
+ currentA->name, current_pipe->pipe[0]);
+
+ /* Do the actual read from pipe */
+ initng_fd_process_read_input(currentA, currentP, current_pipe);
+
+ /* Found match, that means we need to look for one less, if we've found all we should then return */
+ retval--;
+ if (retval == 0)
+ return;
+ }
}
}
}
Modified: initng/trunk/src/initng_fd.h
==============================================================================
--- initng/trunk/src/initng_fd.h (original)
+++ initng/trunk/src/initng_fd.h Thu Jun 1 12:49:43 2006
@@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-void initng_fd_process_read_input(active_db_h * service, process_h * p);
+void initng_fd_process_read_input(active_db_h * service, process_h * p, pipe_h * pipe);
void initng_fd_close_all(void);
void initng_fd_plugin_poll(int timeout);
+
Modified: initng/trunk/src/initng_fork.c
==============================================================================
--- initng/trunk/src/initng_fork.c (original)
+++ initng/trunk/src/initng_fork.c Thu Jun 1 12:49:43 2006
@@ -43,6 +43,30 @@
#include "initng_fork.h"
+/*
+ * This function creates a new pipe, and creates a new
+ * pipe struct entry.
+ */
+static pipe_h * pipe_new(e_pipet type, e_dir dir)
+{
+ pipe_h * pipe_struct = i_calloc(1, sizeof(pipe_h));
+ if(!pipe_struct)
+ return(NULL);
+
+ if(pipe(pipe_struct->pipe) != 0)
+ {
+ F_("Failed adding pipe ! %s\n", strerror(errno));
+ free(pipe_struct);
+ return(NULL);
+ }
+
+ /* set the type */
+ pipe_struct->pipet = type;
+ pipe_struct->dir = dir;
+
+ /* return the pointer */
+ return(pipe_struct);
+}
pid_t initng_fork(active_db_h * service, process_h * process)
{
@@ -50,25 +74,51 @@
pid_t pid_fork; /* pid got from fork() */
int try_count = 0; /* Count tryings */
s_call *current = NULL;
+ pipe_h * current_pipe = NULL; /* used while walking */
+ pipe_h * safe = NULL;
assert(service);
assert(process);
-
- /* open pipe */
- if (pipe(process->out_pipe) != 0)
+
+ /* close all existing pipes first */
+ while_pipes_safe(current_pipe, process, safe)
{
- F_("Failed adding pipe ! %s\n", strerror(errno));
- return (-1);
+ list_del(¤t_pipe->list);
+ if(current_pipe->buffer)
+ free(current_pipe->buffer);
+ free(current_pipe);
}
-
- /* alloc buffer */
- if (process->buffer)
+
+ /* create the output pipe */
+ current_pipe = pipe_new(PIPE_STDOUT, BUFFERED_OUT_PIPE);
+ if(current_pipe)
{
- free(process->buffer);
- process->buffer = NULL;
- process->buffer_allocated = 0;
+ /* we want this pipe to get fd 1 and 2 in the fork */
+ current_pipe->targets[0]=STDOUT_FILENO;
+ current_pipe->targets[1]=STDERR_FILENO;
+ add_pipe(current_pipe, process);
}
-
+
+ /* create the control in pipe */
+ current_pipe = pipe_new(PIPE_CTRL_IN, IN_PIPE);
+ if(current_pipe)
+ {
+ /* we want this pipe to get fd 3, in the fork */
+ current_pipe->targets[0]=3;
+ add_pipe(current_pipe, process);
+ }
+
+ /* create the control out pipe */
+ current_pipe = pipe_new(PIPE_CTRL_OUT, BUFFERED_OUT_PIPE);
+ if(current_pipe)
+ {
+ /* we want this pipe to get fd 4, in the fork */
+ current_pipe->targets[0]=4;
+ add_pipe(current_pipe, process);
+ }
+
+ /* reset, used for walking later */
+ current_pipe = NULL;
/* Try to fork 30 times */
while ((pid_fork = fork()) == -1)
@@ -112,25 +162,32 @@
* the other are mapped to STDOUT and STDERR.
*/
- /* close stdin/stdout/stderr */
- /*close(STDIN_FILENO); */
- close(STDOUT_FILENO);
- close(STDERR_FILENO);
-
- /* Duplicate stdout and stderr to the stdout[1] */
- dup2(process->out_pipe[1], STDOUT_FILENO);
- dup2(process->out_pipe[1], STDERR_FILENO);
-
- /* set stdin, stdout, and stderr, that is should not be closed, if this child do execve() */
- fcntl(STDIN_FILENO, F_SETFD, 0);
- fcntl(STDOUT_FILENO, F_SETFD, 0);
- fcntl(STDERR_FILENO, F_SETFD, 0);
-
- /* Close the sides of the pipes we don't need, as we're in fork we won't need this part. */
- if (process->out_pipe[0] > 0)
- close(process->out_pipe[0]);
- process->out_pipe[0] = -1;
-
+ /* walk thru all the added pipes */
+ while_pipes(current_pipe, process)
+ {
+ int i;
+
+ /* for every target */
+ for(i=0; current_pipe->targets[i]>0 && i<10;i++)
+ {
+ /* close any conflicting one */
+ close(current_pipe->targets[i]);
+
+ if(current_pipe->dir == OUT_PIPE || current_pipe->dir == BUFFERED_OUT_PIPE)
+ {
+ /* duplicate the new target right */
+ dup2(current_pipe->pipe[1], current_pipe->targets[i]);
+ }
+ else if (current_pipe->dir == IN_PIPE)
+ {
+ /* duplicate the input pipe instead */
+ dup2(current_pipe->pipe[0], current_pipe->targets[i]);
+ }
+
+ /* IMPORTANT Tell the os not to close the new target on execve */
+ fcntl(current_pipe->targets[i], F_SETFD, 0);
+ }
+ }
}
/* There might be plug-ins that will work here */
@@ -144,13 +201,6 @@
}
}
- /* close all open fds, except STDIN, STDOUT, STDERR (0, 1, 2) */
- {
- int i;
-
- for (i = 3; i <= 1013; i++)
- close(i);
- }
/* TODO, what does this do? */
if (g.i_am == I_AM_INIT)
@@ -163,11 +213,26 @@
}
else
{
+
+ /* walk all pipes and close all remote sides of pipes */
+ while_pipes(current_pipe, process)
+ {
+ if(current_pipe->dir == OUT_PIPE || current_pipe->dir == BUFFERED_OUT_PIPE)
+ {
+ if(current_pipe->pipe[1] > 0)
+ close(current_pipe->pipe[1]);
+ current_pipe->pipe[1]=-1;
+ }
+ /* close the OUTPUT end */
+ else if(current_pipe->dir == IN_PIPE)
+ {
+ if(current_pipe->pipe[0] > 0)
+ close(current_pipe->pipe[0]);
+ current_pipe->pipe[0]=-1;
+ }
+ }
- /* close the receiving end on pipe, on parent */
- if (process->out_pipe[1] > 0)
- close(process->out_pipe[1]);
- process->out_pipe[1] = -1;
+ /* set process->pid if lucky */
if (pid_fork > 0)
{
process->pid = pid_fork;
Modified: initng/trunk/src/initng_kill_handler.c
==============================================================================
--- initng/trunk/src/initng_kill_handler.c (original)
+++ initng/trunk/src/initng_kill_handler.c Thu Jun 1 12:49:43 2006
@@ -55,6 +55,7 @@
/* The process that got killed */
active_db_h *service = NULL;
process_h *process = NULL;
+ pipe_h *current_pipe = NULL;
D_("handle_killed_by_pid(%i);\n", kpid);
@@ -86,25 +87,27 @@
process->r_code = r_code;
- /*
- * Close the process output fifos to initng.
- */
- if (process->out_pipe[0] > 0)
- {
- /*
- * calling initng_process_read_input, Make sure all buffers read, before closing them.
- */
- initng_fd_process_read_input(service, process);
-
- /* now close */
- close(process->out_pipe[0]);
- process->out_pipe[0] = 0;
- }
- if (process->out_pipe[1] > 0)
+ /* close all pipes */
+ while_pipes(current_pipe, process)
{
- close(process->out_pipe[1]);
- process->out_pipe[1] = 0;
- }
+ if((current_pipe->dir == OUT_PIPE || current_pipe->dir == BUFFERED_OUT_PIPE)&& current_pipe->pipe[0] > 0)
+ {
+ /*
+ * calling initng_process_read_input, Make sure all buffers read, before closing them.
+ */
+ initng_fd_process_read_input(service, process, current_pipe);
+
+ /* now close */
+ close(current_pipe->pipe[0]);
+ current_pipe->pipe[0] = -1;
+ }
+
+ else if(current_pipe->dir == IN_PIPE && current_pipe->pipe[1] > 0)
+ {
+ close(current_pipe->pipe[1]);
+ current_pipe->pipe[1]= -1;
+ }
+ }
/* Check if a plugin wants to override handle_killed behavior */
if (initng_plugin_callers_handle_killed(service, process))
Modified: initng/trunk/src/initng_process_db.c
==============================================================================
--- initng/trunk/src/initng_process_db.c (original)
+++ initng/trunk/src/initng_process_db.c Thu Jun 1 12:49:43 2006
@@ -58,6 +58,8 @@
/* Set this to active, so it wont get freed */
new_p->pst = P_ACTIVE;
+ INIT_LIST_HEAD(&new_p->pipes.list);
+
/* return new process_h pointer */
return (new_p);
}
@@ -151,17 +153,31 @@
/* function to free a process_h struct */
void initng_process_db_real_free(process_h * free_this)
{
+ pipe_h * current_pipe = NULL;
+ pipe_h * current_pipe_safe = NULL;
assert(free_this);
/* Make sure this entry are not on any list */
list_del(&free_this->list);
- if (free_this->out_pipe[0] > 0)
- close(free_this->out_pipe[0]);
- if (free_this->out_pipe[1] > 0)
- close(free_this->out_pipe[1]);
- if (free_this->buffer)
- free(free_this->buffer);
+ while_pipes_safe(current_pipe, free_this, current_pipe_safe)
+ {
+ /* unbound this pipe from list */
+ list_del(¤t_pipe->list);
+
+ /* close all pipes */
+ if(current_pipe->pipe[0] > 0)
+ close(current_pipe->pipe[0]);
+ if(current_pipe->pipe[1] > 0)
+ close(current_pipe->pipe[1]);
+
+ /* free buffer */
+ if(current_pipe->buffer)
+ free(current_pipe->buffer);
+
+ /* free it */
+ free(current_pipe);
+ }
free(free_this);
return;
Modified: initng/trunk/src/initng_process_db.h
==============================================================================
--- initng/trunk/src/initng_process_db.h (original)
+++ initng/trunk/src/initng_process_db.h Thu Jun 1 12:49:43 2006
@@ -44,6 +44,48 @@
P_FREE = 1,
} e_pst;
+/* the types that can be set to a pipe list */
+typedef enum
+{
+ PIPE_UNKNOWN = 0,
+ PIPE_STDOUT = 1,
+ PIPE_STDIN = 2,
+ PIPE_CTRL_OUT = 3,
+ PIPE_CTRL_IN = 4,
+} e_pipet;
+
+typedef enum
+{
+ UNKNOWN_PIPE = 0,
+ OUT_PIPE = 1,
+ IN_PIPE = 2,
+ BUFFERED_OUT_PIPE = 3
+} e_dir;
+
+/* the pipe identifier */
+typedef struct
+{
+ /* this array contains the pipe fds */
+ int pipe[2];
+
+ /* Whats this type?, this will be a pointer to a struct in the future */
+ e_pipet pipet;
+
+ /* The direction of the stream, an OUTPUT or INPUT ?? */
+ e_dir dir;
+
+ /* If targets set (max 10) the fd are duped after fork to match targets */
+ int targets[10];
+
+ /* If this pipe is a BUFFERED_OUT_PIPE stor a buffer here */
+ char *buffer; /* stdout buffer ## THE BEGINNING ## */
+ int buffer_allocated; /* chars right now allocated for this buffer */
+ int buffer_len; /* the count of chars from the beginning in buffer right now */
+
+ /* The list entry */
+ struct list_head list;
+} pipe_h;
+
struct t_process_h
{
ptype_h *pt;
@@ -55,10 +97,11 @@
* example exit_code = WEXITSTATUS(process->r_code);
*/
int r_code;
- int out_pipe[2]; /* pipes of process */
- char *buffer; /* stdout buffer ## THE BEGINNING ## */
- int buffer_allocated; /* chars right now allocated for this buffer */
- int buffer_len; /* the count of chars from the beginning in buffer right now */
+
+ /* This is a list of pipes open to this process */
+ pipe_h pipes;
+
+ /* small mark, this process are not freed directly this will be set to P_FREE */
e_pst pst;
struct list_head list; /* this process should be in a list */
@@ -103,5 +146,9 @@
/* add the process to our service */
#define add_process(pss, sss) list_add(&(pss)->list, &(sss)->processes.list);
+/* used for browing pipes */
+#define add_pipe(PIPE, PROCESS) list_add(&(PIPE)->list, &(PROCESS)->pipes.list);
+#define while_pipes(CURRENT, PROCESS) list_for_each_entry_prev(CURRENT, &(PROCESS)->pipes.list, list)
+#define while_pipes_safe(CURRENT, PROCESS, SAFE) list_for_each_entry_prev_safe(CURRENT, SAFE, &(PROCESS)->pipes.list, list)
#endif
More information about the Initng-svn
mailing list