Ubuntu Pastebin

Paste from ahasenack at Tue, 15 Aug 2017 18:16:59 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifdef ENABLE_SYSTEMD
    int is_systemd_running;
    struct stat a, b;

    /* We simply test whether the systemd cgroup hierarchy is
     * mounted */
    is_systemd_running = (lstat("/sys/fs/cgroup", &a) == 0)
        && (lstat("/sys/fs/cgroup/systemd", &b) == 0)
        && (a.st_dev != b.st_dev);

    if (is_systemd_running) {
        char *cmd, *ret;
        FILE *ask_pass_fp = NULL;

        cmd = ret = NULL;
        if (asprintf(&cmd, "systemd-ask-password \"%s\"", prompt) >= 0) {
            ask_pass_fp = popen (cmd, "re");
            free (cmd);
        }

        if (ask_pass_fp) {
            ret = fgets(input, capacity, ask_pass_fp);
            pclose(ask_pass_fp);
        }

        if (ret) {
            int len = strlen(input);
            if (input[len - 1] == '\n')
                input[len - 1] = '\0';
            return input;
        }
    }
#endif
Download as text