Commit e81fb060 authored by Petr Baudis's avatar Petr Baudis
Browse files

compctl: Fail more gracefully if ran on a non-compctld enabled machine

parent 10ee133c
......@@ -55,6 +55,14 @@ cgroup_create(const char *chier, const char *cgroup)
return 1;
}
bool
cgroup_available(const char *chier, const char *cgroup)
{
char cgroupdir[PATH_MAX];
snprintf(cgroupdir, sizeof(cgroupdir), "%s%s/%s", cgroupfs, chier, cgroup);
return (access(cgroupdir, F_OK) >= 0);
}
int
cgroup_add_task(const char *chier, const char *cgroup, pid_t pid)
......
......@@ -18,6 +18,8 @@ int cgroup_setup(const char *chier, const char *controllers);
/* Setup a given control group. Return 0 if cgroups already set up,
* 1 on success, -1 on failure. */
int cgroup_create(const char *chier, const char *cgroup);
/* Return true if cgroup control is set up, false otherwise. */
bool cgroup_available(const char *chier, const char *cgroup);
/* Add a task to a given cgroup. Return 1 on success, -1 on failure. */
int cgroup_add_task(const char *chier, const char *cgroup, pid_t pid);
......
......@@ -20,6 +20,7 @@ daemon_chat(char *cmd)
struct sockaddr_un sun = { .sun_family = AF_UNIX, .sun_path = SOCKFILE };
if (connect(s, (struct sockaddr *) &sun, sizeof(sun.sun_family) + strlen(sun.sun_path) + 1) < 0) {
perror(SOCKFILE);
fputs("Plese contact " ADMINCONTACT " about this error.\n", stderr);
exit(EXIT_FAILURE);
}
......@@ -202,6 +203,14 @@ main(int argc, char *argv[])
return EXIT_FAILURE;
}
if (!cgroup_available(chier, cgroup)) {
fputs("CGroup-based computation control is not available on this host.\n", stderr);
fputs("Most likely, this computer is not meant for computations,\n", stderr);
fputs("please consider switching to a different host.\n", stderr);
fputs("Plese contact " ADMINCONTACT " if you believe this is an error.\n", stderr);
return EXIT_FAILURE;
}
while (argc > optind) {
char *cmd = argv[optind++];
if (!strcmp(cmd, "--run")) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment