hal: Branch 'master' - 4 commits

Richard Hughes hughsient at kemper.freedesktop.org
Thu Jan 29 00:38:31 PST 2009


 hald/hald.c              |   20 +++++++++++++++-----
 tools/hal-device.c       |    9 ++++++++-
 tools/hal_get_property.c |   14 ++++++++++++++
 3 files changed, 37 insertions(+), 6 deletions(-)

New commits:
commit 879f06a4e4abc87471a030a5f285dc32455082e4
Merge: f3cec03... 101c34a...
Author: Richard Hughes <richard at hughsie.com>
Date:   Thu Jan 29 08:37:46 2009 +0000

    Merge branch 'master' of git+ssh://hughsient@git.freedesktop.org/git/hal

commit f3cec03bef98c0083c2e9a58ab7323e544412700
Author: Richard Hughes <richard at hughsie.com>
Date:   Thu Jan 29 08:37:26 2009 +0000

    allow child timeout to be set so hal starts on big servers
    
    When a server has a _lot_ of disks, hald fails to
    startup as it spends more than 250 seconds probing.
    We don't want to hardocde this number any higher, as
    this may leave haldaemon hung for a long time if there
    is an error. Add as a command line argument that can be
    appended in the init script if this is required.

diff --git a/hald/hald.c b/hald/hald.c
index 051b33b..cc47567 100644
--- a/hald/hald.c
+++ b/hald/hald.c
@@ -299,6 +299,9 @@ usage (void)
 		 "        --daemon=yes|no       Become a daemon\n"
 		 "        --verbose=yes|no      Print out debug (overrides HALD_VERBOSE)\n"
 		 "        --retain-privileges   Retain privileges (for debugging)\n"
+		 "        --child-timeout=time  Set this timout for the child prober. A larger\n"
+		 "                              number than the default 250s is required for systems\n"
+		 "                              with many resources to be probed at boot time\n"
  		 "        --use-syslog          Print out debug messages to syslog instead of\n"
 		 "                              stderr. Use this option to get debug messages\n"
 		 "                              if hald runs as a daemon.\n"
@@ -392,7 +395,7 @@ handle_sigchld (int value)
 }
 
 static int 
-parent_wait_for_child (int child_fd, pid_t child_pid)
+parent_wait_for_child (guint timeout, int child_fd, pid_t child_pid)
 {
 	fd_set rfds;
 	fd_set efds;
@@ -419,8 +422,8 @@ parent_wait_for_child (int child_fd, pid_t child_pid)
 	FD_SET(child_fd, &rfds);
 	FD_ZERO(&efds);
 	FD_SET(child_fd, &efds);
-	/* Wait up to 250 seconds for device probing */
-	tv.tv_sec = 250;
+	/* Wait up to a set time for device probing */
+	tv.tv_sec = timeout;
 	tv.tv_usec = 0;
 
 	retval = select (child_fd + 1, &rfds, NULL, &efds, &tv);
@@ -537,6 +540,7 @@ main (int argc, char *argv[])
 	guint sigterm_iochn_listener_source_id;
 	char *path;
 	char newpath[512];
+	guint opt_child_timeout;
 #ifdef HAVE_POLKIT
         PolKitError *p_error;
 #endif
@@ -584,7 +588,9 @@ main (int argc, char *argv[])
 	g_strlcat (newpath, PACKAGE_SCRIPT_DIR, sizeof (newpath));
 
 	setenv ("PATH", newpath, TRUE);
-	
+
+	/* set the default child timeout to 250 seconds */
+	opt_child_timeout = 250;
 
 	while (1) {
 		int c;
@@ -595,6 +601,7 @@ main (int argc, char *argv[])
 			{"daemon", 1, NULL, 0},
 			{"verbose", 1, NULL, 0},
 			{"retain-privileges", 0, NULL, 0},
+			{"child-timeout", 1, NULL, 0},
 			{"use-syslog", 0, NULL, 0},
 			{"help", 0, NULL, 0},
 			{"version", 0, NULL, 0},
@@ -618,6 +625,8 @@ main (int argc, char *argv[])
 				return 0;
 			} else if (strcmp (opt, "exit-after-probing") == 0) {
 				hald_debug_exit_after_probing = TRUE;
+			} else if (strcmp (opt, "child-timeout") == 0) {
+				opt_child_timeout = atoi (optarg);
 			} else if (strcmp (opt, "daemon") == 0) {
 				if (strcmp ("yes", optarg) == 0) {
 					opt_become_daemon = TRUE;
@@ -669,6 +678,7 @@ main (int argc, char *argv[])
 	loop = g_main_loop_new (NULL, FALSE);
 
 	HAL_INFO ((PACKAGE_STRING));
+	HAL_INFO (("using child timeout %is", opt_child_timeout));
 	
 	if (opt_become_daemon) {
 		int child_pid;
@@ -715,7 +725,7 @@ main (int argc, char *argv[])
 
 		default:
 			/* parent, block until child writes */
-			exit (parent_wait_for_child (startup_daemonize_pipe[0], child_pid));
+			exit (parent_wait_for_child (opt_child_timeout, startup_daemonize_pipe[0], child_pid));
 			break;
 		}
 
commit 82fdfef5942446638c831a0a8381c018376545c7
Author: Richard Hughes <richard at hughsie.com>
Date:   Thu Jan 29 08:34:16 2009 +0000

    set the retval of hal-device correctly on error
    
    At the moment hal-device always returns success.
    Only return success if a device was matched.

diff --git a/tools/hal-device.c b/tools/hal-device.c
index e8bf348..38458a5 100644
--- a/tools/hal-device.c
+++ b/tools/hal-device.c
@@ -189,6 +189,7 @@ int dump_devices(LibHalContext *hal_ctx, char *arg)
 {
 	int i;
 	int num_devices;
+	int retval;
 	char **device_names;
 	DBusError error;
 	char *udi = NULL;
@@ -222,6 +223,9 @@ int dump_devices(LibHalContext *hal_ctx, char *arg)
 		num_devices = 1;
 	}
 
+	/* if _any_ device matches, we return success */
+	retval = 1;
+
 	for(i = 0; i < num_devices; i++) {
 		LibHalPropertySet *props;
 		LibHalPropertySetIterator it;
@@ -233,6 +237,9 @@ int dump_devices(LibHalContext *hal_ctx, char *arg)
 			continue;
 		}
 
+		/* we got some properties */
+		retval = 0;
+
 		if (!udi)
 			printf("%d: ", i);
 		printf("udi = '%s'\n", device_names[i]);
@@ -298,7 +305,7 @@ int dump_devices(LibHalContext *hal_ctx, char *arg)
 	libhal_free_string_array(device_names);
 	dbus_error_free(&error);
 
-	return 0;
+	return retval;
 }
 
 
commit 33b54318f73012e24220456216794dd3ff39fc93
Author: Richard Hughes <richard at hughsie.com>
Date:   Thu Jan 29 08:33:00 2009 +0000

    check udi in hal-get-property
    
    We are not checking if a UDI is valid in hal-get-property
    which means getting a horrible DBUS error if the entry
    is not a valid DBUS path.

diff --git a/tools/hal_get_property.c b/tools/hal_get_property.c
index ecaa6ce..d31261a 100644
--- a/tools/hal_get_property.c
+++ b/tools/hal_get_property.c
@@ -84,6 +84,7 @@ main (int argc, char *argv[])
 	dbus_bool_t is_hex = FALSE;
 	dbus_bool_t is_verbose = FALSE;
 	dbus_bool_t is_version = FALSE;
+	dbus_bool_t udi_exists;
 	char *str;
 	DBusError error;
 
@@ -168,6 +169,19 @@ main (int argc, char *argv[])
 		return 1;
 	}
 
+	/* check UDI exists */
+	udi_exists = libhal_device_exists (hal_ctx, udi, &error);
+	if (!udi_exists) {
+		fprintf (stderr, "error: UDI %s does not exist\n", udi);
+		return 1;
+	}
+	if (dbus_error_is_set(&error)) {
+		fprintf (stderr, "error: libhal_device_exists: %s: %s\n", error.name, error.message);
+		LIBHAL_FREE_DBUS_ERROR (&error);
+		return 1;
+	}
+
+	/* get type */
 	type = libhal_device_get_property_type (hal_ctx, udi, key, &error);
 	if (type == LIBHAL_PROPERTY_TYPE_INVALID) {
 		fprintf (stderr, "error: libhal_device_get_property_type: %s: %s\n", error.name, error.message);


More information about the hal-commit mailing list