1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-09-11 13:30:43 +03:00

Rewrite strerror to ssh_strerror

Signed-off-by: Norbert Pocs <npocs@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Norbert Pocs
2022-07-04 10:07:55 +02:00
committed by Jakub Jelen
parent 9837471c2e
commit b44b749f28

View File

@@ -319,6 +319,7 @@ ssh_exec_shell(char *cmd)
char *shell = NULL;
pid_t pid;
int status, devnull, rc;
char err_msg[SSH_ERRNO_MSG_MAX] = {0};
shell = getenv("SHELL");
if (shell == NULL || shell[0] == '\0') {
@@ -334,7 +335,8 @@ ssh_exec_shell(char *cmd)
/* Need this to redirect subprocess stdin/out */
devnull = open("/dev/null", O_RDWR);
if (devnull == -1) {
SSH_LOG(SSH_LOG_WARN, "Failed to open(/dev/null): %s", strerror(errno));
SSH_LOG(SSH_LOG_WARN, "Failed to open(/dev/null): %s",
ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
return -1;
}
@@ -346,12 +348,14 @@ ssh_exec_shell(char *cmd)
/* Redirect child stdin and stdout. Leave stderr */
rc = dup2(devnull, STDIN_FILENO);
if (rc == -1) {
SSH_LOG(SSH_LOG_WARN, "dup2: %s", strerror(errno));
SSH_LOG(SSH_LOG_WARN, "dup2: %s",
ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
exit(1);
}
rc = dup2(devnull, STDOUT_FILENO);
if (rc == -1) {
SSH_LOG(SSH_LOG_WARN, "dup2: %s", strerror(errno));
SSH_LOG(SSH_LOG_WARN, "dup2: %s",
ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
exit(1);
}
if (devnull > STDERR_FILENO) {
@@ -366,7 +370,7 @@ ssh_exec_shell(char *cmd)
rc = execv(argv[0], argv);
if (rc == -1) {
SSH_LOG(SSH_LOG_WARN, "Failed to execute command '%s': %s", cmd,
strerror(errno));
ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
/* Die with signal to make this error apparent to parent. */
signal(SIGTERM, SIG_DFL);
kill(getpid(), SIGTERM);
@@ -377,14 +381,16 @@ ssh_exec_shell(char *cmd)
/* Parent */
close(devnull);
if (pid == -1) { /* Error */
SSH_LOG(SSH_LOG_WARN, "Failed to fork child: %s", strerror(errno));
SSH_LOG(SSH_LOG_WARN, "Failed to fork child: %s",
ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
return -1;
}
while (waitpid(pid, &status, 0) == -1) {
if (errno != EINTR) {
SSH_LOG(SSH_LOG_WARN, "waitpid failed: %s", strerror(errno));
SSH_LOG(SSH_LOG_WARN, "waitpid failed: %s",
ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
return -1;
}
}