Ubuntu Pastebin

Paste from mborzecki at Thu, 16 Nov 2017 08:57:10 +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
34
35
36
37
38
39
40
#define _GNU_SOURCE

#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

static const char *freezer_cgroup_dir = "/sys/fs/cgroup/freezer";

int main(int argc, char *argv[]) {
        char buf[PATH_MAX] = { 0 };
        int ok = 0;

        snprintf(buf, sizeof(buf), "%s", argv[1]);
        int cgroup_fd  = -1;
        cgroup_fd = open(freezer_cgroup_dir,
                        O_PATH | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
        if (cgroup_fd < 0) {
                fprintf(stderr, "cannot open freezer cgroup (%s)", freezer_cgroup_dir);
        }
        // Create the freezer hierarchy for the given snap.
        if (mkdirat(cgroup_fd, buf, 0755) < 0 && errno != EEXIST) {
                perror("cannot create freezer cgroup hierarchy");
        } else {

                ok = 1;
        }

        if (ok) {
                printf("directory created: %s/%s", freezer_cgroup_dir, buf);
        }

        if (cgroup_fd != -1) {
                close(cgroup_fd);
        }
}
Download as text