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

« back to all changes in this revision

Viewing changes to src/uevent.c

  • Committer: Brian Murray
  • Date: 2013-06-03 22:40:21 UTC
  • mfrom: (781.2.12 distro-cd-detected)
  • Revision ID: brian@canonical.com-20130603224021-17l6xslzhzss1ji9
* Move update-notifier checking for CDs with packages into a new binary
  distro-cd-updater
* Add an upstart user session job that runs upon CD insertion
* Remove sections of uevent related to hp firmware and replace them with an
  upstart user session job
* Modified avahi disabled notification to run as an upstart user session
* Modified new release check to run as an upstart user session
* Added in a weekly cron job to check for a new release of ubuntu
* Added an upstart user session job to check for crashes
* Ensure we ask before launching a pkexec dialog for an apport crash

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
   va_end(va);
22
22
}
23
23
 
24
 
static gboolean
25
 
deal_with_hplip_firmware(GUdevDevice *device)
26
 
{
27
 
    const gchar *id_vendor, *id_product, *id_model;
28
 
    GError *error = NULL;
29
 
    gint ret = 0;
30
 
 
31
 
    id_vendor = g_udev_device_get_sysfs_attr (device, "idVendor");
32
 
    id_product = g_udev_device_get_sysfs_attr (device, "idProduct");
33
 
    id_model = g_udev_device_get_property (device, "ID_MODEL");
34
 
    g_debug_uevent ("uevent.c id_vendor=%s, id_product=%s", id_vendor, id_product);
35
 
 
36
 
    // only idVendor=03f0, idProduct="??{17,2a}" requires firmware
37
 
    if (g_strcmp0 (id_vendor, "03f0") != 0 || 
38
 
        id_product == NULL || 
39
 
        g_utf8_strlen(id_product, -1) != 4)
40
 
       return FALSE;
41
 
    if (! ( ((id_product[2] == '1') && (id_product[3] == '7')) ||
42
 
            ((id_product[2] == '2') && (tolower(id_product[3]) == 'a')) ))
43
 
       return FALSE;
44
 
 
45
 
    // firmware is only required if "hp-mkuri -c" returns 2 or 5
46
 
    const gchar *cmd = "/usr/bin/hp-mkuri -c";
47
 
    g_setenv("hp_model", id_model, TRUE);
48
 
    if (!g_spawn_command_line_sync (cmd, NULL, NULL, &ret, &error))
49
 
    {
50
 
       g_warning("error calling hp-mkuri");
51
 
       return FALSE;
52
 
    }
53
 
 
54
 
    // check return codes, 2 & 5 indicate that it has the firmware already
55
 
    if (WEXITSTATUS(ret) != 2 && WEXITSTATUS(ret) != 5)
56
 
    {
57
 
       g_debug_uevent ("hp-mkuri indicates no firmware needed");
58
 
       return TRUE;
59
 
    }
60
 
 
61
 
    if (!g_spawn_async("/", hplip_helper, NULL, 0, NULL, NULL, NULL, NULL))
62
 
    {
63
 
       g_warning("error calling hplip_helper");
64
 
       return FALSE;
65
 
    }
66
 
    return TRUE;
67
 
}
68
 
 
69
 
#ifdef ENABLE_SCP
70
24
static gboolean scp_checked = FALSE;
71
25
 
72
26
static gboolean
113
67
    }
114
68
    return TRUE;
115
69
}
116
 
#endif
117
70
 
118
71
static void
119
72
on_uevent (GUdevClient *client,
126
79
    if (g_strcmp0 (action, "add") != 0 && g_strcmp0 (action, "change") != 0)
127
80
        return;
128
81
 
129
 
    /* handle firmware */
130
 
    if (deal_with_hplip_firmware(device))
131
 
       return;
132
 
 
133
 
#ifdef ENABLE_SCP
134
82
    if (deal_with_scp(device))
135
83
        return;
136
 
#endif
137
84
}
138
85
 
139
86
void
140
87
uevent_init(void)
141
88
{
142
 
    const gchar* subsytems[] = {"firmware", "usb", NULL};
 
89
    const gchar* subsystems[] = {"firmware", "usb", NULL};
143
90
 
144
 
    /* build firmware search path */
145
91
    struct utsname u;
146
92
    if (uname (&u) != 0) {
147
 
        g_warning("uname() failed, not monitoring firmware");
 
93
        g_warning("uname() failed, not monitoring devices");
148
94
        return;
149
95
    }
150
96
 
151
 
    GUdevClient* gudev = g_udev_client_new (subsytems);
 
97
    GUdevClient* gudev = g_udev_client_new (subsystems);
152
98
    g_signal_connect (gudev, "uevent", G_CALLBACK (on_uevent), NULL);
153
99
 
154
 
    /* cold plug HPLIP firmware */
 
100
    /* cold plug HPLIP devices */
155
101
    GList *usb_devices, *elem;
156
102
    usb_devices = g_udev_client_query_by_subsystem (gudev, "usb");
157
103
    for (elem = usb_devices; elem != NULL; elem = g_list_next(elem)) {
158
 
       deal_with_hplip_firmware(elem->data);
159
 
#ifdef ENABLE_SCP
160
104
       deal_with_scp(elem->data);
161
 
#endif
162
105
       g_object_unref(elem->data);
163
106
    }
164
107
    g_list_free(usb_devices);
168
111
void
169
112
uevent_init(void)
170
113
{
171
 
    g_warning("Installation of firmware disabled.");
 
114
    g_warning("Printer monitoring disabled.");
172
115
}
173
116
#endif // HAVE_GUDEV