hal/hald device_info.c,1.9,1.10 hald.c,1.9,1.10 osspec.h,1.2,1.3
David Zeuthen
david at freedesktop.org
Wed Jul 21 10:14:56 PDT 2004
Update of /cvs/hal/hal/hald
In directory pdx:/tmp/cvs-serv14640a/hald
Modified Files:
device_info.c hald.c osspec.h
Log Message:
2004-07-21 David Zeuthen <david at fubar.dk>
Commit of first stab at callouts for shutdown; needs some more work.
Now to update the spec
* hald/device_info.c: (scan_fdi_files): Remove some noisy debug
* hald/hald.c:
(handle_sigterm): New function
(sigterm_iochn_data): New function
(main): Handle SIGTERM, setup GIOChannel for safe handling of POSIX
signal
* hald/linux/block_class_device.c:
(detect_media): Comment out noisy EBUSY debug
* hald/linux/osspec.c:
(visit_class_device): Removed unused dir variable
(shutdown_callouts_finished): New function
(do_shutdown_callouts): New function
(osspec_shutdown): New function
* hald/osspec.h: Add prototype for osspec_shutdown()
Index: device_info.c
===================================================================
RCS file: /cvs/hal/hal/hald/device_info.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- device_info.c 4 Jul 2004 19:20:00 -0000 1.9
+++ device_info.c 21 Jul 2004 17:14:54 -0000 1.10
@@ -592,7 +592,7 @@
found_fdi_file = 0;
- HAL_INFO(("scan_fdi_files: Processing dir '%s'", dir));
+ /*HAL_INFO(("scan_fdi_files: Processing dir '%s'", dir));*/
num_entries = scandir (dir, &name_list, 0, alphasort);
if (num_entries == -1) {
@@ -609,7 +609,7 @@
len = strlen (filename);
full_path = g_strdup_printf ("%s/%s", dir, filename);
- HAL_INFO (("Full path = %s", full_path));
+ /*HAL_INFO (("Full path = %s", full_path));*/
/* Mmm, d_type can be DT_UNKNOWN, use glib to determine
* the type
@@ -622,8 +622,8 @@
filename[len - 3] == 'f' &&
filename[len - 2] == 'd' &&
filename[len - 1] == 'i') {
- HAL_INFO (("scan_fdi_files: Processing "
- "file '%s'", filename));
+ /*HAL_INFO (("scan_fdi_files: Processing "
+ "file '%s'", filename));*/
found_fdi_file =
process_fdi_file (dir, filename, d);
if (found_fdi_file) {
Index: hald.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- hald.c 20 Jun 2004 13:27:45 -0000 1.9
+++ hald.c 21 Jul 2004 17:14:54 -0000 1.10
@@ -171,10 +171,52 @@
"\n");
}
-
/** If #TRUE, we will daemonize */
static dbus_bool_t opt_become_daemon = TRUE;
+static int sigterm_unix_signal_pipe_fds[2];
+static GIOChannel *sigterm_iochn;
+
+static void
+handle_sigterm (int value)
+{
+ static char marker[1] = {'S'};
+
+ /* write a 'S' character to the other end to tell about
+ * the signal. Note that 'the other end' is a GIOChannel thingy
+ * that is only called from the mainloop - thus this is how we
+ * defer this since UNIX signal handlers are evil
+ *
+ * Oh, and write(2) is indeed reentrant */
+ write (sigterm_unix_signal_pipe_fds[1], marker, 1);
+}
+
+static gboolean
+sigterm_iochn_data (GIOChannel *source,
+ GIOCondition condition,
+ gpointer user_data)
+{
+ GError *err = NULL;
+ gchar data[1];
+ gsize bytes_read;
+
+ /* 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",
+ err->message));
+ g_error_free (err);
+ goto out;
+ }
+
+ HAL_INFO (("Recieved SIGTERM, initiating shutdown"));
+ osspec_shutdown();
+
+out:
+ return TRUE;
+}
+
+
/** Entry point for HAL daemon
*
* @param argc Number of arguments
@@ -186,6 +228,7 @@
{
DBusConnection *dbus_connection;
GMainLoop *loop;
+ guint sigterm_iochn_listener_source_id;
while (1) {
int c;
@@ -295,6 +338,30 @@
/* and detect devices */
osspec_probe ();
+ /* So, now we are up and running...
+ *
+ * We need to do stuff when we are expected to terminate, thus
+ * this involves looking for SIGTERM; UNIX signal handlers are
+ * evil though, so set up a pipe to transmit the signal.
+ */
+
+ /* create pipe */
+ if (pipe (sigterm_unix_signal_pipe_fds) != 0) {
+ DIE (("Could not setup pipe, errno=%d", errno));
+ }
+
+ /* setup glib handler - 0 is for reading, 1 is for writing */
+ sigterm_iochn = g_io_channel_unix_new (sigterm_unix_signal_pipe_fds[0]);
+ if (sigterm_iochn == NULL)
+ DIE (("Could not create GIOChannel"));
+
+ /* get callback when there is data to read */
+ sigterm_iochn_listener_source_id = g_io_add_watch (
+ sigterm_iochn, G_IO_IN, sigterm_iochn_data, NULL);
+
+ /* Finally, setup unix signal handler for TERM */
+ signal (SIGTERM, handle_sigterm);
+
/* run the main loop and serve clients */
g_main_loop_run (loop);
Index: osspec.h
===================================================================
RCS file: /cvs/hal/hal/hald/osspec.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- osspec.h 3 Mar 2004 17:56:56 -0000 1.2
+++ osspec.h 21 Jul 2004 17:14:54 -0000 1.3
@@ -43,6 +43,11 @@
*/
void osspec_probe ();
+/** Prepare shutdown
+ *
+ */
+void osspec_shutdown ();
+
DBusHandlerResult osspec_filter_function (DBusConnection * connection,
DBusMessage * message,
void *user_data);
More information about the hal-commit
mailing list