[Initng-svn] r4354 - in initng/trunk: plugins/bash_parser
svn at initng.thinktux.net
svn at initng.thinktux.net
Sun Jun 4 13:58:07 CEST 2006
Author: jimmy
Date: Sun Jun 4 13:58:06 2006
New Revision: 4354
Modified:
initng/trunk/plugins/bash_parser/initng_bash_parser.c
initng/trunk/src/initng_fd.c
initng/trunk/src/initng_fork.c
initng/trunk/src/initng_process_db.h
Log:
FINALLY, managed to get up an unidirectional 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:58:06 2006
@@ -675,8 +675,8 @@
/* bound to service */
add_process(process, new_active);
- /* create the control in pipe */
- current_pipe = pipe_new(PIPE_CTRL_IN, IN_PIPE);
+ /* create and unidirectional pipe */
+ current_pipe = pipe_new(PIPE_CTRL_IN, IN_AND_OUT_PIPE);
if (current_pipe)
{
/* we want this pipe to get fd 3, in the fork */
@@ -684,15 +684,6 @@
add_pipe(current_pipe, process);
}
- /* create the control out pipe */
- current_pipe = pipe_new(PIPE_CTRL_OUT, 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)
{
@@ -715,22 +706,24 @@
char buffer[1025];
int r;
+ printf("Got and get_pipe: %s, %i, %i\n", service->name, pi->dir, pi->targets[0]);
+
/* extra check */
- if(pi->dir != OUT_PIPE)
+ if(pi->dir != IN_AND_OUT_PIPE)
return(FALSE);
/* the pipe we opened was on fd 3 */
- if(pi->targets[0] != 4)
+ if(pi->targets[0] != 3)
return(FALSE);
- r=read(pi->pipe[0], buffer, 1024);
+ r=read(pi->pipe[1], buffer, 1024);
/* if the other side closed the connection ... */
if(r==0)
{
- close(pi->pipe[0]);
- pi->pipe[0]=-1;
+ close(pi->pipe[1]);
+ pi->pipe[1]=-1;
}
if(r>0)
Modified: initng/trunk/src/initng_fd.c
==============================================================================
--- initng/trunk/src/initng_fd.c (original)
+++ initng/trunk/src/initng_fd.c Sun Jun 4 13:58:06 2006
@@ -350,6 +350,13 @@
added++;
}
+ if (current_pipe->dir == IN_AND_OUT_PIPE &&
+ current_pipe->pipe[1] > 2)
+ {
+ FD_SET(current_pipe->pipe[1], &readset);
+ added++;
+ }
+
if (current_pipe->dir == IN_PIPE &&
current_pipe->pipe[1] > 2)
{
@@ -482,6 +489,17 @@
return;
}
+ if(current_pipe->dir == IN_AND_OUT_PIPE &&
+ current_pipe->pipe[1] > 2 &&
+ FD_ISSET(current_pipe->pipe[1], &readset))
+ {
+ 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;
+ }
if(current_pipe->dir == IN_PIPE &&
current_pipe->pipe[1] > 2 &&
Modified: initng/trunk/src/initng_fork.c
==============================================================================
--- initng/trunk/src/initng_fork.c (original)
+++ initng/trunk/src/initng_fork.c Sun Jun 4 13:58:06 2006
@@ -22,8 +22,10 @@
#include <time.h> /* time() */
#include <fcntl.h> /* fcntl() */
#include <unistd.h> /* execv() pipe() usleep() pause() chown() pid_t */
+#include <sys/types.h>
#include <sys/wait.h> /* waitpid() sa */
#include <sys/ioctl.h> /* ioctl() */
+#include <sys/socket.h> /* socketpair() */
#include <stdlib.h> /* free() exit() */
#include <stdio.h>
#include <string.h>
@@ -57,10 +59,24 @@
/* Create all pipes */
while_pipes(current_pipe, process)
{
- if (pipe(current_pipe->pipe) != 0)
+ if(current_pipe->dir == IN_AND_OUT_PIPE)
{
- F_("Failed adding pipe ! %s\n", strerror(errno));
- return (-1);
+ /*printf("calling socketpair:\n");*/
+ /* create an two directional pipe with socketpair */
+ if(socketpair(AF_UNIX, SOCK_STREAM, 0, current_pipe->pipe) < 0)
+ {
+ F_("Fail call socketpair: \"%s\"\n", strerror(errno));
+ return (-1);
+ }
+ /* printf("parent: fd%i fork: fd%i\n", current_pipe->pipe[1], current_pipe->pipe[0]); */
+
+ } else {
+ /* create an one directional pipe with pipe */
+ if (pipe(current_pipe->pipe) != 0)
+ {
+ F_("Failed adding pipe ! %s\n", strerror(errno));
+ return (-1);
+ }
}
}
@@ -131,8 +147,15 @@
/* duplicate the input pipe instead */
dup2(current_pipe->pipe[0], current_pipe->targets[i]);
}
+ else if (current_pipe->dir == IN_AND_OUT_PIPE)
+ {
+ /* in a unidirectional socket, there is pipe[0] that is used in the child */
+ /*printf("dup2(%i, %i);\n", current_pipe->pipe[0], current_pipe->targets[i]);*/
+ dup2(current_pipe->pipe[0], current_pipe->targets[i]);
+ } else continue;
/* IMPORTANT Tell the os not to close the new target on execve */
+ /*printf("Put non close: fd%i\n", current_pipe->targets[i]);*/
fcntl(current_pipe->targets[i], F_SETFD, 0);
}
}
@@ -179,6 +202,15 @@
close(current_pipe->pipe[0]);
current_pipe->pipe[0] = -1;
}
+
+ else if (current_pipe->dir == IN_AND_OUT_PIPE)
+ {
+ /* in an unidirectional pipe, pipe[0] is fork, and pipe[1] is parrent */
+ /*printf("parrent closing: fd%i\n", current_pipe->pipe[0]);*/
+ if (current_pipe->pipe[0] > 0)
+ close(current_pipe->pipe[0]);
+ current_pipe->pipe[0] = -1;
+ }
}
/* set process->pid if lucky */
Modified: initng/trunk/src/initng_process_db.h
==============================================================================
--- initng/trunk/src/initng_process_db.h (original)
+++ initng/trunk/src/initng_process_db.h Sun Jun 4 13:58:06 2006
@@ -59,7 +59,8 @@
UNKNOWN_PIPE = 0,
OUT_PIPE = 1,
IN_PIPE = 2,
- BUFFERED_OUT_PIPE = 3
+ BUFFERED_OUT_PIPE = 3,
+ IN_AND_OUT_PIPE = 4,
} e_dir;
/* the pipe identifier */
More information about the Initng-svn
mailing list