commit 06f7b693f359ac12862b79fa8293708710dc6399
parent 9b60f53243634295f3d7156672acfc8d54741c3e
Author: Friedel Schön <[email protected]>
Date: Sat, 20 May 2023 17:12:55 +0200
minimalize chpst
Diffstat:
M | src/exec/chpst.c | | | 129 | ++++--------------------------------------------------------------------------- |
1 file changed, 5 insertions(+), 124 deletions(-)
diff --git a/src/exec/chpst.c b/src/exec/chpst.c
@@ -1,18 +1,12 @@
#include "user_group.h"
#include "util.h"
-#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
-#include <getopt.h>
#include <stdbool.h>
-#include <stdint.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>
-#include <sys/resource.h>
-#include <unistd.h>
static long parse_long(const char* str) {
char* end;
@@ -24,19 +18,6 @@ static long parse_long(const char* str) {
return l;
}
-void limit(int what, long l) {
- struct rlimit r;
-
- if (getrlimit(what, &r) == -1)
- print_error("unable to getrlimit(): %s\n");
- if ((l < 0) || (l > (long int) r.rlim_max))
- r.rlim_cur = r.rlim_max;
- else
- r.rlim_cur = l;
- if (setrlimit(what, &r) == -1)
- print_error("unable to setrlimit(): %s\n");
-}
-
void slock(const char* path, bool d) {
int fd;
@@ -57,19 +38,9 @@ int main(int argc, char** argv) {
uid_t uid = 0;
gid_t gid[61];
int gid_len = 0;
- long nicelevel = 0,
- limitd = -2,
- limits = -2,
- limitl = -2,
- limita = -2,
- limito = -2,
- limitp = -2,
- limitf = -2,
- limitc = -2,
- limitr = -2,
- limitt = -2;
- bool lockdelay, ssid = false;
- bool closestd[3] = { false, false, false };
+ long nicelevel = 0;
+ bool lockdelay, ssid = false;
+ bool closestd[3] = { false, false, false };
while ((opt = getopt(argc, argv, "+u:U:b:e:m:d:o:p:f:c:r:t:/:C:n:l:L:vP012V")) != -1) {
switch (opt) {
@@ -84,28 +55,14 @@ int main(int argc, char** argv) {
fprintf(stderr, "`envdir` is ignored\n");
break;
case 'd':
- limitd = parse_long(optarg);
- break;
case 'o':
- limito = parse_long(optarg);
- break;
case 'p':
- limitp = parse_long(optarg);
- break;
case 'f':
- limitf = parse_long(optarg);
- break;
case 'c':
- limitc = parse_long(optarg);
- break;
case 'r':
- limitr = parse_long(optarg);
- break;
case 't':
- limitt = parse_long(optarg);
- break;
- case 'm':
- limits = limitl = limita = limitd = parse_long(optarg);
+ case 'm': // ignored
+ fprintf(stderr, "limits are ignored\n");
break;
case '/':
root = optarg;
@@ -176,82 +133,6 @@ int main(int argc, char** argv) {
if (closestd[2] && close(2) == -1)
print_error("unable to close stderr: %s\n");
- if (limitd >= -1) {
-#ifdef RLIMIT_DATA
- limit(RLIMIT_DATA, limitd);
-#else
- fprintf(stderr, "system does not support RLIMIT_DATA\n");
-#endif
- }
- if (limits >= -1) {
-#ifdef RLIMIT_STACK
- limit(RLIMIT_STACK, limits);
-#else
- fprintf(stderr, "system does not support RLIMIT_STACK\n");
-#endif
- }
- if (limitl >= -1) {
-#ifdef RLIMIT_MEMLOCK
- limit(RLIMIT_MEMLOCK, limitl);
-#else
- fprintf(stderr, "system does not support RLIMIT_MEMLOCK\n");
-#endif
- }
- if (limita >= -1) {
-#ifdef RLIMIT_VMEM
- limit(RLIMIT_VMEM, limita);
-#else
-# ifdef RLIMIT_AS
- limit(RLIMIT_AS, limita);
-# else
- fprintf(stderr, "system does neither support RLIMIT_VMEM nor RLIMIT_AS\n");
-# endif
-#endif
- }
- if (limito >= -1) {
-#if defined(RLIMIT_NOFILE)
- limit(RLIMIT_NOFILE, limito);
-#elif defined(RLIMIT_OFILE)
- limit(RLIMIT_OFILE, limito);
-#else
- fprintf(stderr, "system does neither support RLIMIT_NOFILE nor RLIMIT_OFILE\n");
-#endif
- }
- if (limitp >= -1) {
-#ifdef RLIMIT_NPROC
- limit(RLIMIT_NPROC, limitp);
-#else
- fprintf(stderr, "system does not support RLIMIT_NPROC\n");
-#endif
- }
- if (limitf >= -1) {
-#ifdef RLIMIT_FSIZE
- limit(RLIMIT_FSIZE, limitf);
-#else
- fprintf(stderr, "system does not support RLIMIT_FSIZE\n");
-#endif
- }
- if (limitc >= -1) {
-#ifdef RLIMIT_CORE
- limit(RLIMIT_CORE, limitc);
-#else
- fprintf(stderr, "system does not support RLIMIT_CORE\n");
-#endif
- }
- if (limitr >= -1) {
-#ifdef RLIMIT_RSS
- limit(RLIMIT_RSS, limitr);
-#else
- fprintf(stderr, "system does not support RLIMIT_RSS\n");
-#endif
- }
- if (limitt >= -1) {
-#ifdef RLIMIT_CPU
- limit(RLIMIT_CPU, limitt);
-#else
- fprintf(stderr, "system does not support RLIMIT_CPU\n");
-#endif
- }
const char* exec = argv[0];
if (arg0)
argv[0] = arg0;