~ubuntu-branches/ubuntu/precise/upower/precise-proposed

« back to all changes in this revision

Viewing changes to src/up-main.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-05 14:31:17 UTC
  • mfrom: (15.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20110505143117-9clyzsrw45vt5g6y
Tags: 0.9.10-1
* New upstream release:
  - Fix "unknown" battery status guessing to not be recursive. (LP: #384304)
* debian/control: Drop obsolete devicekit-power-* Conflicts/Replaces.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include "up-kbd-backlight.h"
42
42
#include "up-wakeups.h"
43
43
 
 
44
#if GLIB_CHECK_VERSION(2,28,7)
 
45
 #include <glib-unix.h>
 
46
#endif
 
47
 
44
48
#define DEVKIT_POWER_SERVICE_NAME "org.freedesktop.UPower"
45
49
static GMainLoop *loop = NULL;
46
50
 
88
92
        return ret;
89
93
}
90
94
 
 
95
#if GLIB_CHECK_VERSION(2,28,7)
 
96
 
 
97
/**
 
98
 * up_main_sigint_cb:
 
99
 **/
 
100
static gboolean
 
101
up_main_sigint_cb (gpointer user_data)
 
102
{
 
103
        g_debug ("Handling SIGINT");
 
104
        g_main_loop_quit (loop);
 
105
        return FALSE;
 
106
}
 
107
 
 
108
#else
 
109
 
91
110
/**
92
111
 * up_main_sigint_handler:
93
112
 **/
103
122
        g_main_loop_quit (loop);
104
123
}
105
124
 
 
125
#endif
 
126
 
106
127
/**
107
128
 * up_main_timed_exit_cb:
108
129
 *
133
154
        gint retval = 1;
134
155
        gboolean timed_exit = FALSE;
135
156
        gboolean immediate_exit = FALSE;
 
157
        gboolean session_bus = FALSE;
136
158
        guint timer_id = 0;
137
159
 
138
160
        const GOptionEntry options[] = {
142
164
                { "immediate-exit", '\0', 0, G_OPTION_ARG_NONE, &immediate_exit,
143
165
                  /* TRANSLATORS: exit straight away, used for automatic profiling */
144
166
                  _("Exit after the engine has loaded"), NULL },
 
167
                { "test", '\0', 0, G_OPTION_ARG_NONE, &session_bus,
 
168
                  _("Run on the session bus (only for testing)"), NULL },
145
169
                { NULL}
146
170
        };
147
171
 
153
177
        g_option_context_free (context);
154
178
 
155
179
        /* get bus connection */
156
 
        bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
 
180
        if (session_bus)
 
181
                up_daemon_set_bus_type (DBUS_BUS_SESSION);
 
182
        bus = dbus_g_bus_get (up_daemon_get_bus_type (), &error);
157
183
        if (bus == NULL) {
158
184
                g_warning ("Couldn't connect to system bus: %s", error->message);
159
185
                g_error_free (error);
175
201
                goto out;
176
202
        }
177
203
 
 
204
#if GLIB_CHECK_VERSION(2,28,7)
178
205
        /* do stuff on ctrl-c */
 
206
        g_unix_signal_add_watch_full (SIGINT,
 
207
                                      G_PRIORITY_DEFAULT,
 
208
                                      up_main_sigint_cb,
 
209
                                      loop,
 
210
                                      NULL);
 
211
#else
179
212
        signal (SIGINT, up_main_sigint_handler);
 
213
#endif
180
214
 
181
215
        g_debug ("Starting upowerd version %s", PACKAGE_VERSION);
182
216