[Initng-svn] r2989 - initng/src

svn at initng.thinktux.net svn at initng.thinktux.net
Tue Feb 14 10:00:16 CET 2006


Author: jimmy
Date: Tue Feb 14 10:00:16 2006
New Revision: 2989

Modified:
   initng/src/initng_kill_handler.c
   initng/src/initng_process_db.c
   initng/src/initng_process_db.h
Log:
initng_kill_handler.c a cleanup.
added initng_process_db_get_by_pid() to initng_process_db.c


Modified: initng/src/initng_kill_handler.c
==============================================================================
--- initng/src/initng_kill_handler.c	(original)
+++ initng/src/initng_kill_handler.c	Tue Feb 14 10:00:16 2006
@@ -44,6 +44,7 @@
 #include "initng_active_db.h"
 #include "initng_load_module.h"
 #include "initng_plugin_callers.h"
+#include "initng_process_db.h"
 #include "initng_fd.h"
 
 #include "initng_kill_handler.h"
@@ -55,7 +56,7 @@
 {
     /* The process that got killed */
     active_db_h *service = NULL;
-    process_h *process, *safe = NULL;
+    process_h *process = NULL;
 
     D_("handle_killed_by_pid(%i);\n", kpid);
 
@@ -70,56 +71,45 @@
         return;
     }
 
-    /* check service state */
-    if (!service->current_state)
+    D_("handle_killed_by_pid(%i): found service \"%s\"...\n", kpid,
+       service->name);
+
+    /* Get the process pointer from the service */
+    if(!(process = initng_process_db_get_by_pid(kpid, service)))
     {
-        W_("Service has no state!\n");
-        return;
+	W_("Coud not fetch process, even when initng_active_db_find_by_pid() saw it here!\n");
+	return;
     }
+    
+    D_("(%i), found process type: %s\n", kpid, process->pt->name);    
+    
 
-    D_("handle_killed_by_pid(%i): found service \"%s\"...\n", kpid,
-       service->name);
+    /* set r_code */
+    process->r_code = r_code;
 
-    while_processes_safe(process, safe, service)
+    /* Check if a plugin wants to override handle_killed behavior */
+    if (initng_plugin_callers_handle_killed(service, process))
     {
-        /* make sure it's the right process */
-        D_("There exists a process type %s in db with pid %i\n",
-           process->pt->name, process->pid);
-        if (process->pid != kpid)
-            continue;
-        D_("Found matching process type %s.\n", process->pt->name);
-
-        /* set r_code */
-        process->r_code = r_code;
-
-        /* Check if a plugin wants to override handle_killed behavior */
-        if (initng_plugin_callers_handle_killed(service, process))
-        {
-            D_("Plugin did handle this kill.\n");
-            return;
-        }
-
-        /*
-         * calling initng_process_read_input, with flush true
-         * makes it close read all fd, and close them, that is important.
-         */
-        initng_fd_process_read_input(service, process, TRUE);
-
-        /* launch a kill_handler if any */
-        if (process->pt && process->pt->kill_handler)
-        {
-            D_("Launching process->pt->kill_handler\n");
-            (*process->pt->kill_handler) (service, process);
-        }
-        else
-        {
-            F_("service %s pid %i p_type %s died with unknown handler, freeing process!\n", service->name, kpid, process->pt->name);
-            list_del(&process->list);
-            initng_process_db_free(process);
-        }
+        D_("Plugin did handle this kill.\n");
         return;
     }
 
-    F_("handle_killed_by_pid(%i): traced killed pid to a service but can't find service type!\n", kpid);
-    return;
+    /*
+     * calling initng_process_read_input, with flush true
+     * makes it close read all fd, and close them, that is important.
+     */
+    initng_fd_process_read_input(service, process, TRUE);
+
+    /* launch a kill_handler if any */
+    if (process->pt && process->pt->kill_handler)
+    {
+        D_("Launching process->pt->kill_handler\n");
+        (*process->pt->kill_handler) (service, process);
+    }
+    else
+    {
+        D_("service %s pid %i p_type %s died with unknown handler, freeing process!\n", service->name, kpid, process->pt->name);
+        list_del(&process->list);
+        initng_process_db_free(process);
+    }
 }

Modified: initng/src/initng_process_db.c
==============================================================================
--- initng/src/initng_process_db.c	(original)
+++ initng/src/initng_process_db.c	Tue Feb 14 10:00:16 2006
@@ -90,8 +90,25 @@
             return (current);
     }
     return (NULL);
+
+}
+
+/*
+ * Finds a process by its pid.
+ */
+process_h *initng_process_db_get_by_pid(pid_t pid, active_db_h * service)
+{
+    process_h *current = NULL;
+
+    while_processes(current, service)
+    {
+	if(current->pid==pid)
+	    return(current);
+    }
+    return (NULL);
 }
 
+
 /* function to free a process_h struct */
 void initng_process_db_free(process_h * free_this)
 {

Modified: initng/src/initng_process_db.h
==============================================================================
--- initng/src/initng_process_db.h	(original)
+++ initng/src/initng_process_db.h	Tue Feb 14 10:00:16 2006
@@ -71,6 +71,7 @@
 void initng_process_db_free(process_h * free_this);
 process_h *initng_process_db_get(ptype_h * type, active_db_h * service);
 process_h *initng_process_db_get_by_name(const char *name, active_db_h * service);
+process_h *initng_process_db_get_by_pid(pid_t pid, active_db_h * service);
 
 #define while_processes(current, service) list_for_each_entry_prev(current, &service->processes.list, list)
 #define while_processes_safe(current, safe, service) list_for_each_entry_prev_safe(current, safe, &service->processes.list, list)


More information about the Initng-svn mailing list