diff options
author | trasz <trasz@FreeBSD.org> | 2015-06-21 06:40:43 +0000 |
---|---|---|
committer | trasz <trasz@FreeBSD.org> | 2015-06-21 06:40:43 +0000 |
commit | d057adeb92394fc01f08d690c21335e6fd53dd0a (patch) | |
tree | 6d1fab54c4650466b2341dfb6880a9092edb3618 /usr.bin | |
parent | a79dffff33fdb928a9c2be5c4feb320c6e7ecfd6 (diff) | |
download | FreeBSD-src-d057adeb92394fc01f08d690c21335e6fd53dd0a.zip FreeBSD-src-d057adeb92394fc01f08d690c21335e6fd53dd0a.tar.gz |
MFC r282236:
Make rctl(8) more user-friendly when RACCT/RCTL is disabled for some reason.
Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/rctl/rctl.c | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/usr.bin/rctl/rctl.c b/usr.bin/rctl/rctl.c index 185788d..c48a686 100644 --- a/usr.bin/rctl/rctl.c +++ b/usr.bin/rctl/rctl.c @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/rctl.h> +#include <sys/sysctl.h> #include <assert.h> #include <ctype.h> #include <err.h> @@ -305,13 +306,37 @@ print_rules(char *rules, int hflag, int nflag) } static void +enosys(void) +{ + int error, racct_enable; + size_t racct_enable_len; + + racct_enable_len = sizeof(racct_enable); + error = sysctlbyname("kern.racct.enable", + &racct_enable, &racct_enable_len, NULL, 0); + + if (error != 0) { + if (errno == ENOENT) + errx(1, "RACCT/RCTL support not present in kernel; see rctl(8) for details."); + + err(1, "sysctlbyname"); + } + + if (racct_enable == 0) + errx(1, "RACCT/RCTL present, but disabled; enable using kern.racct.enable=1 tunable"); +} + +static void add_rule(char *rule) { int error; error = rctl_add_rule(rule, strlen(rule) + 1, NULL, 0); - if (error != 0) + if (error != 0) { + if (errno == ENOSYS) + enosys(); err(1, "rctl_add_rule"); + } free(rule); } @@ -330,8 +355,11 @@ show_limits(char *filter, int hflag, int nflag) error = rctl_get_limits(filter, strlen(filter) + 1, outbuf, outbuflen); - if (error && errno != ERANGE) + if (error && errno != ERANGE) { + if (errno == ENOSYS) + enosys(); err(1, "rctl_get_limits"); + } } while (error && errno == ERANGE); print_rules(outbuf, hflag, nflag); @@ -345,8 +373,11 @@ remove_rule(char *filter) int error; error = rctl_remove_rule(filter, strlen(filter) + 1, NULL, 0); - if (error != 0) + if (error != 0) { + if (errno == ENOSYS) + enosys(); err(1, "rctl_remove_rule"); + } free(filter); } @@ -399,8 +430,11 @@ show_usage(char *filter, int hflag) error = rctl_get_racct(filter, strlen(filter) + 1, outbuf, outbuflen); - if (error && errno != ERANGE) + if (error && errno != ERANGE) { + if (errno == ENOSYS) + enosys(); err(1, "rctl_get_racct"); + } } while (error && errno == ERANGE); while ((tmp = strsep(&outbuf, ",")) != NULL) { @@ -439,8 +473,11 @@ show_rules(char *filter, int hflag, int nflag) err(1, "realloc"); error = rctl_get_rules(filter, filterlen, outbuf, outbuflen); - if (error && errno != ERANGE) + if (error && errno != ERANGE) { + if (errno == ENOSYS) + enosys(); err(1, "rctl_get_rules"); + } } while (error && errno == ERANGE); print_rules(outbuf, hflag, nflag); |