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:
Andreas Schneider
2022-08-29 13:32:09 +02:00
committed by Jakub Jelen
parent 90128929e7
commit 5a884b8c5a

View File

@@ -891,6 +891,7 @@ ssh_execute_command(const char *command, socket_t in, socket_t out)
const char *shell = NULL;
const char *args[] = {NULL/*shell*/, "-c", command, NULL};
int devnull;
int rc;
/* Prepare /dev/null socket for the stderr redirection */
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);
close(in);
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);
}