[Initng-svn] r1946 - initng/src
svn at initng.thinktux.net
svn at initng.thinktux.net
Sun Nov 6 16:00:17 CET 2005
Author: jimmy
Date: Sun Nov 6 16:00:16 2005
New Revision: 1946
Modified:
initng/src/initng_global.c
initng/src/initng_global.h
initng/src/initng_main.c
initng/src/main.c
Log:
Major cleanup to main.c
Modified: initng/src/initng_global.c
==============================================================================
--- initng/src/initng_global.c (original)
+++ initng/src/initng_global.c Sun Nov 6 16:00:16 2005
@@ -82,6 +82,7 @@
g.sys_state = STATE_NULL;
g.runlevel = NULL;
g.modules_to_unload = FALSE;
+ g.hot_reload = FALSE;
/* Add defaults (static) to data_types */
initng_sdt_add_defaults();
@@ -98,6 +99,59 @@
#endif
}
+
+
+void initng_parse_argv(char **argv)
+{
+ int i;
+
+ for (i = 0; argv[i]; i++)
+ {
+ /* set opt to argv */
+ char *opt = argv[i];
+
+ /* don't parse options starting with an '+' */
+ if (opt[0] == '+')
+ continue;
+ /*
+ * if arg is --verbose, skip the two -- here, and start checking.
+ * if arg is -verbose, skip and continue for loop.
+ * if arg is verbose, check it below
+ */
+
+ /* if its a double --, its ok */
+ if (opt[0] == '-' && opt[1] == '-')
+ opt += 2;
+ /* but a single is not ! */
+ if (opt[0] == '-')
+ continue;
+
+
+#define R_L "runlevel="
+#define V_T "verbose_add="
+
+#ifdef DEBUG
+ if (strcmp(opt, "verbose") == 0)
+ g.verbose = TRUE;
+#endif
+ if (strcmp(opt, "i_am_init") == 0)
+ g.i_am_init = TRUE;
+ if (strcmp(opt, "hot_reload") == 0)
+ {
+ W_(" Will start after a hot reload ...\n");
+ g.hot_reload = TRUE;
+ }
+ if (strcmp(opt, "i_am_not_init") == 0)
+ g.i_am_init = FALSE;
+ if (strncmp(opt, R_L, strlen(R_L)) == 0)
+ g.runlevel = i_strdup((opt) + strlen(R_L));
+#ifdef DEBUG
+ if (strncmp(opt, V_T, strlen(V_T)) == 0)
+ verbose_add((opt) + strlen(V_T));
+#endif
+ }
+}
+
void initng_free(void)
{
int i;
Modified: initng/src/initng_global.h
==============================================================================
--- initng/src/initng_global.h (original)
+++ initng/src/initng_global.h Sun Nov 6 16:00:16 2005
@@ -67,6 +67,7 @@
/* system state data */
int i_am_init;
+ int hot_reload;
char *runlevel;
int when_out;
@@ -91,5 +92,6 @@
/* functions for initziate and free s_global g */
void initng_new(int argc, char *argv[], char *env[]);
void initng_free(void);
+void initng_parse_argv(char **argv);
#endif
Modified: initng/src/initng_main.c
==============================================================================
--- initng/src/initng_main.c (original)
+++ initng/src/initng_main.c Sun Nov 6 16:00:16 2005
@@ -247,16 +247,6 @@
execve("/sbin/initng", argv, environ);
}
-void sys_state_services_loaded(void)
-{
- h_sys_state oldstate = g.sys_state;
-
- set_sys_state(STATE_SERVICES_LOADED);
- g.sys_state = oldstate;
- return;
-}
-
-
/* this function sets g.sys_state, and call plugins that listen on its change */
void set_sys_state(h_sys_state state)
{
Modified: initng/src/main.c
==============================================================================
--- initng/src/main.c (original)
+++ initng/src/main.c Sun Nov 6 16:00:16 2005
@@ -50,107 +50,23 @@
#include "initng_service_data_types.h"
#include "initng_fd.h"
-/*
- * %%%%%%%%%%%%%%%%%%%% main () %%%%%%%%%%%%%%%%%%%%
- */
-#ifdef BUSYBOX
-int init_main(int argc, char *argv[], char *env[])
-{
-#else
-int main(int argc, char *argv[], char *env[])
-{
-#endif
- time_t last; /* save the time here */
- int hot_reload = FALSE;
-
-#ifdef DEBUG
- int loop_counter = 0; /* a common used for counter */
-#endif
-
- S_;
- /* set console loglevel */
- klogctl(8, NULL, 1);
-
-
- /* enable generation of core files */
- {
- struct rlimit c = { 1000000, 100000 };
- setrlimit(RLIMIT_CORE, &c);
- }
-
- /* get the time */
- last = time(NULL);
-
- /* initialise global variables */
- initng_new(argc, argv, env);
-
- if (getpid() == 1)
- g.i_am_init = TRUE;
-
- D_("MAIN_PARSE_ARGV\n");
+static void setup_console(void)
{
- int i;
+ int fd; /* /dev/console */
+ struct termios tty;
- for (i = 0; argv[i]; i++)
- {
- /* set opt to argv */
- char *opt = argv[i];
+ D_("MAIN_SET_I_AM_INIT_STUFF\n");
- /* don't parse options starting with an '+' */
- if (opt[0] == '+')
- continue;
- /*
- * if arg is --verbose, skip the two -- here, and start checking.
- * if arg is -verbose, skip and continue for loop.
- * if arg is verbose, check it below
- */
- /* if its a double --, its ok */
- if (opt[0] == '-' && opt[1] == '-')
- opt += 2;
- /* but a single is not ! */
- if (opt[0] == '-')
- continue;
+ /* set console loglevel */
+ klogctl(8, NULL, 1);
-#ifdef DEBUG
- if (strcmp(opt, "verbose") == 0)
- g.verbose = TRUE;
-#endif
- if (strcmp(opt, "i_am_init") == 0)
- g.i_am_init = TRUE;
- if (strcmp(opt, "hot_reload") == 0)
- {
- W_(" Will start after a hot reload ...\n");
- hot_reload = TRUE;
- }
- if (strcmp(opt, "i_am_not_init") == 0)
- g.i_am_init = FALSE;
-#define R_L "runlevel="
- if (strncmp(opt, R_L, strlen(R_L)) == 0)
- g.runlevel = i_strdup((opt) + strlen(R_L));
-#ifdef DEBUG
-#define V_T "verbose_add="
- if (strncmp(opt, V_T, strlen(V_T)) == 0)
- verbose_add((opt) + strlen(V_T));
-#endif
- }
- }
-
- if (g.i_am_init)
- {
- g.when_out = THEN_SULOGIN;
- }
- else
- {
- g.when_out = THEN_QUIT;
- }
- /* See if we are the first process born in the system */
- if (g.i_am_init && !hot_reload)
- {
- int fd; /* /dev/console */
-
- D_("MAIN_SET_I_AM_INIT_STUFF\n");
+ /* enable generation of core files */
+ {
+ struct rlimit c = { 1000000, 100000 };
+ setrlimit(RLIMIT_CORE, &c);
+ }
reboot(RB_DISABLE_CAD); /* Disable Ctrl + Alt + Delete */
@@ -169,9 +85,6 @@
/* TODO: this block may be incorrect or incomplete */
/* Q: What does this block really do? */
- {
- struct termios tty;
- int fd;
/*
* TODO: /dev/console may still be open from before. Also, if it
@@ -213,10 +126,63 @@
(void) tcsetattr(fd, TCSANOW, &tty);
(void) tcflush(fd, TCIOFLUSH);
(void) close(fd);
- }
}
+
+/*
+ * %%%%%%%%%%%%%%%%%%%% main () %%%%%%%%%%%%%%%%%%%%
+ */
+#ifdef BUSYBOX
+int init_main(int argc, char *argv[], char *env[])
+{
+#else
+int main(int argc, char *argv[], char *env[])
+{
+#endif
+ time_t last; /* save the time here */
+
+#ifdef DEBUG
+ int loop_counter = 0; /* a common used for counter */
+#endif
+
+ S_;
+
+ /* get the time */
+ last = time(NULL);
+
+ /* initialise global variables */
+ initng_new(argc, argv, env);
+
+ /* set i_am_init if pid == 1 */
+ if (getpid() == 1)
+ g.i_am_init = TRUE;
+
+ /* parse all options, set in argv */
+ initng_parse_argv(argv);
+
+ /* if this is real init */
+ if (g.i_am_init)
+ {
+ /* when last service stoped, offer a sulogin */
+ g.when_out = THEN_SULOGIN;
+ g.runlevel = i_strdup("default");
+
+ if(!g.hot_reload)
+ {
+ /* static function abowe, initziates the system */
+ setup_console();
+ }
+
+ }
+ else
+ {
+ /* when last service stoped, quit initng */
+ g.when_out = THEN_QUIT;
+ g.runlevel = i_strdup("fake-default");
+ }
+
+
D_("MAIN_LOAD_MODULES\n");
/* Load modules, if fails - launch sulogin and then try again */
while (!initng_load_all_modules())
@@ -225,47 +191,29 @@
su_login();
}
+ /* set title of initng, can be watched in ps -ax */
+ set_proc_title("initng [%s]", g.runlevel);
+
/* Configure signal handlers */
(void) enable_signals();
/* change system state */
set_sys_state(STATE_STARTING);
- D_("MAIN_START_DEFAULT_SERVICE\n");
- /* If no starting services found, use default */
- if (!g.runlevel)
- {
- if (g.i_am_init)
- {
- g.runlevel = i_strdup("default");
- }
- else
- {
- g.runlevel = i_strdup("fake-default");
- }
- }
-
- /* set title of initng, can be watched in ps -ax */
- set_proc_title("initng [%s]", g.runlevel);
-
-
/* make sure this is not a hot reload */
- if (!hot_reload)
+ if (!g.hot_reload)
{
/* first start all services, prompted at boot with +daemon/test */
start_extra_services();
/* try load the default service, if it fails - launch sulogin and try again */
- while (!start_new_service_named(g.runlevel))
+ if (!start_new_service_named(g.runlevel))
{
F_("Failed to load runlevel (%s)!\n", g.runlevel);
su_login();
}
}
- /* set system state, plugins can hook here */
- sys_state_services_loaded();
-
D_("MAIN_GOING_MAIN_LOOP\n");
/* %%%%%%%%%%%%%%% MAIN LOOP %%%%%%%%%%%%%%% */
for (;;)
More information about the Initng-svn
mailing list