Skip to content
Snippets Groups Projects
Commit 6376a40e authored by Petr Baudis's avatar Petr Baudis
Browse files

/etc/compctl-unlimited control file support

Compctl client now works as simple server-less agent if
/etc/compctl-unlimited exists; so-called 'kamenolom mode'.
parent 7c222758
No related branches found
No related tags found
No related merge requests found
...@@ -45,3 +45,11 @@ Examples ...@@ -45,3 +45,11 @@ Examples
compctl --limitmem 4096 compctl --limitmem 4096
compctl --kill 27134 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.
...@@ -58,5 +58,9 @@ compctl --limitmem 4096 ...@@ -58,5 +58,9 @@ compctl --limitmem 4096
.br .br
compctl --kill 27134 compctl --kill 27134
.br .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 .SH AUTHOR
\fBcompctl\fP was written by Petr Baudis <pasky@ucw.cz>. \fBcompctl\fP was written by Petr Baudis <pasky@ucw.cz>.
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
#include "common.h" #include "common.h"
bool unlimited;
char * char *
daemon_chat(char *cmd) daemon_chat(char *cmd)
{ {
...@@ -99,12 +102,14 @@ help(FILE *f) ...@@ -99,12 +102,14 @@ help(FILE *f)
int int
run(int argc, char *argv[]) run(int argc, char *argv[])
{ {
if (!unlimited) {
char *line = daemon_chat("blessme"); char *line = daemon_chat("blessme");
if (line[0] != '1') { if (line[0] != '1') {
fprintf(stderr, "%s\n", *line ? line : "unexpected hangup"); fprintf(stderr, "%s\n", *line ? line : "unexpected hangup");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
free(line); free(line);
}
setpgrp(); setpgrp();
if (setpriority(PRIO_PROCESS, 0, COMPNICE) < 0) if (setpriority(PRIO_PROCESS, 0, COMPNICE) < 0)
...@@ -133,6 +138,11 @@ screen(int argc, char *argv[]) ...@@ -133,6 +138,11 @@ screen(int argc, char *argv[])
void void
kill_task(pid_t pid) 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 cmd[256]; snprintf(cmd, sizeof(cmd), "kill %d", pid);
char *line = daemon_chat(cmd); char *line = daemon_chat(cmd);
if (line[0] != '1') { if (line[0] != '1') {
...@@ -145,6 +155,11 @@ kill_task(pid_t pid) ...@@ -145,6 +155,11 @@ kill_task(pid_t pid)
void void
kill_all(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"); char *line = daemon_chat("killall");
if (line[0] != '1') { if (line[0] != '1') {
fprintf(stderr, "%s\n", *line ? line : "unexpected hangup"); fprintf(stderr, "%s\n", *line ? line : "unexpected hangup");
...@@ -157,6 +172,11 @@ kill_all(void) ...@@ -157,6 +172,11 @@ kill_all(void)
void void
limit_mem(size_t limit) limit_mem(size_t limit)
{ {
if (unlimited) {
fputs("Computations are not limited.\n", stderr);
exit(EXIT_FAILURE);
}
char cmd[256]; char cmd[256];
snprintf(cmd, sizeof(cmd), "limitmem %zu", limit * 1048576); snprintf(cmd, sizeof(cmd), "limitmem %zu", limit * 1048576);
char *line = daemon_chat(cmd); char *line = daemon_chat(cmd);
...@@ -175,6 +195,11 @@ limit_mem(size_t limit) ...@@ -175,6 +195,11 @@ limit_mem(size_t limit)
void void
usage(void) usage(void)
{ {
if (unlimited) {
puts("unlimited");
return;
}
size_t usage = cgroup_get_mem_usage(chier, cgroup); size_t usage = cgroup_get_mem_usage(chier, cgroup);
size_t limit = cgroup_get_mem_limit(chier, cgroup); size_t limit = cgroup_get_mem_limit(chier, cgroup);
printf("Memory usage:\t%zuM / %zuM\n", usage / 1048576, limit / 1048576); printf("Memory usage:\t%zuM / %zuM\n", usage / 1048576, limit / 1048576);
...@@ -183,6 +208,11 @@ usage(void) ...@@ -183,6 +208,11 @@ usage(void)
void void
list(void) list(void)
{ {
if (unlimited) {
fputs("List not available when computations are not limited.\n", stderr);
exit(EXIT_FAILURE);
}
pid_t *tasks; pid_t *tasks;
int tasks_n = cgroup_task_list(chier, cgroup, &tasks); int tasks_n = cgroup_task_list(chier, cgroup, &tasks);
if (tasks_n < 0) if (tasks_n < 0)
...@@ -203,7 +233,8 @@ main(int argc, char *argv[]) ...@@ -203,7 +233,8 @@ main(int argc, char *argv[])
return EXIT_FAILURE; 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("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("Most likely, this computer is not meant for computations,\n", stderr);
fputs("please consider switching to a different host.\n", stderr); fputs("please consider switching to a different host.\n", stderr);
......
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 compctl (1.0-1) unstable; urgency=low
* Few further bugfixes, first production-ready release * Few further bugfixes, first production-ready release
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment