[134] | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
---|
| 2 | * |
---|
| 3 | * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> |
---|
| 4 | * |
---|
| 5 | * This program is free software; you can redistribute it and/or |
---|
| 6 | * modify it under the terms of the GNU General Public License as |
---|
| 7 | * published by the Free Software Foundation; either version 2 of the |
---|
| 8 | * License, or (at your option) any later version. |
---|
| 9 | * |
---|
| 10 | * This program is distributed in the hope that it will be useful, but |
---|
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 13 | * General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU General Public License |
---|
| 16 | * along with this program; if not, write to the Free Software |
---|
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
| 18 | * 02111-1307, USA. |
---|
| 19 | * |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #include "config.h" |
---|
| 23 | |
---|
| 24 | #include <stdlib.h> |
---|
| 25 | #include <stdio.h> |
---|
| 26 | #include <sys/types.h> |
---|
| 27 | #include <string.h> |
---|
| 28 | #include <errno.h> |
---|
| 29 | |
---|
| 30 | #include <locale.h> |
---|
| 31 | |
---|
| 32 | #include <glib.h> |
---|
| 33 | |
---|
| 34 | #define DBUS_API_SUBJECT_TO_CHANGE |
---|
| 35 | #include <dbus/dbus-glib.h> |
---|
| 36 | #include <dbus/dbus-glib-lowlevel.h> |
---|
| 37 | |
---|
| 38 | #include "gdm-settings.h" |
---|
| 39 | |
---|
| 40 | #define GDM_DBUS_NAME "org.gnome.DisplayManager" |
---|
| 41 | |
---|
| 42 | static GdmSettings *settings = NULL; |
---|
| 43 | |
---|
| 44 | static gboolean |
---|
| 45 | acquire_name_on_proxy (DBusGProxy *bus_proxy) |
---|
| 46 | { |
---|
| 47 | GError *error; |
---|
| 48 | guint result; |
---|
| 49 | gboolean res; |
---|
| 50 | gboolean ret; |
---|
| 51 | |
---|
| 52 | ret = FALSE; |
---|
| 53 | |
---|
| 54 | if (bus_proxy == NULL) { |
---|
| 55 | goto out; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | error = NULL; |
---|
| 59 | res = dbus_g_proxy_call (bus_proxy, |
---|
| 60 | "RequestName", |
---|
| 61 | &error, |
---|
| 62 | G_TYPE_STRING, GDM_DBUS_NAME, |
---|
| 63 | G_TYPE_UINT, 0, |
---|
| 64 | G_TYPE_INVALID, |
---|
| 65 | G_TYPE_UINT, &result, |
---|
| 66 | G_TYPE_INVALID); |
---|
| 67 | if (! res) { |
---|
| 68 | if (error != NULL) { |
---|
| 69 | g_warning ("Failed to acquire %s: %s", GDM_DBUS_NAME, error->message); |
---|
| 70 | g_error_free (error); |
---|
| 71 | } else { |
---|
| 72 | g_warning ("Failed to acquire %s", GDM_DBUS_NAME); |
---|
| 73 | } |
---|
| 74 | goto out; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { |
---|
| 78 | if (error != NULL) { |
---|
| 79 | g_warning ("Failed to acquire %s: %s", GDM_DBUS_NAME, error->message); |
---|
| 80 | g_error_free (error); |
---|
| 81 | } else { |
---|
| 82 | g_warning ("Failed to acquire %s", GDM_DBUS_NAME); |
---|
| 83 | } |
---|
| 84 | goto out; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | ret = TRUE; |
---|
| 88 | |
---|
| 89 | out: |
---|
| 90 | return ret; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | static DBusGProxy * |
---|
| 94 | get_bus_proxy (DBusGConnection *connection) |
---|
| 95 | { |
---|
| 96 | DBusGProxy *bus_proxy; |
---|
| 97 | |
---|
| 98 | bus_proxy = dbus_g_proxy_new_for_name (connection, |
---|
| 99 | DBUS_SERVICE_DBUS, |
---|
| 100 | DBUS_PATH_DBUS, |
---|
| 101 | DBUS_INTERFACE_DBUS); |
---|
| 102 | return bus_proxy; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | static DBusGConnection * |
---|
| 106 | get_system_bus (void) |
---|
| 107 | { |
---|
| 108 | GError *error; |
---|
| 109 | DBusGConnection *bus; |
---|
| 110 | DBusConnection *connection; |
---|
| 111 | |
---|
| 112 | error = NULL; |
---|
| 113 | bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); |
---|
| 114 | if (bus == NULL) { |
---|
| 115 | g_warning ("Couldn't connect to system bus: %s", |
---|
| 116 | error->message); |
---|
| 117 | g_error_free (error); |
---|
| 118 | goto out; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | connection = dbus_g_connection_get_connection (bus); |
---|
| 122 | dbus_connection_set_exit_on_disconnect (connection, FALSE); |
---|
| 123 | |
---|
| 124 | out: |
---|
| 125 | return bus; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | int |
---|
| 129 | main (int argc, char **argv) |
---|
| 130 | { |
---|
| 131 | GMainLoop *main_loop; |
---|
| 132 | DBusGConnection *connection; |
---|
| 133 | DBusGProxy *bus_proxy; |
---|
| 134 | |
---|
| 135 | g_type_init (); |
---|
| 136 | |
---|
| 137 | connection = get_system_bus (); |
---|
| 138 | if (connection == NULL) { |
---|
| 139 | goto out; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | bus_proxy = get_bus_proxy (connection); |
---|
| 143 | if (bus_proxy == NULL) { |
---|
| 144 | g_warning ("Could not construct bus_proxy object; bailing out"); |
---|
| 145 | goto out; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | if (! acquire_name_on_proxy (bus_proxy) ) { |
---|
| 149 | g_warning ("Could not acquire name; bailing out"); |
---|
| 150 | goto out; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | settings = gdm_settings_new (); |
---|
| 154 | if (settings == NULL) { |
---|
| 155 | g_warning ("Unable to initialize settings"); |
---|
| 156 | exit (1); |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | main_loop = g_main_loop_new (NULL, FALSE); |
---|
| 160 | g_main_loop_run (main_loop); |
---|
| 161 | |
---|
| 162 | g_main_loop_unref (main_loop); |
---|
| 163 | |
---|
| 164 | g_object_unref (settings); |
---|
| 165 | |
---|
| 166 | out: |
---|
| 167 | return 0; |
---|
| 168 | } |
---|