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

« back to all changes in this revision

Viewing changes to src/login/logind.c

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "dbus-loop.h"
38
38
#include "strv.h"
39
39
#include "conf-parser.h"
 
40
#include "mkdir.h"
40
41
 
41
42
Manager *manager_new(void) {
42
43
        Manager *m;
1040
1041
                return 1;
1041
1042
        }
1042
1043
 
1043
 
        p = strdup(cgroup);
1044
 
        if (!p)
1045
 
                return log_oom();
 
1044
        p = strdupa(cgroup);
1046
1045
 
1047
1046
        for (;;) {
1048
1047
                char *e;
1049
1048
 
1050
1049
                e = strrchr(p, '/');
1051
1050
                if (!e || e == p) {
1052
 
                        free(p);
1053
1051
                        *session = NULL;
1054
1052
                        return 0;
1055
1053
                }
1058
1056
 
1059
1057
                s = hashmap_get(m->session_cgroups, p);
1060
1058
                if (s) {
1061
 
                        free(p);
1062
1059
                        *session = s;
1063
1060
                        return 1;
1064
1061
                }
1079
1076
                return 1;
1080
1077
        }
1081
1078
 
1082
 
        p = strdup(cgroup);
 
1079
        p = strdupa(cgroup);
1083
1080
        if (!p)
1084
1081
                return log_oom();
1085
1082
 
1088
1085
 
1089
1086
                e = strrchr(p, '/');
1090
1087
                if (!e || e == p) {
1091
 
                        free(p);
1092
1088
                        *user = NULL;
1093
1089
                        return 0;
1094
1090
                }
1097
1093
 
1098
1094
                u = hashmap_get(m->user_cgroups, p);
1099
1095
                if (u) {
1100
 
                        free(p);
1101
1096
                        *user = u;
1102
1097
                        return 1;
1103
1098
                }
1105
1100
}
1106
1101
 
1107
1102
int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session) {
1108
 
        char *p;
 
1103
        _cleanup_free_ char *p = NULL;
1109
1104
        int r;
1110
1105
 
1111
1106
        assert(m);
1112
1107
        assert(pid >= 1);
1113
1108
        assert(session);
1114
1109
 
1115
 
        r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, pid, &p);
 
1110
        r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &p);
1116
1111
        if (r < 0)
1117
1112
                return r;
1118
1113
 
1119
 
        r = manager_get_session_by_cgroup(m, p, session);
1120
 
        free(p);
1121
 
 
1122
 
        return r;
 
1114
        return manager_get_session_by_cgroup(m, p, session);
1123
1115
}
1124
1116
 
1125
1117
void manager_cgroup_notify_empty(Manager *m, const char *cgroup) {
1173
1165
static int manager_connect_bus(Manager *m) {
1174
1166
        DBusError error;
1175
1167
        int r;
1176
 
        struct epoll_event ev;
 
1168
        struct epoll_event ev = {
 
1169
                .events = EPOLLIN,
 
1170
                .data.u32 = FD_BUS,
 
1171
        };
1177
1172
 
1178
1173
        assert(m);
1179
1174
        assert(!m->bus);
1229
1224
                goto fail;
1230
1225
        }
1231
1226
 
1232
 
        zero(ev);
1233
 
        ev.events = EPOLLIN;
1234
 
        ev.data.u32 = FD_BUS;
1235
 
 
1236
1227
        if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->bus_fd, &ev) < 0)
1237
1228
                goto fail;
1238
1229
 
1245
1236
}
1246
1237
 
1247
1238
static int manager_connect_console(Manager *m) {
1248
 
        struct epoll_event ev;
 
1239
        struct epoll_event ev = {
 
1240
                .events = 0,
 
1241
                .data.u32 = FD_CONSOLE,
 
1242
        };
1249
1243
 
1250
1244
        assert(m);
1251
1245
        assert(m->console_active_fd < 0);
1270
1264
                return -errno;
1271
1265
        }
1272
1266
 
1273
 
        zero(ev);
1274
 
        ev.events = 0;
1275
 
        ev.data.u32 = FD_CONSOLE;
1276
 
 
1277
1267
        if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->console_active_fd, &ev) < 0)
1278
1268
                return -errno;
1279
1269
 
1281
1271
}
1282
1272
 
1283
1273
static int manager_connect_udev(Manager *m) {
1284
 
        struct epoll_event ev;
1285
1274
        int r;
 
1275
        struct epoll_event ev = {
 
1276
                .events = EPOLLIN,
 
1277
                .data.u32 = FD_SEAT_UDEV,
 
1278
        };
1286
1279
 
1287
1280
        assert(m);
1288
1281
        assert(!m->udev_seat_monitor);
1303
1296
 
1304
1297
        m->udev_seat_fd = udev_monitor_get_fd(m->udev_seat_monitor);
1305
1298
 
1306
 
        zero(ev);
1307
 
        ev.events = EPOLLIN;
1308
 
        ev.data.u32 = FD_SEAT_UDEV;
1309
1299
        if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->udev_seat_fd, &ev) < 0)
1310
1300
                return -errno;
1311
1301
 
1446
1436
 
1447
1437
int manager_dispatch_idle_action(Manager *m) {
1448
1438
        struct dual_timestamp since;
1449
 
        struct itimerspec its;
 
1439
        struct itimerspec its = {};
1450
1440
        int r;
1451
1441
        usec_t n;
1452
1442
 
1458
1448
                goto finish;
1459
1449
        }
1460
1450
 
1461
 
        zero(its);
1462
1451
        n = now(CLOCK_MONOTONIC);
1463
1452
 
1464
1453
        r = manager_get_idle_hint(m, &since);
1481
1470
        }
1482
1471
 
1483
1472
        if (m->idle_action_fd < 0) {
1484
 
                struct epoll_event ev;
 
1473
                struct epoll_event ev = {
 
1474
                        .events = EPOLLIN,
 
1475
                        .data.u32 = FD_IDLE_ACTION,
 
1476
                };
1485
1477
 
1486
1478
                m->idle_action_fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC);
1487
1479
                if (m->idle_action_fd < 0) {
1490
1482
                        goto finish;
1491
1483
                }
1492
1484
 
1493
 
                zero(ev);
1494
 
                ev.events = EPOLLIN;
1495
 
                ev.data.u32 = FD_IDLE_ACTION;
1496
 
 
1497
1485
                if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->idle_action_fd, &ev) < 0) {
1498
1486
                        log_error("Failed to add idle action timer to epoll: %m");
1499
1487
                        r = -errno;
1701
1689
                return -errno;
1702
1690
        }
1703
1691
 
1704
 
        r = config_parse(fn, f, "Login\0", config_item_perf_lookup, (void*) logind_gperf_lookup, false, m);
 
1692
        r = config_parse(NULL, fn, f, "Login\0", config_item_perf_lookup, (void*) logind_gperf_lookup, false, m);
1705
1693
        if (r < 0)
1706
1694
                log_warning("Failed to parse configuration file: %s", strerror(-r));
1707
1695
 
1727
1715
                goto finish;
1728
1716
        }
1729
1717
 
 
1718
        /* Always create the directories people can create inotify
 
1719
         * watches in. Note that some applications might check for the
 
1720
         * existence of /run/systemd/seats/ to determine whether
 
1721
         * logind is available, so please always make sure this check
 
1722
         * stays in. */
 
1723
        mkdir_label("/run/systemd/seats", 0755);
 
1724
        mkdir_label("/run/systemd/users", 0755);
 
1725
        mkdir_label("/run/systemd/sessions", 0755);
 
1726
 
1730
1727
        m = manager_new();
1731
1728
        if (!m) {
1732
1729
                r = log_oom();