display next file name as part of "END" prompt
[unix-history] / usr / src / usr.bin / rsh / rsh.c
index 5df2537..56ca56f 100644 (file)
@@ -1,6 +1,29 @@
+/*
+ * Copyright (c) 1983 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)rsh.c      4.9 84/12/03";
-#endif
+static char sccsid[] = "@(#)rsh.c      5.7 (Berkeley) %G%";
+#endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/socket.h>
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -20,13 +43,14 @@ static char sccsid[] = "@(#)rsh.c   4.9 84/12/03";
  */
 /* VARARGS */
 int    error();
  */
 /* VARARGS */
 int    error();
-char   *index(), *rindex(), *malloc(), *getpass(), *sprintf(), *strcpy();
+char   *index(), *rindex(), *malloc(), *getpass(), *strcpy();
 
 struct passwd *getpwuid();
 
 int    errno;
 int    options;
 int    rfd2;
 
 struct passwd *getpwuid();
 
 int    errno;
 int    options;
 int    rfd2;
+int    nflag;
 int    sendsig();
 
 #define        mask(s) (1 << ((s) - 1))
 int    sendsig();
 
 #define        mask(s) (1 << ((s) - 1))
@@ -64,8 +88,7 @@ another:
        }
        if (argc > 0 && !strcmp(*argv, "-n")) {
                argv++, argc--;
        }
        if (argc > 0 && !strcmp(*argv, "-n")) {
                argv++, argc--;
-               (void) close(0);
-               (void) open("/dev/null", 0);
+               nflag++;
                goto another;
        }
        if (argc > 0 && !strcmp(*argv, "-d")) {
                goto another;
        }
        if (argc > 0 && !strcmp(*argv, "-d")) {
@@ -74,13 +97,27 @@ another:
                goto another;
        }
        /*
                goto another;
        }
        /*
-        * Ignore the -e flag to allow aliases with rlogin
+        * Ignore the -L, -w, -e and -8 flags to allow aliases with rlogin
         * to work
         * to work
+        *
+        * There must be a better way to do this! -jmb
         */
         */
+       if (argc > 0 && !strncmp(*argv, "-L", 2)) {
+               argv++, argc--;
+               goto another;
+       }
+       if (argc > 0 && !strncmp(*argv, "-w", 2)) {
+               argv++, argc--;
+               goto another;
+       }
        if (argc > 0 && !strncmp(*argv, "-e", 2)) {
                argv++, argc--;
                goto another;
        }
        if (argc > 0 && !strncmp(*argv, "-e", 2)) {
                argv++, argc--;
                goto another;
        }
+       if (argc > 0 && !strncmp(*argv, "-8", 2)) {
+               argv++, argc--;
+               goto another;
+       }
        if (host == 0)
                goto usage;
        if (argv[0] == 0) {
        if (host == 0)
                goto usage;
        if (argv[0] == 0) {
@@ -127,17 +164,22 @@ another:
        }
        (void) setuid(getuid());
        omask = sigblock(mask(SIGINT)|mask(SIGQUIT)|mask(SIGTERM));
        }
        (void) setuid(getuid());
        omask = sigblock(mask(SIGINT)|mask(SIGQUIT)|mask(SIGTERM));
-       signal(SIGINT, sendsig);
-       signal(SIGQUIT, sendsig);
-       signal(SIGTERM, sendsig);
-        pid = fork();
-        if (pid < 0) {
-               perror("fork");
-                exit(1);
-        }
+       if (signal(SIGINT, SIG_IGN) != SIG_IGN)
+               signal(SIGINT, sendsig);
+       if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
+               signal(SIGQUIT, sendsig);
+       if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
+               signal(SIGTERM, sendsig);
+       if (nflag == 0) {
+               pid = fork();
+               if (pid < 0) {
+                       perror("fork");
+                       exit(1);
+               }
+       }
        ioctl(rfd2, FIONBIO, &one);
        ioctl(rem, FIONBIO, &one);
        ioctl(rfd2, FIONBIO, &one);
        ioctl(rem, FIONBIO, &one);
-        if (pid == 0) {
+        if (nflag == 0 && pid == 0) {
                char *bp; int rembits, wc;
                (void) close(rfd2);
        reread:
                char *bp; int rembits, wc;
                (void) close(rfd2);
        reread:
@@ -201,17 +243,18 @@ another:
                                (void) write(1, buf, cc);
                }
         } while (readfrom);
                                (void) write(1, buf, cc);
                }
         } while (readfrom);
-        (void) kill(pid, SIGKILL);
+       if (nflag == 0)
+               (void) kill(pid, SIGKILL);
        exit(0);
 usage:
        fprintf(stderr,
        exit(0);
 usage:
        fprintf(stderr,
-           "usage: rsh host [ -l login ] [ -p passwd ] command\n");
+           "usage: rsh host [ -l login ] [ -n ] command\n");
        exit(1);
 }
 
 sendsig(signo)
        exit(1);
 }
 
 sendsig(signo)
-       int signo;
+       char signo;
 {
 
 {
 
-       (void) write(rfd2, (char *)&signo, 1);
+       (void) write(rfd2, &signo, 1);
 }
 }