60
56
// the timeout (in sec) when a further activity from dpkg/apt
61
57
// causes the applet to "ungray"
62
#define TIMEOUT_APT_RUN 600 /* 600 sec */
58
#define TIMEOUT_APT_RUN 120 /* 120 sec */
64
// force startup even if the user is not in the admin group
60
// force statup even if the user is not in the admin group
65
61
static gboolean FORCE_START=FALSE;
67
63
// force gksu for all menu actions
68
64
static gboolean FORCE_GKSU=FALSE;
70
66
// delay on startup (to make session startup faster)
71
static int STARTUP_DELAY=1;
73
// make the release upgrader check for a devel release
74
gboolean DEVEL_RELEASE=FALSE;
76
// force release check
77
static gboolean FORCE_RELEASE_CHECK=FALSE;
79
// global debug options
82
int INOTIFY_DEBUG = 0;
84
int RELEASE_DEBUG = 0;
88
static void debug_log_handler (const gchar *log_domain,
89
GLogLevelFlags log_level,
93
if (log_domain && strcmp(log_domain, "hooks") == 0) {
95
g_log_default_handler (log_domain, log_level, message, user_data);
97
else if (log_domain && strcmp(log_domain, "update") == 0) {
99
g_log_default_handler (log_domain, log_level, message, user_data);
101
else if (log_domain && strcmp(log_domain, "inotify") == 0) {
102
if (INOTIFY_DEBUG > 0)
103
g_log_default_handler (log_domain, log_level, message, user_data);
105
else if (log_domain && strcmp(log_domain, "uevent") == 0) {
106
if (UEVENT_DEBUG > 0)
107
g_log_default_handler (log_domain, log_level, message, user_data);
109
else if (log_domain && strcmp(log_domain, "release") == 0) {
110
if (RELEASE_DEBUG > 0)
111
g_log_default_handler (log_domain, log_level, message, user_data);
113
else if (MISC_DEBUG > 0)
114
g_log_default_handler (log_domain, log_level, message, user_data);
118
g_debug_inotify(const char *msg, ...)
122
g_logv("inotify",G_LOG_LEVEL_DEBUG, msg, va);
126
// launch async scripts one after another
127
static void start_next_script(GPid pid,
129
GSList *remaining_scripts_to_run)
131
if(remaining_scripts_to_run) {
132
gboolean ret = False;
133
gchar* full_path = remaining_scripts_to_run->data;
134
gchar *argv[] = { full_path, NULL };
136
g_debug_inotify ("executing: %s\n", full_path);
137
if (g_file_test(full_path, G_FILE_TEST_IS_EXECUTABLE ))
138
ret = g_spawn_async("/", argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL);
139
remaining_scripts_to_run = g_slist_remove(remaining_scripts_to_run, full_path);
143
g_warning("script execution failed or not executable");
144
start_next_script(0, 0, remaining_scripts_to_run);
147
g_child_watch_add(pid, (GChildWatchFunc)start_next_script, remaining_scripts_to_run);
152
void invoke(const gchar *cmd, const gchar *desktop, gboolean with_gksu)
154
GdkAppLaunchContext *context;
156
GError *error = NULL;
157
static GtkWidget *w = NULL;
160
if(with_gksu || FORCE_GKSU) {
67
static int STARTUP_DELAY=5;
69
void invoke(gchar *cmd, gchar *desktop, gboolean with_gksu)
71
if(with_gksu || FORCE_GKSU)
161
72
invoke_with_gksu(cmd, desktop, FALSE);
165
// fake window to get the current server time *urgh*
167
w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
168
gtk_widget_realize (w);
172
context = gdk_app_launch_context_new ();
173
guint32 timestamp = gdk_x11_get_server_time (gtk_widget_get_window (w));
174
appinfo = g_app_info_create_from_commandline(cmd,
176
G_APP_INFO_CREATE_NONE,
178
gdk_app_launch_context_set_timestamp (context, timestamp);
179
if (!g_app_info_launch (appinfo, NULL, (GAppLaunchContext*)context, &error))
180
g_warning ("Launching failed: %s\n", error->message);
181
g_object_unref (context);
182
g_object_unref (appinfo);
74
g_spawn_command_line_async(cmd, NULL);
187
invoke_with_gksu(const gchar *cmd, const gchar *descr, gboolean whole_message)
78
invoke_with_gksu(gchar *cmd, gchar *descr, gboolean whole_message)
189
g_debug("invoke_update_manager ()\n");
80
//g_print("invoke_update_manager ()\n");
191
82
argv[0] = "/usr/bin/gksu";
192
83
argv[1] = whole_message ? "--message" : "--desktop";
193
argv[2] = (gchar*)descr;
194
argv[3] = (gchar*)cmd;
197
88
g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL);
249
140
if(g_str_has_prefix(info_uri,"/var/lib/apt/")
250
141
|| g_str_has_prefix(info_uri,"/var/cache/apt/")
251
142
|| strcmp(info_uri,"/var/lib/dpkg/status") == 0) {
252
g_debug_inotify("apt_get_running=TRUE");
253
143
un->apt_get_runing=TRUE;
255
145
if(strstr(info_uri, "/var/lib/update-notifier/dpkg-run-stamp") ||
256
146
strstr(info_uri, "/var/lib/apt/periodic/update-success-stamp")) {
257
g_debug_inotify("dpkg_was_run=TRUE");
258
147
un->dpkg_was_run = TRUE;
260
149
if(strstr(info_uri, REBOOT_FILE)) {
261
g_debug_inotify("reboot required\n");
150
//g_print("reboot required\n");
262
151
un->reboot_pending = TRUE;
264
153
if(strstr(info_uri, HOOKS_DIR)) {
265
g_debug_inotify("new hook!\n");
154
//g_print("new hook!\n");
266
155
un->hook_pending = TRUE;
268
157
if(strstr(info_uri, CRASHREPORT_DIR)) {
269
g_debug_inotify("crashreport found\n");
158
//g_print("crashreport found\n");
270
159
un->crashreport_pending = TRUE;
272
161
if(strstr(info_uri, UNICAST_LOCAL_AVAHI_FILE)) {
273
g_debug_inotify("avahi disabled due to unicast .local domain\n");
162
//g_print("avahi disabled due to unicast .local domain\n");
274
163
un->unicast_local_avahi_pending = TRUE;
304
193
update_check(un->update);
306
// run cache-changed plugin scripts
307
GDir *dir = g_dir_open(CACHE_CHANGED_PLUGIN_DIR, 0, NULL);
308
const gchar *fname, *full_path;
309
GSList *cache_changed_scripts = NULL;
310
while ( (fname = g_dir_read_name(dir)) != NULL ) {
311
full_path = g_build_filename(CACHE_CHANGED_PLUGIN_DIR, fname, NULL);
312
cache_changed_scripts = g_slist_insert_sorted(cache_changed_scripts,
313
(gpointer)full_path, (GCompareFunc)g_strcmp0);
315
// launch first script and queue others
316
start_next_script(0, 0, cache_changed_scripts);
318
195
// any apt-get update must be finished, otherwise
319
196
// apt-get install wouldn't be finished
320
197
update_apt_is_running(un->update, FALSE);
540
406
static GOptionEntry entries[] =
542
408
{ "debug-hooks", 0, 0, G_OPTION_ARG_NONE, &HOOK_DEBUG, "Enable hooks debugging"},
543
{ "debug-updates", 0, 0, G_OPTION_ARG_NONE, &UPDATE_DEBUG, "Enable updates/autolaunch debugging"},
544
{ "debug-inotify", 0, 0, G_OPTION_ARG_NONE, &INOTIFY_DEBUG, "Enable inotify debugging"},
545
{ "debug-uevent", 0, 0, G_OPTION_ARG_NONE, &UEVENT_DEBUG, "Enable uevent debugging"},
546
{ "debug-new-release-check", 0, 0, G_OPTION_ARG_NONE, &RELEASE_DEBUG, "Enable new release check debugging"},
547
{ "debug-misc", 0, 0, G_OPTION_ARG_NONE, &MISC_DEBUG, "Enable uncategorized debug prints"},
548
409
{ "force", 0, 0, G_OPTION_ARG_NONE, &FORCE_START, "Force start even if the user is not in the admin group"},
549
410
{ "force-use-gksu", 0, 0, G_OPTION_ARG_NONE, &FORCE_GKSU, "Force running all commands (update-manager, synaptic) with gksu" },
550
{ "startup-delay", 0, 0, G_OPTION_ARG_INT, &STARTUP_DELAY, "Delay startup by given amount of seconds" },
551
{ "devel-release", 0, 0, G_OPTION_ARG_NONE, &DEVEL_RELEASE, "Make the release checker check for a new development release" },
552
{ "force-release-check", 0, 0, G_OPTION_ARG_NONE, &FORCE_RELEASE_CHECK, "Force release check" },
411
{ "startup-delay", 0, 0, G_OPTION_ARG_INT, &STARTUP_DELAY, "Delay statup by given amount of seconds" },
557
main (int argc, char **argv)
416
main (int argc, char *argv[])
559
418
UpgradeNotifier *un;
560
GError *error = NULL;
563
if(!gtk_init_with_args (&argc, &argv,
564
_("- inform about updates"), entries,
565
"update-notifier", &error) ) {
566
fprintf(stderr, _("Failed to init the UI: %s\n"),
567
error ? error->message : _("unknown error"));
421
GOptionContext *context;
422
context = g_option_context_new (" - inform about updates");
423
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
424
gtk_init_with_args (&argc, &argv, "",
425
entries, PACKAGE, NULL);
571
427
notify_init("update-notifier");
572
428
bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR);
573
429
bind_textdomain_codeset(PACKAGE, "UTF-8");
574
430
textdomain(PACKAGE);
576
// setup a custom debug log handler
577
g_log_set_handler ("inotify", G_LOG_LEVEL_DEBUG,
578
debug_log_handler, NULL);
579
g_log_set_handler ("hooks", G_LOG_LEVEL_DEBUG,
580
debug_log_handler, NULL);
581
g_log_set_handler ("update", G_LOG_LEVEL_DEBUG,
582
debug_log_handler, NULL);
583
g_log_set_handler ("uevent", G_LOG_LEVEL_DEBUG,
584
debug_log_handler, NULL);
585
g_log_set_handler ("release", G_LOG_LEVEL_DEBUG,
586
debug_log_handler, NULL);
587
g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG,
588
debug_log_handler, NULL);
590
432
g_set_application_name (_("update-notifier"));
591
433
gtk_window_set_default_icon_name ("update-notifier");
593
435
//g_print("starting update-notifier\n");
595
437
// do not run as system user (e.g. guest user)
596
if (system_user() && !FORCE_START) {
597
439
g_warning("not starting for system user\n");
601
// do not run as system user (e.g. guest user)
602
if (FORCE_RELEASE_CHECK) {
603
GConfClient *gconf = gconf_client_get_default();
604
gconf_client_unset(gconf, GCONF_KEY_LAST_RELEASE_CHECK, NULL);
607
443
// check if it is running already
608
444
if (!up_get_clipboard ()) {
609
445
g_warning ("already running?\n");
613
449
/* Create the UpgradeNotifier object */
614
450
un = g_new0 (UpgradeNotifier, 1);
616
// check for update-notifier dir and create if needed
617
gchar *dirname = g_strdup_printf("%s/update-notifier",
618
g_get_user_config_dir());
452
// check for .update-notifier dir and create if needed
453
gchar *dirname = g_strdup_printf("%s/.update-notifier",
619
455
if(!g_file_test(dirname, G_FILE_TEST_IS_DIR))
620
456
g_mkdir(dirname, 0700);
623
459
// delay icon creation for 30s so that the desktop
624
460
// login is not slowed down by update-notifier
625
g_timeout_add_seconds(STARTUP_DELAY,
626
(GSourceFunc)(tray_icons_init), un);
461
g_timeout_add_seconds(STARTUP_DELAY, (GSourceFunc)(tray_icons_init), un);
628
463
// initial check for avahi
629
464
avahi_disabled_check();
466
// init hal (needs to be done _after_ the icons are created)
631
467
/* setup hal so that inserted cdroms can be checked */
632
if(!up_do_hal_init(un)) {
633
g_warning("initializing gdu failed");
468
LibHalContext *hal_ctx = up_do_hal_init();
470
u_abort("failed to initialize HAL!\n");
636
// init release checker
637
release_checker_init();
639
// init uevent monitoring (missing firmware, etc.)
642
// init gio file monitoring
473
libhal_ctx_set_user_data(hal_ctx, un);
645
478
/* Start the main gtk loop */