From 6376a40ebfe62a124d052a6478b6f2bf9ae5093e Mon Sep 17 00:00:00 2001 From: Petr Baudis <pasky@ucw.cz> Date: Thu, 12 Apr 2012 03:51:38 +0200 Subject: [PATCH] /etc/compctl-unlimited control file support Compctl client now works as simple server-less agent if /etc/compctl-unlimited exists; so-called 'kamenolom mode'. --- README.client | 8 ++++++++ compctl.1 | 4 ++++ compctl.c | 43 +++++++++++++++++++++++++++++++++++++------ debian/changelog | 7 +++++++ 4 files changed, 56 insertions(+), 6 deletions(-) diff --git a/README.client b/README.client index d60a4cb..f9236c3 100644 --- a/README.client +++ b/README.client @@ -45,3 +45,11 @@ Examples compctl --limitmem 4096 compctl --kill 27134 + + +Files +===== + +If /etc/compctl-unlimited exists, compctl acts as a simple serverless agent +that allows launching computations (with priority reduced as usual), but +not limiting their memory usage or killing them. diff --git a/compctl.1 b/compctl.1 index 53b9bca..ef83ec6 100644 --- a/compctl.1 +++ b/compctl.1 @@ -58,5 +58,9 @@ compctl --limitmem 4096 .br compctl --kill 27134 .br +.SH FILES +If \fB/etc/compctl-unlimited\fP exists, compctl acts as a simple +serverless agent that allows launching computations (with priority +reduced as usual), but not limiting their memory usage or killing them. .SH AUTHOR \fBcompctl\fP was written by Petr Baudis <pasky@ucw.cz>. diff --git a/compctl.c b/compctl.c index 785cd4d..6d65932 100644 --- a/compctl.c +++ b/compctl.c @@ -13,6 +13,9 @@ #include "common.h" +bool unlimited; + + char * daemon_chat(char *cmd) { @@ -99,12 +102,14 @@ help(FILE *f) int run(int argc, char *argv[]) { - char *line = daemon_chat("blessme"); - if (line[0] != '1') { - fprintf(stderr, "%s\n", *line ? line : "unexpected hangup"); - return EXIT_FAILURE; + if (!unlimited) { + char *line = daemon_chat("blessme"); + if (line[0] != '1') { + fprintf(stderr, "%s\n", *line ? line : "unexpected hangup"); + return EXIT_FAILURE; + } + free(line); } - free(line); setpgrp(); if (setpriority(PRIO_PROCESS, 0, COMPNICE) < 0) @@ -133,6 +138,11 @@ screen(int argc, char *argv[]) void kill_task(pid_t pid) { + if (unlimited) { + fputs("Killing computations not possible when computations are not limited..\n", stderr); + exit(EXIT_FAILURE); + } + char cmd[256]; snprintf(cmd, sizeof(cmd), "kill %d", pid); char *line = daemon_chat(cmd); if (line[0] != '1') { @@ -145,6 +155,11 @@ kill_task(pid_t pid) void kill_all(void) { + if (unlimited) { + fputs("Killing computations not possible when computations are not limited..\n", stderr); + exit(EXIT_FAILURE); + } + char *line = daemon_chat("killall"); if (line[0] != '1') { fprintf(stderr, "%s\n", *line ? line : "unexpected hangup"); @@ -157,6 +172,11 @@ kill_all(void) void limit_mem(size_t limit) { + if (unlimited) { + fputs("Computations are not limited.\n", stderr); + exit(EXIT_FAILURE); + } + char cmd[256]; snprintf(cmd, sizeof(cmd), "limitmem %zu", limit * 1048576); char *line = daemon_chat(cmd); @@ -175,6 +195,11 @@ limit_mem(size_t limit) void usage(void) { + if (unlimited) { + puts("unlimited"); + return; + } + size_t usage = cgroup_get_mem_usage(chier, cgroup); size_t limit = cgroup_get_mem_limit(chier, cgroup); printf("Memory usage:\t%zuM / %zuM\n", usage / 1048576, limit / 1048576); @@ -183,6 +208,11 @@ usage(void) void list(void) { + if (unlimited) { + fputs("List not available when computations are not limited.\n", stderr); + exit(EXIT_FAILURE); + } + pid_t *tasks; int tasks_n = cgroup_task_list(chier, cgroup, &tasks); if (tasks_n < 0) @@ -203,7 +233,8 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } - if (!cgroup_available(chier, cgroup)) { + unlimited = access("/etc/compctl-unlimited", F_OK) >= 0; + if (!unlimited && !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); diff --git a/debian/changelog b/debian/changelog index 7a39cc7..3bf5886 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +compctl (1.1-1) unstable; urgency=low + + * Compctl client now works as simple server-less agent + if /etc/compctl-unlimited exists. + + -- Petr Baudis <pasky@ucw.cz> Thu, 12 Apr 2012 03:46:58 +0200 + compctl (1.0-1) unstable; urgency=low * Few further bugfixes, first production-ready release -- GitLab