[Initng-svn] r2719 - in initng: initfiles/daemon initfiles/system
plugins/iparser plugins/simple_launcher src
svn at initng.thinktux.net
svn at initng.thinktux.net
Wed Jan 4 20:43:00 CET 2006
Author: jimmy
Date: Wed Jan 4 20:42:59 2006
New Revision: 2719
Modified:
initng/initfiles/daemon/fetchmail.ii
initng/initfiles/daemon/gdm.ii
initng/initfiles/daemon/ifplugd.ii
initng/initfiles/system/anacron.ii
initng/plugins/iparser/initng_i_parser.c
initng/plugins/simple_launcher/initng_simple_launcher.c
initng/src/initng_load_module.c
initng/src/initng_string_tools.c
initng/src/initng_string_tools.h
initng/src/initng_struct_data.c
Log:
made exec = be an STRING option, and wont user exec_args anymore, but itroduced execs to use with exec_args.
Fixed bug in initng_i_parser, for VARIABLE_STRINGS
Modified: initng/initfiles/daemon/fetchmail.ii
==============================================================================
--- initng/initfiles/daemon/fetchmail.ii (original)
+++ initng/initfiles/daemon/fetchmail.ii Wed Jan 4 20:42:59 2006
@@ -1,6 +1,6 @@
daemon daemon/fetchmail {
need = system/bootmisc daemon/sendmail;
require_network;
- exec daemon = @/usr/bin/fetchmail@;
+ execs daemon = @/usr/bin/fetchmail@;
exec_args daemon = -f /etc/fetchmailrc;
}
Modified: initng/initfiles/daemon/gdm.ii
==============================================================================
--- initng/initfiles/daemon/gdm.ii (original)
+++ initng/initfiles/daemon/gdm.ii Wed Jan 4 20:42:59 2006
@@ -5,9 +5,9 @@
#ifd debian
env_file = /etc/default/gdm;
# Latest gdm lives in /usr/sbin - temporary workaround
- exec daemon = /usr/bin/gdm -nodaemon;
- exec daemon = /usr/sbin/gdm -nodaemon;
+ execs daemon = /usr/bin/gdm /usr/sbin/gdm;
#elsed
- exec daemon = @/usr/sbin/gdm@ -nodaemon;
+ execs daemon = @/usr/sbin/gdm@ ;
#endd
+ exec_args = -nodaemon;
}
Modified: initng/initfiles/daemon/ifplugd.ii
==============================================================================
--- initng/initfiles/daemon/ifplugd.ii (original)
+++ initng/initfiles/daemon/ifplugd.ii Wed Jan 4 20:42:59 2006
@@ -14,10 +14,10 @@
exec @/usr/sbin/ifplugd@ --no-daemon -i ${NAME} ${A};
}
#elsed
- exec daemon = @/usr/sbin/ifplugd@;
+ execs daemon = @/usr/sbin/ifplugd@;
exec_args daemon = -i ${NAME} --no-daemon;
#endd
- exec kill = @/usr/sbin/ifplugd@;
+ execs kill = @/usr/sbin/ifplugd@;
exec_args kill = -k --wait-on-kill -i ${NAME};
#pid_file = /var/run/ifplugd.${NAME}.pid;
}
Modified: initng/initfiles/system/anacron.ii
==============================================================================
--- initng/initfiles/system/anacron.ii (original)
+++ initng/initfiles/system/anacron.ii Wed Jan 4 20:42:59 2006
@@ -1,5 +1,5 @@
service system/anacron {
need = system/initial system/clock system/mountfs;
- exec start = @/usr/sbin/anacron@;
+ execs start = @/usr/sbin/anacron@;
exec_args start = -s -d;
}
Modified: initng/plugins/iparser/initng_i_parser.c
==============================================================================
--- initng/plugins/iparser/initng_i_parser.c (original)
+++ initng/plugins/iparser/initng_i_parser.c Wed Jan 4 20:42:59 2006
@@ -49,7 +49,7 @@
/* set this to have a really verbose walking output */
-/*#define DL_(a,m) err_print_line2t(a, m, MSG, __FILE__, (const char*)__PRETTY_FUNCTION__, __LINE__)*/
+/* #define DL_(a,m) err_print_line2t(a, m, MSG, __FILE__, (const char*)__PRETTY_FUNCTION__, __LINE__)*/
#define DL_(a,m)
#define FL_(a,m) err_print_line2t(a, m, MSG_FAIL, __FILE__, (const char*)__PRETTY_FUNCTION__, __LINE__)
@@ -1144,9 +1144,14 @@
while ((to = dup_string_and_walk(value, TRUE)))
{
DL_(*value, "adding");
- initng_service_cache_set_another_string_var(type, va, from_service,
+ if(va)
+ {
+ initng_service_cache_set_another_string_var(type, i_strdup(va), from_service,
+ to);
+ } else {
+ initng_service_cache_set_another_string_var(type, NULL, from_service,
to);
-
+ }
/* check if this is end */
if ((*value)[0]==';')
break;
@@ -1160,6 +1165,13 @@
break;
DL_(*value, "a_add");
}
+
+ /* dont forgot to free va */
+ if(va)
+ {
+ free(va);
+ va=NULL;
+ }
/* Parsometer
*
* " need = test service; "
Modified: initng/plugins/simple_launcher/initng_simple_launcher.c
==============================================================================
--- initng/plugins/simple_launcher/initng_simple_launcher.c (original)
+++ initng/plugins/simple_launcher/initng_simple_launcher.c Wed Jan 4 20:42:59 2006
@@ -48,16 +48,19 @@
#include "initng_simple_launcher.h"
-s_entry EXEC = { "exec", VARIABLE_STRING, NULL,
- "The path and name for an executable."
+/*#undef D_
+#define D_ W_*/
+
+s_entry EXEC = { "exec", VARIABLE_STRING, NULL, "Contains the path and argumetns to a file to exec." };
+
+s_entry EXECS = { "execs", VARIABLE_STRINGS, NULL,
+ "The path for one ore more executables."
};
s_entry EXEC_ARGS = { "exec_args", VARIABLE_STRING, NULL,
"The arguments for the executable."
};
-static int simple_exec(process_h * p, active_db_h * s, size_t c, char **v);
-
-#ifdef DEBUG
+/*#ifdef DEBUG
static void D_argv(const char *o, char **argv)
{
int i;
@@ -68,7 +71,7 @@
for (i = 0; argv[i]; i++)
D_("%s[%-2i]: %s\n", o, i, argv[i]);
}
-#endif
+#endif*/
/*
* Searches for exec in PATH.
@@ -126,7 +129,7 @@
D_("PATH determined to be %s\n", PATH);
/* split path by ':' char */
- path_argv = split_delim(PATH, ":", &path_c);
+ path_argv = split_delim(PATH, ":", &path_c, 0);
/* walk the list of entrys */
for (i = 0; path_argv[i]; i++)
@@ -156,6 +159,8 @@
/* free */
free(PATH);
free(path_argv);
+ PATH=NULL;
+ path_argv=NULL;
/* make sure we got a filename to use */
if (!filename)
@@ -165,154 +170,18 @@
return filename;
}
-static int initng_s_launch(active_db_h * service, process_h * process)
-{
- const char *exec = NULL;
-
- assert(service);
- assert(service->name);
-
- /* WE ARE EXECUTING A START FILE */
- while ((exec =
- initng_active_db_get_string_var(&EXEC, process->pt->name,
- service)))
- {
- const char *exec_args = NULL;
- char *exec_t = NULL, *exec_args_t = NULL;
- size_t exec_c = 0;
- size_t exec_args_c = 0;
- char *argv0 = NULL;
- char **exec_argv = NULL;
- char **exec_args_argv = NULL;
- int i = 0;
- int result = FALSE;
-
- /* be aware that fix_variables() return is a malloc, and needs to be free */
- exec_t = fix_variables(exec, service);
-
- /* argv-entries are pointer to exec_t[x] */
- exec_argv = split_delim(exec_t, WHITESPACE, &exec_c);
-
- /* make sure we got something from the split */
- if (!exec_argv || !exec_argv[0])
- {
- D_("split_delim on exec returns NULL.\n");
- goto go_free;
- }
-
- /* if it not contains a full path */
- if (exec_argv[0][0] != '/')
- {
- argv0 = expand_exec(exec_argv[0]);
- if (!argv0)
- {
- D_("%s was not found in search path.\n", exec_argv[0]);
- goto go_free;
- }
- exec_argv[0] = argv0;
- }
-
- /* exec_args should be parsed at the moment, too */
- exec_args = initng_active_db_get_string_var(&EXEC_ARGS,
- process->pt->name,
- service);
- if (exec_args)
- {
- /* get some fixed variables, with ${VARIABLES} fixed, be aware that this is a new malloc and needs to be free() */
- exec_args_t = fix_variables(exec_args, service);
-
- if (!exec_args_t)
- {
- W_("Failed to fix_variables: \"%s\"\n", exec_args);
- goto go_free;
- }
-
- exec_args_argv = split_delim(exec_args_t, WHITESPACE,
- &exec_args_c);
- if (!exec_args_argv || !exec_args_argv[0])
- {
- D_("split_delim exec_args returns NULL.\n");
- goto go_free;
- }
-
- /* what does this part do ??? */
- exec_argv = (char **) i_realloc(exec_argv,
- (exec_c + exec_args_c +
- 1) * sizeof(char *));
- for (i = 0; exec_args_argv[i]; i++)
- exec_argv[i + exec_c] = exec_args_argv[i];
-
- exec_argv[i + exec_c] = NULL;
- exec_c += exec_args_c;
-
- /* this have to exist */
- free(exec_args_argv);
- exec_args_argv = NULL;
- }
-
- /* try to execute, remember the result */
- result = simple_exec(process, service, exec_c, exec_argv);
-
- /* this is a fallback, that we can go to if anything fail */
- go_free:
- /* Start freeing */
- if (exec_t)
- {
- free(exec_t);
- exec_t = NULL;
- }
- if (exec_argv)
- {
- free(exec_argv);
- exec_argv = NULL;
- }
- if (argv0)
- {
- free(argv0);
- argv0 = NULL;
- }
- if (exec_args_t)
- {
- free(exec_args_t);
- exec_args_t = NULL;
- }
-
- /* return if sucessfull */
- if (result == TRUE)
- return (TRUE);
-
- /* if something failed return false directly */
- if (result == FAIL)
- return (FALSE);
-
- /* continue the next otherwise */
- }
-
- return (FALSE);
-}
-
-/* 2005-11-28 DEac-: char *e, char *ea => char **argv, size_t argc
- */
-static int simple_exec(process_h * process_to_exec, active_db_h * s,
+static int simple_exec_fork(process_h * process_to_exec, active_db_h * s,
size_t argc, char **argv)
{
- /* called from inside the service directory, return the PID or 0 on error */
-
/* This is the real service kicker */
pid_t pid_fork; /* pid got from fork() */
- assert(process_to_exec);
- assert(s);
- assert(s->name);
- assert(argc);
- assert(argv);
-
if ((pid_fork = initng_fork(s, process_to_exec)) == 0)
{
#ifdef DEBUG
D_("FROM_FORK simple_exec(%i,%s, ...);\n", argc, argv[0]);
- D_argv("simple_exec: ", argv);
+ /*D_argv("simple_exec: ", argv);*/
#endif
/* FINALLY EXECUTE *//* execve replaces the running process */
@@ -340,6 +209,183 @@
} /* end fork_and_exec() */
+static int simple_exec_try(char *exec, active_db_h *service, process_h * process)
+{
+ const char *exec_args_unfixed = NULL;
+ char **argv = NULL;
+ size_t argc = 0;
+
+ D_("exec: %s, service: %s, process: %s\n", exec, service->name, process->pt->name);
+
+ /* exec_args should be parsed at the moment, too */
+ exec_args_unfixed = initng_active_db_get_string_var(&EXEC_ARGS, process->pt->name, service);
+ if (exec_args_unfixed)
+ {
+ char *exec_args = NULL;
+
+
+ /* get some fixed variables, with ${VARIABLES} fixed, be aware that this is a new malloc and needs to be free() */
+ exec_args = fix_variables(exec_args_unfixed, service);
+ if (!exec_args)
+ {
+ F_("Failed to fix_variables: \"%s\"\n", exec_args);
+ return(FALSE);
+ }
+
+ /* split the string, with entrys to an array of strings */
+ argv = split_delim(exec_args, WHITESPACE, &argc, 1);
+
+ /* make sure it succeded */
+ if (!argv || !argv[0])
+ {
+ F_("split_delim exec_args returns NULL.\n");
+ free(exec_args);
+ exec_args=NULL;
+ return(FALSE);
+ }
+
+
+ } else {
+ /* we need a empty argv anyway */
+ argv = (char **) i_calloc(2, sizeof(char *));
+ argv[1]=NULL;
+ argc=0;
+ }
+
+ argv[0] = exec;
+
+ return(simple_exec_fork(process, service, argc, argv));
+
+}
+
+static int simple_exec(active_db_h *service, process_h * process)
+{
+ const char *exec = NULL;
+ D_("service: %s, process: %s\n", service->name, process->pt->name);
+
+ while ((exec = initng_active_db_get_next_string_var(&EXECS, process->pt->name, service, exec)))
+ {
+ int res=FALSE;
+ char *exec_fixed = NULL;
+
+ /* be aware that fix_variables() return is a malloc, and needs to be free */
+ exec_fixed = fix_variables(exec, service);
+
+ if(!exec_fixed)
+ {
+ F_("Unable to fix_variables!\n");
+ return(FALSE);
+ }
+
+ /* Try to execute that one */
+ res = simple_exec_try(exec_fixed, service, process);
+
+ /* cleanup */
+ free(exec_fixed);
+ exec_fixed=NULL;
+
+ /* Return true if sucessfull */
+ if(res==TRUE)
+ return(TRUE);
+
+ }
+
+ return (FALSE);
+}
+
+static int simple_run(active_db_h *service, process_h *process)
+{
+ const char *exec = NULL;
+ char *exec_fixed = NULL;
+ char **argv = NULL;
+ size_t argc = 0;
+ int result = FALSE;
+ char *argv0 = NULL;
+
+ D_("service: %s process: %s.\n", service->name, process->pt->name);
+
+ exec = initng_active_db_get_string_var(&EXEC, process->pt->name, service);
+ if(!exec)
+ return(FALSE);
+
+
+ /* be aware that fix_variables() return is a malloc, and needs to be free */
+ exec_fixed = fix_variables(exec, service);
+ if(!exec_fixed)
+ {
+ F_("Unable to fix_variables!\n");
+ return(FALSE);
+ }
+
+ /* argv-entries are pointer to exec_t[x] */
+ argv = split_delim(exec_fixed, WHITESPACE, &argc, 0);
+
+ /* make sure we got something from the split */
+ if (!argv || !argv[0])
+ {
+ D_("split_delim on exec returns NULL.\n");
+ free(exec_fixed);
+ exec_fixed=NULL;
+ return(FALSE);
+ }
+
+ /* if it not contains a full path */
+ if (argv[0][0] != '/')
+ {
+ argv0 = expand_exec(argv[0]);
+ if (!argv0)
+ {
+ D_("%s was not found in search path.\n", argv[0]);
+ free(argv);
+ argv=NULL;
+ free(exec_fixed);
+ exec_fixed=NULL;
+ return(FALSE);
+ }
+ argv[0]=argv0;
+ }
+
+
+ /* try to execute, remember the result */
+ result = simple_exec_fork(process, service, argc, argv);
+
+ /* clean up */
+ free(argv);
+ argv=NULL;
+ free(exec_fixed);
+ exec_fixed=NULL;
+ if(argv0)
+ {
+ free(argv0);
+ argv0=NULL;
+ }
+
+ /* return result */
+ if (result == FAIL)
+ return (FALSE);
+ return(result);
+}
+
+static int initng_s_launch(active_db_h * service, process_h * process)
+{
+
+ assert(service);
+ assert(service->name);
+ assert(process);
+
+ D_("service: %s, process: %s\n", service->name, process->pt->name);
+
+ if(initng_active_db_is_var(&EXECS, process->pt->name, service))
+ return(simple_exec(service, process));
+
+ if(initng_active_db_is_var(&EXEC, process->pt->name, service))
+ return(simple_run(service, process));
+
+ return (FALSE);
+}
+
+
+
int module_init(const char *version)
{
D_("initng_simple_plugin: module_init();\n");
@@ -352,6 +398,7 @@
initng_plugin_hook_add(LAUNCH, 40, &initng_s_launch);
initng_service_data_types_add(&EXEC);
+ initng_service_data_types_add(&EXECS);
initng_service_data_types_add(&EXEC_ARGS);
return (TRUE);
}
@@ -361,6 +408,7 @@
D_("initng_simple_plugin: module_unload();\n");
initng_service_data_types_del(&EXEC);
+ initng_service_data_types_del(&EXECS);
initng_service_data_types_del(&EXEC_ARGS);
initng_plugin_hook_del(LAUNCH, &initng_s_launch);
Modified: initng/src/initng_load_module.c
==============================================================================
--- initng/src/initng_load_module.c (original)
+++ initng/src/initng_load_module.c Wed Jan 4 20:42:59 2006
@@ -233,8 +233,9 @@
}
/* close the lib */
+ /*
if (m->module_dlhandle)
- dlclose(m->module_dlhandle);
+ dlclose(m->module_dlhandle);*/
/* remove from list if added */
list_del(&m->list);
@@ -398,8 +399,8 @@
{
DIR *d;
struct dirent *e;
- char *module_path;
- char *module_name;
+ char *module_path = NULL;
+ char *module_name = NULL;
m_h *current, *safe = NULL;
@@ -426,6 +427,7 @@
{
F_("Plugin %s blacklisted.\n", module_name);
free(module_name);
+ module_name = NULL;
continue;
}
Modified: initng/src/initng_string_tools.c
==============================================================================
--- initng/src/initng_string_tools.c (original)
+++ initng/src/initng_string_tools.c Wed Jan 4 20:42:59 2006
@@ -80,42 +80,48 @@
/** Relinks a string to a argv-like string-array.
- * Something like split_n().
* Example: \t /bin/executeable --ham -flt --moohoho lalala
* => \t /bin/executeable\0--ham\0-flt\0 --moo\0hoho\0 lalala
* argv: ^[0] ^[1] ^[2] ^[3] ^[4] ^[5]
* argc: 6
+ *
+ * string: String to split.
+ * delim : Char that splits the strings.
+ * argc : Pointer, sets the number of splits done.
+ * ofs : Offset, start from this arg to fill.
* @idea DEac-
* @author TheLich
+ * @got_it_working powerj
*/
-char **split_delim(char *string, const char *delim, size_t * argc)
+char **split_delim(char *string, const char *delim, size_t * argc, int ofs)
{
- int len, pos = 0;
+ int len;
char **array = (char **) i_calloc(1, sizeof(char *));
size_t i = 0;
- if (string)
+ if (!string)
+ return(NULL);
+
+ while (string[ofs] != '\0')
{
- while (string[pos] != '\0')
+ len = strcspn(string + ofs, delim);
+ if (len != 0)
{
- len = strcspn(string + pos, delim);
- if (len != 0)
+ i++;
+ array = (char **) i_realloc(array, sizeof(char *) * (i + 1));
+ array[i - 1] = string + ofs;
+ if (string[len + ofs] != '\0')
{
- i++;
- array = (char **) i_realloc(array, sizeof(char *) * (i + 1));
- array[i - 1] = string + pos;
- if (string[len + pos] != '\0')
- {
- string[len + pos] = '\0';
- len++;
- }
+ string[len + ofs] = '\0';
+ len++;
}
- else
- len = 1;
-
- pos += len;
}
+ else
+ len = 1;
+
+ ofs += len;
}
+
array[i] = NULL;
*argc = i;
return array;
Modified: initng/src/initng_string_tools.h
==============================================================================
--- initng/src/initng_string_tools.h (original)
+++ initng/src/initng_string_tools.h Wed Jan 4 20:42:59 2006
@@ -72,7 +72,7 @@
/* to use with split_delim */
#define WHITESPACE " \t\n\r\v"
-char **split_delim(char *string, const char *delim, size_t * argc);
+char **split_delim(char *string, const char *delim, size_t * argc, int ofs);
/* pattern searching */
int service_match(const char *string, const char *pattern);
Modified: initng/src/initng_struct_data.c
==============================================================================
--- initng/src/initng_struct_data.c (original)
+++ initng/src/initng_struct_data.c Wed Jan 4 20:42:59 2006
@@ -504,6 +504,7 @@
D_("vn not set, freeing all.\n");
list_del(¤t->list);
d_free(current);
+ current=NULL;
continue;
}
@@ -513,6 +514,7 @@
F_("vn matches, freeing\n");
list_del(¤t->list);
d_free(current);
+ current=NULL;
continue;
}
}
@@ -531,6 +533,7 @@
/* walk, and remove all */
list_del(¤t->list);
d_free(current);
+ current=NULL;
}
}
More information about the Initng-svn
mailing list