[Initng-svn] r1961 - in initng: plugins/pidfile src
svn at initng.thinktux.net
svn at initng.thinktux.net
Sun Nov 6 20:38:40 CET 2005
Author: jimmy
Date: Sun Nov 6 20:38:38 2005
New Revision: 1961
Modified:
initng/plugins/pidfile/initng_pidfile.c
initng/src/initng_handler.c
initng/src/initng_service_data_types.c
initng/src/initng_static_data_id.c
Log:
More pidfile fixes.
Modified: initng/plugins/pidfile/initng_pidfile.c
==============================================================================
--- initng/plugins/pidfile/initng_pidfile.c (original)
+++ initng/plugins/pidfile/initng_pidfile.c Sun Nov 6 20:38:38 2005
@@ -37,11 +37,16 @@
#include "initng_pidfile.h"
+/* The name of the process, initng shud probe */
s_entry PIDOF = { "pid_of", STRING, 6, DAEMON_OPT };
+/* The filename/path of a pidfile that initng can fetch pid no */
s_entry PIDFILE = { "pid_file", STRING, 8, DAEMON_OPT };
-
-int is_ok=FALSE;
+/*
+ * this is an internal option, that is set after the
+ * service died once, and the pid is updated.
+ */
+s_entry INTERNAL_GOT_PID = { NULL, SET, 0, INTERNAL_OPT };
static pid_t pid_of(const char *name)
{
@@ -121,7 +126,7 @@
if (status != RUNNING)
return (TRUE);
- if(is_ok == TRUE)
+ if(active_db_is(&INTERNAL_GOT_PID, s))
return(TRUE);
/* Make sure the service uses a pidfile */
@@ -269,9 +274,8 @@
p->pid = pid;
/* this will alter check_if_done abowe */
- is_ok=TRUE;
+ active_db_set(&INTERNAL_GOT_PID, s);
mark_service(s, RUNNING);
- is_ok=FALSE;
return (TRUE);
}
@@ -284,9 +288,9 @@
return (FALSE);
}
- is_ok=FALSE;
initng_sdt_add(&PIDFILE);
initng_sdt_add(&PIDOF);
+ initng_sdt_add(&INTERNAL_GOT_PID);
initng_add_hook(CONFIRM_ASTATUS_CHANGE, 90, &check_if_done);
initng_add_hook(HANDLE_KILLED, 10, &check_on_kill);
@@ -298,6 +302,7 @@
D_("module_unload();\n");
initng_sdt_del(&PIDFILE);
initng_sdt_del(&PIDOF);
+ initng_sdt_del(&INTERNAL_GOT_PID);
initng_del_hook(CONFIRM_ASTATUS_CHANGE, &check_if_done);
initng_del_hook(HANDLE_KILLED, &check_on_kill);
Modified: initng/src/initng_handler.c
==============================================================================
--- initng/src/initng_handler.c (original)
+++ initng/src/initng_handler.c Sun Nov 6 20:38:38 2005
@@ -678,37 +678,51 @@
static void kill_daemon(active_h * service_to_stop)
{
- process_h *process, *safe = NULL;
-
+ process_h *process = NULL;
assert(service_to_stop);
- while_processes_safe(process, safe, service_to_stop)
+ /* look for a T_DAEMON process */
+ while_processes(process, service_to_stop)
{
- if (process->pt != T_DAEMON)
- continue;
- if (process->pid <= 0)
- continue;
-
+ if (process->pt == T_DAEMON)
+ break;
+ }
+
+ /* check so we got one */
+ if(process->pt != T_DAEMON)
+ {
+ F_("This daemon does not have a daemon_process!\n");
+ list_del(&process->list);
+ process_db_free(process);
+ return;
+ }
+
+ /* check so that pid is good */
+ if (process->pid <= 0)
+ {
+ F_("Bad PID %d in database!\n", process->pid);
+ list_del(&process->list);
+ process_db_free(process);
+ return;
+ }
- if (kill(process->pid, 0) && errno == ESRCH)
- {
- F_("Trying to kill a service (%s) with a pid (%d), but there exists no process with this pid!\n", service_to_stop->name, process->pid);
- list_del(&process->list);
- process_db_free(process);
- }
- else
- {
- D_(" -- (%s): REAL KILLING PID %i!\n",
- service_to_stop->name, process->pid);
-
- /* Uhm, this doesnt work : kill(-service_to_stop->start_process->pid, SIGTERM); */
- kill(process->pid, SIGTERM);
-
- alarm(SECONDS_BEFORE_KILL + 1); /* the alarm will try to kill stopping services */
- D_("Clock is set, killed process %i (%s), have %i seconds to quit before SIGKILL\n", process->pid, service_to_stop->name, SECONDS_BEFORE_KILL);
- /*kill(service_to_stop->start_process->pid,SIGKILL); */
- }
+ /* check so there exits an process with this pid */
+ if (kill(process->pid, 0) && errno == ESRCH)
+ {
+ F_("Trying to kill a service (%s) with a pid (%d), but there exists no process with this pid!\n", service_to_stop->name, process->pid);
+ list_del(&process->list);
+ process_db_free(process);
+ return;
}
+
+ W_(" Sending the process %i of %s, the SIGTERM signal!\n",
+ process->pid, service_to_stop->name);
+
+ /* Uhm, this doesnt work : kill(-service_to_stop->start_process->pid, SIGTERM); */
+ kill(process->pid, SIGTERM);
+
+ alarm(SECONDS_BEFORE_KILL + 1); /* the alarm will try to kill stopping services */
+ D_("Clock is set, killed process %i (%s), have %i seconds to quit before SIGKILL\n", process->pid, service_to_stop->name, SECONDS_BEFORE_KILL);
}
static void handle_STOPPED(active_h * service_stopped)
Modified: initng/src/initng_service_data_types.c
==============================================================================
--- initng/src/initng_service_data_types.c (original)
+++ initng/src/initng_service_data_types.c Sun Nov 6 20:38:38 2005
@@ -46,10 +46,14 @@
{
if (current == ent)
{
- F_("Option %s, alredy added!\n", ent->opt_name);
+ if(ent->opt_name)
+ F_("Option %s, alredy added!\n", ent->opt_name);
+ else
+ F_("Option, alredy added!\n");
+
return;
}
- if (current->opt_name
+ if (current->opt_name && ent->opt_name
&& strcmp(current->opt_name, ent->opt_name) == 0)
{
F_("option %s, name taken.\n");
@@ -58,7 +62,10 @@
}
/* add the option to the option_db list */
list_add(&ent->list, &g.option_db.list);
- D_(" \"%s\" added to option_db!\n", ent->opt_name);
+#ifdef DEBUG
+ if(ent->opt_name)
+ D_(" \"%s\" added to option_db!\n", ent->opt_name);
+#endif
}
/*
Modified: initng/src/initng_static_data_id.c
==============================================================================
--- initng/src/initng_static_data_id.c (original)
+++ initng/src/initng_static_data_id.c Sun Nov 6 20:38:38 2005
@@ -17,6 +17,9 @@
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
+
+#include <stdlib.h>
+#include <stdio.h>
#include "initng_static_data_id.h"
#include "initng_service_data_types.h"
@@ -31,7 +34,7 @@
s_entry NEED = { "need", STRINGS, 4, STD_OPT };
s_entry FROM_FILE = { "from_file", STRING, 9, INTERNAL_OPT };
s_entry ENV = { "env", STRINGS, 3, STD_OPT };
-s_entry RESTARTING = { "internal_restarting", SET, 10, INTERNAL_OPT };
+s_entry RESTARTING = { NULL, SET, 0, INTERNAL_OPT };
s_entry UP_ON_FAILURE = { "up_on_failure", SET, 13, STD_OPT };
/*
More information about the Initng-svn
mailing list