diff --git a/src/Transport.cpp b/src/Transport.cpp index 8b3afc655..37f5efd56 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -30,6 +30,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -87,7 +91,17 @@ int Transport::execute() it->append("\""); } } - return ::execute(_executable, _arguments); + int result = ::execute (_executable, _arguments); + int err; + switch (result) { + case 127: + throw format (STRING_TRANSPORT_NORUN, _executable); + case -1: + err = errno; + throw format (STRING_TRANSPORT_NOFORK, _executable, ::strerror(err)); + default: + return result; + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/TransportCurl.cpp b/src/TransportCurl.cpp index 1c1a52459..b436a3b18 100644 --- a/src/TransportCurl.cpp +++ b/src/TransportCurl.cpp @@ -80,14 +80,8 @@ void TransportCurl::send(const std::string& source) _arguments.push_back (_uri._protocol + "://" + _uri._host + "/" + _uri._path); } - int result = execute(); - if (result) - { - if (result == 127) // command not found - throw std::string (STRING_TRANSPORT_CURL_NORUN); - else - throw std::string (STRING_TRANSPORT_CURL_FAIL); - } + if (execute ()) + throw std::string (STRING_TRANSPORT_CURL_FAIL); } //////////////////////////////////////////////////////////////////////////////// @@ -148,14 +142,8 @@ void TransportCurl::recv(std::string target) _arguments.insert (_arguments.end (), targetargs.begin (), targetargs.end ()); - int result = execute(); - if (result) - { - if (result == 127) // command not found - throw std::string (STRING_TRANSPORT_CURL_NORUN); - else - throw std::string (STRING_TRANSPORT_CURL_FAIL); - } + if (execute ()) + throw std::string (STRING_TRANSPORT_CURL_FAIL); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/TransportRSYNC.cpp b/src/TransportRSYNC.cpp index f3d2e276e..70908bcd2 100644 --- a/src/TransportRSYNC.cpp +++ b/src/TransportRSYNC.cpp @@ -65,8 +65,8 @@ void TransportRSYNC::send(const std::string& source) _arguments.push_back (_uri._host + "::" + _uri._path); } - if (execute()) - throw std::string (STRING_TRANSPORT_RSYNC_NORUN); + if (execute ()) + throw std::string (STRING_TRANSPORT_RSYNC_FAIL); } //////////////////////////////////////////////////////////////////////////////// @@ -95,8 +95,8 @@ void TransportRSYNC::recv(std::string target) _arguments.push_back (target); - if (execute()) - throw std::string (STRING_TRANSPORT_RSYNC_NORUN); + if (execute ()) + throw std::string (STRING_TRANSPORT_RSYNC_FAIL); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/TransportSSH.cpp b/src/TransportSSH.cpp index 889c7a671..c42cbaa39 100644 --- a/src/TransportSSH.cpp +++ b/src/TransportSSH.cpp @@ -67,8 +67,8 @@ void TransportSSH::send(const std::string& source) _arguments.push_back (_uri._host + ":" + escape (_uri._path, ' ')); } - if (execute()) - throw std::string (STRING_TRANSPORT_SSH_NORUN); + if (execute ()) + throw std::string (STRING_TRANSPORT_SSH_FAIL); } //////////////////////////////////////////////////////////////////////////////// @@ -100,8 +100,8 @@ void TransportSSH::recv(std::string target) _arguments.push_back (target); - if (execute()) - throw std::string (STRING_TRANSPORT_SSH_NORUN); + if (execute ()) + throw std::string (STRING_TRANSPORT_SSH_FAIL); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/en-US.h b/src/en-US.h index 793555864..9eccb4954 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -837,15 +837,16 @@ #define STRING_TEXT_AMBIGUOUS "Ambiguous {1} '{2}' - could be either of " // Transport +#define STRING_TRANSPORT_NORUN "Could not run '{1}'. Is it installed, and available in $PATH?" +#define STRING_TRANSPORT_NOFORK "Could not run '{1}': {2}. Are you out of system resources?" #define STRING_TRANSPORT_URI_NODIR "The uri '{1}' does not appear to be a directory." #define STRING_TRANSPORT_CURL_URI "When using the 'curl' protocol, the uri must contain a hostname." #define STRING_TRANSPORT_CURL_WILDCD "When using the 'curl' protocol, wildcards are not supported." -#define STRING_TRANSPORT_CURL_NORUN "Could not run curl. Is it installed, and available in $PATH?" #define STRING_TRANSPORT_CURL_FAIL "Curl failed, see output above." #define STRING_TRANSPORT_RSYNC_URI "When using the 'rsync' protocol, the uri must contain a hostname." -#define STRING_TRANSPORT_RSYNC_NORUN "Could not run rsync. Is it installed, and available in $PATH?" +#define STRING_TRANSPORT_RSYNC_FAIL "rsync failed, see output above." #define STRING_TRANSPORT_SSH_URI "When using the 'ssh' protocol, the uri must contain a hostname." -#define STRING_TRANSPORT_SSH_NORUN "Could not run ssh. Is it installed, and available in $PATH?" +#define STRING_TRANSPORT_SSH_FAIL "ssh failed, see output above." // Uri #define STRING_URI_QUOTES "Could not parse uri '{1}', wrong usage of single quotes." diff --git a/src/es-ES.h b/src/es-ES.h index 37f61e67e..89ad6db74 100644 --- a/src/es-ES.h +++ b/src/es-ES.h @@ -853,15 +853,16 @@ #define STRING_TEXT_AMBIGUOUS "Ambiguo {1} '{2}' - puede ser " // Transport +#define STRING_TRANSPORT_NORUN "Could not run '{1}'. Is it installed, and available in $PATH?" +#define STRING_TRANSPORT_NOFORK "Could not run '{1}': {2}. Are you out of system resources?" #define STRING_TRANSPORT_URI_NODIR "El uri '{1}' no parece ser un directorio." #define STRING_TRANSPORT_CURL_URI "Cuando se usa el protocolo 'curl' el uri debe contener un nombre de máquina." #define STRING_TRANSPORT_CURL_WILDCD "Cuando se usa el protocolo 'curl' no están soportados los comodines." -#define STRING_TRANSPORT_CURL_NORUN "No se pudo lanzar curl. ¿Está instalado y disponible en $PATH?" #define STRING_TRANSPORT_CURL_FAIL "Curl falló, consulte los mensajes precedentes." #define STRING_TRANSPORT_RSYNC_URI "Cuando se usa el protocolo 'rsync' el uri debe contener un nombre de máquina." -#define STRING_TRANSPORT_RSYNC_NORUN "No se pudo lanzar rsync. ¿Está instalado y disponible en $PATH?" +#define STRING_TRANSPORT_RSYNC_FAIL "rsync failed, see output above." #define STRING_TRANSPORT_SSH_URI "Cuando se usa el protocolo 'ssh' el uri debe contener un nombre de máquina." -#define STRING_TRANSPORT_SSH_NORUN "No se pudo lanzar ssh. ¿Está instalado y disponible en $PATH?" +#define STRING_TRANSPORT_SSH_FAIL "ssh failed, see output above." // Uri #define STRING_URI_QUOTES "No se pudo interpretar el uri '{1}', uso erróneo de comillas simples." diff --git a/src/util.cpp b/src/util.cpp index 2481371fb..98a399ece 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -417,7 +417,7 @@ int execute(const std::string& executable, std::vector arguments) cmdline += " " + (std::string)*it; } - context.debug ("Executing: " + std::string(shell) + " " + std::string(opt) + " " + cmdline); + context.debug ("Executing: " + std::string(shell) + " " + std::string(opt) + " " + cmdline); pid_t child_pid = fork(); @@ -435,6 +435,10 @@ int execute(const std::string& executable, std::vector arguments) exit(ret); } + else if (child_pid == -1) + { + return -1; + } else { // this is done by the parent process @@ -445,7 +449,7 @@ int execute(const std::string& executable, std::vector arguments) if (pid == -1) return -1; else - return child_status; + return WEXITSTATUS (child_status); } }