18
23
// command, description, desktopfile, needs_gksu
19
24
const char* actions[][4] = {
20
25
{ "/usr/bin/update-manager", N_("Show updates"),
21
"/usr/share/applications/update-manager.desktop", FALSE },
26
"/usr/share/applications/update-manager.desktop",
27
GINT_TO_POINTER(FALSE) },
23
29
{ "/usr/sbin/synaptic --dist-upgrade-mode --non-interactive --hide-main-window -o Synaptic::AskRelated=true",
24
N_("Install all updates"), "/usr/share/applications/synaptic.desktop", TRUE
30
N_("Install all updates"), "/usr/share/applications/synaptic.desktop",
26
33
{ "/usr/sbin/synaptic --update-at-startup --non-interactive --hide-main-window",
27
N_("Check for updates"), "/usr/share/applications/synaptic.desktop", TRUE },
34
N_("Check for updates"), "/usr/share/applications/synaptic.desktop",
35
GINT_TO_POINTER(TRUE) },
28
36
{ "/usr/sbin/synaptic", N_("Start package manager"),
29
"/usr/share/applications/synaptic.desktop", TRUE},
37
"/usr/share/applications/synaptic.desktop",
38
GINT_TO_POINTER(TRUE)},
30
39
{ NULL, NULL, NULL }
45
NOTIFICATION_SHOW_UPDATES
34
enum { NOTIFICATION_DEFAULT, NOTIFICATION_IGNORE, NOTIFICATION_SHOW_UPDATES };
49
g_debug_update(const char *msg, ...)
53
g_logv("update",G_LOG_LEVEL_DEBUG, msg, va);
37
58
activate_cb (GtkWidget *widget,
324
// use ubuntu-system-service (if available) to check
325
// if the dpkg lock is taken currently or not
327
// if uncertain, return FALSE
329
dpkg_lock_is_taken ()
331
DBusGConnection *connection;
334
gboolean locked = FALSE;
337
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
338
if (connection == NULL) {
339
g_debug_update ("Failed to open connection to bus: %s\n", error->message);
340
g_error_free (error);
344
proxy = dbus_g_proxy_new_for_name (connection,
345
"com.ubuntu.SystemService",
347
"com.ubuntu.SystemService");
349
if (!dbus_g_proxy_call (proxy, "is_package_system_locked", &error,
351
G_TYPE_BOOLEAN, &locked, G_TYPE_INVALID)) {
352
g_debug_update ("error during dbus call: %s\n", error->message);
353
g_error_free (error);
354
g_object_unref (proxy);
357
g_object_unref (proxy);
359
g_debug_update ("is_package_system_locked: %i", locked);
364
// ask devicekit.Power if we run on battery
366
running_on_battery ()
368
DBusGConnection *connection;
371
gboolean on_battery = FALSE;
374
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
375
if (connection == NULL) {
376
g_debug_update ("Failed to open connection to bus: %s\n", error->message);
377
g_error_free (error);
381
proxy = dbus_g_proxy_new_for_name (connection,
382
"org.freedesktop.DeviceKit.Power",
383
"/org/freedesktop/DeviceKit/Power",
384
"org.freedesktop.DBus.Properties");
386
if (!dbus_g_proxy_call (proxy, "Get", &error,
387
G_TYPE_STRING, "org.freedesktop.DeviceKit.Power",
388
G_TYPE_STRING, "on_battery",
390
G_TYPE_BOOLEAN, &on_battery,
392
g_debug_update ("failed Get dbus call: %s\n",
393
error?error->message:"no error given");
395
g_error_free (error);
398
g_debug_update ("on_battery: %i", on_battery);
404
security_updates_are_installed_unattended()
407
GError *error = NULL;
409
// run apt_check.py in "check if we install updates unattended" mode
410
// a exit status > 0 indicates that its unattended-upgrades is used
411
if ( g_file_test ("/usr/bin/unattended-upgrades",
412
G_FILE_TEST_IS_EXECUTABLE) ) {
413
char *cmd[] = { "/usr/bin/nice",
414
"/usr/bin/ionice", "-c3",
416
"--security-updates-unattended",
419
if (g_spawn_sync("/", cmd, NULL, 0, NULL, NULL,
420
NULL, NULL, &ret, &error)) {
421
g_debug("--security-updates-unattended: %i\n", WEXITSTATUS(ret));
422
if( WEXITSTATUS(ret) > 0 )
425
g_print("error: %s\n", error->message);
431
// check if the security auto launch interval is over
432
// and if the user is not using auto install of security
435
auto_launch_security_now(UpdateTrayAppletPrivate *priv,
440
// no security updates
441
if (priv->num_security == 0)
444
// security updates, but already launched recently
445
if ((last_launch + AUTOLAUNCH_MINIMAL_SECURITY_INTERVAL) > now) {
446
g_debug_update("security updates, but update-manager was launched "
447
"within the AUTOLAUNCH_MINIMAL_SECURITY_INTERVAL\n");
451
// if security updates are installed unattended, there is nothing
453
if (security_updates_are_installed_unattended())
456
g_debug_update("security updates, auto-launching");
460
// check the logs of dpkg and apt for timestamps, the idea
461
// is to not auto launch if dpkg/apt were run manually by the
464
newest_log_file_timestamp()
468
time_t newest_log_stamp = 0;
470
char *log_glob[] = { "/var/log/dpkg.log*",
471
"/var/log/apt/term.log*",
474
for (i=0; log_glob[i] != NULL; i++)
477
if(glob(log_glob[i], 0, NULL, &pglob) != 0) {
478
g_warning("error from glob %s\n", log_glob[i]);
481
for(j=0;j < pglob.gl_pathc; j++) {
483
const char *log = pglob.gl_pathv[j];
484
if(g_stat(log, &buf) <0) {
485
g_warning("can't stat %s\n", log);
488
if(buf.st_size == 0) {
489
g_warning("log file empty (logrotate?) %s\n", log);
492
time_t mtime = buf.st_mtime;
493
g_debug_update ("mtime from %s: %i (%s)\n", log, mtime, ctime(&mtime));
494
time_t bctime = buf.st_ctime;
495
g_debug_update ("ctime from %s: %i (%s)\n", log, bctime, ctime(&bctime));
496
newest_log_stamp = MAX(MAX(mtime, bctime), newest_log_stamp);
497
g_debug_update ("last_launch from %s: %i (%s)\n", log, newest_log_stamp, ctime(&newest_log_stamp));
501
return newest_log_stamp;
504
// check if the auto launch interval is over and its
505
// time to launch again and if the dpkg lock is currently
508
auto_launch_now (UpdateTrayAppletPrivate *priv)
510
int interval_days = 0;
511
time_t last_launch = 0;
513
if (dpkg_lock_is_taken())
516
#if 0 // disabled because we need more cleverness here in order to cover
517
// the case where people always work on battery (and charge overnight)
518
if (running_on_battery())
522
// when checking for regular updates honor the
523
// regular_auto_launch_interval
524
interval_days = gconf_client_get_int(priv->gconf,
525
GCONF_KEY_AUTO_LAUNCH_INTERVAL,
527
g_debug_update ("interval_days from gconf: %i\n", interval_days);
529
if (interval_days <= 0)
532
// check last launch time
533
last_launch = gconf_client_get_int(priv->gconf,
534
GCONF_KEY_LAST_LAUNCH,
536
g_debug_update ("last_launch from gconf: %i (%s)\n", last_launch, ctime(&last_launch));
538
time_t now = time(NULL);
539
if (auto_launch_security_now(priv, now, last_launch))
542
time_t log_files = newest_log_file_timestamp();
543
last_launch = MAX(log_files, last_launch);
545
g_debug_update("time now %i (%s), delta: %i", now, ctime(&now), now-last_launch);
546
if ((last_launch + (24*60*60*interval_days)) < now) {
547
g_debug_update ("need to auto launch");
282
555
update_check (TrayApplet *ta)
287
//g_print("update_check()\n");
560
g_debug_update ("update_check()\n");
288
561
UpdateTrayAppletPrivate *priv = (UpdateTrayAppletPrivate*)ta->user_data;
290
int num_upgrades = 0;
291
int num_security = 0;
563
priv->num_upgrades = 0;
564
priv->num_security = 0;
292
565
int exit_status = 0;
566
GError *error = NULL;
295
char *cmd[] = { UPGRADE_CHECKER, NULL };
568
char *cmd[] = { "/usr/bin/nice",
569
"/usr/bin/ionice", "-c3",
298
574
if(g_spawn_sync(NULL, cmd, NULL,