tags 211301 + patch
thanks

The attached patch implements the -n option (+entry in manual page).

-- 
-- arthur de jong - [EMAIL PROTECTED] - west consulting b.v. --
Index: rsh.1
===================================================================
--- rsh.1	(revision 71)
+++ rsh.1	(working copy)
@@ -30,6 +30,8 @@
 Use only IPv6 to connect to the remote host.
 .It Fl v
 Be verbose.
+.It Fl n
+Redirect stdin to /dev/null to be able to run rsh in the background.
 .It Fl l Ar user
 Connect to the remote host as a different user than on the local machine.
 .It Fl p Ar port
Index: rsh.c
===================================================================
--- rsh.c	(revision 71)
+++ rsh.c	(working copy)
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <stdbool.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <pwd.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -33,7 +34,7 @@
 char *argv0;
 
 void usage(void) {
-	fprintf(stderr, "Usage: %s [-46v] [-l user] [-p port] [EMAIL PROTECTED] command...\n", argv0);
+	fprintf(stderr, "Usage: %s [-46vn] [-l user] [-p port] [EMAIL PROTECTED] command...\n", argv0);
 }
 
 /* Make sure everything gets written */
@@ -71,6 +72,24 @@
 	}
 }
 
+void closestdin(void) {
+	int fd;
+	/* close stdin */
+	close(0);
+	/* open /dev/null */
+	if ((fd = open("/dev/null", O_RDONLY)) < 0)
+	{
+		fprintf(stderr, "%s: Error opening /dev/null: %s\n", argv0, strerror(errno));
+		exit(1);
+	
+	}
+	/* copy file descriptor to stdin if we didn't open stdin already */
+	if (fd!=0) {
+		dup2(fd, 0);
+		close(fd);
+	}
+}
+
 int main(int argc, char **argv) {
 	char *user = NULL;
 	char *luser = NULL;
@@ -113,7 +132,7 @@
 	
 	/* Process options */
 			
-	while((opt = getopt(argc, argv, "+l:p:46v")) != -1) {
+	while((opt = getopt(argc, argv, "+l:p:46vn")) != -1) {
 		switch(opt) {
 			case 'l':
 				user = optarg;
@@ -130,6 +149,9 @@
 			case 'v':
 				verbose = true;
 				break;
+			case 'n':
+				closestdin();
+				break;
 			default:
 				fprintf(stderr, "%s: Unknown option!\n", argv0);
 				usage();

Reply via email to