~ubuntu-core-dev/update-notifier/ubuntu

« back to all changes in this revision

Viewing changes to src/release.c

  • Committer: Balint Reczey
  • Date: 2020-06-11 18:46:02 UTC
  • Revision ID: balint.reczey@canonical.com-20200611184602-2rv1zan3xu723x2u
Moved to git at https://git.launchpad.net/update-notifier

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifdef HAVE_CONFIG_H
2
 
#include "config.h"
3
 
#endif
4
 
 
5
 
#include <glib.h>
6
 
#include <glib-object.h>
7
 
 
8
 
#include <sys/types.h>
9
 
#include <sys/wait.h>
10
 
#include <time.h>
11
 
 
12
 
#include "update-notifier.h"
13
 
 
14
 
extern gboolean DEVEL_RELEASE;
15
 
 
16
 
static inline void
17
 
g_debug_release(const char *msg, ...)
18
 
{
19
 
   va_list va;
20
 
   va_start(va, msg);
21
 
   g_logv("release",G_LOG_LEVEL_DEBUG, msg, va);
22
 
   va_end(va);
23
 
}
24
 
 
25
 
// actually show the notification
26
 
static gboolean
27
 
check_new_release(gpointer user_data)
28
 
{
29
 
   g_debug_release ("check_new_release");
30
 
 
31
 
   GSettings *settings = (GSettings*)user_data;
32
 
 
33
 
   time_t now = time(NULL);
34
 
   time_t last_check = (time_t)g_settings_get_uint(settings,
35
 
                                                   SETTINGS_KEY_LAST_RELEASE_CHECK);
36
 
 
37
 
   // test if we need to run
38
 
   if ( (last_check + RELEASE_UPGRADE_CHECK_WAIT) > now ) {
39
 
      g_debug_release ("release upgrade check not needed (%i > %i)", last_check + RELEASE_UPGRADE_CHECK_WAIT, now);
40
 
      return TRUE;
41
 
   }
42
 
 
43
 
   // run the checker
44
 
   gchar *argv[10] = { "/bin/sh", "-c", RELEASE_UPGRADE_CHECKER, };
45
 
   if (DEVEL_RELEASE) {
46
 
      g_debug_release ("running the release upgrade checker %s in devel mode", RELEASE_UPGRADE_CHECKER);
47
 
      argv[3] = "--devel-release";
48
 
      argv[4] = NULL;
49
 
   } else {
50
 
      g_debug_release ("running the release upgrade checker %s", RELEASE_UPGRADE_CHECKER);
51
 
      argv[3] = NULL;
52
 
   }
53
 
   g_spawn_async ("/", argv, NULL, 0, NULL, NULL, NULL, NULL);
54
 
 
55
 
   // and update the timestamp so we don't check again too soon
56
 
   g_settings_set_uint(settings, SETTINGS_KEY_LAST_RELEASE_CHECK, (guint)now);
57
 
 
58
 
   return TRUE;
59
 
}
60
 
 
61
 
gboolean
62
 
release_checker_init (UpgradeNotifier *un)
63
 
{
64
 
   g_debug_release ("release_checker_init");
65
 
 
66
 
   // check once at startup
67
 
   check_new_release (un->settings);
68
 
   // release upgrades happen not that frequently, we use two timers
69
 
   // check every 10 min if 48h are reached and then run 
70
 
   // "check-release-upgrade-gtk" again
71
 
   g_timeout_add_seconds (60*10, check_new_release, un->settings);
72
 
 
73
 
   return TRUE;
74
 
}