From: Christian Brauner Date: Wed, 9 Dec 2020 09:06:22 +0000 (+0100) Subject: confile_utils: cleanup lxc_container_name_to_pid() X-Git-Tag: lxc-5.0.0~330^2~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd47e5f1da0a7e744157b4323332371c1a3fd41f;p=thirdparty%2Flxc.git confile_utils: cleanup lxc_container_name_to_pid() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c index d98b5cd9c..01ccd0c34 100644 --- a/src/lxc/confile_utils.c +++ b/src/lxc/confile_utils.c @@ -15,6 +15,7 @@ #include "confile_utils.h" #include "error.h" #include "list.h" +#include "lxc.h" #include "log.h" #include "lxccontainer.h" #include "macro.h" @@ -867,37 +868,24 @@ static int lxc_container_name_to_pid(const char *lxcname_or_pid, pid = strtol(lxcname_or_pid, &err, 10); if (*err != '\0' || pid < 1) { - struct lxc_container *c; + __put_lxc_container struct lxc_container *c = NULL; c = lxc_container_new(lxcname_or_pid, lxcpath); - if (!c) { - ERROR("\"%s\" is not a valid pid nor a container name", - lxcname_or_pid); - return -1; - } + if (!c) + return log_error_errno(-EINVAL, EINVAL, "\"%s\" is not a valid pid nor a container name", lxcname_or_pid); - if (!c->may_control(c)) { - ERROR("Insufficient privileges to control container " - "\"%s\"", c->name); - lxc_container_put(c); - return -1; - } + if (!c->may_control(c)) + return log_error_errno(-EPERM, EPERM, "Insufficient privileges to control container \"%s\"", c->name); pid = c->init_pid(c); - if (pid < 1) { - ERROR("Container \"%s\" is not running", c->name); - lxc_container_put(c); - return -1; - } + if (pid < 1) + return log_error_errno(-EINVAL, EINVAL, "Container \"%s\" is not running", c->name); - lxc_container_put(c); } ret = kill(pid, 0); - if (ret < 0) { - SYSERROR("Failed to send signal to pid %d", (int)pid); - return -1; - } + if (ret < 0) + return log_error_errno(-errno, errno, "Failed to send signal to pid %d", (int)pid); return pid; }