hal/hald callout.c, 1.13, 1.14 hald.c, 1.11, 1.12 hald.h, 1.5, 1.6 logger.c, 1.5, 1.6 logger.h, 1.6, 1.7 osspec.h, 1.4, 1.5

David Zeuthen david at freedesktop.org
Sun Aug 22 12:27:24 PDT 2004


Update of /cvs/hal/hal/hald
In directory gabe:/tmp/cvs-serv2401/hald

Modified Files:
	callout.c hald.c hald.h logger.c logger.h osspec.h 
Log Message:
2004-08-22  David Zeuthen  <david at fubar.dk>

	* hald/callout.c: Only invoke callouts if they have the .hal extension.
	Export HALD_VERBOSE if the hald instance is started with verbose.
	Add HALD_STARTUP resp. HALD_SHUTDOWN only if the callout is in response
	to hald starting up/shutting down.

	* hald/hald.c: Add an verbose option. Use the HALD_VERBOSE environment
	variable. Postpone daemonization until we are done probing.

	* hald/hald.h: Move hald_is_[verbose|initialising|is_shutting_down] here

	* hald/linux/bus_device.c: 
	(bus_device_visit): We can now always assume we got a parent

	* hald/linux/class_device.c: 
	(class_device_visit): We can now always assume we got a parent

	* hald/linux/common.h:

	* hald/linux/drive_id/drive_id.c:

	* hald/linux/osspec.c: Complete rewrite of probing code; now we
	construct a list of ''coldplug events'' and feed them to the
	two new functions add_device() and rem_device(); this unifies 
	a few codepaths and it's much faster, cleaner and just yummier. 
	Also ensure that callouts are run sequentially.

	* hald/logger.c: 
	(logger_enable),
	(logger_disable): New functions 
	(logger_emit): Print time and don't print function name

	* hald/logger.h: Add logger_[enable|disable].

	* tools/fstab-sync.c:
	(open_temp_fstab_file): Use /tmp for the temporary file
	(fs_table_has_volume): Remove debug spew
	(add_udi): Log a message to the syslog on success
	(remove_udi): Log a message to the syslog on success
	(clean): Log a message to the syslog on success
	(main): Use HALD_VERBOSE. When invoked for the ''computer'' device
	object on hald startup, automatically clean the fstab (but only if
	using a managed keyword). Don't remove entries on hald
	shutdown. In line with the osspec.c changes (sequential callouts)
	we now get a fully sanitized /etc/fstab at hald startup, Yay!

	* tools/linux/hal_dev.c: (main): Less syslog spamming

	* tools/linux/hal_hotplug.c: 
	(wait_for_sysfs_info): Less syslog spamming
	(main): Less syslog spamming



Index: callout.c
===================================================================
RCS file: /cvs/hal/hal/hald/callout.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- callout.c	1 May 2004 19:46:41 -0000	1.13
+++ callout.c	22 Aug 2004 19:27:22 -0000	1.14
@@ -33,6 +33,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "hald.h"
 #include "callout.h"
 #include "logger.h"
 
@@ -328,6 +329,8 @@
 
 	active_callouts = g_slist_append (active_callouts, callout);
 
+	HAL_INFO (("Invoking %s", argv[0]));
+
 	if (!g_spawn_async (callout->working_dir, argv, callout->envp,
 			    G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL,
 			    &callout->pid, &err)) {
@@ -370,10 +373,14 @@
 		char *full_filename;
 		Callout *callout;
 		int num_props;
+		int i;
 
 		full_filename = g_build_filename (DEVICE_CALLOUT_DIR,
 						  filename, NULL);
 
+		if (!g_str_has_suffix (filename, ".hal"))
+			continue;
+
 		if (!g_file_test (full_filename, G_FILE_TEST_IS_EXECUTABLE)) {
 			g_free (full_filename);
 			continue;
@@ -391,10 +398,23 @@
 		num_props = hal_device_num_properties (device);
 
 		callout->envp_index = 1;
+		if (hald_is_verbose)
+			callout->envp_index++;
+		if (hald_is_initialising)
+			callout->envp_index++;
+		if (hald_is_shutting_down)
+			callout->envp_index++;
 		callout->envp = g_new (char *, callout->envp_index);
 
-		callout->envp[0] = g_strdup_printf ("UDI=%s",
-						    hal_device_get_udi (device));
+		i = 0;
+		callout->envp[i++] = g_strdup_printf ("UDI=%s", hal_device_get_udi (device));
+		if (hald_is_verbose)
+			callout->envp[i++] = g_strdup ("HALD_VERBOSE=1");
+		if (hald_is_initialising)
+			callout->envp[i++] = g_strdup ("HALD_STARTUP=1");
+		if (hald_is_shutting_down)
+			callout->envp[i++] = g_strdup ("HALD_SHUTDOWN=1");
+
 		add_pending_callout (callout->device, callout);
 
 		any_callouts = TRUE;
@@ -440,10 +460,14 @@
 		char *full_filename;
 		Callout *callout;
 		int num_props;
+		int i;
 
 		full_filename = g_build_filename (CAPABILITY_CALLOUT_DIR,
 						  filename, NULL);
 
+		if (!g_str_has_suffix (filename, ".hal"))
+			continue;
+
 		if (!g_file_test (full_filename, G_FILE_TEST_IS_EXECUTABLE)) {
 			g_free (full_filename);
 			continue;
@@ -461,12 +485,23 @@
 		num_props = hal_device_num_properties (device);
 
 		callout->envp_index = 2;
+		if (hald_is_verbose)
+			callout->envp_index++;
+		if (hald_is_initialising)
+			callout->envp_index++;
+		if (hald_is_shutting_down)
+			callout->envp_index++;
 		callout->envp = g_new (char *, callout->envp_index);
 
-		callout->envp[0] = g_strdup_printf ("UDI=%s",
-						    hal_device_get_udi (device));
-		callout->envp[1] = g_strdup_printf ("CAPABILITY=%s",
-						    capability);
+		i = 0;
+		callout->envp[i++] = g_strdup_printf ("UDI=%s", hal_device_get_udi (device));
+		callout->envp[i++] = g_strdup_printf ("CAPABILITY=%s", capability);
+		if (hald_is_verbose)
+			callout->envp[i++] = g_strdup ("HALD_VERBOSE=1");
+		if (hald_is_initialising)
+			callout->envp[i++] = g_strdup ("HALD_STARTUP=1");
+		if (hald_is_shutting_down)
+			callout->envp[i++] = g_strdup ("HALD_SHUTDOWN=1");
 
 		add_pending_callout (callout->device, callout);
 	}
@@ -502,10 +537,14 @@
 		char *full_filename, *value;
 		Callout *callout;
 		int num_props;
+		int i;
 
 		full_filename = g_build_filename (PROPERTY_CALLOUT_DIR,
 						  filename, NULL);
 
+		if (!g_str_has_suffix (filename, ".hal"))
+			continue;
+
 		if (!g_file_test (full_filename, G_FILE_TEST_IS_EXECUTABLE)) {
 			g_free (full_filename);
 			continue;
@@ -525,12 +564,23 @@
 		value = hal_device_property_to_string (device, key);
 
 		callout->envp_index = 3;
+		if (hald_is_verbose)
+			callout->envp_index++;
+		if (hald_is_initialising)
+			callout->envp_index++;
+		if (hald_is_shutting_down)
+			callout->envp_index++;
 		callout->envp = g_new (char *, callout->envp_index);
-
-		callout->envp[0] = g_strdup_printf ("UDI=%s",
-						    hal_device_get_udi (device));
-		callout->envp[1] = g_strdup_printf ("PROPERTY=%s", key);
-		callout->envp[2] = g_strdup_printf ("VALUE=%s", value);
+		i = 0;
+		callout->envp[i++] = g_strdup_printf ("UDI=%s", hal_device_get_udi (device));
+		callout->envp[i++] = g_strdup_printf ("PROPERTY=%s", key);
+		callout->envp[i++] = g_strdup_printf ("VALUE=%s", value);
+		if (hald_is_verbose)
+			callout->envp[i++] = g_strdup ("HALD_VERBOSE=1");
+		if (hald_is_initialising)
+			callout->envp[i++] = g_strdup ("HALD_STARTUP=1");
+		if (hald_is_shutting_down)
+			callout->envp[i++] = g_strdup ("HALD_SHUTDOWN=1");
 
 		add_pending_callout (callout->device, callout);
 

Index: hald.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- hald.c	30 Jul 2004 17:00:42 -0000	1.11
+++ hald.c	22 Aug 2004 19:27:22 -0000	1.12
@@ -157,16 +157,17 @@
 static void
 usage ()
 {
-	fprintf (stderr, "\n" "usage : hald [--daemon=yes|no] [--help]\n");
+	fprintf (stderr, "\n" "usage : hald [--daemon=yes|no] [--verbose=yes|no] [--help]\n");
 	fprintf (stderr,
 		 "\n"
 		 "        --daemon=yes|no    Become a daemon\n"
+		 "        --verbose=yes|no   Print out debug (overrides HALD_VERBOSE)\n"
 		 "        --help             Show this information and exit\n"
 		 "\n"
 		 "The HAL daemon detects devices present in the system and provides the\n"
-		 "org.freedesktop.Hal service through D-BUS. The commandline options given\n"
-		 "overrides the configuration given in "
-		 PACKAGE_SYSCONF_DIR "/hald.conf\n" "\n"
+		 "org.freedesktop.Hal service through the system-wide message bus provided\n"
+		 "by D-BUS.\n"
+		 "\n"
 		 "For more information visit http://freedesktop.org/Software/hal\n"
 		 "\n");
 }
@@ -174,6 +175,9 @@
 /** If #TRUE, we will daemonize */
 static dbus_bool_t opt_become_daemon = TRUE;
 
+/** If #TRUE, we will spew out debug */
+dbus_bool_t hald_is_verbose = FALSE;
+
 static int sigterm_unix_signal_pipe_fds[2];
 static GIOChannel *sigterm_iochn;
 
@@ -209,13 +213,28 @@
 		goto out;
 	}
 
-	HAL_INFO (("Recieved SIGTERM, initiating shutdown"));
+	fprintf (stderr, "SIGTERM, initiating shutdown");
+
+	hald_is_shutting_down = TRUE;
+
 	osspec_shutdown();
 
 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;
 
 /** Entry point for HAL daemon
  *
@@ -227,7 +246,12 @@
 main (int argc, char *argv[])
 {
 	GMainLoop *loop;
-	guint sigterm_iochn_listener_source_id;
+
+	logger_init ();
+	if (getenv ("HALD_VERBOSE"))
+		hald_is_verbose = TRUE;
+	else
+		hald_is_verbose = FALSE;
 
 	while (1) {
 		int c;
@@ -235,6 +259,7 @@
 		const char *opt;
 		static struct option long_options[] = {
 			{"daemon", 1, NULL, 0},
+			{"verbose", 1, NULL, 0},
 			{"help", 0, NULL, 0},
 			{NULL, 0, NULL, 0}
 		};
@@ -260,6 +285,15 @@
 					usage ();
 					return 1;
 				}
+			} else if (strcmp (opt, "verbose") == 0) {
+				if (strcmp ("yes", optarg) == 0) {
+					hald_is_verbose = TRUE;
+				} else if (strcmp ("no", optarg) == 0) {
+					hald_is_verbose = FALSE;
+				} else {
+					usage ();
+					return 1;
+				}
 			}
 			break;
 
@@ -270,27 +304,65 @@
 		}
 	}
 
-	logger_init ();
-	HAL_INFO (("HAL daemon version " PACKAGE_VERSION " starting up"));
+	if (hald_is_verbose)
+		logger_enable ();
+	else
+		logger_disable ();
 
 	HAL_DEBUG (("opt_become_daemon = %d", opt_become_daemon));
 
 	hald_read_conf_file ();
 
+	g_type_init ();
+
+	/* set up the dbus services */
+	if (!hald_dbus_init ())
+		return 1;
+
+	loop = g_main_loop_new (NULL, FALSE);
+
+	/* initialize persitent property store, read uuid from path */
+	if (hald_get_conf ()->persistent_device_list)
+		hal_pstore_init (PACKAGE_LOCALSTATEDIR "/lib/hal/uuid");
+
+	/* initialize operating system specific parts */
+	osspec_init ();
+
+	hald_is_initialising = TRUE;
+
+	/* detect devices */
+	osspec_probe ();
+
+	/* run the main loop and serve clients */
+	g_main_loop_run (loop);
+
+	return 0;
+}
+
+void 
+osspec_probe_done (void)
+{
+	guint sigterm_iochn_listener_source_id;
+
+	HAL_INFO (("Device probing completed"));
+
+	hald_is_initialising = FALSE;
+
 	if (opt_become_daemon) {
 		int child_pid;
 		int dev_null_fd;
 
+		HAL_INFO (("Becoming a daemon"));
+
 		if (chdir ("/") < 0) {
-			HAL_ERROR (("Could not chdir to /, errno=%d",
-				    errno));
-			return 1;
+			fprintf (stderr, "Could not chdir to /: %s\n", strerror(errno));
+			exit (1);
 		}
 
 		child_pid = fork ();
 		switch (child_pid) {
 		case -1:
-			HAL_ERROR (("Cannot fork(), errno=%d", errno));
+			fprintf (stderr, "Cannot fork(): %s\n", strerror(errno));
 			break;
 
 		case 0:
@@ -306,9 +378,6 @@
 			}
 
 			umask (022);
-
-			/** @todo FIXME change logger to direct to syslog */
-
 			break;
 
 		default:
@@ -321,26 +390,8 @@
 		setsid ();
 	}
 
-	g_type_init ();
-
-	/* set up the dbus services */
-	if (!hald_dbus_init ())
-		exit (1);
-
-	loop = g_main_loop_new (NULL, FALSE);
-
-	/* initialize persitent property store, read uuid from path */
-	if (hald_get_conf ()->persistent_device_list)
-		hal_pstore_init (PACKAGE_LOCALSTATEDIR "/lib/hal/uuid");
 
-	/* initialize operating system specific parts */
-	osspec_init ();
-	/* and detect devices */
-	osspec_probe ();
-
-	/* So, now we are up and running...
-	 * 
-	 * We need to do stuff when we are expected to terminate, thus
+	/* 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.
 	 */
@@ -361,11 +412,7 @@
 	
 	/* Finally, setup unix signal handler for TERM */
 	signal (SIGTERM, handle_sigterm);
-
-	/* run the main loop and serve clients */
-	g_main_loop_run (loop);
-
-	return 0;
 }
 
+
 /** @} */

Index: hald.h
===================================================================
RCS file: /cvs/hal/hal/hald/hald.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- hald.h	20 Jun 2004 13:27:45 -0000	1.5
+++ hald.h	22 Aug 2004 19:27:22 -0000	1.6
@@ -46,6 +46,10 @@
 void property_atomic_update_begin ();
 void property_atomic_update_end ();
 
+extern dbus_bool_t hald_is_verbose;
+extern dbus_bool_t hald_is_initialising;
+extern dbus_bool_t hald_is_shutting_down;
+
 /**
  *  @}
  */

Index: logger.c
===================================================================
RCS file: /cvs/hal/hal/hald/logger.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- logger.c	3 Apr 2004 07:46:33 -0000	1.5
+++ logger.c	22 Aug 2004 19:27:22 -0000	1.6
@@ -31,6 +31,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
+#include <time.h>
+#include <sys/time.h>
 
 #include "logger.h"
 
@@ -47,12 +49,33 @@
 static int line;
 static const char *function;
 
+static int is_enabled = 1;
+
+
 /** Initialize logging system
  *
  */
 void
-logger_init ()
+logger_init (void)
+{
+}
+
+/** Disable all logging
+ *
+ */
+void 
+logger_disable (void)
+{
+	is_enabled = 0;
+}
+
+/** Enable all logging
+ *
+ */
+void 
+logger_enable (void)
 {
+	is_enabled = 1;
 }
 
 /** Setup logging entry
@@ -63,8 +86,7 @@
  *  @param  function            Name of function
  */
 void
-logger_setup (int _priority, const char *_file, int _line,
-	      const char *_function)
+logger_setup (int _priority, const char *_file, int _line, const char *_function)
 {
 	priority = _priority;
 	file = _file;
@@ -83,9 +105,16 @@
 	va_list args;
 	char buf[512];
 	char *pri;
+	char tbuf[256];
+	struct timeval tnow;
+	struct tm *tlocaltime;
+	struct timezone tzone;
+
+	if (!is_enabled)
+		return;
 
 	va_start (args, format);
-	vsnprintf (buf, 512, format, args);
+	vsnprintf (buf, sizeof (buf), format, args);
 
 	switch (priority) {
 	case HAL_LOGPRI_TRACE:
@@ -106,10 +135,13 @@
 		break;
 	}
 
+	gettimeofday (&tnow, &tzone);
+	tlocaltime = localtime (&tnow.tv_sec);
+	strftime (tbuf, sizeof (tbuf), "%H:%M:%S", tlocaltime);
+
 	/** @todo Make programmatic interface to logging */
 	if (priority != HAL_LOGPRI_TRACE)
-		fprintf (stderr, "%s %s:%d %s() : %s\n",
-			 pri, file, line, function, buf);
+		fprintf (stderr, "%s.%03d %s %s:%d: %s\n", tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf);
 
 	va_end (args);
 }

Index: logger.h
===================================================================
RCS file: /cvs/hal/hal/hald/logger.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- logger.h	1 May 2004 19:29:17 -0000	1.6
+++ logger.h	22 Aug 2004 19:27:22 -0000	1.7
@@ -46,13 +46,15 @@
 	HAL_LOGPRI_ERROR = (1 << 4)    /**< error */
 };
 
-void logger_init ();
+void logger_init (void);
 
-void logger_setup (int priority, const char *file, int line,
-		   const char *function);
+void logger_setup (int priority, const char *file, int line, const char *function);
 
 void logger_emit (const char *format, ...);
 
+void logger_enable (void);
+void logger_disable (void);
+
 #ifdef ENABLE_VERBOSE_MODE
 
 /* Verbose mode */

Index: osspec.h
===================================================================
RCS file: /cvs/hal/hal/hald/osspec.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- osspec.h	30 Jul 2004 17:00:42 -0000	1.4
+++ osspec.h	22 Aug 2004 19:27:22 -0000	1.5
@@ -31,24 +31,29 @@
 #include <dbus/dbus.h>
 
 
-/** Initialize the OS specific parts of the daemon
- *
- */
+/** Initialize the kernel specific parts of the daemon */
 void osspec_init (void);
 
-/** Probe all hardware present in the system and synchronize with the
- *  device list
- *
- */
+/** Probe all devices present in the system and build the device list */
 void osspec_probe (void);
 
-/** Prepare shutdown
- *
- */
+/* Called by kernel specific parts when probing is done */
+void osspec_probe_done (void);
+
+/** Prepare shutdown */
 void osspec_shutdown (void);
 
-DBusHandlerResult osspec_filter_function (DBusConnection * connection,
-					  DBusMessage * message,
-					  void *user_data);
+/* Called by kernel specific parts when probing is done */
+void osspec_shutdown_done (void);
 
-#endif				/* OSSPEC_H */
+/** Called when the org.freedesktop.Hal service receives a messaged that the generic daemon 
+ *  doesn't handle. Can be used for intercepting messages from kernel or core OS components.
+ *
+ *  @param  connection          D-BUS connection
+ *  @param  message             Message
+ *  @param  user_data           User data
+ *  @return                     What to do with the message
+ */
+DBusHandlerResult osspec_filter_function (DBusConnection *connection, DBusMessage *message, void *user_data);
+
+#endif /* OSSPEC_H */




More information about the hal-commit mailing list