[Initng-svn] r4333 - in initng/trunk: plugins/bash_parser

svn at initng.thinktux.net svn at initng.thinktux.net
Thu Jun 1 13:04:39 CEST 2006


Author: jimmy
Date: Thu Jun  1 13:04:37 2006
New Revision: 4333

Modified:
   initng/trunk/plugins/bash_parser/initng_bash_parser.c
   initng/trunk/src/initng_fork.c
   initng/trunk/src/initng_process_db.c
   initng/trunk/src/initng_process_db.h

Log:
Finnaly, we mab add pipes to only some forks,
there are still missing an hook to fetch pipe data from initng_fd.c but i fix
that when i get home from work.


Modified: initng/trunk/plugins/bash_parser/initng_bash_parser.c
==============================================================================
--- initng/trunk/plugins/bash_parser/initng_bash_parser.c	(original)
+++ initng/trunk/plugins/bash_parser/initng_bash_parser.c	Thu Jun  1 13:04:37 2006
@@ -631,6 +631,7 @@
 	struct stat fstat;
 	active_db_h *new_active;
 	process_h *process;
+	pipe_h *current_pipe;
 
 	/* check if initfile exists */
 	strncat(file, name, 1020 - strlen(SCRIPT_PATH));
@@ -673,6 +674,24 @@
 	/* bound to service */
 	add_process(process, new_active);
 
+	/* 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);
+	}
+
 	/* start parse process */
 	if (initng_fork(new_active, process) == 0)
 	{

Modified: initng/trunk/src/initng_fork.c
==============================================================================
--- initng/trunk/src/initng_fork.c	(original)
+++ initng/trunk/src/initng_fork.c	Thu Jun  1 13:04:37 2006
@@ -43,32 +43,6 @@
 #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)
 {
 	/* This is the real service kicker */
@@ -76,46 +50,18 @@
 	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);
 
-	/* close all existing pipes first */
-	while_pipes_safe(current_pipe, process, safe)
-	{
-		list_del(&current_pipe->list);
-		if (current_pipe->buffer)
-			free(current_pipe->buffer);
-		free(current_pipe);
-	}
-
-	/* create the output pipe */
-	current_pipe = pipe_new(PIPE_STDOUT, BUFFERED_OUT_PIPE);
-	if (current_pipe)
-	{
-		/* 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)
+	/* Create all pipes */
+	while_pipes(current_pipe, process)
 	{
-		/* 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);
+		if (pipe(current_pipe->pipe) != 0)
+		{
+			F_("Failed adding pipe ! %s\n", strerror(errno));
+			return (-1);
+		}
 	}
 
 	/* reset, used for walking later */

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 13:04:37 2006
@@ -34,10 +34,32 @@
 
 #include "initng_toolbox.h"
 
+
+
+/*
+ * This function creates a new pipe, and creates a new
+ * pipe struct entry.
+ */
+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);
+
+	/* set the type */
+	pipe_struct->pipet = type;
+	pipe_struct->dir = dir;
+
+	/* return the pointer */
+	return (pipe_struct);
+}
+
 /* creates a process_h struct with defaults */
 process_h *initng_process_db_new(ptype_h * type)
 {
 	process_h *new_p = NULL;
+	pipe_h * current_pipe;
 
 	/* allocate a new process entry */
 	new_p = (process_h *) i_calloc(1, sizeof(process_h));	/* Allocate memory for a new process */
@@ -58,8 +80,22 @@
 	/* Set this to active, so it wont get freed */
 	new_p->pst = P_ACTIVE;
 
+	/* initziate list of pipes, so we can run add_pipe below without segfault */
 	INIT_LIST_HEAD(&new_p->pipes.list);
 
+	/* create the output pipe */
+	current_pipe = pipe_new(PIPE_STDOUT, BUFFERED_OUT_PIPE);
+	if (!current_pipe)
+	{
+		free(new_p);
+		return(NULL);
+	}
+	
+	/* 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, new_p);
+
 	/* return new process_h pointer */
 	return (new_p);
 }

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 13:04:37 2006
@@ -147,6 +147,7 @@
 #define add_process(pss, sss) list_add(&(pss)->list, &(sss)->processes.list);
 
 /* used for browing pipes */
+pipe_h * pipe_new(e_pipet type, e_dir dir);
 #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)


More information about the Initng-svn mailing list