hal/tools lshal.c,1.16,1.17

Danny Kukawka dkukawka at freedesktop.org
Wed Nov 9 13:13:33 PST 2005


Update of /cvs/hal/hal/tools
In directory gabe:/tmp/cvs-serv15322/tools

Modified Files:
	lshal.c 
Log Message:
2005-11-09  Danny Kukawka  <danny.kukawka at web.de>

        * hald/linux2/addons/addon-acpi.c: (acpi_get_event_fp_kernel),
        (acpi_get_event_fp_acpid), (main): fix problems with addon if acpid socket
        is not available if HAL starts. In this case retry to connect until we get
        the socket. Also added the proc kernel eventinterface to the loop to prevent
        problems on resume from suspend. This should prevent restart the whole HAL
        if lost acpid or proc event source.

        * tools/lshal.c: (dump_devices), (usage), (main): added new option -s|--short
        for short output, changed short option for show to -u, added new status line
        to --monitor mode, allowed combine --monitor with --long|short|tree, added
        restrict check for incorrect command options (e.g. 'lshal --'), set --long
        as default if called lshal without option.



Index: lshal.c
===================================================================
RCS file: /cvs/hal/hal/tools/lshal.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- lshal.c	7 Nov 2005 14:33:44 -0000	1.16
+++ lshal.c	9 Nov 2005 21:13:31 -0000	1.17
@@ -58,6 +58,7 @@
 static LibHalContext *hal_ctx;
 static dbus_bool_t long_list = FALSE;
 static dbus_bool_t tree_view = FALSE;
+static dbus_bool_t short_list = FALSE;
 static char *show_device = NULL;
 
 struct Device {
@@ -285,7 +286,7 @@
 
 	if (long_list) {
 		printf ("\n"
-			"Dumped %d device(s) from the Global Device List:\n"
+			"Dumped %d device(s) from the Global Device List.\n"
 			"------------------------------------------------\n",
 			num_devices);
 
@@ -532,12 +533,16 @@
 		 "\n"
 		 "Options:\n"
 		 "    -m, --monitor        Monitor device list\n"
+		 "    -s, --short          short output (print only nonstatic part of udi)\n"
 		 "    -l, --long           Long output\n"
 		 "    -t, --tree           Tree view\n"
-		 "    -s, --show <udi>     Show only the specified device\n"
+		 "    -u, --show <udi>     Show only the specified device\n"
+		 "\n"
 		 "    -h, --help           Show this information and exit\n"
 		 "    -V, --version        Print version number\n"
 		 "\n"
+		 "Without any given options lshal will start with option --long."
+		 "\n"
 		 "Shows all devices and their properties. If the --monitor option is given\n"
 		 "then the device list and all devices are monitored for changes.\n"
 		 "\n");
@@ -557,61 +562,83 @@
 	GMainLoop *loop;
 	DBusConnection *conn;
 
-	while (1) {
-		int c;
+	if (argc == 1) {
+		/* This is the default case lshal without any options */
+		long_list = TRUE;
+	}
+	else {
 		static const struct option long_options[] = {
 			{"monitor", no_argument, NULL, 'm'},
 			{"long", no_argument, NULL, 'l'},
+			{"short", no_argument, NULL, 's'},
 			{"tree", no_argument, NULL, 't'},
-			{"show", required_argument, NULL, 's'},
+			{"show", required_argument, NULL, 'u'},
 			{"help", no_argument, NULL, 'h'},
+			{"usage", no_argument, NULL, 'U'},
 			{"version", no_argument, NULL, 'V'},
 			{NULL, 0, NULL, 0}
 		};
 
-		c = getopt_long (argc, argv, "mlts:hV",
-				 long_options, NULL);
-		if (c == -1)
-			break;
-
-		switch (c) {
-		case 'm':
-			do_monitor = TRUE;
-			break;
-
-		case 'l':
-			long_list = TRUE;
-			break;
-
-		case 't':
-			tree_view = TRUE;
-			break;
+		while (1) {
+			int c;
+			
+			c = getopt_long (argc, argv, "mlstu:hUV", long_options, NULL);
 
-		case 's':
-			if (strchr(optarg, '/') != NULL)
-				show_device = strdup(optarg);
-			else {
-				show_device = malloc(strlen(UDI_BASE) + strlen(optarg) + 1);
-				memcpy(show_device, UDI_BASE, strlen(UDI_BASE));
-				memcpy(show_device + strlen(UDI_BASE), optarg, strlen(optarg) + 1);
+			if (c == -1) {
+				/* this should happen e.g. if 'lshal -' and this is incorrect/incomplete option */
+				if (!do_monitor && !long_list && !short_list && !tree_view && !show_device) {
+					usage (argc, argv);
+					return 1;
+				}
+				
+				break;
 			}
-			break;
 
-		case 'h':
-			usage (argc, argv);
-			return 0;
+			switch (c) {
+			case 'm': 
+				do_monitor = TRUE;
+				break;
 
-		case 'V':
-			printf ("lshal version " PACKAGE_VERSION "\n");
-			return 0;
+			case 'l':
+				long_list = TRUE;
+				break;
 
-		default:
-			usage (argc, argv);
-			return 1;
-			break;
+			case 's':
+				short_list = TRUE;
+				long_list = FALSE;
+				break;
+			
+			case 't':
+				tree_view = TRUE;
+				break;
+				
+			case 'u':
+				if (strchr(optarg, '/') != NULL)
+					show_device = strdup(optarg);
+				else {
+					show_device = malloc(strlen(UDI_BASE) + strlen(optarg) + 1);
+					memcpy(show_device, UDI_BASE, strlen(UDI_BASE));
+					memcpy(show_device + strlen(UDI_BASE), optarg, strlen(optarg) + 1);
+				}
+				
+				break;
+			
+			case 'h':
+			case 'U':
+				usage (argc, argv);
+				return 0;
+			
+			case 'V':
+				printf ("lshal version " PACKAGE_VERSION "\n");
+				return 0;
+
+			default:
+				usage (argc, argv);
+				return 1;
+			}
 		}
 	}
-
+	
 	if (do_monitor)
 		loop = g_main_loop_new (NULL, FALSE);
 	else
@@ -657,6 +684,11 @@
 
 	/* run the main loop only if we should monitor */
 	if (do_monitor && loop != NULL) {
+		if( long_list || short_list || tree_view )
+			dump_devices ();
+		
+		printf ("\nStart monitoring devicelist:\n"
+			"-------------------------------------------------\n");
 		libhal_device_property_watch_all (hal_ctx, &error);
 		g_main_loop_run (loop);
 	}




More information about the hal-commit mailing list