hal/hald Makefile.am, 1.46, 1.47 device_info.c, 1.24, 1.25 hald.c,
1.26, 1.27 haldaemon.in, 1.5, 1.6 osspec.h, 1.6, 1.7 util.c,
1.5, 1.6 util.h, 1.4, 1.5
David Zeuthen
david at freedesktop.org
Thu Feb 24 17:55:10 PST 2005
Update of /cvs/hal/hal/hald
In directory gabe:/tmp/cvs-serv13820/hald
Modified Files:
Makefile.am device_info.c hald.c haldaemon.in osspec.h util.c
util.h
Log Message:
2005-02-24 David Zeuthen <davidz at redhat.com>
* hald/linux2/osspec.c (osspec_shutdown): Remove this function
* hald/dummy/osspec.c (computer_callouts_add_done): New function
(osspec_probe): Fixup to use new di_search_and_merge stuff
* hald/util.h: Export prototype for hal_util_kill_all_helpers
* hald/util.c (helper_child_exited): Remove from running_helpers list
(hal_util_helper_invoke): Add to running_helpers list
(hal_util_kill_all_helpers): New function (uses running_helpers list)
* hald/osspec.h: Don't export osspec_shutdown and osspec_shutdown_done
* hald/haldaemon.in: No need to add @LIBEXECDIR@ to PATH now that
hald does that itself
* hald/hald.c (main): Add PACKAGE_LIBEXEC_DIR to out path. Fix a fd
leak also (pointed out by Kay Sievers).
(sigterm_iochn_data): Kill all pending helpers and exit
* hald/device_info.c (di_search_and_merge): Fixup some stupid typos
* hald/Makefile.am (INCLUDES): Include PACKAGE_LIBEXEC_DIR
Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/hald/Makefile.am,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- Makefile.am 24 Feb 2005 17:33:03 -0000 1.46
+++ Makefile.am 25 Feb 2005 01:55:08 -0000 1.47
@@ -3,6 +3,7 @@
SUBDIRS = dummy linux2 .
INCLUDES = \
+ -DPACKAGE_LIBEXEC_DIR=\""$(libexecdir)"\" \
-DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\" \
-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
-DPACKAGE_BIN_DIR=\""$(bindir)"\" \
Index: device_info.c
===================================================================
RCS file: /cvs/hal/hal/hald/device_info.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- device_info.c 24 Feb 2005 19:51:04 -0000 1.24
+++ device_info.c 25 Feb 2005 01:55:08 -0000 1.25
@@ -1437,8 +1437,8 @@
break;
case DEVICE_INFO_TYPE_INFORMATION:
- if (hal_fdi_source_preprobe != NULL) {
- s1 = hal_fdi_source_preprobe;
+ if (hal_fdi_source_information != NULL) {
+ s1 = hal_fdi_source_information;
s2 = NULL;
} else {
s1 = PACKAGE_DATA_DIR "/hal/fdi/information";
@@ -1447,8 +1447,8 @@
break;
case DEVICE_INFO_TYPE_POLICY:
- if (hal_fdi_source_preprobe != NULL) {
- s1 = hal_fdi_source_preprobe;
+ if (hal_fdi_source_policy != NULL) {
+ s1 = hal_fdi_source_policy;
s2 = NULL;
} else {
s1 = PACKAGE_DATA_DIR "/hal/fdi/policy";
Index: hald.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- hald.c 24 Feb 2005 16:50:34 -0000 1.26
+++ hald.c 25 Feb 2005 01:55:08 -0000 1.27
@@ -56,8 +56,9 @@
#include "hald_dbus.h"
#include "util.h"
-static void delete_pid(void) {
- unlink(HALD_PID_FILE);
+static void delete_pid(void)
+{
+ unlink(HALD_PID_FILE);
}
/**
@@ -255,39 +256,30 @@
GError *err = NULL;
gchar data[1];
gsize bytes_read;
+ unsigned int num_helpers;
/* Empty the pipe */
if (G_IO_STATUS_NORMAL !=
g_io_channel_read_chars (source, data, 1, &bytes_read, &err)) {
- HAL_ERROR (("Error emptying callout notify pipe: %s",
+ HAL_ERROR (("Error emptying sigterm pipe: %s",
err->message));
g_error_free (err);
goto out;
}
- fprintf (stderr, "SIGTERM, initiating shutdown");
-
- hald_is_shutting_down = TRUE;
-
- osspec_shutdown();
+ HAL_INFO (("Caught SIGTERM, initiating shutdown"));
+ num_helpers = hal_util_kill_all_helpers ();
+ HAL_INFO (("Killed %d helpers; exiting"));
+ exit (0);
out:
return TRUE;
}
-void
-osspec_shutdown_done (void)
-{
- exit (0);
-}
-
/** This is set to #TRUE if we are probing and #FALSE otherwise */
dbus_bool_t hald_is_initialising;
-/** This is set to #TRUE if we are shutting down and #FALSE otherwise */
-dbus_bool_t hald_is_shutting_down;
-
static int startup_daemonize_pipe[2];
/** Drop all but necessary privileges from hald when it runs as root. Set the
@@ -342,6 +334,8 @@
GMainLoop *loop;
guint sigterm_iochn_listener_source_id;
gboolean retain_privs;
+ char *path;
+ char newpath[512];
retain_privs = FALSE;
@@ -355,6 +349,15 @@
else
hald_is_verbose = FALSE;
+ /* our helpers are installed into libexec, so adjust out $PATH to include this */
+ path = getenv ("PATH");
+ g_strlcpy (newpath, PACKAGE_LIBEXEC_DIR, sizeof (newpath));
+ if (path != NULL) {
+ g_strlcat (newpath, ":", sizeof (newpath));
+ g_strlcat (newpath, path, sizeof (newpath));
+ }
+ setenv ("PATH", newpath, TRUE);
+
while (1) {
int c;
int option_index = 0;
@@ -463,6 +466,7 @@
dup2 (dev_null_fd, 0);
dup2 (dev_null_fd, 1);
dup2 (dev_null_fd, 2);
+ close (dev_null_fd);
}
umask (022);
@@ -482,18 +486,15 @@
setsid ();
/* remove old pid file */
- unlink(HALD_PID_FILE);
+ unlink (HALD_PID_FILE);
/* Make a new one */
- if ((pf=open(HALD_PID_FILE, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL,
- 0644)) == -1) {
- HAL_ERROR (("Cannot create pid file"));
- exit(1);
+ if ((pf= open (HALD_PID_FILE, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644)) > 0) {
+ snprintf (pid, sizeof(pid), "%lu\n", (long unsigned) getpid ());
+ write (pf, pid, strlen(pid));
+ close (pf);
+ atexit (delete_pid);
}
- sprintf(pid, "%lu\n", (long unsigned)getpid());
- write(pf, pid, strlen(pid));
- close(pf);
- atexit(delete_pid);
}
Index: haldaemon.in
===================================================================
RCS file: /cvs/hal/hal/hald/haldaemon.in,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- haldaemon.in 24 Feb 2005 17:57:48 -0000 1.5
+++ haldaemon.in 25 Feb 2005 01:55:08 -0000 1.6
@@ -25,7 +25,6 @@
start() {
echo -n $"Starting HAL daemon: "
- export PATH=@LIBEXECDIR@:$PATH
daemon --check $servicename $processname --retain-privileges
RETVAL=$?
echo
Index: osspec.h
===================================================================
RCS file: /cvs/hal/hal/hald/osspec.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- osspec.h 2 Feb 2005 20:44:25 -0000 1.6
+++ osspec.h 25 Feb 2005 01:55:08 -0000 1.7
@@ -41,12 +41,6 @@
/* Called by kernel specific parts when probing is done */
void osspec_probe_done (void);
-/** Prepare shutdown */
-void osspec_shutdown (void);
-
-/* Called by kernel specific parts when probing is done */
-void osspec_shutdown_done (void);
-
gboolean osspec_device_rescan (HalDevice *d);
gboolean osspec_device_reprobe (HalDevice *d);
Index: util.c
===================================================================
RCS file: /cvs/hal/hal/hald/util.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- util.c 24 Feb 2005 16:50:34 -0000 1.5
+++ util.c 25 Feb 2005 01:55:08 -0000 1.6
@@ -463,6 +463,8 @@
return FALSE;
}
+static GSList *running_helpers = NULL;
+
static void
helper_child_exited (GPid pid, gint status, gpointer data)
{
@@ -476,7 +478,8 @@
if (!ed->already_issued_callback)
ed->cb (ed->d, FALSE, WEXITSTATUS (status), ed->data1, ed->data2, ed);
-
+
+ running_helpers = g_slist_remove (running_helpers, ed);
g_free (ed);
}
@@ -542,8 +545,6 @@
num_env_vars++;
if (hald_is_initialising)
num_env_vars++;
- if (hald_is_shutting_down)
- num_env_vars++;
envp = g_new (char *, num_env_vars);
ienvp = envp;
@@ -554,8 +555,6 @@
envp[i++] = g_strdup ("HALD_VERBOSE=1");
if (hald_is_initialising)
envp[i++] = g_strdup ("HALD_STARTUP=1");
- if (hald_is_shutting_down)
- envp[i++] = g_strdup ("HALD_SHUTDOWN=1");
for (j = 0; j < num_extras; j++) {
envp[i++] = g_strdup (extra_env[j]);
}
@@ -587,6 +586,8 @@
ed->timeout_watch_id = g_timeout_add (timeout, helper_child_timeout, (gpointer) ed);
else
ed->timeout_watch_id = (guint) -1;
+
+ running_helpers = g_slist_prepend (running_helpers, ed);
}
}
@@ -1032,3 +1033,26 @@
out:
;
}
+
+/** Kill all helpers we have running; useful when exiting hald.
+ *
+ * @return Number of childs killed
+ */
+unsigned int
+hal_util_kill_all_helpers (void)
+{
+ unsigned int n;
+ GSList *i;
+
+ n = 0;
+ for (i = running_helpers; i != NULL; i = i->next) {
+ HalHelperData *ed;
+
+ ed = i->data;
+ HAL_INFO (("Killing helper with pid %d", ed->pid));
+ kill (ed->pid, SIGTERM);
+ n++;
+ }
+
+ return n;
+}
Index: util.h
===================================================================
RCS file: /cvs/hal/hal/hald/util.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- util.h 24 Feb 2005 16:50:34 -0000 1.4
+++ util.h 25 Feb 2005 01:55:08 -0000 1.5
@@ -95,6 +95,8 @@
gboolean already_issued_callback;
};
+unsigned int hal_util_kill_all_helpers (void);
+
HalHelperData *hal_util_helper_invoke (const gchar *command_line, gchar **extra_env, HalDevice *d,
gpointer data1, gpointer data2, HalHelperTerminatedCB cb, guint timeout);
More information about the hal-commit
mailing list