mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-08 00:09:42 +00:00
confile: move signal helpers to confile utils
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
parent
63f9c9e607
commit
f6e32eb05b
@ -238,90 +238,6 @@ static struct lxc_config_t config[] = {
|
|||||||
{ "lxc.proc", set_config_proc, get_config_proc, clr_config_proc, },
|
{ "lxc.proc", set_config_proc, get_config_proc, clr_config_proc, },
|
||||||
};
|
};
|
||||||
|
|
||||||
struct signame {
|
|
||||||
int num;
|
|
||||||
const char *name;
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct signame signames[] = {
|
|
||||||
{ SIGHUP, "HUP" },
|
|
||||||
{ SIGINT, "INT" },
|
|
||||||
{ SIGQUIT, "QUIT" },
|
|
||||||
{ SIGILL, "ILL" },
|
|
||||||
{ SIGABRT, "ABRT" },
|
|
||||||
{ SIGFPE, "FPE" },
|
|
||||||
{ SIGKILL, "KILL" },
|
|
||||||
{ SIGSEGV, "SEGV" },
|
|
||||||
{ SIGPIPE, "PIPE" },
|
|
||||||
{ SIGALRM, "ALRM" },
|
|
||||||
{ SIGTERM, "TERM" },
|
|
||||||
{ SIGUSR1, "USR1" },
|
|
||||||
{ SIGUSR2, "USR2" },
|
|
||||||
{ SIGCHLD, "CHLD" },
|
|
||||||
{ SIGCONT, "CONT" },
|
|
||||||
{ SIGSTOP, "STOP" },
|
|
||||||
{ SIGTSTP, "TSTP" },
|
|
||||||
{ SIGTTIN, "TTIN" },
|
|
||||||
{ SIGTTOU, "TTOU" },
|
|
||||||
#ifdef SIGTRAP
|
|
||||||
{ SIGTRAP, "TRAP" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGIOT
|
|
||||||
{ SIGIOT, "IOT" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGEMT
|
|
||||||
{ SIGEMT, "EMT" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGBUS
|
|
||||||
{ SIGBUS, "BUS" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGSTKFLT
|
|
||||||
{ SIGSTKFLT, "STKFLT" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGCLD
|
|
||||||
{ SIGCLD, "CLD" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGURG
|
|
||||||
{ SIGURG, "URG" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGXCPU
|
|
||||||
{ SIGXCPU, "XCPU" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGXFSZ
|
|
||||||
{ SIGXFSZ, "XFSZ" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGVTALRM
|
|
||||||
{ SIGVTALRM, "VTALRM" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGPROF
|
|
||||||
{ SIGPROF, "PROF" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGWINCH
|
|
||||||
{ SIGWINCH, "WINCH" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGIO
|
|
||||||
{ SIGIO, "IO" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGPOLL
|
|
||||||
{ SIGPOLL, "POLL" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGINFO
|
|
||||||
{ SIGINFO, "INFO" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGLOST
|
|
||||||
{ SIGLOST, "LOST" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGPWR
|
|
||||||
{ SIGPWR, "PWR" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGUNUSED
|
|
||||||
{ SIGUNUSED, "UNUSED" },
|
|
||||||
#endif
|
|
||||||
#ifdef SIGSYS
|
|
||||||
{ SIGSYS, "SYS" },
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
static const size_t config_size = sizeof(config) / sizeof(struct lxc_config_t);
|
static const size_t config_size = sizeof(config) / sizeof(struct lxc_config_t);
|
||||||
|
|
||||||
struct lxc_config_t *lxc_get_config(const char *key)
|
struct lxc_config_t *lxc_get_config(const char *key)
|
||||||
@ -1260,55 +1176,6 @@ static int set_config_autodev(const char *key, const char *value,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sig_num(const char *sig)
|
|
||||||
{
|
|
||||||
unsigned int signum;
|
|
||||||
|
|
||||||
if (lxc_safe_uint(sig, &signum) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return signum;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int rt_sig_num(const char *signame)
|
|
||||||
{
|
|
||||||
int rtmax = 0, sig_n = 0;
|
|
||||||
|
|
||||||
if (strncasecmp(signame, "max-", 4) == 0) {
|
|
||||||
rtmax = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
signame += 4;
|
|
||||||
if (!isdigit(*signame))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
sig_n = sig_num(signame);
|
|
||||||
sig_n = rtmax ? SIGRTMAX - sig_n : SIGRTMIN + sig_n;
|
|
||||||
if (sig_n > SIGRTMAX || sig_n < SIGRTMIN)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return sig_n;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int sig_parse(const char *signame)
|
|
||||||
{
|
|
||||||
size_t n;
|
|
||||||
|
|
||||||
if (isdigit(*signame)) {
|
|
||||||
return sig_num(signame);
|
|
||||||
} else if (strncasecmp(signame, "sig", 3) == 0) {
|
|
||||||
signame += 3;
|
|
||||||
if (strncasecmp(signame, "rt", 2) == 0)
|
|
||||||
return rt_sig_num(signame + 2);
|
|
||||||
for (n = 0; n < sizeof(signames) / sizeof((signames)[0]); n++) {
|
|
||||||
if (strcasecmp(signames[n].name, signame) == 0)
|
|
||||||
return signames[n].num;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int set_config_signal_halt(const char *key, const char *value,
|
static int set_config_signal_halt(const char *key, const char *value,
|
||||||
struct lxc_conf *lxc_conf, void *data)
|
struct lxc_conf *lxc_conf, void *data)
|
||||||
{
|
{
|
||||||
|
@ -778,3 +778,136 @@ int lxc_inherit_namespace(const char *lxcname_or_pid, const char *lxcpath,
|
|||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct signame {
|
||||||
|
int num;
|
||||||
|
const char *name;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct signame signames[] = {
|
||||||
|
{ SIGHUP, "HUP" },
|
||||||
|
{ SIGINT, "INT" },
|
||||||
|
{ SIGQUIT, "QUIT" },
|
||||||
|
{ SIGILL, "ILL" },
|
||||||
|
{ SIGABRT, "ABRT" },
|
||||||
|
{ SIGFPE, "FPE" },
|
||||||
|
{ SIGKILL, "KILL" },
|
||||||
|
{ SIGSEGV, "SEGV" },
|
||||||
|
{ SIGPIPE, "PIPE" },
|
||||||
|
{ SIGALRM, "ALRM" },
|
||||||
|
{ SIGTERM, "TERM" },
|
||||||
|
{ SIGUSR1, "USR1" },
|
||||||
|
{ SIGUSR2, "USR2" },
|
||||||
|
{ SIGCHLD, "CHLD" },
|
||||||
|
{ SIGCONT, "CONT" },
|
||||||
|
{ SIGSTOP, "STOP" },
|
||||||
|
{ SIGTSTP, "TSTP" },
|
||||||
|
{ SIGTTIN, "TTIN" },
|
||||||
|
{ SIGTTOU, "TTOU" },
|
||||||
|
#ifdef SIGTRAP
|
||||||
|
{ SIGTRAP, "TRAP" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGIOT
|
||||||
|
{ SIGIOT, "IOT" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGEMT
|
||||||
|
{ SIGEMT, "EMT" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGBUS
|
||||||
|
{ SIGBUS, "BUS" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGSTKFLT
|
||||||
|
{ SIGSTKFLT, "STKFLT" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGCLD
|
||||||
|
{ SIGCLD, "CLD" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGURG
|
||||||
|
{ SIGURG, "URG" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGXCPU
|
||||||
|
{ SIGXCPU, "XCPU" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGXFSZ
|
||||||
|
{ SIGXFSZ, "XFSZ" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGVTALRM
|
||||||
|
{ SIGVTALRM, "VTALRM" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGPROF
|
||||||
|
{ SIGPROF, "PROF" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGWINCH
|
||||||
|
{ SIGWINCH, "WINCH" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGIO
|
||||||
|
{ SIGIO, "IO" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGPOLL
|
||||||
|
{ SIGPOLL, "POLL" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGINFO
|
||||||
|
{ SIGINFO, "INFO" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGLOST
|
||||||
|
{ SIGLOST, "LOST" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGPWR
|
||||||
|
{ SIGPWR, "PWR" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGUNUSED
|
||||||
|
{ SIGUNUSED, "UNUSED" },
|
||||||
|
#endif
|
||||||
|
#ifdef SIGSYS
|
||||||
|
{ SIGSYS, "SYS" },
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
static int sig_num(const char *sig)
|
||||||
|
{
|
||||||
|
unsigned int signum;
|
||||||
|
|
||||||
|
if (lxc_safe_uint(sig, &signum) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return signum;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int rt_sig_num(const char *signame)
|
||||||
|
{
|
||||||
|
int rtmax = 0, sig_n = 0;
|
||||||
|
|
||||||
|
if (strncasecmp(signame, "max-", 4) == 0) {
|
||||||
|
rtmax = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
signame += 4;
|
||||||
|
if (!isdigit(*signame))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
sig_n = sig_num(signame);
|
||||||
|
sig_n = rtmax ? SIGRTMAX - sig_n : SIGRTMIN + sig_n;
|
||||||
|
if (sig_n > SIGRTMAX || sig_n < SIGRTMIN)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return sig_n;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sig_parse(const char *signame)
|
||||||
|
{
|
||||||
|
size_t n;
|
||||||
|
|
||||||
|
if (isdigit(*signame)) {
|
||||||
|
return sig_num(signame);
|
||||||
|
} else if (strncasecmp(signame, "sig", 3) == 0) {
|
||||||
|
signame += 3;
|
||||||
|
if (strncasecmp(signame, "rt", 2) == 0)
|
||||||
|
return rt_sig_num(signame + 2);
|
||||||
|
for (n = 0; n < sizeof(signames) / sizeof((signames)[0]); n++) {
|
||||||
|
if (strcasecmp(signames[n].name, signame) == 0)
|
||||||
|
return signames[n].num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
@ -92,5 +92,6 @@ extern int lxc_get_conf_uint64(struct lxc_conf *c, char *retv, int inlen, uint64
|
|||||||
extern bool parse_limit_value(const char **value, rlim_t *res);
|
extern bool parse_limit_value(const char **value, rlim_t *res);
|
||||||
extern int lxc_inherit_namespace(const char *lxcname_or_pid,
|
extern int lxc_inherit_namespace(const char *lxcname_or_pid,
|
||||||
const char *lxcpath, const char *namespace);
|
const char *lxcpath, const char *namespace);
|
||||||
|
extern int sig_parse(const char *signame);
|
||||||
|
|
||||||
#endif /* __LXC_CONFILE_UTILS_H */
|
#endif /* __LXC_CONFILE_UTILS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user