diff --git a/src/Makefile.am b/src/Makefile.am index ac6f2d19..1c239f6a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,7 +48,7 @@ AUTH_SOURCES=auth/pam.c auth/pam.h auth/plain.c auth/plain.h auth/radius.c auth/ ACCT_SOURCES=acct/radius.c acct/radius.h acct/pam.c acct/pam.h ocserv_SOURCES = main.c main-auth.c worker-vpn.c worker-auth.c tlslib.c \ - cookies.c main-misc.c ip-lease.c ip-lease.h main-proc.c \ + cookies.c main-worker-cmd.c ip-lease.c ip-lease.h main-proc.c \ vpn.h cookies.h tlslib.h log.c tun.c tun.h config-kkdcp.c \ config.c worker-resume.c worker.h sec-mod-resume.c main.h \ worker-http-handlers.c html.c html.h worker-http.c \ diff --git a/src/main-auth.c b/src/main-auth.c index 78373017..c7ca0877 100644 --- a/src/main-auth.c +++ b/src/main-auth.c @@ -46,6 +46,59 @@ #include #include +/* Puts the provided PIN into the config's cgroup */ +void put_into_cgroup(main_server_st * s, const char *_cgroup, pid_t pid) +{ + char *name, *p, *savep; + char cgroup[128]; + char file[_POSIX_PATH_MAX]; + FILE *fd; + + if (_cgroup == NULL) + return; + +#ifdef __linux__ + /* format: cpu,memory:cgroup-name */ + strlcpy(cgroup, _cgroup, sizeof(cgroup)); + + name = strchr(cgroup, ':'); + if (name == NULL) { + mslog(s, NULL, LOG_ERR, "error parsing cgroup name: %s", + cgroup); + return; + } + name[0] = 0; + name++; + + p = strtok_r(cgroup, ",", &savep); + while (p != NULL) { + mslog(s, NULL, LOG_DEBUG, + "putting process %u to cgroup '%s:%s'", (unsigned)pid, p, + name); + + snprintf(file, sizeof(file), "/sys/fs/cgroup/%s/%s/tasks", p, + name); + + fd = fopen(file, "w"); + if (fd == NULL) { + mslog(s, NULL, LOG_ERR, "cannot open: %s", file); + return; + } + + if (fprintf(fd, "%u", (unsigned)pid) <= 0) { + mslog(s, NULL, LOG_ERR, "could not write to: %s", file); + } + fclose(fd); + p = strtok_r(NULL, ",", &savep); + } + + return; +#else + mslog(s, NULL, LOG_DEBUG, + "Ignoring cgroup option as it is not supported on this system"); +#endif +} + int send_cookie_auth_reply(main_server_st* s, struct proc_st* proc, AUTHREP r) { diff --git a/src/main-misc.c b/src/main-worker-cmd.c similarity index 90% rename from src/main-misc.c rename to src/main-worker-cmd.c index 17383dac..c90a2503 100644 --- a/src/main-misc.c +++ b/src/main-worker-cmd.c @@ -451,55 +451,3 @@ int handle_worker_commands(main_server_st * s, struct proc_st *proc) return ret; } -/* Puts the provided PIN into the config's cgroup */ -void put_into_cgroup(main_server_st * s, const char *_cgroup, pid_t pid) -{ - char *name, *p, *savep; - char cgroup[128]; - char file[_POSIX_PATH_MAX]; - FILE *fd; - - if (_cgroup == NULL) - return; - -#ifdef __linux__ - /* format: cpu,memory:cgroup-name */ - strlcpy(cgroup, _cgroup, sizeof(cgroup)); - - name = strchr(cgroup, ':'); - if (name == NULL) { - mslog(s, NULL, LOG_ERR, "error parsing cgroup name: %s", - cgroup); - return; - } - name[0] = 0; - name++; - - p = strtok_r(cgroup, ",", &savep); - while (p != NULL) { - mslog(s, NULL, LOG_DEBUG, - "putting process %u to cgroup '%s:%s'", (unsigned)pid, p, - name); - - snprintf(file, sizeof(file), "/sys/fs/cgroup/%s/%s/tasks", p, - name); - - fd = fopen(file, "w"); - if (fd == NULL) { - mslog(s, NULL, LOG_ERR, "cannot open: %s", file); - return; - } - - if (fprintf(fd, "%u", (unsigned)pid) <= 0) { - mslog(s, NULL, LOG_ERR, "could not write to: %s", file); - } - fclose(fd); - p = strtok_r(NULL, ",", &savep); - } - - return; -#else - mslog(s, NULL, LOG_DEBUG, - "Ignoring cgroup option as it is not supported on this system"); -#endif -}