From: Christian Brauner Date: Sat, 26 Aug 2017 16:53:29 +0000 (+0200) Subject: lxc-user-nic: non-functional changes X-Git-Tag: lxc-2.0.9~49^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b59c609a72c2c6fb75914e8be9adc3dbdb651866;p=thirdparty%2Flxc.git lxc-user-nic: non-functional changes Signed-off-by: Christian Brauner --- diff --git a/src/lxc/lxc_user_nic.c b/src/lxc/lxc_user_nic.c index 96af8363b..6478d7508 100644 --- a/src/lxc/lxc_user_nic.c +++ b/src/lxc/lxc_user_nic.c @@ -918,32 +918,29 @@ static bool may_access_netns(int pid) int main(int argc, char *argv[]) { - int n, fd; + int fd, n, pid, ret; char *me; - char *nicname; - int pid; - char *cnic = NULL; /* Created nic name in container is returned here. */ - char *vethname = NULL; + char nicname[100]; + char *cnic = NULL, *vethname = NULL; bool gotone = false; struct alloted_s *alloted = NULL; - nicname = alloca(40); - if (!nicname) { - usernic_error("Failed allocate memory: %s.\n", strerror(errno)); + /* Set a sane env, because we are setuid-root. */ + ret = clearenv(); + if (ret) { + usernic_error("%s", "Failed to clear environment\n"); exit(EXIT_FAILURE); } - /* set a sane env, because we are setuid-root */ - if (clearenv() < 0) { - usernic_error("%s", "Failed to clear environment.\n"); - exit(EXIT_FAILURE); - } - if (setenv("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", 1) < 0) { - usernic_error("%s", "Failed to set PATH, exiting.\n"); + ret = setenv("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", 1); + if (ret < 0) { + usernic_error("%s", "Failed to set PATH, exiting\n"); exit(EXIT_FAILURE); } - if ((me = get_username()) == NULL) { - usernic_error("%s", "Failed to get username.\n"); + + me = get_username(); + if (!me) { + usernic_error("%s", "Failed to get username\n"); exit(EXIT_FAILURE); } @@ -956,10 +953,9 @@ int main(int argc, char *argv[]) lxcpath = argv[1]; lxcname = argv[2]; - errno = 0; - pid = strtol(argv[3], NULL, 10); - if (errno) { - usernic_error("Could not read pid: %s.\n", argv[1]); + ret = lxc_safe_int(argv[3], &pid); + if (ret < 0) { + usernic_error("Could not read pid: %s\n", argv[1]); exit(EXIT_FAILURE); } @@ -968,8 +964,9 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - if ((fd = open_and_lock(LXC_USERNIC_DB)) < 0) { - usernic_error("Failed to lock %s.\n", LXC_USERNIC_DB); + fd = open_and_lock(LXC_USERNIC_DB); + if (fd < 0) { + usernic_error("Failed to lock %s\n", LXC_USERNIC_DB); exit(EXIT_FAILURE); } @@ -980,7 +977,7 @@ int main(int argc, char *argv[]) n = get_alloted(me, argv[4], argv[5], &alloted); if (n > 0) - gotone = get_nic_if_avail(fd, alloted, pid, argv[4], argv[5], n, &nicname, &cnic); + gotone = get_nic_if_avail(fd, alloted, pid, argv[4], argv[5], n, (char **)&nicname, &cnic); close(fd); free_alloted(&alloted); @@ -990,16 +987,16 @@ int main(int argc, char *argv[]) } /* Now rename the link. */ - if (rename_in_ns(pid, cnic, &vethname) < 0) { - usernic_error("%s", "Failed to rename the link.\n"); - if (lxc_netdev_delete_by_name(cnic) < 0) - usernic_error("Failed to delete link \"%s\" the link. Manual cleanup needed.\n", cnic); + ret = rename_in_ns(pid, cnic, &vethname); + if (ret < 0) { + usernic_error("%s", "Failed to rename the link\n"); + ret = lxc_netdev_delete_by_name(cnic); + if (ret < 0) + usernic_error("Failed to delete \"%s\"\n", cnic); exit(EXIT_FAILURE); } - /* Write the name of the interface pair to the stdout - like - * eth0:veth9MT2L4. - */ + /* Write the name of the interface pair to the stdout: eth0:veth9MT2L4 */ fprintf(stdout, "%s:%s\n", vethname, nicname); exit(EXIT_SUCCESS); }