summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pppctl/pppctl.c
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1997-11-18 00:20:29 +0000
committerbrian <brian@FreeBSD.org>1997-11-18 00:20:29 +0000
commit12fd795d924055603617fd039782a3df47f0a6c8 (patch)
treeac3eabdfd0093d6364b7301362c7239fba40c11a /usr.sbin/pppctl/pppctl.c
parentcb499269d89363f5b47627aad82a37b8f36ac63a (diff)
downloadFreeBSD-src-12fd795d924055603617fd039782a3df47f0a6c8.zip
FreeBSD-src-12fd795d924055603617fd039782a3df47f0a6c8.tar.gz
Notice that ppp has closed the connection properly.
Remove the timeout hack to notice that ppp has closed the connection. Remove the ``special case'' hacks for "quit" and "bye", as pppctl now exits immediately when the connection is closed by ppp. Suggest a secure "set server" line for connecting ppp & pppctl. Tidy up and correct a few man page typos.
Diffstat (limited to 'usr.sbin/pppctl/pppctl.c')
-rw-r--r--usr.sbin/pppctl/pppctl.c59
1 files changed, 23 insertions, 36 deletions
diff --git a/usr.sbin/pppctl/pppctl.c b/usr.sbin/pppctl/pppctl.c
index 253983c..0e18c6f 100644
--- a/usr.sbin/pppctl/pppctl.c
+++ b/usr.sbin/pppctl/pppctl.c
@@ -7,7 +7,9 @@
#include <netdb.h>
#include <sys/time.h>
+#include <errno.h>
#include <histedit.h>
+#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -26,7 +28,7 @@ Usage()
fprintf(stderr, " -v tells pppctl to output all"
" conversation\n");
fprintf(stderr, " -t n specifies a timeout of n"
- " seconds (default 2)\n");
+ " seconds when connecting (default 2)\n");
fprintf(stderr, " -p passwd specifies your password\n");
return 1;
}
@@ -54,25 +56,19 @@ GetPrompt(EditLine *e)
}
static int
-Receive(int fd, unsigned TimeoutVal, int display)
+Receive(int fd, int display)
{
int Result;
- struct sigaction act, oact;
int len;
char *last;
- TimedOut = 0;
- if (TimeoutVal) {
- act.sa_handler = Timeout;
- sigemptyset(&act.sa_mask);
- act.sa_flags = 0;
- sigaction(SIGALRM, &act, &oact);
- alarm(TimeoutVal);
- }
-
prompt = Buffer;
len = 0;
while (Result = read(fd, Buffer+len, sizeof(Buffer)-len-1), Result != -1) {
+ if (Result == 0 && errno != EINTR) {
+ Result = -1;
+ break;
+ }
len += Result;
Buffer[len] = '\0';
if (TimedOut) {
@@ -98,10 +94,6 @@ Receive(int fd, unsigned TimeoutVal, int display)
if (last > Buffer+3 && !strncmp(last-3, " on", 3)) {
/* a password is required ! */
if (display & REC_PASSWD) {
- if (TimeoutVal) {
- alarm(0);
- sigaction(SIGALRM, &oact, 0);
- }
/* password time */
if (!passwd)
passwd = getpass("Password: ");
@@ -111,7 +103,7 @@ Receive(int fd, unsigned TimeoutVal, int display)
write(1, Buffer, strlen(Buffer));
write(fd, Buffer, strlen(Buffer));
memset(Buffer, '\0', strlen(Buffer));
- return Receive(fd, TimeoutVal, display & ~REC_PASSWD);
+ return Receive(fd, display & ~REC_PASSWD);
}
Result = 1;
} else
@@ -120,17 +112,11 @@ Receive(int fd, unsigned TimeoutVal, int display)
}
}
- if (TimedOut)
- Result = -1;
-
- if (TimeoutVal) {
- alarm(0);
- sigaction(SIGALRM, &oact, 0);
- }
return Result;
}
static int data = -1;
+static jmp_buf pppdead;
static void
check_fd(int sig)
@@ -139,12 +125,18 @@ check_fd(int sig)
struct timeval t;
fd_set f;
static char buf[LINELEN];
+ int len;
FD_ZERO(&f);
FD_SET(data, &f);
t.tv_sec = t.tv_usec = 0;
- if (select(data+1, &f, NULL, NULL, &t) > 0)
- write(1, buf, read(data, buf, sizeof buf));
+ if (select(data+1, &f, NULL, NULL, &t) > 0) {
+ len = read(data, buf, sizeof buf);
+ if (len > 0)
+ write(1, buf, len);
+ else
+ longjmp(pppdead, -1);
+ }
}
}
@@ -152,12 +144,11 @@ static const char *
smartgets(EditLine *e, int *count, int fd)
{
const char *result;
- /* struct itimerval it; */
data = fd;
signal(SIGALRM, check_fd);
ualarm(500000, 500000);
- result = el_gets(e, count);
+ result = setjmp(pppdead) ? NULL : el_gets(e, count);
ualarm(0,0);
signal(SIGALRM, SIG_DFL);
data = -1;
@@ -312,7 +303,7 @@ main(int argc, char **argv)
len += strlen(Command+len);
}
- switch (Receive(fd, TimeoutVal, verbose | REC_PASSWD))
+ switch (Receive(fd, verbose | REC_PASSWD))
{
case 1:
fprintf(stderr, "Password incorrect\n");
@@ -348,14 +339,10 @@ main(int argc, char **argv)
if (len > 1)
history(hist, H_ENTER, l);
write(fd, l, len);
- if (!strcasecmp(l, "quit\n") ||
- !strcasecmp(l, "bye\n")) /* ok, we're cheating */
+ if (Receive(fd, REC_SHOW) != 0)
break;
- if (Receive(fd, TimeoutVal, REC_SHOW) != 0) {
- fprintf(stderr, "Connection closed\n");
- break;
- }
}
+ fprintf(stderr, "Connection closed\n");
el_end(edit);
history_end(hist);
} else {
@@ -372,7 +359,7 @@ main(int argc, char **argv)
if (verbose)
write(1, Buffer, strlen(Buffer));
write(fd, Buffer, strlen(Buffer));
- if (Receive(fd, TimeoutVal, verbose | REC_SHOW) != 0) {
+ if (Receive(fd, verbose | REC_SHOW) != 0) {
fprintf(stderr, "No reply from ppp\n");
break;
}
OpenPOWER on IntegriCloud