9
#define G_UDEV_API_IS_SUBJECT_TO_CHANGE
10
#include <gudev/gudev.h>
11
#include <sys/utsname.h>
13
gchar *hplip_helper[] = { "/usr/bin/hp-plugin-ubuntu", NULL };
16
g_debug_uevent(const char *msg, ...)
20
g_logv("uevent",G_LOG_LEVEL_DEBUG, msg, va);
24
static gboolean scp_checked = FALSE;
27
deal_with_scp(GUdevDevice *device)
31
/* only do this once */
35
/* check if we just added a printer */
36
if ((g_strcmp0(g_udev_device_get_sysfs_attr(device, "bInterfaceClass"), "07") != 0 ||
37
g_strcmp0(g_udev_device_get_sysfs_attr(device, "bInterfaceSubClass"), "01") != 0) &&
38
!g_str_has_prefix(g_udev_device_get_name (device), "lp")) {
39
g_debug_uevent ("deal_with_scp: devpath=%s: not a printer", g_udev_device_get_sysfs_path(device));
43
g_debug_uevent ("deal_with_scp: devpath=%s: printer identified", g_udev_device_get_sysfs_path(device));
47
gchar* ps_argv[] = {"ps", "h", "-ocommand", "-Cpython", NULL};
49
if (!g_spawn_sync (NULL, ps_argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
50
&ps_out, NULL, NULL, &error)) {
51
g_warning ("deal_with_scp: error calling ps: %s", error->message);
55
g_debug_uevent ("deal_with_scp: running python processes:%s", ps_out);
56
if (strstr (ps_out, "system-config-printer") != NULL) {
57
g_debug_uevent ("deal_with_scp: system-config-printer already running");
61
g_debug_uevent ("deal_with_scp: launching system-config-printer");
62
gchar* scp_argv[] = {"system-config-printer-applet", NULL};
64
if (!g_spawn_async(NULL, scp_argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error)) {
65
g_warning("%s could not be called: %s", scp_argv[0], error->message);
72
on_uevent (GUdevClient *client,
77
g_debug_uevent ("uevent.c on_uevent: action=%s, devpath=%s", action, g_udev_device_get_sysfs_path(device));
79
if (g_strcmp0 (action, "add") != 0 && g_strcmp0 (action, "change") != 0)
82
if (deal_with_scp(device))
89
const gchar* subsystems[] = {"firmware", "usb", NULL};
92
if (uname (&u) != 0) {
93
g_warning("uname() failed, not monitoring devices");
97
GUdevClient* gudev = g_udev_client_new (subsystems);
98
g_signal_connect (gudev, "uevent", G_CALLBACK (on_uevent), NULL);
100
/* cold plug HPLIP devices */
101
GList *usb_devices, *elem;
102
usb_devices = g_udev_client_query_by_subsystem (gudev, "usb");
103
for (elem = usb_devices; elem != NULL; elem = g_list_next(elem)) {
104
deal_with_scp(elem->data);
105
g_object_unref(elem->data);
107
g_list_free(usb_devices);
114
g_warning("Printer monitoring disabled.");