Browse Source

Plan 9 from Bell Labs 2009-07-18

David du Colombier 15 years ago
parent
commit
94241b3dd3
2 changed files with 33 additions and 5 deletions
  1. 4 1
      sys/man/8/listen
  2. 29 4
      sys/src/cmd/aux/listen.c

+ 4 - 1
sys/man/8/listen

@@ -3,7 +3,7 @@
 listen, listen1, tcp7, tcp9, tcp19, tcp21, tcp22, tcp23, tcp25, tcp53, tcp110, tcp113, tcp143, tcp513, tcp515, tcp564, tcp565, tcp566, tcp567, tcp993, tcp995, tcp1723, tcp17007, tcp17008, tcp17009, tcp17010, tcp17013 \- listen for calls on a network device
 .SH SYNOPSIS
 .B aux/listen
-.RB [ -q ]
+.RB [ -iq ]
 .RB [ -d
 .IR srvdir ]
 .RB [ -t
@@ -59,6 +59,9 @@ selects an alternate
 Option
 .B -q
 suppresses affirmative log information.
+Option
+.B -i
+suppresses the periodic scan of the service directories for changes.
 .PP
 Service names are made by concatenating the name of
 the network with the name of the service or port.

+ 29 - 4
sys/src/cmd/aux/listen.c

@@ -34,6 +34,7 @@ void	listendir(char*, char*, int);
 char	listenlog[] = "listen";
 
 int	quiet;
+int	immutable;
 char	*cpu;
 char	*proto;
 Announce *announcements;
@@ -85,6 +86,7 @@ main(int argc, char *argv[])
 	trustdir = 0;
 	proto = "tcp";
 	quiet = 0;
+	immutable = 0;
 	argv0 = argv[0];
 	cpu = getenv("cputype");
 	if(cpu == 0)
@@ -103,6 +105,13 @@ main(int argc, char *argv[])
 	case 'n':
 		namespace = EARGF(usage());
 		break;
+	case 'i':
+		/*
+		 * fixed configuration, no periodic
+		 * rescan of the service directory.
+		 */
+		immutable = 1;
+		break;
 	default:
 		usage();
 	}ARGEND;
@@ -180,12 +189,12 @@ listendir(char *protodir, char *srvdir, int trusted)
 	notify(dingdong);
 
 	pid = getpid();
+	scandir(proto, protodir, srvdir);
 	for(;;){
 		/*
 		 * loop through announcements and process trusted services in
 		 * invoker's ns and untrusted in none's.
 		 */
-		scandir(proto, protodir, srvdir);
 		for(a = announcements; a; a = a->next){
 			if(a->announced > 0)
 				continue;
@@ -221,9 +230,20 @@ listendir(char *protodir, char *srvdir, int trusted)
 			}
 		}
 
-		/* pick up any children that gave up and sleep for at least 60 seconds */
+		/*
+		 * if not running a fixed configuration,
+		 * pick up any children that gave up and
+		 * sleep for at least 60 seconds.
+		 * If a service process dies in a fixed
+		 * configuration what should be done -
+		 * nothing? restart? restart after a delay?
+		 * - currently just wait for something to
+		 * die and delay at least 60 seconds
+		 * between restarts.
+		 */
 		start = time(0);
-		alarm(60*1000);
+		if(!immutable)
+			alarm(60*1000);
 		while((wm = wait()) != nil) {
 			for(a = announcements; a; a = a->next)
 				if(a->announced == wm->pid) {
@@ -234,8 +254,13 @@ listendir(char *protodir, char *srvdir, int trusted)
 						a->whined = 1;
 				}
 			free(wm);
+			if(immutable)
+				break;
+		}
+		if(!immutable){
+			alarm(0);
+			scandir(proto, protodir, srvdir);
 		}
-		alarm(0);
 		start = 60 - (time(0)-start);
 		if(start > 0)
 			sleep(start*1000);