~ubuntu-branches/ubuntu/trusty/systemd/trusty

« back to all changes in this revision

Viewing changes to src/login/logind-session-dbus.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl, Michael Biebl, Michael Stapelberg, Daniel Schaal, Ondrej Balaz
  • Date: 2013-09-12 00:13:11 UTC
  • mfrom: (1.1.11) (9.1.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: package-import@ubuntu.com-20130912001311-dz35it34wr2lbday
Tags: 204-3
[ Michael Biebl ]
* Upload to unstable.
* Use /bin/bash in debug-shell.service as Debian doesn't have /sbin/sushell.
* Only import net.ifaces cmdline property for network devices.
* Generate strict dependencies between the binary packages using a
  shlibs.local file and add an explicit versioned dependency on
  libsystemd-login0 to systemd to ensure packages are upgraded in sync.
  Closes: #719444
* Drop obsolete Replaces: libudev0 from udev package.
* Use correct paths for various binaries, like /sbin/quotaon, which are
  installed in / and not /usr in Debian.  Closes: #721347
* Don't install kernel-install(8) man page since we don't install the
  corresponding binary either.  Closes: #722180
* Cherry-pick upstream fixes to make switching runlevels and starting
  reboot via ctrl-alt-del more robust.
* Cherry-pick upstream fix to properly apply ACLs to Journal files.

[ Michael Stapelberg ]
* Make systemctl enable|disable call update-rc.d for SysV init scripts.
  Closes: #709780
* Don't mount /tmp as tmpfs by default and make it possible to enable this
  feature via "systemctl enable tmp.mount".

[ Daniel Schaal ]
* Add bug-script to systemd and udev.  Closes: #711245

[ Ondrej Balaz ]
* Recognize discard option in /etc/crypttab.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
  Copyright 2011 Lennart Poettering
7
7
 
8
8
  systemd is free software; you can redistribute it and/or modify it
9
 
  under the terms of the GNU General Public License as published by
10
 
  the Free Software Foundation; either version 2 of the License, or
 
9
  under the terms of the GNU Lesser General Public License as published by
 
10
  the Free Software Foundation; either version 2.1 of the License, or
11
11
  (at your option) any later version.
12
12
 
13
13
  systemd is distributed in the hope that it will be useful, but
14
14
  WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
 
  General Public License for more details.
 
16
  Lesser General Public License for more details.
17
17
 
18
 
  You should have received a copy of the GNU General Public License
 
18
  You should have received a copy of the GNU Lesser General Public License
19
19
  along with systemd; If not, see <http://www.gnu.org/licenses/>.
20
20
***/
21
21
 
40
40
        "   <arg name=\"who\" type=\"s\"/>\n"                           \
41
41
        "   <arg name=\"signal\" type=\"s\"/>\n"                        \
42
42
        "  </method>\n"                                                 \
 
43
        "  <signal name=\"Lock\"/>\n"                                   \
 
44
        "  <signal name=\"Unlock\"/>\n"                                 \
43
45
        "  <property name=\"Id\" type=\"s\" access=\"read\"/>\n"        \
44
46
        "  <property name=\"User\" type=\"(uo)\" access=\"read\"/>\n"   \
45
47
        "  <property name=\"Name\" type=\"s\" access=\"read\"/>\n"      \
46
48
        "  <property name=\"Timestamp\" type=\"t\" access=\"read\"/>\n" \
47
49
        "  <property name=\"TimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
48
 
        "  <property name=\"ControlGroupPath\" type=\"s\" access=\"read\"/>\n" \
 
50
        "  <property name=\"DefaultControlGroup\" type=\"s\" access=\"read\"/>\n" \
49
51
        "  <property name=\"VTNr\" type=\"u\" access=\"read\"/>\n"      \
50
52
        "  <property name=\"Seat\" type=\"(so)\" access=\"read\"/>\n"   \
51
53
        "  <property name=\"TTY\" type=\"s\" access=\"read\"/>\n"       \
53
55
        "  <property name=\"Remote\" type=\"b\" access=\"read\"/>\n"    \
54
56
        "  <property name=\"RemoteHost\" type=\"s\" access=\"read\"/>\n" \
55
57
        "  <property name=\"RemoteUser\" type=\"s\" access=\"read\"/>\n" \
56
 
        "  <property name=\"Service\" type=\"s\" access=\"read\"/>\n" \
 
58
        "  <property name=\"Service\" type=\"s\" access=\"read\"/>\n"   \
57
59
        "  <property name=\"Leader\" type=\"u\" access=\"read\"/>\n"    \
58
60
        "  <property name=\"Audit\" type=\"u\" access=\"read\"/>\n"     \
59
61
        "  <property name=\"Type\" type=\"s\" access=\"read\"/>\n"      \
60
 
        "  <property name=\"Class\" type=\"s\" access=\"read\"/>\n"      \
 
62
        "  <property name=\"Class\" type=\"s\" access=\"read\"/>\n"     \
61
63
        "  <property name=\"Active\" type=\"b\" access=\"read\"/>\n"    \
 
64
        "  <property name=\"State\" type=\"s\" access=\"read\"/>\n"     \
62
65
        "  <property name=\"Controllers\" type=\"as\" access=\"read\"/>\n" \
63
66
        "  <property name=\"ResetControllers\" type=\"as\" access=\"read\"/>\n" \
64
67
        "  <property name=\"KillProcesses\" type=\"b\" access=\"read\"/>\n" \
105
108
        }
106
109
 
107
110
        if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &id) ||
108
 
            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path)) {
109
 
                free(p);
 
111
            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path))
110
112
                return -ENOMEM;
111
 
        }
112
 
 
113
 
        free(p);
114
113
 
115
114
        if (!dbus_message_iter_close_container(i, &sub))
116
115
                return -ENOMEM;
121
120
static int bus_session_append_user(DBusMessageIter *i, const char *property, void *data) {
122
121
        DBusMessageIter sub;
123
122
        User *u = data;
124
 
        char *p = NULL;
 
123
        _cleanup_free_ char *p = NULL;
125
124
 
126
125
        assert(i);
127
126
        assert(property);
135
134
                return -ENOMEM;
136
135
 
137
136
        if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_UINT32, &u->uid) ||
138
 
            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &p)) {
139
 
                free(p);
 
137
            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &p))
140
138
                return -ENOMEM;
141
 
        }
142
 
 
143
 
        free(p);
144
139
 
145
140
        if (!dbus_message_iter_close_container(i, &sub))
146
141
                return -ENOMEM;
182
177
        Session *s = data;
183
178
        dual_timestamp t;
184
179
        uint64_t u;
 
180
        int r;
185
181
 
186
182
        assert(i);
187
183
        assert(property);
188
184
        assert(s);
189
185
 
190
 
        session_get_idle_hint(s, &t);
 
186
        r = session_get_idle_hint(s, &t);
 
187
        if (r < 0)
 
188
                return r;
 
189
 
191
190
        u = streq(property, "IdleSinceHint") ? t.realtime : t.monotonic;
192
191
 
193
192
        if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
196
195
        return 0;
197
196
}
198
197
 
 
198
static int bus_session_append_default_cgroup(DBusMessageIter *i, const char *property, void *data) {
 
199
        Session *s = data;
 
200
        _cleanup_free_ char *t = NULL;
 
201
        int r;
 
202
        bool success;
 
203
 
 
204
        assert(i);
 
205
        assert(property);
 
206
        assert(s);
 
207
 
 
208
        r = cg_join_spec(SYSTEMD_CGROUP_CONTROLLER, s->cgroup_path, &t);
 
209
        if (r < 0)
 
210
                return r;
 
211
 
 
212
        success = dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t);
 
213
        return success ? 0 : -ENOMEM;
 
214
}
 
215
 
199
216
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_session_append_type, session_type, SessionType);
200
217
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_session_append_class, session_class, SessionClass);
201
218
 
 
219
static int bus_session_append_state(DBusMessageIter *i, const char *property, void *data) {
 
220
        Session *s = data;
 
221
        const char *state;
 
222
 
 
223
        assert(i);
 
224
        assert(property);
 
225
        assert(s);
 
226
 
 
227
        state = session_state_to_string(session_get_state(s));
 
228
 
 
229
        if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &state))
 
230
                return -ENOMEM;
 
231
 
 
232
        return 0;
 
233
}
 
234
 
202
235
static int get_session_for_path(Manager *m, const char *path, Session **_s) {
203
236
        Session *s;
204
237
        char *id;
228
261
        { "Id",                     bus_property_append_string,         "s", offsetof(Session, id),                 true },
229
262
        { "Timestamp",              bus_property_append_usec,           "t", offsetof(Session, timestamp.realtime)  },
230
263
        { "TimestampMonotonic",     bus_property_append_usec,           "t", offsetof(Session, timestamp.monotonic) },
231
 
        { "ControlGroupPath",       bus_property_append_string,         "s", offsetof(Session, cgroup_path),        true },
 
264
        { "DefaultControlGroup",    bus_session_append_default_cgroup,  "s", 0,                                     },
232
265
        { "VTNr",                   bus_property_append_uint32,         "u", offsetof(Session, vtnr)                },
233
266
        { "Seat",                   bus_session_append_seat,         "(so)", 0 },
234
267
        { "TTY",                    bus_property_append_string,         "s", offsetof(Session, tty),                true },
242
275
        { "Type",                   bus_session_append_type,            "s", offsetof(Session, type)                },
243
276
        { "Class",                  bus_session_append_class,           "s", offsetof(Session, class)               },
244
277
        { "Active",                 bus_session_append_active,          "b", 0 },
 
278
        { "State",                  bus_session_append_state,           "s", 0 },
245
279
        { "Controllers",            bus_property_append_strv,          "as", offsetof(Session, controllers),        true },
246
280
        { "ResetControllers",       bus_property_append_strv,          "as", offsetof(Session, reset_controllers),  true },
247
281
        { "KillProcesses",          bus_property_append_bool,           "b", offsetof(Session, kill_processes)      },
263
297
                DBusMessage *message) {
264
298
 
265
299
        DBusError error;
266
 
        DBusMessage *reply = NULL;
 
300
        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
267
301
        int r;
268
302
 
269
303
        assert(s);
368
402
        }
369
403
 
370
404
        if (reply) {
371
 
                if (!dbus_connection_send(connection, reply, NULL))
 
405
                if (!bus_maybe_send_reply(connection, message, reply))
372
406
                        goto oom;
373
 
 
374
 
                dbus_message_unref(reply);
375
407
        }
376
408
 
377
409
        return DBUS_HANDLER_RESULT_HANDLED;
378
410
 
379
411
oom:
380
 
        if (reply)
381
 
                dbus_message_unref(reply);
382
 
 
383
412
        dbus_error_free(&error);
384
413
 
385
414
        return DBUS_HANDLER_RESULT_NEED_MEMORY;
419
448
};
420
449
 
421
450
char *session_bus_path(Session *s) {
422
 
        char *t, *r;
 
451
        _cleanup_free_ char *t;
423
452
 
424
453
        assert(s);
425
454
 
427
456
        if (!t)
428
457
                return NULL;
429
458
 
430
 
        r = strappend("/org/freedesktop/login1/session/", t);
431
 
        free(t);
432
 
 
433
 
        return r;
 
459
        return strappend("/org/freedesktop/login1/session/", t);
434
460
}
435
461
 
436
462
int session_send_signal(Session *s, bool new_session) {
437
 
        DBusMessage *m;
438
 
        int r = -ENOMEM;
439
 
        char *p = NULL;
 
463
        _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
 
464
        _cleanup_free_ char *p = NULL;
440
465
 
441
466
        assert(s);
442
467
 
449
474
 
450
475
        p = session_bus_path(s);
451
476
        if (!p)
452
 
                goto finish;
 
477
                return -ENOMEM;
453
478
 
454
479
        if (!dbus_message_append_args(
455
480
                            m,
456
481
                            DBUS_TYPE_STRING, &s->id,
457
482
                            DBUS_TYPE_OBJECT_PATH, &p,
458
483
                            DBUS_TYPE_INVALID))
459
 
                goto finish;
 
484
                return -ENOMEM;
460
485
 
461
486
        if (!dbus_connection_send(s->manager->bus, m, NULL))
462
 
                goto finish;
463
 
 
464
 
        r = 0;
465
 
 
466
 
finish:
467
 
        dbus_message_unref(m);
468
 
        free(p);
469
 
 
470
 
        return r;
 
487
                return -ENOMEM;
 
488
 
 
489
        return 0;
471
490
}
472
491
 
473
492
int session_send_changed(Session *s, const char *properties) {
474
 
        DBusMessage *m;
475
 
        int r = -ENOMEM;
476
 
        char *p = NULL;
 
493
        _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
 
494
        _cleanup_free_ char *p = NULL;
477
495
 
478
496
        assert(s);
479
497
 
486
504
 
487
505
        m = bus_properties_changed_new(p, "org.freedesktop.login1.Session", properties);
488
506
        if (!m)
489
 
                goto finish;
 
507
                return -ENOMEM;
490
508
 
491
509
        if (!dbus_connection_send(s->manager->bus, m, NULL))
492
 
                goto finish;
493
 
 
494
 
        r = 0;
495
 
 
496
 
finish:
497
 
        if (m)
498
 
                dbus_message_unref(m);
499
 
        free(p);
500
 
 
501
 
        return r;
 
510
                return -ENOMEM;
 
511
 
 
512
        return 0;
502
513
}
503
514
 
504
515
int session_send_lock(Session *s, bool lock) {
505
 
        DBusMessage *m;
 
516
        _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
506
517
        bool b;
507
 
        char *p;
 
518
        _cleanup_free_ char *p = NULL;
508
519
 
509
520
        assert(s);
510
521
 
513
524
                return -ENOMEM;
514
525
 
515
526
        m = dbus_message_new_signal(p, "org.freedesktop.login1.Session", lock ? "Lock" : "Unlock");
516
 
        free(p);
517
527
 
518
528
        if (!m)
519
529
                return -ENOMEM;
520
530
 
521
531
        b = dbus_connection_send(s->manager->bus, m, NULL);
522
 
        dbus_message_unref(m);
523
 
 
524
532
        if (!b)
525
533
                return -ENOMEM;
526
534
 
527
535
        return 0;
528
536
}
 
537
 
 
538
int session_send_lock_all(Manager *m, bool lock) {
 
539
        Session *session;
 
540
        Iterator i;
 
541
        int r = 0;
 
542
 
 
543
        assert(m);
 
544
 
 
545
        HASHMAP_FOREACH(session, m->sessions, i) {
 
546
                int k;
 
547
 
 
548
                k = session_send_lock(session, lock);
 
549
                if (k < 0)
 
550
                        r = k;
 
551
        }
 
552
 
 
553
        return r;
 
554
}