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

« back to all changes in this revision

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

Tags: upstream-202
ImportĀ upstreamĀ versionĀ 202

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
        }
109
109
 
110
110
        if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &id) ||
111
 
            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path)) {
112
 
                free(p);
 
111
            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path))
113
112
                return -ENOMEM;
114
 
        }
115
 
 
116
 
        free(p);
117
113
 
118
114
        if (!dbus_message_iter_close_container(i, &sub))
119
115
                return -ENOMEM;
124
120
static int bus_session_append_user(DBusMessageIter *i, const char *property, void *data) {
125
121
        DBusMessageIter sub;
126
122
        User *u = data;
127
 
        char *p = NULL;
 
123
        _cleanup_free_ char *p = NULL;
128
124
 
129
125
        assert(i);
130
126
        assert(property);
138
134
                return -ENOMEM;
139
135
 
140
136
        if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_UINT32, &u->uid) ||
141
 
            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &p)) {
142
 
                free(p);
 
137
            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &p))
143
138
                return -ENOMEM;
144
 
        }
145
 
 
146
 
        free(p);
147
139
 
148
140
        if (!dbus_message_iter_close_container(i, &sub))
149
141
                return -ENOMEM;
205
197
 
206
198
static int bus_session_append_default_cgroup(DBusMessageIter *i, const char *property, void *data) {
207
199
        Session *s = data;
208
 
        char *t;
 
200
        _cleanup_free_ char *t = NULL;
209
201
        int r;
210
202
        bool success;
211
203
 
218
210
                return r;
219
211
 
220
212
        success = dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t);
221
 
        free(t);
222
 
 
223
213
        return success ? 0 : -ENOMEM;
224
214
}
225
215
 
307
297
                DBusMessage *message) {
308
298
 
309
299
        DBusError error;
310
 
        DBusMessage *reply = NULL;
 
300
        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
311
301
        int r;
312
302
 
313
303
        assert(s);
412
402
        }
413
403
 
414
404
        if (reply) {
415
 
                if (!dbus_connection_send(connection, reply, NULL))
 
405
                if (!bus_maybe_send_reply(connection, message, reply))
416
406
                        goto oom;
417
 
 
418
 
                dbus_message_unref(reply);
419
407
        }
420
408
 
421
409
        return DBUS_HANDLER_RESULT_HANDLED;
422
410
 
423
411
oom:
424
 
        if (reply)
425
 
                dbus_message_unref(reply);
426
 
 
427
412
        dbus_error_free(&error);
428
413
 
429
414
        return DBUS_HANDLER_RESULT_NEED_MEMORY;
463
448
};
464
449
 
465
450
char *session_bus_path(Session *s) {
466
 
        char *t, *r;
 
451
        _cleanup_free_ char *t;
467
452
 
468
453
        assert(s);
469
454
 
471
456
        if (!t)
472
457
                return NULL;
473
458
 
474
 
        r = strappend("/org/freedesktop/login1/session/", t);
475
 
        free(t);
476
 
 
477
 
        return r;
 
459
        return strappend("/org/freedesktop/login1/session/", t);
478
460
}
479
461
 
480
462
int session_send_signal(Session *s, bool new_session) {
481
 
        DBusMessage *m;
482
 
        int r = -ENOMEM;
483
 
        char *p = NULL;
 
463
        _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
 
464
        _cleanup_free_ char *p = NULL;
484
465
 
485
466
        assert(s);
486
467
 
493
474
 
494
475
        p = session_bus_path(s);
495
476
        if (!p)
496
 
                goto finish;
 
477
                return -ENOMEM;
497
478
 
498
479
        if (!dbus_message_append_args(
499
480
                            m,
500
481
                            DBUS_TYPE_STRING, &s->id,
501
482
                            DBUS_TYPE_OBJECT_PATH, &p,
502
483
                            DBUS_TYPE_INVALID))
503
 
                goto finish;
 
484
                return -ENOMEM;
504
485
 
505
486
        if (!dbus_connection_send(s->manager->bus, m, NULL))
506
 
                goto finish;
507
 
 
508
 
        r = 0;
509
 
 
510
 
finish:
511
 
        dbus_message_unref(m);
512
 
        free(p);
513
 
 
514
 
        return r;
 
487
                return -ENOMEM;
 
488
 
 
489
        return 0;
515
490
}
516
491
 
517
492
int session_send_changed(Session *s, const char *properties) {
518
 
        DBusMessage *m;
519
 
        int r = -ENOMEM;
520
 
        char *p = NULL;
 
493
        _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
 
494
        _cleanup_free_ char *p = NULL;
521
495
 
522
496
        assert(s);
523
497
 
530
504
 
531
505
        m = bus_properties_changed_new(p, "org.freedesktop.login1.Session", properties);
532
506
        if (!m)
533
 
                goto finish;
 
507
                return -ENOMEM;
534
508
 
535
509
        if (!dbus_connection_send(s->manager->bus, m, NULL))
536
 
                goto finish;
537
 
 
538
 
        r = 0;
539
 
 
540
 
finish:
541
 
        if (m)
542
 
                dbus_message_unref(m);
543
 
        free(p);
544
 
 
545
 
        return r;
 
510
                return -ENOMEM;
 
511
 
 
512
        return 0;
546
513
}
547
514
 
548
515
int session_send_lock(Session *s, bool lock) {
549
 
        DBusMessage *m;
 
516
        _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
550
517
        bool b;
551
 
        char *p;
 
518
        _cleanup_free_ char *p = NULL;
552
519
 
553
520
        assert(s);
554
521
 
557
524
                return -ENOMEM;
558
525
 
559
526
        m = dbus_message_new_signal(p, "org.freedesktop.login1.Session", lock ? "Lock" : "Unlock");
560
 
        free(p);
561
527
 
562
528
        if (!m)
563
529
                return -ENOMEM;
564
530
 
565
531
        b = dbus_connection_send(s->manager->bus, m, NULL);
566
 
        dbus_message_unref(m);
567
 
 
568
532
        if (!b)
569
533
                return -ENOMEM;
570
534