#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 <signal.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;
pid_t self = getpid();
fprintf(stderr, "waiting for SIGCONT signal, pid: %u\n", self);
kill(self, SIGSTOP);
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\n", freezer_cgroup_dir, buf);
}
if (cgroup_fd != -1) {
close(cgroup_fd);
}
}