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

svn at initng.thinktux.net svn at initng.thinktux.net
Sun Jun 4 13:12:31 CEST 2006


Author: jimmy
Date: Sun Jun  4 13:12:30 2006
New Revision: 4352

Modified:
   initng/trunk/plugins/bash_parser/initng_bash_parser.c
   initng/trunk/plugins/ngc4/initng_ngc4.c
   initng/trunk/src/initng.h
   initng/trunk/src/initng_fd.c
   initng/trunk/src/initng_global.c
   initng/trunk/src/initng_global.h
   initng/trunk/src/initng_plugin.h

Log:
Working on bash_parser comunicating over a pipe.


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	Sun Jun  4 13:12:30 2006
@@ -632,6 +632,7 @@
 	active_db_h *new_active;
 	process_h *process;
 	pipe_h *current_pipe;
+	printf("create_new_active(%s);\n", name);
 
 	/* check if initfile exists */
 	strncat(file, name, 1020 - strlen(SCRIPT_PATH));
@@ -709,6 +710,38 @@
 	return (new_active);
 }
 
+static int get_pipe(active_db_h * service, process_h * process, pipe_h * pi)
+{
+	char buffer[1025];
+	int r;
+	
+	/* extra check */
+	if(pi->dir != OUT_PIPE)
+		return(FALSE);
+
+	/* the pipe we opened was on fd 3 */
+	if(pi->targets[0] != 3)
+		return(FALSE);
+		
+	r=read(pi->pipe[0], buffer, 1024);
+	
+	
+	/* if the other side closed the connection ... */
+	if(r==0)
+	{
+		close(pi->pipe[0]);
+		pi->pipe[0]=-1;
+	}
+	
+	if(r>0)
+	{
+		/* terminate end, read does not do that */
+		buffer[r]='\0';	
+		printf("LOOK: \"%s\"\n", buffer);
+	}
+	
+	return(TRUE);
+}
 
 int module_init(int api_version)
 {
@@ -728,6 +761,7 @@
 	initng_plugin_hook_register(&g.FDWATCHERS, 30, &bpf);
 	initng_plugin_hook_register(&g.SIGNAL, 50, &bp_check_socket);
 	initng_plugin_hook_register(&g.NEW_ACTIVE, 50, &create_new_active);
+	initng_plugin_hook_register(&g.PIPE_WATCHER, 30, &get_pipe);
 	initng_active_state_register(&PARSING);
 	initng_active_state_register(&PARSE_FAIL);
 
@@ -749,6 +783,7 @@
 	initng_plugin_hook_unregister(&g.FDWATCHERS, &bpf);
 	initng_plugin_hook_unregister(&g.SIGNAL, &bp_check_socket);
 	initng_plugin_hook_unregister(&g.NEW_ACTIVE, &create_new_active);
+	initng_plugin_hook_unregister(&g.PIPE_WATCHER, &get_pipe);
 	initng_active_state_unregister(&PARSING);
 	initng_active_state_unregister(&PARSE_FAIL);
 }

Modified: initng/trunk/plugins/ngc4/initng_ngc4.c
==============================================================================
--- initng/trunk/plugins/ngc4/initng_ngc4.c	(original)
+++ initng/trunk/plugins/ngc4/initng_ngc4.c	Sun Jun  4 13:12:30 2006
@@ -924,7 +924,7 @@
 	row->dt = ACTIVE_ROW;
 
 	/* argument required */
-	if (!arg || strlen(arg) < 2)
+	if (!arg || strlen(arg) < 1)
 	{
 		strcpy(row->state, "NOT_FOUND");
 		row->is = IS_FAILED;

Modified: initng/trunk/src/initng.h
==============================================================================
--- initng/trunk/src/initng.h	(original)
+++ initng/trunk/src/initng.h	Sun Jun  4 13:12:30 2006
@@ -56,7 +56,7 @@
 #define INITNG_CREATOR "Jimmy Wennlund <jimmy.wennlund at gmail.com>"
 
 /* Add to this counter everytime the api changes, and plugins need to recompile */
-#define API_VERSION 17
+#define API_VERSION 18
 
 /* define this macro in start of every plugin to check api version */
 #define INITNG_PLUGIN_MACRO int plugin_api_version = API_VERSION;

Modified: initng/trunk/src/initng_fd.c
==============================================================================
--- initng/trunk/src/initng_fd.c	(original)
+++ initng/trunk/src/initng_fd.c	Sun Jun  4 13:12:30 2006
@@ -89,6 +89,21 @@
 }
 
 
+/* if there is data incomming in a pipe, tell the plugins */
+static int initng_fd_pipe(active_db_h * service, process_h * process, pipe_h * pi)
+{
+	s_call *current = NULL;
+
+	while_list(current, &g.PIPE_WATCHER)
+	{
+		if ((*current->c.pipe_watcher) (service, process, pi) == TRUE)
+			return(TRUE);
+	}
+
+	return(FALSE);
+}
+
+
 /*
  * This function is called when data is polled below,
  * or when a process is freed ( with flush_buffer set)
@@ -334,6 +349,13 @@
 					FD_SET(current_pipe->pipe[0], &readset);
 					added++;
 				}
+				
+				if (current_pipe->dir == IN_PIPE &&
+				    current_pipe->pipe[1] > 2)
+				{
+					FD_SET(current_pipe->pipe[1], &writeset);
+					added++;
+				}
 			}
 		}
 	}
@@ -452,7 +474,7 @@
 				   current_pipe->pipe[0] > 2 &&
 				   FD_ISSET(current_pipe->pipe[0], &readset))
 				{
-					D_("TODO, call pipe watchers...\n");
+					initng_fd_pipe(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--;
@@ -460,6 +482,19 @@
 						return;
 				}
 					
+
+				if(current_pipe->dir == IN_PIPE &&
+				   current_pipe->pipe[1] > 2 &&
+				   FD_ISSET(current_pipe->pipe[1], &writeset))
+				{
+					initng_fd_pipe(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_global.c
==============================================================================
--- initng/trunk/src/initng_global.c	(original)
+++ initng/trunk/src/initng_global.c	Sun Jun  4 13:12:30 2006
@@ -126,6 +126,7 @@
 	INIT_LIST_HEAD(&g.STOP_DEP_MET.list);
 	INIT_LIST_HEAD(&g.UP_MET.list);
 	INIT_LIST_HEAD(&g.NEW_ACTIVE.list);
+	INIT_LIST_HEAD(&g.PIPE_WATCHER.list);
 
 	/*
 	 * default global variables - cleared by memset above

Modified: initng/trunk/src/initng_global.h
==============================================================================
--- initng/trunk/src/initng_global.h	(original)
+++ initng/trunk/src/initng_global.h	Sun Jun  4 13:12:30 2006
@@ -72,7 +72,7 @@
 	s_call ADDITIONAL_PARSE;	/* Called after a service been parsed, and extra parsing may exist */
 	s_call SWATCHERS;			/* Called when system state changes */
 	s_call FDWATCHERS;			/* Called when initng open file descriptors receive data */
-	s_call BUFFER_WATCHER;		/* Called when a service has some output, that initng received */
+	s_call BUFFER_WATCHER;		/* Called when a service have outputed, and initng have filled its output buffer. */
 	s_call SIGNAL;				/* Called when initng rescives a signal, like SIGHUP */
 	s_call MAIN;				/* Called every main loop */
 	s_call A_FORK;				/* Called after a process forks to start */
@@ -84,6 +84,7 @@
 	s_call RELOAD_ACTIVE_DB;	/* Asks for a plugin willing to reload the active_db from a dump */
 	s_call DEP_ON;				/* Called when a function tries to find out a service dependency */
 	s_call NEW_ACTIVE;			/* Called when initng trys to resolve a nonexistive service to start */
+	s_call PIPE_WATCHER;		/* watch pipes for communication */
 
 	/* new ones */
 	s_call IS_CHANGE;			/* Called when the rough state of a service changes */

Modified: initng/trunk/src/initng_plugin.h
==============================================================================
--- initng/trunk/src/initng_plugin.h	(original)
+++ initng/trunk/src/initng_plugin.h	Sun Jun  4 13:12:30 2006
@@ -50,6 +50,7 @@
 	void (*swatcher) (h_sys_state state);
 	int (*buffer_watcher) (active_db_h * service, process_h * process, pipe_h * pi,
 						char *buffer_pos);
+	int (*pipe_watcher) (active_db_h * service, process_h * process, pipe_h * pi);
 	int (*launch) (active_db_h * service, process_h * process,
 				   const char *exec_name);
 	int (*af_launcher) (active_db_h * service, process_h * process);


More information about the Initng-svn mailing list