]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
When PSFTP exits in batch mode due to a command failure, set exit status != 0.
authorBen Harris <bjh21@bjh21.me.uk>
Thu, 25 Jun 2015 22:27:16 +0000 (23:27 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Thu, 25 Jun 2015 22:36:17 +0000 (23:36 +0100)
There are possibly other circumstances when PSFTP should also return
failure, but that one seems particularly obvious.

psftp.c

diff --git a/psftp.c b/psftp.c
index 1d331603cbf7f5ea67a641466ce1eba546c9d670..2a82ff8e33bcf8c83b25cd62f95c6aa2125a3d72 100644 (file)
--- a/psftp.c
+++ b/psftp.c
@@ -2388,7 +2388,7 @@ void do_sftp_cleanup()
     }
 }
 
-void do_sftp(int mode, int modeflags, char *batchfile)
+int do_sftp(int mode, int modeflags, char *batchfile)
 {
     FILE *fp;
     int ret;
@@ -2421,8 +2421,9 @@ void do_sftp(int mode, int modeflags, char *batchfile)
         fp = fopen(batchfile, "r");
         if (!fp) {
            printf("Fatal: unable to open %s\n", batchfile);
-           return;
+           return 1;
         }
+       ret = 0;
         while (1) {
            struct sftp_command *cmd;
            cmd = sftp_getcmd(fp, mode, modeflags);
@@ -2437,8 +2438,13 @@ void do_sftp(int mode, int modeflags, char *batchfile)
            }
         }
        fclose(fp);
-
+       /*
+        * In batch mode, and if exit on command failure is enabled,
+        * any command failure causes the whole of PSFTP to fail.
+        */
+       if (ret == 0 && !(modeflags & 2)) return 2;
     }
+    return 0;
 }
 
 /* ----------------------------------------------------------------------
@@ -2894,7 +2900,7 @@ const int share_can_be_upstream = FALSE;
  */
 int psftp_main(int argc, char *argv[])
 {
-    int i;
+    int i, ret;
     int portnumber = 0;
     char *userhost, *user;
     int mode = 0;
@@ -2990,7 +2996,7 @@ int psftp_main(int argc, char *argv[])
               " to connect\n");
     }
 
-    do_sftp(mode, modeflags, batchfile);
+    ret = do_sftp(mode, modeflags, batchfile);
 
     if (back != NULL && back->connected(backhandle)) {
        char ch;
@@ -3004,5 +3010,5 @@ int psftp_main(int argc, char *argv[])
     console_provide_logctx(NULL);
     sk_cleanup();
 
-    return 0;
+    return ret;
 }