nsenter: use %m instead of strerror(errno)
Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
parent
0f8f0601ae
commit
85cd86999f
|
@ -101,8 +101,7 @@ void nsenter()
|
||||||
|
|
||||||
#ifdef PR_SET_CHILD_SUBREAPER
|
#ifdef PR_SET_CHILD_SUBREAPER
|
||||||
if (prctl(PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0) == -1) {
|
if (prctl(PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0) == -1) {
|
||||||
fprintf(stderr, "nsenter: failed to set child subreaper: %s",
|
fprintf(stderr, "nsenter: failed to set child subreaper: %m\n");
|
||||||
strerror(errno));
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -135,8 +134,8 @@ void nsenter()
|
||||||
init_pid = strtol(init_pid_str, NULL, 10);
|
init_pid = strtol(init_pid_str, NULL, 10);
|
||||||
if ((init_pid == 0 && errno == EINVAL) || errno == ERANGE) {
|
if ((init_pid == 0 && errno == EINVAL) || errno == ERANGE) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"nsenter: Failed to parse PID from \"%s\" with output \"%d\" and error: \"%s\"\n",
|
"nsenter: Failed to parse PID from \"%s\" with output \"%d\" and error: %m\n",
|
||||||
init_pid_str, init_pid, strerror(errno));
|
init_pid_str, init_pid);
|
||||||
print_usage();
|
print_usage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -145,7 +144,7 @@ void nsenter()
|
||||||
argv += 3;
|
argv += 3;
|
||||||
|
|
||||||
if (setsid() == -1) {
|
if (setsid() == -1) {
|
||||||
fprintf(stderr, "setsid failed. Error: %s\n", strerror(errno));
|
fprintf(stderr, "setsid failed. Error: %m\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
// before we setns we need to dup the console
|
// before we setns we need to dup the console
|
||||||
|
@ -154,8 +153,8 @@ void nsenter()
|
||||||
consolefd = open(console, O_RDWR);
|
consolefd = open(console, O_RDWR);
|
||||||
if (consolefd < 0) {
|
if (consolefd < 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"nsenter: failed to open console %s %s\n",
|
"nsenter: failed to open console %s: %m\n",
|
||||||
console, strerror(errno));
|
console);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,8 +166,7 @@ void nsenter()
|
||||||
int ns_dir_fd;
|
int ns_dir_fd;
|
||||||
ns_dir_fd = open(ns_dir, O_RDONLY | O_DIRECTORY);
|
ns_dir_fd = open(ns_dir, O_RDONLY | O_DIRECTORY);
|
||||||
if (ns_dir_fd < 0) {
|
if (ns_dir_fd < 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr, "Unable to open %s: %m\n", ns_dir);
|
||||||
"Unable to open %s: %m\n", ns_dir);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,23 +180,23 @@ void nsenter()
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
continue;
|
continue;
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"nsenter: Failed to stat ns file \"%s\" for ns \"%s\" with error: \"%s\"\n",
|
"nsenter: Failed to stat ns file \"%s\" for ns \"%s\" with error: %m\n",
|
||||||
ns_dir, namespaces[i], strerror(errno));
|
ns_dir, namespaces[i]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = openat(ns_dir_fd, namespaces[i], O_RDONLY);
|
int fd = openat(ns_dir_fd, namespaces[i], O_RDONLY);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"nsenter: Failed to open ns file \"%s\" for ns \"%s\" with error: \"%s\"\n",
|
"nsenter: Failed to open ns file \"%s\" for ns \"%s\" with error: %m\n",
|
||||||
ns_dir, namespaces[i], strerror(errno));
|
ns_dir, namespaces[i]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
// Set the namespace.
|
// Set the namespace.
|
||||||
if (setns(fd, 0) == -1) {
|
if (setns(fd, 0) == -1) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"nsenter: Failed to setns for \"%s\" with error: \"%s\"\n",
|
"nsenter: Failed to setns for \"%s\" with error: %m\n",
|
||||||
namespaces[i], strerror(errno));
|
namespaces[i]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -214,18 +212,15 @@ void nsenter()
|
||||||
if (child == 0) {
|
if (child == 0) {
|
||||||
if (consolefd != -1) {
|
if (consolefd != -1) {
|
||||||
if (dup2(consolefd, STDIN_FILENO) != 0) {
|
if (dup2(consolefd, STDIN_FILENO) != 0) {
|
||||||
fprintf(stderr, "nsenter: failed to dup 0 %s\n",
|
fprintf(stderr, "nsenter: failed to dup 0: %m\n");
|
||||||
strerror(errno));
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (dup2(consolefd, STDOUT_FILENO) != STDOUT_FILENO) {
|
if (dup2(consolefd, STDOUT_FILENO) != STDOUT_FILENO) {
|
||||||
fprintf(stderr, "nsenter: failed to dup 1 %s\n",
|
fprintf(stderr, "nsenter: failed to dup 1: %m\n");
|
||||||
strerror(errno));
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (dup2(consolefd, STDERR_FILENO) != STDERR_FILENO) {
|
if (dup2(consolefd, STDERR_FILENO) != STDERR_FILENO) {
|
||||||
fprintf(stderr, "nsenter: failed to dup 2 %s\n",
|
fprintf(stderr, "nsenter: failed to dup 2: %m\n");
|
||||||
strerror(errno));
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,8 +231,7 @@ void nsenter()
|
||||||
int status = 0;
|
int status = 0;
|
||||||
if (waitpid(child, &status, 0) == -1) {
|
if (waitpid(child, &status, 0) == -1) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"nsenter: Failed to waitpid with error: \"%s\"\n",
|
"nsenter: Failed to waitpid with error: %m\n");
|
||||||
strerror(errno));
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
// Forward the child's exit code or re-send its death signal.
|
// Forward the child's exit code or re-send its death signal.
|
||||||
|
|
Loading…
Reference in New Issue