util: implement rLimName() to use in cmdline/config
This commit is contained in:
parent
e7c7583aaa
commit
94b022fece
@ -342,11 +342,10 @@ uint64_t parseRLimit(int res, const char *optarg, unsigned long mul) {
|
|||||||
return cur.rlim_max;
|
return cur.rlim_max;
|
||||||
}
|
}
|
||||||
if (!util::isANumber(optarg)) {
|
if (!util::isANumber(optarg)) {
|
||||||
LOG_F("RLIMIT %d needs a numeric or 'max'/'hard'/'def'/'soft'/'inf' "
|
LOG_F(
|
||||||
"value "
|
"RLIMIT %s (%d) needs a numeric value or 'max'/'hard'/'def'/'soft'/'inf' value "
|
||||||
"('%s' "
|
"(%s provided)",
|
||||||
"provided)",
|
util::rLimName(res).c_str(), res, QC(optarg));
|
||||||
res, optarg);
|
|
||||||
}
|
}
|
||||||
errno = 0;
|
errno = 0;
|
||||||
uint64_t val = strtoull(optarg, NULL, 0);
|
uint64_t val = strtoull(optarg, NULL, 0);
|
||||||
|
@ -230,7 +230,7 @@ static void newProc(nsjconf_t* nsjconf, int netfd, int fd_in, int fd_out, int fd
|
|||||||
execv(nsjconf->exec_file.c_str(), (char* const*)argv.data());
|
execv(nsjconf->exec_file.c_str(), (char* const*)argv.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
PLOG_E("execve('%s') failed", nsjconf->exec_file.c_str());
|
PLOG_E("execve(%s) failed", QC(nsjconf->exec_file));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addProc(nsjconf_t* nsjconf, pid_t pid, int sock) {
|
static void addProc(nsjconf_t* nsjconf, pid_t pid, int sock) {
|
||||||
|
38
util.cc
38
util.cc
@ -313,6 +313,44 @@ const std::string sigName(int signo) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string rLimName(int res) {
|
||||||
|
std::string ret;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
const int res;
|
||||||
|
const char* const name;
|
||||||
|
} static const rLimNames[] = {
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_CPU),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_FSIZE),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_DATA),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_STACK),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_CORE),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_RSS),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_NOFILE),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_AS),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_NPROC),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_MEMLOCK),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_LOCKS),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_SIGPENDING),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_MSGQUEUE),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_NICE),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_RTPRIO),
|
||||||
|
NS_VALSTR_STRUCT(RLIMIT_RTTIME),
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const auto& i : rLimNames) {
|
||||||
|
if (res == i.res) {
|
||||||
|
ret.append(i.name);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.append("RLIMITUNKNOWN(");
|
||||||
|
ret.append(std::to_string(res));
|
||||||
|
ret.append(")");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string timeToStr(time_t t) {
|
const std::string timeToStr(time_t t) {
|
||||||
char timestr[128];
|
char timestr[128];
|
||||||
struct tm utctime;
|
struct tm utctime;
|
||||||
|
1
util.h
1
util.h
@ -65,6 +65,7 @@ const std::string StrQuote(const std::string& str);
|
|||||||
bool isANumber(const char* s);
|
bool isANumber(const char* s);
|
||||||
uint64_t rnd64(void);
|
uint64_t rnd64(void);
|
||||||
const std::string sigName(int signo);
|
const std::string sigName(int signo);
|
||||||
|
const std::string rLimName(int res);
|
||||||
const std::string timeToStr(time_t t);
|
const std::string timeToStr(time_t t);
|
||||||
std::vector<std::string> strSplit(const std::string str, char delim);
|
std::vector<std::string> strSplit(const std::string str, char delim);
|
||||||
long syscall(long sysno, uintptr_t a0 = 0, uintptr_t a1 = 0, uintptr_t a2 = 0, uintptr_t a3 = 0,
|
long syscall(long sysno, uintptr_t a0 = 0, uintptr_t a1 = 0, uintptr_t a2 = 0, uintptr_t a3 = 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user