narrow possible window for losing window size change
[unix-history] / usr / src / usr.bin / rlogin / rlogin.c
index 778bbcd..db58360 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)rlogin.c   5.35 (Berkeley) %G%";
+static char sccsid[] = "@(#)rlogin.c   5.37 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -98,11 +98,12 @@ main(argc, argv)
        extern int optind;
        struct passwd *pw;
        struct servent *sp;
        extern int optind;
        struct passwd *pw;
        struct servent *sp;
+       struct hostent *hp;
        struct sgttyb ttyb;
        long omask;
        int argoff, ch, dflag, one, uid;
        char *host, *p, *user, term[1024];
        struct sgttyb ttyb;
        long omask;
        int argoff, ch, dflag, one, uid;
        char *host, *p, *user, term[1024];
-       void lostpeer();
+       void lostpeer(), copytochild(), writeroob();
        u_char getescape();
        char *getenv();
 
        u_char getescape();
        char *getenv();
 
@@ -212,10 +213,25 @@ main(argc, argv)
        (void)signal(SIGPIPE, lostpeer);
        /* will use SIGUSR1 for window size hack, so hold it off */
        omask = sigblock(sigmask(SIGURG) | sigmask(SIGUSR1));
        (void)signal(SIGPIPE, lostpeer);
        /* will use SIGUSR1 for window size hack, so hold it off */
        omask = sigblock(sigmask(SIGURG) | sigmask(SIGUSR1));
+       /*
+        * We set SIGURG and SIGUSR1 below so that an
+        * incoming signal will be held pending rather than being
+        * discarded. Note that these routines will be ready to get
+        * a signal by the time that they are unblocked below.
+        */
+       (void)signal(SIGURG, copytochild);
+       (void)signal(SIGUSR1, writeroob);
 
 #ifdef KERBEROS
 try_connect:
        if (use_kerberos) {
 
 #ifdef KERBEROS
 try_connect:
        if (use_kerberos) {
+               /* fully qualify hostname (needed for krb_realmofhost) */
+               hp = gethostbyname(host);
+               if (hp != NULL && !(host = strdup(hp->h_name))) {
+                       (void)fprintf(stderr, "rlogin: %s.\n", strerror(ENOMEM));
+                       exit(1);
+               }
+
                rem = KSUCCESS;
                errno = 0;
                if (dest_realm == NULL)
                rem = KSUCCESS;
                errno = 0;
                if (dest_realm == NULL)
@@ -271,7 +287,7 @@ doit(omask)
        long omask;
 {
        struct sgttyb sb;
        long omask;
 {
        struct sgttyb sb;
-       void catch_child(), copytochild(), exit(), writeroob();
+       void catch_child(), exit();
 
        (void)ioctl(0, TIOCGETP, (char *)&sb);
        defflags = sb.sg_flags;
 
        (void)ioctl(0, TIOCGETP, (char *)&sb);
        defflags = sb.sg_flags;
@@ -305,11 +321,11 @@ doit(omask)
 
        /*
         * We may still own the socket, and may have a pending SIGURG (or might
 
        /*
         * We may still own the socket, and may have a pending SIGURG (or might
-        * receive one soon) that we really want to send to the reader.  Set a
-        * trap that simply copies such signals to the child.
+        * receive one soon) that we really want to send to the reader.  When
+        * one of these comes in, the trap copytochild simply copies such
+        * signals to the child. We can now unblock SIGURG and SIGUSR1
+        * that were set above.
         */
         */
-       (void)signal(SIGURG, copytochild);
-       (void)signal(SIGUSR1, writeroob);
        (void)sigsetmask(omask);
        (void)signal(SIGCHLD, catch_child);
        writer();
        (void)sigsetmask(omask);
        (void)signal(SIGCHLD, catch_child);
        writer();