Unverified Commit ee555b28 by Stéphane Graber Committed by GitHub

Merge pull request #3303 from brauner/2020-03-17/fixes

tools: fix -g and -u parameters for lxc-execute and lxc-attach and fix pidfd detection logic
parents a1d5a1d4 8ad4fa68
...@@ -689,7 +689,7 @@ static int lxc_cmd_stop_callback(int fd, struct lxc_cmd_req *req, ...@@ -689,7 +689,7 @@ static int lxc_cmd_stop_callback(int fd, struct lxc_cmd_req *req,
stopsignal = handler->conf->stopsignal; stopsignal = handler->conf->stopsignal;
memset(&rsp, 0, sizeof(rsp)); memset(&rsp, 0, sizeof(rsp));
if (handler-> pidfd >= 0) if (handler->pidfd >= 0)
rsp.ret = lxc_raw_pidfd_send_signal(handler->pidfd, stopsignal, NULL, 0); rsp.ret = lxc_raw_pidfd_send_signal(handler->pidfd, stopsignal, NULL, 0);
else else
rsp.ret = kill(handler->pid, stopsignal); rsp.ret = kill(handler->pid, stopsignal);
......
...@@ -123,13 +123,13 @@ pid_t lxc_raw_clone_cb(int (*fn)(void *), void *args, unsigned long flags, ...@@ -123,13 +123,13 @@ pid_t lxc_raw_clone_cb(int (*fn)(void *), void *args, unsigned long flags,
return pid; return pid;
} }
/* For all the architectures we care about it's the same syscall number. */
#ifndef __NR_pidfd_send_signal
#define __NR_pidfd_send_signal 424
#endif
int lxc_raw_pidfd_send_signal(int pidfd, int sig, siginfo_t *info, int lxc_raw_pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
unsigned int flags) unsigned int flags)
{ {
#ifdef __NR_pidfd_send_signal
return syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags); return syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
#else
errno = ENOSYS;
return -1;
#endif
} }
...@@ -132,6 +132,8 @@ Options :\n\ ...@@ -132,6 +132,8 @@ Options :\n\
.checker = NULL, .checker = NULL,
.log_priority = "ERROR", .log_priority = "ERROR",
.log_file = "none", .log_file = "none",
.uid = LXC_INVALID_UID,
.gid = LXC_INVALID_GID,
}; };
static int my_parser(struct lxc_arguments *args, int c, char *arg) static int my_parser(struct lxc_arguments *args, int c, char *arg)
...@@ -345,10 +347,10 @@ int main(int argc, char *argv[]) ...@@ -345,10 +347,10 @@ int main(int argc, char *argv[])
goto out; goto out;
} }
if (my_args.uid) if (my_args.uid != LXC_INVALID_UID)
attach_options.uid = my_args.uid; attach_options.uid = my_args.uid;
if (my_args.gid) if (my_args.gid != LXC_INVALID_GID)
attach_options.gid = my_args.gid; attach_options.gid = my_args.gid;
if (command.program) { if (command.program) {
......
...@@ -63,6 +63,8 @@ Options :\n\ ...@@ -63,6 +63,8 @@ Options :\n\
.log_priority = "ERROR", .log_priority = "ERROR",
.log_file = "none", .log_file = "none",
.daemonize = 0, .daemonize = 0,
.uid = LXC_INVALID_UID,
.gid = LXC_INVALID_GID,
}; };
static int my_parser(struct lxc_arguments *args, int c, char *arg) static int my_parser(struct lxc_arguments *args, int c, char *arg)
...@@ -190,7 +192,7 @@ int main(int argc, char *argv[]) ...@@ -190,7 +192,7 @@ int main(int argc, char *argv[])
if (!bret) if (!bret)
goto out; goto out;
if (my_args.uid) { if (my_args.uid != LXC_INVALID_UID) {
char buf[256]; char buf[256];
ret = snprintf(buf, 256, "%d", my_args.uid); ret = snprintf(buf, 256, "%d", my_args.uid);
...@@ -202,7 +204,7 @@ int main(int argc, char *argv[]) ...@@ -202,7 +204,7 @@ int main(int argc, char *argv[])
goto out; goto out;
} }
if (my_args.gid) { if (my_args.gid != LXC_INVALID_GID) {
char buf[256]; char buf[256];
ret = snprintf(buf, 256, "%d", my_args.gid); ret = snprintf(buf, 256, "%d", my_args.gid);
......
...@@ -1833,5 +1833,9 @@ bool lxc_can_use_pidfd(int pidfd) ...@@ -1833,5 +1833,9 @@ bool lxc_can_use_pidfd(int pidfd)
if (ret < 0) if (ret < 0)
return log_error_errno(false, errno, "Kernel does not support waiting on processes through pidfds"); return log_error_errno(false, errno, "Kernel does not support waiting on processes through pidfds");
ret = lxc_raw_pidfd_send_signal(pidfd, 0, NULL, 0);
if (ret)
return log_error_errno(false, errno, "Kernel does not support sending singals through pidfds");
return log_trace(true, "Kernel supports pidfds"); return log_trace(true, "Kernel supports pidfds");
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment