]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/passprompt.c
pppd: Handle SIGINT and SIGTERM during interrupted syscalls (#148)
[ppp.git] / pppd / plugins / passprompt.c
index 768901718e884d6654265817ee9c3ced1e2118e7..44e381501fdd6eeb8e02148ddb892cdde5384198 100644 (file)
@@ -50,7 +50,7 @@ static int promptpass(char *user, char *passwd)
     }
     if (!kid) {
        /* we are the child, exec the program */
-       char *argv[4], fdstr[32];
+       char *argv[5], fdstr[32];
        sys_close();
        closelog();
        close(p[0]);
@@ -74,7 +74,7 @@ static int promptpass(char *user, char *passwd)
        if (red == 0)
            break;
        if (red < 0) {
-           if (errno == EINTR)
+           if (errno == EINTR && !got_sigterm)
                continue;
            error("Can't read secret from %s: %m", promptprog);
            readgood = -1;
@@ -82,12 +82,11 @@ static int promptpass(char *user, char *passwd)
        }
        readgood += red;
     } while (readgood < MAXSECRETLEN - 1);
-    passwd[readgood] = 0;
     close(p[0]);
 
     /* now wait for child to exit */
     while (waitpid(kid, &wstat, 0) < 0) {
-       if (errno != EINTR) {
+       if (errno != EINTR || got_sigterm) {
            warn("error waiting for %s: %m", promptprog);
            break;
        }
@@ -95,6 +94,7 @@ static int promptpass(char *user, char *passwd)
 
     if (readgood < 0)
        return 0;
+    passwd[readgood] = 0;
     if (!WIFEXITED(wstat))
        warn("%s terminated abnormally", promptprog);
     if (WEXITSTATUS(wstat))