Skip to content

Commit

Permalink
pppd: Handle SIGINT and SIGTERM during interrupted syscalls (#148)
Browse files Browse the repository at this point in the history
When pppd receives SIGINT or SIGTERM it should handle it and not try to
restart interrupted syscall.

This change fixes problem that pppd cannot be terminated by SIGINT or
SIGTERM signal when pppd plugins are used.

Signed-off-by: Pali Rohár <pali@kernel.org>
  • Loading branch information
pali committed May 25, 2020
1 parent 0bc11fb commit c319558
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pppd/plugins/passprompt.c
Expand Up @@ -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;
Expand All @@ -86,7 +86,7 @@ static int promptpass(char *user, char *passwd)

/* 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;
}
Expand Down
2 changes: 1 addition & 1 deletion pppd/plugins/radius/sendserver.c
Expand Up @@ -302,7 +302,7 @@ int rc_send_server (SEND_DATA *data, char *msg, REQUEST_INFO *info)
FD_SET (sockfd, &readfds);
if (select (sockfd + 1, &readfds, NULL, NULL, &authtime) < 0)
{
if (errno == EINTR)
if (errno == EINTR && !got_sigterm)
continue;
error("rc_send_server: select: %m");
memset (secret, '\0', sizeof (secret));
Expand Down
8 changes: 4 additions & 4 deletions pppd/plugins/rp-pppoe/discovery.c
Expand Up @@ -369,7 +369,7 @@ waitForPADO(PPPoEConnection *conn, int timeout)

while(1) {
r = select(conn->discoverySocket+1, &readable, NULL, NULL, &tv);
if (r >= 0 || errno != EINTR) break;
if (r >= 0 || errno != EINTR || got_sigterm) break;
}
if (r < 0) {
error("select (waitForPADO): %m");
Expand Down Expand Up @@ -550,7 +550,7 @@ waitForPADS(PPPoEConnection *conn, int timeout)

while(1) {
r = select(conn->discoverySocket+1, &readable, NULL, NULL, &tv);
if (r >= 0 || errno != EINTR) break;
if (r >= 0 || errno != EINTR || got_sigterm) break;
}
if (r < 0) {
error("select (waitForPADS): %m");
Expand Down Expand Up @@ -622,7 +622,7 @@ discovery(PPPoEConnection *conn)

do {
padiAttempts++;
if (padiAttempts > conn->discoveryAttempts) {
if (got_sigterm || padiAttempts > conn->discoveryAttempts) {
warn("Timeout waiting for PADO packets");
close(conn->discoverySocket);
conn->discoverySocket = -1;
Expand All @@ -638,7 +638,7 @@ discovery(PPPoEConnection *conn)
timeout = conn->discoveryTimeout;
do {
padrAttempts++;
if (padrAttempts > conn->discoveryAttempts) {
if (got_sigterm || padrAttempts > conn->discoveryAttempts) {
warn("Timeout waiting for PADS packets");
close(conn->discoverySocket);
conn->discoverySocket = -1;
Expand Down
2 changes: 1 addition & 1 deletion pppd/plugins/winbind.c
Expand Up @@ -443,7 +443,7 @@ unsigned int run_ntlm_auth(const char *username,
return NOT_AUTHENTICATED;
}

while ((wait(&status) == -1) && errno == EINTR)
while ((wait(&status) == -1) && errno == EINTR && !got_sigterm)
;

if ((authenticated == AUTHENTICATED) && nt_key && !got_user_session_key) {
Expand Down
1 change: 1 addition & 0 deletions pppd/pppd.h
Expand Up @@ -223,6 +223,7 @@ struct notifier {
* Global variables.
*/

extern int got_sigterm; /* SIGINT or SIGTERM was received */
extern int hungup; /* Physical layer has disconnected */
extern int ifunit; /* Interface unit number */
extern char ifname[]; /* Interface name */
Expand Down
2 changes: 1 addition & 1 deletion pppd/sys-solaris.c
Expand Up @@ -2427,7 +2427,7 @@ dlpi_get_reply(fd, reply, expected_prim, maxlen)
pfd.events = POLLIN | POLLPRI;
do {
n = poll(&pfd, 1, 1000);
} while (n == -1 && errno == EINTR);
} while (n == -1 && errno == EINTR && !got_sigterm);
if (n <= 0)
return -1;

Expand Down
2 changes: 1 addition & 1 deletion pppd/utils.c
Expand Up @@ -835,7 +835,7 @@ complete_read(int fd, void *buf, size_t count)
for (done = 0; done < count; ) {
nb = read(fd, ptr, count - done);
if (nb < 0) {
if (errno == EINTR)
if (errno == EINTR && !got_sigterm)
continue;
return -1;
}
Expand Down

0 comments on commit c319558

Please sign in to comment.