[Initng-svn] r2953 - in initng: plugins/daemon plugins/netprobe plugins/ngc2 src

svn at initng.thinktux.net svn at initng.thinktux.net
Tue Feb 7 09:23:38 CET 2006


Author: thelich
Date: Tue Feb  7 09:23:37 2006
New Revision: 2953

Modified:
   initng/plugins/daemon/initng_daemon.c
   initng/plugins/netprobe/initng_netprobe.c
   initng/plugins/ngc2/initng_ngc2.c
   initng/src/initng_global.c
   initng/src/initng_global.h
   initng/src/initng_plugin.h
   initng/src/initng_plugin_callers.c
   initng/src/initng_plugin_callers.h
   initng/src/initng_plugin_hook.c
   initng/src/initng_signal.c
   initng/src/initng_signal.h
   initng/src/main.c
Log:
* added sighup handler for plugins (for example initng_ngc will recheck /dev/initng/initng and recreate it if it's not exist, when you send sighup to initng (kill -HUP 1)
* modules like netprobe should add their hook to system-wide lists (g.START_DEP_MET, for example), otherwise the will neve be called for such plugins like "service" and "daemon"

Modified: initng/plugins/daemon/initng_daemon.c
==============================================================================
--- initng/plugins/daemon/initng_daemon.c	(original)
+++ initng/plugins/daemon/initng_daemon.c	Tue Feb  7 09:23:37 2006
@@ -319,6 +319,10 @@
         }
     }
 
+    /* this checks with external plugins, if its ok to start this service now */
+    if(initng_depend_start_dep_met(daemon)!=TRUE)
+	return;
+
     /* if system is shuting down, Dont start anything. */
     if (g.sys_state != STATE_STARTING && g.sys_state != STATE_UP)
     {
@@ -372,6 +376,10 @@
         return;
     }
 
+    /* check with other plugins, if it is ok to stop this service now */
+    if(initng_depend_stop_dep_met(daemon)!=TRUE)
+	return;
+
     /* ok, stopping deps are met */
     initng_common_mark_service(daemon, &DAEMON_STOP_DEPS_MET);
 }

Modified: initng/plugins/netprobe/initng_netprobe.c
==============================================================================
--- initng/plugins/netprobe/initng_netprobe.c	(original)
+++ initng/plugins/netprobe/initng_netprobe.c	Tue Feb  7 09:23:37 2006
@@ -195,8 +195,12 @@
 
     initng_service_data_types_add(&REQUIRE_NETWORK);
     initng_service_data_types_add(&NETWORK_PROVIDER);
+    initng_plugin_hook_add(&g.START_DEP_MET, 55, &check_START_DEP_MET);
+    initng_plugin_hook_add(&g.STOP_DEP_MET, 55, &check_STOP_DEP_MET);
+/*
     initng_active_state_add_test(&START_DEP_MET, 55, &check_START_DEP_MET);
     initng_active_state_add_test(&STOP_DEP_MET, 55, &check_STOP_DEP_MET);
+*/
     return (TRUE);
 }
 
@@ -205,6 +209,10 @@
     S_;
     initng_service_data_types_del(&REQUIRE_NETWORK);
     initng_service_data_types_del(&NETWORK_PROVIDER);
+    initng_plugin_hook_del(&g.START_DEP_MET, &check_START_DEP_MET);
+    initng_plugin_hook_del(&g.STOP_DEP_MET, &check_STOP_DEP_MET);
+/*
     initng_active_state_del_test(&START_DEP_MET, &check_START_DEP_MET);
     initng_active_state_del_test(&STOP_DEP_MET, &check_STOP_DEP_MET);
+*/
 }

Modified: initng/plugins/ngc2/initng_ngc2.c
==============================================================================
--- initng/plugins/ngc2/initng_ngc2.c	(original)
+++ initng/plugins/ngc2/initng_ngc2.c	Tue Feb  7 09:23:37 2006
@@ -940,6 +940,7 @@
     D_("adding hook, that will reopen socket, for every started service.\n");
     initng_plugin_hook_add(&g.ASTATUS_CHANGE, 50, &service_status);
     initng_plugin_hook_add(&g.FDWATCHERS, 30, &fdh);
+    initng_plugin_hook_add(&g.HUP, 50, &check_socket);
 
     /* add the help command, that list commands to the client */
     initng_command_add(&HELP);
@@ -969,6 +970,7 @@
     /* remove hooks */
     initng_plugin_hook_del(&g.FDWATCHERS, &fdh);
     initng_plugin_hook_del(&g.ASTATUS_CHANGE, &service_status);
+    initng_plugin_hook_del(&g.HUP, &check_socket);
     initng_command_del(&HELP);
     initng_command_del(&HELP_ALL);
     initng_command_del(&SERVICES);

Modified: initng/src/initng_global.c
==============================================================================
--- initng/src/initng_global.c	(original)
+++ initng/src/initng_global.c	Tue Feb  7 09:23:37 2006
@@ -96,6 +96,7 @@
     INIT_LIST_HEAD(&g.FDWATCHERS.list);
     INIT_LIST_HEAD(&g.PIPEWATCHERS.list);
     INIT_LIST_HEAD(&g.ALARM.list);
+    INIT_LIST_HEAD(&g.HUP.list);
     INIT_LIST_HEAD(&g.MAIN.list);
     INIT_LIST_HEAD(&g.A_FORK.list);
     INIT_LIST_HEAD(&g.HANDLE_KILLED.list);

Modified: initng/src/initng_global.h
==============================================================================
--- initng/src/initng_global.h	(original)
+++ initng/src/initng_global.h	Tue Feb  7 09:23:37 2006
@@ -66,6 +66,7 @@
     s_call FDWATCHERS;		/* Called when initng open filedescriptors recive data */
     s_call PIPEWATCHERS;	/* Called when a service has some output, that initng rescived */
     s_call ALARM;		/* Called when the sceduler is set, and go of */
+    s_call HUP;			/* Called when sighup signal was received */
     s_call MAIN;		/* Called every main loop */
     s_call A_FORK;		/* Called after a process forks to start */
     s_call HANDLE_KILLED;	/* Called when a process dies */

Modified: initng/src/initng_plugin.h
==============================================================================
--- initng/src/initng_plugin.h	(original)
+++ initng/src/initng_plugin.h	Tue Feb  7 09:23:37 2006
@@ -51,6 +51,7 @@
                 const char *format, va_list ap);
     int (*dep_on_check) (active_db_h * service, active_db_h * check);
     void (*alarm) (void);
+    void (*hup) (void);
     f_module_h *fdh;
     int (*additional_parse) (service_cache_h * service);
     int (*dump_state) (void);

Modified: initng/src/initng_plugin_callers.c
==============================================================================
--- initng/src/initng_plugin_callers.c	(original)
+++ initng/src/initng_plugin_callers.c	Tue Feb  7 09:23:37 2006
@@ -48,6 +48,16 @@
     }
 }
 
+void initng_plugin_callers_hup(void)
+{
+    s_call *current, *q = NULL;
+
+    while_list_safe(current, &g.HUP, q)
+    {
+        (*current->c.hup) ();
+    }
+}
+
 int initng_plugin_callers_handle_killed(active_db_h * s, process_h * p)
 {
     s_call *current, *q = NULL;

Modified: initng/src/initng_plugin_callers.h
==============================================================================
--- initng/src/initng_plugin_callers.h	(original)
+++ initng/src/initng_plugin_callers.h	Tue Feb  7 09:23:37 2006
@@ -28,6 +28,7 @@
 int initng_plugin_callers_handle_killed(active_db_h * s, process_h * p);
 void initng_plugin_callers_compensate_time(int t);
 void initng_plugin_callers_alarm(void);
+void initng_plugin_callers_hup(void);
 
 void initng_plugin_callers_load_module_system_changed(h_sys_state state);
 int initng_plugin_callers_dump_state(void);

Modified: initng/src/initng_plugin_hook.c
==============================================================================
--- initng/src/initng_plugin_hook.c	(original)
+++ initng/src/initng_plugin_hook.c	Tue Feb  7 09:23:37 2006
@@ -1,4 +1,3 @@
-
 /* Initng, a next generation sysvinit replacement.
  * Copyright (C) 2005 Jimmy Wennlund <jimmy.wennlund at gmail.com>
  *
@@ -7,16 +6,17 @@
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
-                                                                                                     * This program is distributed in the hope that it will be useful,
-                                                                                                     * but WITHOUT ANY WARRANTY; without even the implied warranty of
-                                                                                                     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-                                                                                                     * Lesser General Public License for more details.
-                                                                                                     *
-                                                                                                     * You should have received a copy of the GNU Lesser General
-                                                                                                     * Public License along with this library; if not, write to the
-                                                                                                     * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
-                                                                                                     * Boston, MA 02111-1307, USA.
-                                                                                                     */
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+*/
+
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>

Modified: initng/src/initng_signal.c
==============================================================================
--- initng/src/initng_signal.c	(original)
+++ initng/src/initng_signal.c	Tue Feb  7 09:23:37 2006
@@ -38,6 +38,7 @@
 static void sigwinch(int sig);
 static void sigint(int sig);
 static void sigalarm(int sig);
+static void sighup(int sig);
 
 /*
  * These are gloval variables, that got set,
@@ -47,6 +48,7 @@
 volatile int initng_signal_got_ctrl_alt_del = FALSE;
 volatile int initng_signal_got_alarm = FALSE;
 volatile int initng_signal_got_sigchld = FALSE;
+volatile int initng_signal_got_sighup = FALSE;
 
 /*
  * If we got an chiled that died, this haldler is called.
@@ -109,7 +111,7 @@
     }
 }
 
-/* called by signal SIGCHILD */
+/* called by signal SIGSEGV */
 static void sigsegv(int sig)
 {
     (void) sig;
@@ -155,6 +157,15 @@
     initng_signal_got_ctrl_alt_del = TRUE;
 }
 
+/* called by signal SIGINT */
+static void sighup(int sig)
+{
+    (void) sig;
+    initng_global_set_interrupt();
+    D_("sigint():     Got Sighup\n");
+    initng_signal_got_sighup = TRUE;
+}
+
 /*
  * This is called in main() initziation, and will enable signals when it happends.
  */
@@ -165,7 +176,8 @@
     /* clear interrupt cache */
     /* TODO FIGUREITOUT - Catch signals */
     /*  signal(SIGPWR,sighandler); don't know what to do about it */
-    /*  signal(SIGHUP,sighandler); ??? */
+    /*  signal(SIGHUP,sighandler); signal for plugins to do something */
+    /*  (recreate control file for example) */
     /* SA_NOCLDSTOP -->  Get notification when childs stops living */
     /* SA_RESTART --> make certain system calls restartable across signals */
     /*   Normally if a program is in a system call and a signal is */
@@ -205,6 +217,9 @@
     sa.sa_handler = sigalarm;
     sigaction(SIGALRM, &sa, 0);             /* alarm, something has to be checked */
 
+    sa.sa_handler = sighup;
+    sigaction(SIGHUP, &sa, 0);              /* sighup, plugin actions */
+
 }
 
 /* 
@@ -229,5 +244,6 @@
     sigaction(SIGINT, &sa, 0);              /* ctrl-alt-del */
     sigaction(SIGWINCH, &sa, 0);            /* keyboard request */
     sigaction(SIGALRM, &sa, 0);             /* alarm, something has to be checked */
+    sigaction(SIGHUP, &sa, 0);              /* sighup, plugin actions */
 
 }

Modified: initng/src/initng_signal.h
==============================================================================
--- initng/src/initng_signal.h	(original)
+++ initng/src/initng_signal.h	Tue Feb  7 09:23:37 2006
@@ -27,6 +27,7 @@
 extern volatile int initng_signal_got_ctrl_alt_del;
 extern volatile int initng_signal_got_alarm;
 extern volatile int initng_signal_got_sigchld;
+extern volatile int initng_signal_got_sighup;
 
 struct sigaction sa;
 

Modified: initng/src/main.c
==============================================================================
--- initng/src/main.c	(original)
+++ initng/src/main.c	Tue Feb  7 09:23:37 2006
@@ -487,6 +487,15 @@
             initng_plugin_callers_alarm();
         }
 
+        /* Check for sighup */
+        if (initng_signal_got_sighup)
+        {
+            D_("Got sighup, checking sighup plugin ...\n");
+            initng_signal_got_sighup = FALSE;
+            /* Check timers plugins */
+            initng_plugin_callers_hup();
+        }
+
         /* If we got an interrupt load ctrlaltdel */
         if (initng_signal_got_ctrl_alt_del)
         {


More information about the Initng-svn mailing list