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
......@@ -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.
......@@ -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>.
......@@ -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);
......
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
......
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