diff options
author | eugeni <eugeni@99302b65-d5f7-0310-b3dd-f8cd6f4e3d94> | 2009-02-10 14:02:05 +0000 |
---|---|---|
committer | eugeni <eugeni@99302b65-d5f7-0310-b3dd-f8cd6f4e3d94> | 2009-02-10 14:02:05 +0000 |
commit | c333cea5dd6b1c8e9da36e00eae25044682894bd (patch) | |
tree | 08bb0a6d200fd04bc4629bf5c4accae5711f2d17 | |
parent | 465980c0306cb3672514110264231a9e600561d7 (diff) | |
download | s2u-c333cea5dd6b1c8e9da36e00eae25044682894bd.tar s2u-c333cea5dd6b1c8e9da36e00eae25044682894bd.tar.gz s2u-c333cea5dd6b1c8e9da36e00eae25044682894bd.tar.bz2 s2u-c333cea5dd6b1c8e9da36e00eae25044682894bd.tar.xz s2u-c333cea5dd6b1c8e9da36e00eae25044682894bd.zip |
Removed trailing spacing.
git-svn-id: svn+ssh://svn.mandriva.com/svn/soft/s2u/trunk@252687 99302b65-d5f7-0310-b3dd-f8cd6f4e3d94
-rw-r--r-- | s2u.c | 382 |
1 files changed, 191 insertions, 191 deletions
@@ -17,8 +17,8 @@ * Stew Benedict, <sbenedict@mandriva.com> * Frederic Lepied, <flepied@mandriva.com> * - * code borrowed/adapted from the hal project - - * http://www.freedesktop.org/Software/hal + * code borrowed/adapted from the hal project - + * http://www.freedesktop.org/Software/hal * * Licensed under the GNU General Public License version 2.0 * @@ -67,15 +67,15 @@ static gchar *cookie = NULL; static void usage () { - g_printerr ("\n" "usage : s2u [--daemon=yes|no] [--help] [--debug]\n"); - g_printerr ( - "\n" - " --daemon=yes|no Become a daemon\n" - " --debug Print debug informations\n" - " --help Show this information and exit\n" - "\n" - "s2u monitors messages through D-BUS,\n" - "taking appropraite actions.\n"); + g_printerr ("\n" "usage : s2u [--daemon=yes|no] [--help] [--debug]\n"); + g_printerr ( + "\n" + " --daemon=yes|no Become a daemon\n" + " --debug Print debug informations\n" + " --help Show this information and exit\n" + "\n" + "s2u monitors messages through D-BUS,\n" + "taking appropraite actions.\n"); } @@ -100,214 +100,214 @@ die (const char *message) static DBusHandlerResult filter_function (DBusConnection * connection, - DBusMessage * message, void *user_data) + DBusMessage * message, void *user_data) { /* - INFO (("obj_path=%s interface=%s method=%s", - dbus_message_get_path(message), + INFO (("obj_path=%s interface=%s method=%s", + dbus_message_get_path(message), dbus_message_get_interface(message), dbus_message_get_member(message))); */ - /* message, interface, method */ - if (dbus_message_is_signal (message, - "com.mandriva.user", - "message") && - strcmp (dbus_message_get_path (message), - "/com/mandriva/user") == 0) { - gchar* args[] = - { - "/usr/bin/xauth", - "add", - NULL, - ".", - NULL, - NULL - }; - - args[2] = getenv("DISPLAY"); - args[4] = cookie; - - g_print("s2u: detected hostname change; setting cookie to '%s' for %s.\n", cookie, args[2]); - - g_spawn_async("/", args, NULL, 0, NULL, NULL, NULL, NULL); - - return DBUS_HANDLER_RESULT_HANDLED; - } else { - if (dbus_message_is_signal (message, - "com.mandriva.user", - "updatemenu")) { + /* message, interface, method */ + if (dbus_message_is_signal (message, + "com.mandriva.user", + "message") && + strcmp (dbus_message_get_path (message), + "/com/mandriva/user") == 0) { + gchar* args[] = + { + "/usr/bin/xauth", + "add", + NULL, + ".", + NULL, + NULL + }; + + args[2] = getenv("DISPLAY"); + args[4] = cookie; + + g_print("s2u: detected hostname change; setting cookie to '%s' for %s.\n", cookie, args[2]); + + g_spawn_async("/", args, NULL, 0, NULL, NULL, NULL, NULL); + + return DBUS_HANDLER_RESULT_HANDLED; + } else { + if (dbus_message_is_signal (message, + "com.mandriva.user", + "updatemenu")) { g_print("s2u: updatemenu signal received.\n"); - - g_spawn_command_line_async("/etc/X11/xinit.d/menu", NULL); - - return DBUS_HANDLER_RESULT_HANDLED; - } - else - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } + + g_spawn_command_line_async("/etc/X11/xinit.d/menu", NULL); + + return DBUS_HANDLER_RESULT_HANDLED; + } + else + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } } static void service_dbus_init (void) { - GError *error = NULL; + GError *error = NULL; - dbus_connection = dbus_g_connection_get_connection (dbus_g_bus_get (DBUS_BUS_SYSTEM, &error)); - if (dbus_connection == NULL) { - g_printerr ("dbus_bus_get(): %s", error->message); - exit (1); - } + dbus_connection = dbus_g_connection_get_connection (dbus_g_bus_get (DBUS_BUS_SYSTEM, &error)); + if (dbus_connection == NULL) { + g_printerr ("dbus_bus_get(): %s", error->message); + exit (1); + } dbus_bus_add_match (dbus_connection, "type='signal'," "interface='com.mandriva.user'", - NULL); + NULL); - dbus_connection_add_filter (dbus_connection, filter_function, NULL, - NULL); + dbus_connection_add_filter (dbus_connection, filter_function, NULL, + NULL); } int main (int argc, char *argv[]) { - GMainLoop *loop; - gchar* args[] = { - "/usr/bin/xauth", - "list", - NULL, - NULL - }; - gint in; - gchar result[255]; - gchar* idx; - dbus_bool_t opt_debug = FALSE; - - while (1) { - int c; - int option_index = 0; - const char *opt; - static struct option long_options[] = { - {"daemon", 1, NULL, 0}, - {"help", 0, NULL, 0}, - {"debug", 0, NULL, 0}, - {NULL, 0, NULL, 0} - }; - - c = getopt_long (argc, argv, "", - long_options, &option_index); - if (c == -1) - break; - - switch (c) { - case 0: - opt = long_options[option_index].name; - - if (strcmp (opt, "help") == 0) { - usage (); - return 0; - } else if (strcmp (opt, "daemon") == 0) { - if (strcmp ("yes", optarg) == 0) { - opt_become_daemon = TRUE; - } else if (strcmp ("no", optarg) == 0) { - opt_become_daemon = FALSE; - } else { - usage (); - return 1; - } - } else if (strcmp (opt, "debug") == 0) { - opt_debug = TRUE; - } - break; - - default: - usage (); - return 1; - break; - } - } - - memset(result, 0, sizeof(result)); - - args[2] = getenv("DISPLAY"); - - g_spawn_async_with_pipes("/", args, NULL, 0, NULL, NULL, NULL, - NULL, &in, NULL, NULL); - if (read(in, result, sizeof(result)) <= 0) { - die("unable to read X11 cookie"); - } else { - close(in); - - idx = rindex(result, ' '); - if (idx == NULL) { - die ("unable to read X11 cookie"); - } - cookie = g_strdup(idx+1); - cookie[strlen(cookie) - 1] = '\0'; - if (opt_debug) { - g_print("%s: cookie for %s = '%s'\n", argv[0], args[2], cookie); - } - } - - if (opt_become_daemon) { - int child_pid; - int dev_null_fd; - - if (chdir ("/") < 0) { - g_printerr ("Could not chdir to /, errno=%d", errno); - return 1; - } - - child_pid = fork (); - switch (child_pid) { - case -1: - g_printerr ("Cannot fork(), errno=%d", errno); - break; - - case 0: - /* child */ - - dev_null_fd = open ("/dev/null", O_RDWR); - /* ignore if we can't open /dev/null */ - if (dev_null_fd > 0) { - /* attach /dev/null to stdout, stdin, stderr */ - dup2 (dev_null_fd, 0); - if (opt_debug == FALSE) { - dup2 (dev_null_fd, 1); - dup2 (dev_null_fd, 2); - } - } - - umask (022); - break; - - default: - /* parent */ - exit (0); - break; - } - - /* Create session */ - setsid (); - } - - gdk_init(&argc, &argv); - - loop = g_main_loop_new (NULL, FALSE); - - /* set up the dbus services */ - service_dbus_init (); - - /* run the main loop and serve clients */ - - g_main_loop_run (loop); - - return 0; + GMainLoop *loop; + gchar* args[] = { + "/usr/bin/xauth", + "list", + NULL, + NULL + }; + gint in; + gchar result[255]; + gchar* idx; + dbus_bool_t opt_debug = FALSE; + + while (1) { + int c; + int option_index = 0; + const char *opt; + static struct option long_options[] = { + {"daemon", 1, NULL, 0}, + {"help", 0, NULL, 0}, + {"debug", 0, NULL, 0}, + {NULL, 0, NULL, 0} + }; + + c = getopt_long (argc, argv, "", + long_options, &option_index); + if (c == -1) + break; + + switch (c) { + case 0: + opt = long_options[option_index].name; + + if (strcmp (opt, "help") == 0) { + usage (); + return 0; + } else if (strcmp (opt, "daemon") == 0) { + if (strcmp ("yes", optarg) == 0) { + opt_become_daemon = TRUE; + } else if (strcmp ("no", optarg) == 0) { + opt_become_daemon = FALSE; + } else { + usage (); + return 1; + } + } else if (strcmp (opt, "debug") == 0) { + opt_debug = TRUE; + } + break; + + default: + usage (); + return 1; + break; + } + } + + memset(result, 0, sizeof(result)); + + args[2] = getenv("DISPLAY"); + + g_spawn_async_with_pipes("/", args, NULL, 0, NULL, NULL, NULL, + NULL, &in, NULL, NULL); + if (read(in, result, sizeof(result)) <= 0) { + die("unable to read X11 cookie"); + } else { + close(in); + + idx = rindex(result, ' '); + if (idx == NULL) { + die ("unable to read X11 cookie"); + } + cookie = g_strdup(idx+1); + cookie[strlen(cookie) - 1] = '\0'; + if (opt_debug) { + g_print("%s: cookie for %s = '%s'\n", argv[0], args[2], cookie); + } + } + + if (opt_become_daemon) { + int child_pid; + int dev_null_fd; + + if (chdir ("/") < 0) { + g_printerr ("Could not chdir to /, errno=%d", errno); + return 1; + } + + child_pid = fork (); + switch (child_pid) { + case -1: + g_printerr ("Cannot fork(), errno=%d", errno); + break; + + case 0: + /* child */ + + dev_null_fd = open ("/dev/null", O_RDWR); + /* ignore if we can't open /dev/null */ + if (dev_null_fd > 0) { + /* attach /dev/null to stdout, stdin, stderr */ + dup2 (dev_null_fd, 0); + if (opt_debug == FALSE) { + dup2 (dev_null_fd, 1); + dup2 (dev_null_fd, 2); + } + } + + umask (022); + break; + + default: + /* parent */ + exit (0); + break; + } + + /* Create session */ + setsid (); + } + + gdk_init(&argc, &argv); + + loop = g_main_loop_new (NULL, FALSE); + + /* set up the dbus services */ + service_dbus_init (); + + /* run the main loop and serve clients */ + + g_main_loop_run (loop); + + return 0; } /* |