display next file name as part of "END" prompt
[unix-history] / usr / src / usr.bin / rsh / rsh.c
index 254b7d3..56ca56f 100644 (file)
@@ -1,18 +1,29 @@
 /*
 /*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * 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[] =
  */
 
 #ifndef lint
 char copyright[] =
-"@(#) Copyright (c) 1983 Regents of the University of California.\n\
+"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
  All rights reserved.\n";
  All rights reserved.\n";
-#endif not lint
+#endif /* not lint */
 
 #ifndef lint
 
 #ifndef lint
-static char sccsid[] = "@(#)rsh.c      5.4 (Berkeley) %G%";
-#endif not lint
+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>
@@ -32,13 +43,14 @@ static char sccsid[] = "@(#)rsh.c   5.4 (Berkeley) %G%";
  */
 /* 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))
@@ -76,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")) {
@@ -159,14 +170,16 @@ another:
                signal(SIGQUIT, sendsig);
        if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
                signal(SIGTERM, sendsig);
                signal(SIGQUIT, sendsig);
        if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
                signal(SIGTERM, sendsig);
-        pid = fork();
-        if (pid < 0) {
-               perror("fork");
-                exit(1);
-        }
+       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:
@@ -230,7 +243,8 @@ 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,