[Initng-svn] r4374 - initng/trunk/plugins/bash_parser
svn at initng.thinktux.net
svn at initng.thinktux.net
Wed Jun 7 01:33:20 CEST 2006
Author: jimmy
Date: Wed Jun 7 01:33:18 2006
New Revision: 4374
Modified:
initng/trunk/plugins/bash_parser/bp.c
initng/trunk/plugins/bash_parser/create_links.cmake.in
initng/trunk/plugins/bash_parser/initng_bash_parser.c
initng/trunk/plugins/bash_parser/initng_bash_parser.h
Log:
Some more bash_parser work.
Modified: initng/trunk/plugins/bash_parser/bp.c
==============================================================================
--- initng/trunk/plugins/bash_parser/bp.c (original)
+++ initng/trunk/plugins/bash_parser/bp.c Wed Jun 7 01:33:18 2006
@@ -52,6 +52,7 @@
int bp_done(char *service, int argc, char **argv);
int bp_get_variable(char *service, int argc, char **argv);
int bp_set_variable(char *service, int argc, char **argv);
+int bp_add_exec(char *service, int argc, char **argv);
char *message;
typedef struct
@@ -71,6 +72,10 @@
{"iget", &bp_get_variable},
{"set", &bp_set_variable},
{"iset", &bp_set_variable},
+ {"add_exec", &bp_add_exec},
+ {"iadd_exec", &bp_add_exec},
+ {"exec", &bp_add_exec},
+ {"iexec", &bp_add_exec},
{NULL, NULL}
};
@@ -94,8 +99,13 @@
/* allocate a new argv to use */
new_argv = calloc(argc + 1, sizeof(char *));
- /* fill it up */
- new_argv[0] = argv0;
+ /* first is the full path to service file */
+ new_argv[0] = getenv("SERVICE_FILE");
+ if (!new_argv[0])
+ {
+ printf("SERVICE_FILE path is unset!\n");
+ exit(1);
+ }
/* copy all, but not options */
new_argc = 0;
@@ -133,7 +143,7 @@
exit(1);
}
-#ifdef DEBUG
+#ifdef DEBUG_EXTRA
{
printf(" ** %-12s ** ", service);
for (i = 0; argv[i]; i++)
@@ -175,6 +185,57 @@
exit(status == TRUE ? 0 : 1);
}
+/*
+ * usage: iexec start will run /etc/init/service internal_start
+ * iexec start = dodo will run /etc/init/service internal_dodo
+ */
+int bp_add_exec(char *service, int argc, char **argv)
+{
+ /* the request to send */
+ bp_req to_send;
+
+ memset(&to_send, 0, sizeof(bp_req));
+ to_send.request = SET_VARIABLE;
+
+ /* "/etc/init/file" */
+ strncpy(to_send.u.set_variable.value, argv[0], 1024);
+
+ /* " internal_" */
+ strncat(to_send.u.set_variable.value, " internal_",
+ 1024 - strlen(to_send.u.set_variable.value));
+
+
+ if (argc == 3 && argv[2][0] == '=')
+ {
+
+ /* "dodo" */
+ strncat(to_send.u.set_variable.value, argv[3],
+ 1024 - strlen(to_send.u.set_variable.value));
+
+ }
+ else if (argc == 1)
+ {
+
+ /* "start" */
+ strncat(to_send.u.set_variable.value, argv[1],
+ 1024 - strlen(to_send.u.set_variable.value));
+
+ }
+ else
+ return (FALSE);
+
+ /* use service */
+ strncpy(to_send.u.get_variable.service, service, 100);
+
+ /* the type is "exec" */
+ strcpy(to_send.u.set_variable.vartype, "exec");
+
+ /* the varname is "start" */
+ strncpy(to_send.u.set_variable.varname, argv[1], 100);
+
+ return (bp_send(&to_send));
+}
+
int bp_abort(char *service, int argc, char **argv)
{
/* the request to send */
@@ -336,6 +397,7 @@
/* set the type */
strncpy(to_send.u.new_active.type, argv[1], 40);
+ strncpy(to_send.u.new_active.from_file, argv[0], 100);
return (bp_send(&to_send));
Modified: initng/trunk/plugins/bash_parser/create_links.cmake.in
==============================================================================
--- initng/trunk/plugins/bash_parser/create_links.cmake.in (original)
+++ initng/trunk/plugins/bash_parser/create_links.cmake.in Wed Jun 7 01:33:18 2006
@@ -5,6 +5,7 @@
iget
iregister
iset
+ iexec
)
FOREACH(target ${TARGETS})
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 Wed Jun 7 01:33:18 2006
@@ -64,7 +64,7 @@
static int bp_open_socket(void);
static void bp_check_socket(int signal);
static void bp_new_active(bp_rep * rep, const char *type,
- const char *service);
+ const char *service, const char *from_file);
static void bp_set_variable(bp_rep * rep, const char *service,
const char *vartype, const char *varname,
const char *value);
@@ -150,7 +150,8 @@
{
case NEW_ACTIVE:
bp_new_active(&rep, req.u.new_active.type,
- req.u.new_active.service);
+ req.u.new_active.service,
+ req.u.new_active.from_file);
break;
case SET_VARIABLE:
bp_set_variable(&rep, req.u.set_variable.service,
@@ -177,7 +178,8 @@
SEND();
}
-static void bp_new_active(bp_rep * rep, const char *type, const char *service)
+static void bp_new_active(bp_rep * rep, const char *type, const char *service,
+ const char *from_file)
{
active_db_h *new_active;
stype_h *stype;
@@ -212,6 +214,8 @@
return;
}
+ set_string(&FROM_FILE, new_active, i_strdup(from_file));
+
new_active->type = stype;
rep->success = TRUE;
@@ -767,6 +771,58 @@
return (TRUE);
}
+#ifdef USE_LOCALEXEC
+static int initng_bash_run(active_db_h * service, process_h * process,
+ const char *exec_name)
+{
+ pid_t pid_fork; /* pid got from fork() */
+
+ assert(service);
+ assert(service->name);
+ assert(process);
+ assert(exec_name);
+
+ if ((pid_fork = initng_fork(service, process)) == 0)
+ {
+ struct stat fstat; /* file stat storage */
+ char *av[3]; /* use only 3 args */
+ char *e[] = { NULL }; /* use an empty environment */
+ char *file; /* the file to execute from */
+
+ /* get the file path */
+ file = get_string(&FROM_FILE, service);
+
+ /* check that it exists */
+ if (!file || stat(file, &fstat) != 0)
+ {
+ printf("Service file not found.\n");
+ _exit(1);
+ }
+
+ /* execute this */
+ av[0] = file;
+ av[1] = i_calloc(10 + strlen(exec_name), sizeof(char));
+ strcpy(av[1], "internal_");
+ strcat(av[1], exec_name);
+ av[2] = NULL;
+
+ execve(av[0], av, e);
+
+ printf("Error executing!\n");
+ _exit(2);
+ }
+
+ if (pid_fork > 0)
+ {
+ process->pid = pid_fork;
+ return (TRUE);
+ }
+ process->pid = 0;
+ return (FALSE);
+}
+#endif
+
+
int module_init(int api_version)
{
D_("module_init(ngc2);\n");
@@ -788,7 +844,9 @@
initng_plugin_hook_register(&g.PIPE_WATCHER, 30, &get_pipe);
initng_active_state_register(&PARSING);
initng_active_state_register(&PARSE_FAIL);
-
+#ifdef USE_LOCALEXEC
+ initng_plugin_hook_register(&g.LAUNCH, 10, &initng_bash_run);
+#endif
/* do the first socket directly */
bp_open_socket();
@@ -810,4 +868,7 @@
initng_plugin_hook_unregister(&g.PIPE_WATCHER, &get_pipe);
initng_active_state_unregister(&PARSING);
initng_active_state_unregister(&PARSE_FAIL);
+#ifdef USE_LOCALEXEC
+ initng_plugin_hook_unregister(&g.LAUNCH, &initng_bash_run);
+#endif
}
Modified: initng/trunk/plugins/bash_parser/initng_bash_parser.h
==============================================================================
--- initng/trunk/plugins/bash_parser/initng_bash_parser.h (original)
+++ initng/trunk/plugins/bash_parser/initng_bash_parser.h Wed Jun 7 01:33:18 2006
@@ -47,6 +47,7 @@
{
char type[41]; /* What service type this is */
char service[101]; /* New service name */
+ char from_file[101]; /* The source file added from */
} new_active;
/* set value */
More information about the Initng-svn
mailing list