~ubuntu-branches/ubuntu/maverick/hal/maverick

« back to all changes in this revision

Viewing changes to hald/hald_runner.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-10-23 12:33:58 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071023123358-6g6378l5cna09c6z
Tags: 0.5.10-1ubuntu1
* Redo the bzr branch of this package as clean fork from the Debian svn
  (https://code.launchpad.net/~ubuntu-core-dev/hal/debian, thanks bzr-svn!)
  and commit the remaining relevant Ubuntu patches to it:
  https://code.launchpad.net/~ubuntu-core-dev/hal/ubuntu
* Merge with Debian unstable; remaining Ubuntu changes:
 - Ubuntu udev world order:
   + debian/hal.links: Remove rules symlink, we install the rules file
     directly into rules/.
   + debian/rules: Install udev rules into /etc/udev/rules.d/.
   + debian/hal.{preinst,postinst,postrm}: Transition code for changing the
     udev rule priority (see 0.5.8.1-3ubuntu7, needs to be kept until after
     next LTS).
 - debian/rules: Enable MacBook (Pro) support on i386 and amd64. Add
   pciutils-dev build dependency.
 - debian/hal.init: Remove stray gparted-disable-automount.fdi on startup.
   (LP #134712)
 - debian/rules: Do not run stop init.d script for levels 1 and 6
   (TearDown).
 - debian/preferences.fdi: Disable automounting for fixed disks. On session
   startup it is not done anyway (since that disables the gnome-mount UI
   which would ask for authentication) and it leads to confusion when
   restarting hal while a session is running. (LP #138537)
 - 80_allow_vfat_usefree.patch: Allow vfat mount option "usefree".
   (LP #133567)
 - 81_ignore_single_slash_label.patch: Ignore labels which only consist of a
   slash, so that they do not end up as /media/-. An earlier Ubuntu
   d-i/ubiquity created those labels by default. (LP #83323)
 - 82_ignore_fixed_nonmedia.patch: Ignore fixed partitions which mounted,
   but not below /media/.
 - 83_ssb_bus_support.patch: Add support for devices on the SSB bus; patch
   by Matthew Garrett (not applied upstream yet, this needs to update the
   spec, too).
 - 84_memstick_bus_support.patch: Add support for devices on the "memstick"
   bus; patch by Matthew Garrett (not reported upstream yet, this needs to
   update the spec, too).
 - 85_read_brightness_not_actual_brightness.patch: Read the brightness from
   /sys/class/backlight/foo/brightness, not actual_brightness. It makes more
   sense to change based on the brightness that we wanted to set, not the
   brightness that we actually set. Patch by Matthew Garrett. Forwarded to
   FD#12891.
* Now build with libsmbios to get Dell backlight support. (LP: #43572)
* Dropped the following Ubuntu changes:
  - hwdb icons and patches, python-launchpad-integration, .desktop file
    translation fixes: hal-device-manager is gone, will be replaced by
    indepentent gnome-device-manager project.
  - symlinking of doc directories in debian/rules: current cdbs does that
    automatically now.
  - 02_powerscripts.patch, 90_pmi.patch: pm-utils is the only supported
    backend now.
  - 26-addon-acpi-fix-free-before-init.diff,
    63_my_dbus_is_full_of_uints.patch, 69_set_dmi_before_matching.patch,
    macbook-backlight.diff: Applied upstream.
  - 56_probe_fstab.patch and the disabling of mounting for unmounted
    partitions which are 'auto' in fstab: The patch does not fit into hal's
    design to always show current information, was rejected upstream,
    only handles a corner case, and we do not automount fixed drives anyway.
* Add 86_allow_ufs_ufstype.patch: Allow ufs mount option 'ufstype', thanks
  to Georges Discry. (LP: #110865, FD#10998)

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * hald_runner.c - Interface to the hal runner helper daemon
5
5
 *
6
6
 * Copyright (C) 2006 Sjoerd Simons, <sjoerd@luon.net>
 
7
 * Copyright (C) 2007 Codethink Ltd. Author Rob Taylor <rob.taylor@codethink.co.uk>
7
8
 *
8
9
 * Licensed under the Academic Free License version 2.1
9
10
 *
65
66
        GPid pid;
66
67
        HalDevice *device;
67
68
        HalRunTerminatedCB cb;
 
69
        gboolean is_singleton;
68
70
        gpointer data1;
69
71
        gpointer data2;
70
72
} RunningProcess;
341
343
static void
342
344
add_env (DBusMessageIter * iter, const gchar * key, const gchar * value)
343
345
{
344
 
        gchar *env;
345
 
        env = g_strdup_printf ("%s=%s", key, value);
346
 
        dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &env);
347
 
        g_free (env);
 
346
        if (value != NULL) {
 
347
                gchar *env;
 
348
                env = g_strdup_printf ("%s=%s", key, value);
 
349
                dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &env);
 
350
                g_free (env);
 
351
        }
348
352
}
349
353
 
350
354
static void
364
368
        if (hald_use_syslog) {
365
369
                add_env (iter, "HALD_USE_SYSLOG", "1");
366
370
        }
367
 
        add_env (iter, "UDI", udi);
 
371
        if (udi)
 
372
                add_env (iter, "UDI", udi);
368
373
        add_env (iter, "HALD_DIRECT_ADDR", hald_dbus_local_server_addr ());
 
374
 
 
375
        /* I'm sure it would be easy to remove use of getenv(3) to add these variables... */
 
376
 
 
377
        add_env (iter, "LD_LIBRARY_PATH", getenv ("LD_LIBRARY_PATH"));
369
378
#ifdef HAVE_POLKIT
370
379
        add_env (iter, "HAVE_POLKIT", "1");
 
380
        add_env (iter, "POLKIT_POLICY_DIR", getenv ("POLKIT_POLICY_DIR"));
 
381
        add_env (iter, "POLKIT_DEBUG", getenv ("POLKIT_DEBUG"));
371
382
#endif
372
383
 
373
384
 
379
390
                GString *seats_string;
380
391
                char *s;
381
392
                char *p;
 
393
                int num_seats;
 
394
                int num_sessions_total;
382
395
 
383
396
                seats_string = g_string_new ("");
384
397
 
385
398
                seats = ck_tracker_get_seats (ck_tracker);
 
399
                num_seats = g_slist_length (seats);
 
400
                num_sessions_total = 0;
386
401
                for (i = seats; i != NULL; i = g_slist_next (i)) {
387
402
                        GSList *j;
388
403
                        CKSeat *seat;
389
404
                        GSList *sessions;
390
405
                        const char *seat_id;
391
406
                        GString *sessions_string;
 
407
                        int num_sessions;
392
408
 
393
409
                        sessions_string = g_string_new ("");
394
410
 
404
420
                        g_string_append (seats_string, seat_id);
405
421
 
406
422
                        sessions = ck_seat_get_sessions (seat);
 
423
                        num_sessions = g_slist_length (sessions);
 
424
                        num_sessions_total += num_sessions;
407
425
                        for (j = sessions; j != NULL; j = g_slist_next (j)) {
408
426
                                CKSession *session;
409
427
                                const char *session_id;
 
428
                                const char *q;
410
429
 
411
430
                                session = j->data;
412
431
                                /* basename again; e.g. Session1 rather than /org/freedesktop/ConsoleKit/Session1 */
417
436
                                }
418
437
                                g_string_append (sessions_string, session_id);
419
438
 
420
 
                                /* for each Session, export IS_ACTIVE and UID 
 
439
                                /* for each Session, export IS_ACTIVE, UID, IS_LOCAL, HOSTNAME
421
440
                                 *
 
441
                                 * CK_SESSION_SEAT_Session2=Seat1
422
442
                                 * CK_SESSION_IS_ACTIVE_Session2=true|false
423
443
                                 * CK_SESSION_UID_Session2=501
424
444
                                 * CK_SESSION_IS_LOCAL_Session2=true|false
425
445
                                 * CK_SESSION_HOSTNAME_Session2=192.168.1.112
426
446
                                 */
 
447
                                s = g_strdup_printf ("CK_SESSION_SEAT_%s", session_id);
 
448
                                add_env (iter, s, seat_id);
 
449
                                g_free (s);
427
450
                                s = g_strdup_printf ("CK_SESSION_IS_ACTIVE_%s", session_id);
428
451
                                add_env (iter, s, ck_session_is_active (session) ? "true" : "false");
429
452
                                g_free (s);
435
458
                                s = g_strdup_printf ("CK_SESSION_IS_LOCAL_%s", session_id);
436
459
                                add_env (iter, s, ck_session_is_local (session) ? "true" : "false");
437
460
                                g_free (s);
438
 
                                s = g_strdup_printf ("CK_SESSION_HOSTNAME_%s", session_id);
439
 
                                p = g_strdup_printf ("%s", ck_session_get_hostname (session));
440
 
                                add_env (iter, s, p);
441
 
                                g_free (s);
442
 
                                g_free (p);
 
461
                                q = ck_session_get_hostname (session);
 
462
                                if (q != NULL && strlen (q) > 0) {
 
463
                                        s = g_strdup_printf ("CK_SESSION_HOSTNAME_%s", session_id);
 
464
                                        add_env (iter, s, q);
 
465
                                        g_free (s);
 
466
                                }
443
467
                        }
444
468
 
445
469
                        /* for each Seat, export sessions on each seat 
446
470
                         *
447
471
                         * CK_SEAT_Seat1=Session1 Session3 Session7
 
472
                         * CK_SEAT_NUM_SESSIONS_Seat1=3
448
473
                         */
449
474
                        s = g_strdup_printf ("CK_SEAT_%s", seat_id);
450
475
                        add_env (iter, s, sessions_string->str);
451
476
                        g_string_free (sessions_string, TRUE);
452
477
                        g_free (s);
453
478
 
 
479
                        s = g_strdup_printf ("CK_SEAT_NUM_SESSIONS_%s", seat_id);
 
480
                        p = g_strdup_printf ("%d", num_sessions);
 
481
                        add_env (iter, s, p);
 
482
                        g_free (p);
 
483
                        g_free (s);
 
484
 
454
485
                }
455
486
 
456
487
                /* Export all detected seats 
459
490
                 */
460
491
                add_env (iter, "CK_SEATS", seats_string->str);
461
492
                g_string_free (seats_string, TRUE);
 
493
 
 
494
                /* Export total number of sessions
 
495
                 *
 
496
                 * CK_NUM_SESSIONS=5
 
497
                 */
 
498
                p = g_strdup_printf ("%d", num_sessions_total);
 
499
                add_env (iter, "CK_NUM_SESSIONS", p);
 
500
                g_free (p);
 
501
 
 
502
                /* Export number of seats
 
503
                 *
 
504
                 * CK_NUM_SEATS=5
 
505
                 */
 
506
                p = g_strdup_printf ("%d", num_seats);
 
507
                add_env (iter, "CK_NUM_SEATS", p);
 
508
                g_free (p);
 
509
 
462
510
        }
463
511
#endif /* HAVE_CONKIT */
464
512
 
514
562
        return TRUE;
515
563
}
516
564
 
517
 
static gboolean
518
 
add_first_part (DBusMessageIter * iter, HalDevice * device,
519
 
                const gchar * command_line, char **extra_env)
 
565
static void
 
566
add_udi (DBusMessageIter * iter, HalDevice * device)
520
567
{
521
 
        DBusMessageIter array_iter;
522
568
        const char *udi;
523
569
 
524
570
        if (device != NULL)
527
573
                udi = "";
528
574
 
529
575
        dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &udi);
 
576
}
530
577
 
 
578
static gboolean
 
579
add_environment (DBusMessageIter * iter, HalDevice * device,
 
580
                const gchar * command_line, char **extra_env)
 
581
{
 
582
        DBusMessageIter array_iter;
531
583
        dbus_message_iter_open_container (iter,
532
584
                                          DBUS_TYPE_ARRAY,
533
585
                                          DBUS_TYPE_STRING_AS_STRING,
535
587
        if (device != NULL)
536
588
                hal_device_property_foreach (device, add_property_to_msg,
537
589
                                             &array_iter);
538
 
        add_basic_env (&array_iter, udi);
 
590
        add_basic_env (&array_iter, device ? hal_device_get_udi (device): NULL);
539
591
        add_extra_env (&array_iter, extra_env);
540
592
        dbus_message_iter_close_container (iter, &array_iter);
541
593
 
546
598
}
547
599
 
548
600
/* Start a helper, returns true on a successfull start */
549
 
gboolean
550
 
hald_runner_start (HalDevice * device, const gchar * command_line,
551
 
                   char **extra_env, HalRunTerminatedCB cb, gpointer data1,
552
 
                   gpointer data2)
 
601
static gboolean
 
602
runner_start (HalDevice * device, const gchar * command_line,
 
603
              char **extra_env, gboolean singleton,
 
604
              HalRunTerminatedCB cb, gpointer data1, gpointer data2)
553
605
{
554
606
        DBusMessage *msg, *reply;
555
 
        DBusError err;
 
607
        DBusError error;
556
608
        DBusMessageIter iter;
557
609
 
558
 
        dbus_error_init (&err);
 
610
        dbus_error_init (&error);
559
611
        msg = dbus_message_new_method_call ("org.freedesktop.HalRunner",
560
612
                                            "/org/freedesktop/HalRunner",
561
613
                                            "org.freedesktop.HalRunner",
562
 
                                            "Start");
 
614
                                            singleton ? "StartSingleton" : "Start");
563
615
        if (msg == NULL)
564
616
                DIE (("No memory"));
565
617
        dbus_message_iter_init_append (msg, &iter);
566
618
 
567
 
        if (!add_first_part (&iter, device, command_line, extra_env))
 
619
        if (!singleton)
 
620
                add_udi (&iter, device);
 
621
 
 
622
        if (!add_environment (&iter, device, command_line, extra_env)) {
 
623
                HAL_ERROR (("Error adding environment, device =%p, singleton=%d",
 
624
                        device, singleton));
568
625
                goto error;
 
626
        }
569
627
 
570
628
        /* Wait for the reply, should be almost instantanious */
571
629
        reply =
572
630
            dbus_connection_send_with_reply_and_block (runner_connection,
573
 
                                                       msg, -1, &err);
 
631
                                                       msg, -1, &error);
574
632
        if (reply) {
575
633
                gboolean ret =
576
634
                    (dbus_message_get_type (reply) ==
578
636
 
579
637
                if (ret) {
580
638
                        dbus_int64_t pid_from_runner;
581
 
                        if (dbus_message_get_args (reply, &err,
 
639
                        if (dbus_message_get_args (reply, &error,
582
640
                                                   DBUS_TYPE_INT64,
583
641
                                                   &pid_from_runner,
584
642
                                                   DBUS_TYPE_INVALID)) {
587
645
                                        rp = g_new0 (RunningProcess, 1);
588
646
                                        rp->pid = (GPid) pid_from_runner;
589
647
                                        rp->cb = cb;
590
 
                                        rp->device = device;
 
648
                                        rp->is_singleton = singleton;
 
649
                                        if (singleton)
 
650
                                                rp->device = NULL;
 
651
                                        else
 
652
                                                rp->device = device;
591
653
                                        rp->data1 = data1;
592
654
                                        rp->data2 = data2;
593
655
 
604
666
                dbus_message_unref (reply);
605
667
                dbus_message_unref (msg);
606
668
                return ret;
 
669
        } else {
 
670
                if (dbus_error_is_set (&error)) {
 
671
                        HAL_ERROR (("Error running '%s': %s: %s", command_line, error.name, error.message));
 
672
                }
607
673
        }
608
674
 
609
675
      error:
611
677
        return FALSE;
612
678
}
613
679
 
 
680
gboolean
 
681
hald_runner_start (HalDevice * device, const gchar * command_line,
 
682
                   char **extra_env, HalRunTerminatedCB cb,
 
683
                   gpointer data1, gpointer data2)
 
684
{
 
685
        return runner_start (device, command_line, extra_env, FALSE, cb, data1, data2);
 
686
}
 
687
 
 
688
gboolean
 
689
hald_runner_start_singleton (const gchar * command_line,
 
690
                             char **extra_env, HalRunTerminatedCB cb,
 
691
                             gpointer data1, gpointer data2)
 
692
{
 
693
        return runner_start (NULL, command_line, extra_env, TRUE, cb, data1, data2);
 
694
}
 
695
 
 
696
 
614
697
static void
615
698
process_reply (DBusMessage *m, HelperData *hb)
616
699
{
714
797
                DIE (("No memory"));
715
798
        dbus_message_iter_init_append (msg, &iter);
716
799
 
717
 
        if (!add_first_part (&iter, device, command_line, extra_env))
 
800
        add_udi (&iter, device);
 
801
        if (!add_environment (&iter, device, command_line, extra_env))
718
802
                goto error;
719
803
 
720
804
        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &input);
783
867
                DIE (("No memory"));
784
868
        dbus_message_iter_init_append (msg, &iter);
785
869
 
786
 
        if (!add_first_part (&iter, device, command_line, extra_env))
 
870
        add_udi (&iter, device);
 
871
        if (!add_environment (&iter, device, command_line, extra_env))
787
872
                goto error;
788
873
 
789
874
        dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &input);
853
938
}
854
939
 
855
940
void
856
 
hald_runner_kill_all (HalDevice * device)
 
941
hald_runner_kill_all ()
857
942
{
858
943
        DBusMessage *msg, *reply;
859
944
        DBusError err;
860
945
 
861
 
        running_processes_remove_device (device);
862
 
 
863
946
        msg = dbus_message_new_method_call ("org.freedesktop.HalRunner",
864
947
                                            "/org/freedesktop/HalRunner",
865
948
                                            "org.freedesktop.HalRunner",