nsenter: use %m instead of strerror(errno)

Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin 2015-01-06 09:17:48 +03:00 committed by Andrew Vagin
parent 0f8f0601ae
commit 85cd86999f
1 changed files with 17 additions and 23 deletions

View File

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