mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 18:50:28 +09:00
socket: Add error message if execv fails
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
(cherry picked from commit 2546b62242)
This commit is contained in:
committed by
Jakub Jelen
parent
90128929e7
commit
5a884b8c5a
@@ -891,6 +891,7 @@ ssh_execute_command(const char *command, socket_t in, socket_t out)
|
|||||||
const char *shell = NULL;
|
const char *shell = NULL;
|
||||||
const char *args[] = {NULL/*shell*/, "-c", command, NULL};
|
const char *args[] = {NULL/*shell*/, "-c", command, NULL};
|
||||||
int devnull;
|
int devnull;
|
||||||
|
int rc;
|
||||||
|
|
||||||
/* Prepare /dev/null socket for the stderr redirection */
|
/* Prepare /dev/null socket for the stderr redirection */
|
||||||
devnull = open("/dev/null", O_WRONLY);
|
devnull = open("/dev/null", O_WRONLY);
|
||||||
@@ -915,7 +916,13 @@ ssh_execute_command(const char *command, socket_t in, socket_t out)
|
|||||||
dup2(devnull, STDERR_FILENO);
|
dup2(devnull, STDERR_FILENO);
|
||||||
close(in);
|
close(in);
|
||||||
close(out);
|
close(out);
|
||||||
execv(args[0], (char * const *)args);
|
rc = execv(args[0], (char * const *)args);
|
||||||
|
if (rc < 0) {
|
||||||
|
char err_msg[SSH_ERRNO_MSG_MAX] = {0};
|
||||||
|
|
||||||
|
SSH_LOG(SSH_LOG_WARN, "Failed to execute command %s: %s",
|
||||||
|
command, ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
|
||||||
|
}
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user