~ubuntu-branches/debian/sid/hal/sid

« back to all changes in this revision

Viewing changes to hald/hald.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-10-23 12:33:58 UTC
  • Revision ID: james.westby@ubuntu.com-20071023123358-xaf8mjc5n84d5gtz
Tags: upstream-0.5.10
ImportĀ upstreamĀ versionĀ 0.5.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *
6
6
 * Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
7
7
 * Copyright (C) 2005 Danny Kukawka, <danny.kukawka@web.de>
 
8
 * Copyright (C) 2007 Codethink Ltd. Author Rob Taylor <rob.taylor@codethink.co.uk>
8
9
 *
9
10
 * Licensed under the Academic Free License version 2.1
10
11
 *
30
31
 
31
32
#include <stdio.h>
32
33
#include <stdlib.h>
 
34
 
 
35
#ifdef HAVE_MALLOPT
 
36
#include <malloc.h>
 
37
#endif
 
38
 
33
39
#include <string.h>
34
40
#include <unistd.h>
35
41
#include <getopt.h>
43
49
#include <syslog.h>
44
50
#include <sys/time.h>
45
51
#include <sys/resource.h>
46
 
#include <malloc.h>
47
52
#include <dbus/dbus.h>
48
53
#include <dbus/dbus-glib.h>
49
54
#include <dbus/dbus-glib-lowlevel.h>
119
124
                                            command_line, hal_device_get_udi(device)));
120
125
                        }
121
126
                }
 
127
                for (hal_device_property_strlist_iter_init (device, "info.addons.singleton", &iter);
 
128
                     hal_device_property_strlist_iter_is_valid (&iter);
 
129
                     hal_device_property_strlist_iter_next (&iter)) {
 
130
                        const gchar *command_line;
 
131
 
 
132
                        command_line = hal_device_property_strlist_iter_get_value (&iter);
 
133
 
 
134
                        if (hald_singleton_device_added (command_line, device))
 
135
                                hal_device_inc_num_addons (device);
 
136
                        else
 
137
                                HAL_ERROR(("Couldn't add device to singleton"));
 
138
                }
 
139
 
122
140
        } else {
 
141
                HalDeviceStrListIter iter;
 
142
 
123
143
                HAL_INFO (("Removed device from GDL; udi=%s", hal_device_get_udi(device)));
 
144
                for (hal_device_property_strlist_iter_init (device, "info.addons.singleton", &iter);
 
145
                     hal_device_property_strlist_iter_is_valid (&iter);
 
146
                     hal_device_property_strlist_iter_next (&iter)) {
 
147
                        const gchar *command_line;
 
148
 
 
149
                        command_line = hal_device_property_strlist_iter_get_value (&iter);
 
150
 
 
151
                        hald_singleton_device_removed (command_line, device);
 
152
                }
 
153
 
124
154
                hald_runner_kill_device(device);
125
155
        }
126
156
 
265
295
dbus_bool_t hald_use_syslog = FALSE;
266
296
dbus_bool_t hald_debug_exit_after_probing = FALSE;
267
297
 
 
298
#ifdef HAVE_POLKIT
 
299
PolKitContext *pk_context;
 
300
#endif
 
301
 
268
302
static int sigterm_unix_signal_pipe_fds[2];
269
303
static GIOChannel *sigterm_iochn;
270
304
 
382
416
 
383
417
/*--------------------------------------------------------------------------------------------------*/
384
418
 
 
419
#ifdef HAVE_POLKIT
 
420
 
 
421
static gboolean
 
422
_polkit_io_watch_have_data (GIOChannel *channel, GIOCondition condition, gpointer user_data)
 
423
{
 
424
        int fd;
 
425
        PolKitContext *pk_context = user_data;
 
426
        fd = g_io_channel_unix_get_fd (channel);
 
427
        polkit_context_io_func (pk_context, fd);
 
428
        return TRUE;
 
429
}
 
430
 
 
431
static int 
 
432
_polkit_io_add_watch (PolKitContext *pk_context, int fd)
 
433
{
 
434
        guint id = 0;
 
435
        GIOChannel *channel;
 
436
        channel = g_io_channel_unix_new (fd);
 
437
        if (channel == NULL)
 
438
                goto out;
 
439
        id = g_io_add_watch (channel, G_IO_IN, _polkit_io_watch_have_data, pk_context);
 
440
        if (id == 0) {
 
441
                g_io_channel_unref (channel);
 
442
                goto out;
 
443
        }
 
444
        g_io_channel_unref (channel);
 
445
out:
 
446
        return id;
 
447
}
 
448
 
 
449
static void 
 
450
_polkit_io_remove_watch (PolKitContext *pk_context, int watch_id)
 
451
{
 
452
        g_source_remove (watch_id);
 
453
}
 
454
 
 
455
static guint _polkit_cooloff_timer = 0;
 
456
 
 
457
static gboolean
 
458
_polkit_config_really_changed (gpointer user_data)
 
459
{
 
460
        HAL_INFO (("Acting on PolicyKit config change"));
 
461
        _polkit_cooloff_timer = 0;
 
462
        reconfigure_all_policy ();
 
463
        return FALSE;
 
464
}
 
465
 
 
466
static void
 
467
_polkit_config_changed_cb (PolKitContext *pk_context, gpointer user_data)
 
468
{
 
469
        HAL_INFO (("PolicyKit reports that the config have changed; starting cool-off timer"));
 
470
 
 
471
        /* Start a cool-off timer since we get a lot of events within
 
472
         * a short time-frame...
 
473
         */
 
474
 
 
475
        if (_polkit_cooloff_timer > 0) {
 
476
                /* cancel old cool-off timer */
 
477
                g_source_remove (_polkit_cooloff_timer);
 
478
                HAL_INFO (("restarting cool-off timer"));
 
479
        }
 
480
        _polkit_cooloff_timer = g_timeout_add (1000, /* one second... */
 
481
                                               _polkit_config_really_changed,
 
482
                                               NULL);
 
483
}
 
484
 
 
485
#endif /* HAVE_POLKIT */
 
486
 
 
487
 
385
488
/**  
386
489
 *  main:
387
490
 *  @argc:               Number of arguments
397
500
        guint sigterm_iochn_listener_source_id;
398
501
        char *path;
399
502
        char newpath[512];
400
 
 
 
503
#ifdef HAVE_POLKIT
 
504
        PolKitError *p_error;
 
505
#endif
401
506
        openlog ("hald", LOG_PID, LOG_DAEMON);
402
507
 
403
508
#ifdef HAVE_MALLOPT
632
737
        /* initialize privileged operating system specific parts */
633
738
        osspec_privileged_init ();
634
739
 
 
740
#ifdef HAVE_POLKIT
 
741
        p_error = NULL;
 
742
        pk_context = polkit_context_new ();
 
743
        if (pk_context == NULL)
 
744
                DIE (("Could not create PolicyKit context"));
 
745
        polkit_context_set_config_changed (pk_context,
 
746
                                           _polkit_config_changed_cb,
 
747
                                           NULL);
 
748
        polkit_context_set_io_watch_functions (pk_context, _polkit_io_add_watch, _polkit_io_remove_watch);
 
749
        if (!polkit_context_init (pk_context, &p_error))
 
750
                DIE (("Could not init PolicyKit context: %s", polkit_error_get_error_message (p_error)));
 
751
#endif
 
752
 
635
753
        /* sometimes we don't want to drop root privs, for instance
636
754
           if we are profiling memory usage */
637
755
        if (opt_retain_privileges == FALSE) {
640
758
 
641
759
        hald_is_initialising = TRUE;
642
760
 
643
 
        /* make sure our fdi rule cache is up to date */
644
 
        di_cache_coherency_check();
 
761
        /* make sure our fdi rule cache is up to date and setup file monitoring */
 
762
        di_cache_coherency_check(TRUE);
645
763
 
646
764
        /* initialize operating system specific parts */
647
765
        osspec_init ();