Vanilla Development Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CVS update: Vanilla/newstartd



Date:	Thursday December 30, 1999 @ 0:40
Author:	cameron

Update of /home/netrek/cvsroot/Vanilla/newstartd
In directory swashbuckler.fortress.real-time.com:/var/tmp/cvs-serv7254/newstartd

Modified Files:
	newstartd.c 
Log Message:
Mass changes (see ChangeLog) prior to 2.9pl4 release.


****************************************

Index: Vanilla/newstartd/newstartd.c
diff -u Vanilla/newstartd/newstartd.c:1.15 Vanilla/newstartd/newstartd.c:1.16
--- Vanilla/newstartd/newstartd.c:1.15	Fri Jul 16 08:31:15 1999
+++ Vanilla/newstartd/newstartd.c	Thu Dec 30 00:40:00 1999
@@ -1,7 +1,7 @@
-/* 	$Id: newstartd.c,v 1.15 1999/07/16 13:31:15 cameron Exp $	 */
+/* 	$Id: newstartd.c,v 1.16 1999/12/30 06:40:00 cameron Exp $	 */
 
 #ifndef lint
-static char vcid[] = "$Id: newstartd.c,v 1.15 1999/07/16 13:31:15 cameron Exp $";
+static char vcid[] = "$Id: newstartd.c,v 1.16 1999/12/30 06:40:00 cameron Exp $";
 #endif /* lint */
 
 /*
@@ -25,7 +25,7 @@
  *     to run this under dbx.  Link this with access.o and subnet.o.
  *  
  *   Summary of changes:
- *   - subsumes xtrekII.sock into startd (newstartd calls ntserv directly to
+ *   - subsumes xtrekII.sock into startd (this calls ntserv directly to
  *       reduce OS overhead)
  *   - some debugger support code added
  *   - uses reaper() to keep process table clean (removes <exiting> procs)
@@ -80,7 +80,6 @@
   char pad3;
 };
 
-#define PORTFILE LIBDIR"/.ports"	/* default .ports file path	*/
 #define MAXPROG 16			/* maximum ports to listen to	*/
 #define MAXPROCESSES 8+MAXPLAYER+TESTERS+MAXWAITING
 					/* maximum processes to create	*/
@@ -139,11 +138,12 @@
 
 int main (int argc, char *argv[])
 {
-  char *portfile = PORTFILE;
+  char *portfile = N_PORTS;
   int port_idx = -1;
   int num_progs = 0;
   int i;
   pid_t pid;
+  FILE *file;
 
   active = 0;
   getpath ();
@@ -155,27 +155,55 @@
     exit (1);
   }
 
+  /* fetch our previous pid if available */
+  file = fopen (N_NETREKDPID, "r");
+  if (file != NULL) {
+    fscanf (file, "%d", &pid);
+    fclose (file);
+  } else {
+    /* only a total lack of the file is acceptable */
+    if (errno != ENOENT) {
+      perror (N_NETREKDPID);
+      exit(1);
+    }
+  }
+
   /* check for a request to stop the listener */
   if (argc == 2) {
-    if (!strcmp(argv[1], "stop")) {
-      FILE *file;
-
-      file = fopen (LIBDIR"/.newstartd.pid", "r");
+    if (!strcmp (argv[1], "stop")) {
       if (file != NULL) {
-	fscanf (file, "%d", &pid);
-	fclose (file);
 	if (kill (pid, SIGINT) == 0) {
-	  remove (LIBDIR"/.newstartd.pid");
-	  exit(0);
+	  remove (N_NETREKDPID);
+	  fprintf (stderr, "netrekd: stopped pid %d\n", pid);
+	  exit (0);
 	}
+	fprintf (stderr, "netrekd: cannot stop, pid %d\n, may be already stopped", pid);
 	perror ("kill");
-	exit(1);
+	exit (1);
       }
-      perror (LIBDIR"/.newstartd.pid");
-      exit(1);
+      fprintf (stderr, "netrekd: cannot stop, no %s file\n", N_NETREKDPID);
+      exit (1);
     }
   }
 
+  /* check for duplicate start */
+  if (file != NULL) {
+    /* there is a pid file, test the pid is valid */
+    if (kill (pid, 0) == 0) {
+      fprintf (stderr, "netrekd: cannot start, already running as pid %d\n", pid);
+      exit (1);
+    } else {
+      if (errno != ESRCH) {
+	fprintf (stderr, "netrekd: failed on test of pid %d existence\n", pid);
+	perror ("kill");
+	exit (1);
+      }
+    }
+
+    /* pid was not valid but file was present, so remove it */
+    remove (N_NETREKDPID);
+  }
+
   /* allow user to specify a port file to use */
   if (argc == 2) portfile = argv[1];
 
@@ -215,8 +243,8 @@
       perror("fork"); 
       exit(1); 
     }
-    fprintf (stderr, "Vanilla Netrek Listener %spl%d started, pid %d,\n"
-	     "\tlogging to %s\n", 
+    fprintf (stderr, "netrekd: Vanilla Netrek Listener %spl%d started, pid %d,\n"
+	     "netrekd: logging to %s\n", 
 	     mvers, PATCHLEVEL, pid, LogFile );
     exit(0);
   }
@@ -266,7 +294,7 @@
       /* check for limit */
       if (active > MAXPROCESSES) {
 	fprintf(stderr, 
-		"newstartd: hit maximum processes, connection closed\n");
+		"netrekd: hit maximum processes, connection closed\n");
 	close (0);
 	continue;
       }
@@ -302,7 +330,7 @@
     } /* while (!restart) */
     
     /* SIGHUP restart requested, close all listening sockets */
-    fprintf (stderr, "newstartd restarting on SIGHUP\n");
+    fprintf (stderr, "netrekd: restarting on SIGHUP\n");
 
     for (i = 0; i < num_progs; i++) {
       if (prog[i].sock >= 0) close(prog[i].sock);
@@ -329,7 +357,7 @@
     sock = prog[i].sock;
     if (sock < 0) {
 
-      fprintf (stderr, "port %d, %s, ", prog[i].port, prog[i].prog);
+      fprintf (stderr, "netrekd: port %d, %s, ", prog[i].port, prog[i].prog);
       if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
 	perror ("socket");
 	sleep (1);
@@ -350,7 +378,7 @@
       
       /* set the listening socket to close on exec so that children
 	 don't hold open the file descriptor, thus preventing us from
-	 restarting newstartd. */
+	 restarting netrekd. */
       
       if (fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) {
 	perror ("fcntl F_SETFD FD_CLOEXEC");
@@ -412,7 +440,7 @@
 
     /* paranoia, it could be possible that we have no sockets ready */
     if (st == 0) {
-      fprintf(stderr, "paranoia: no sockets to listen for\n");
+      fprintf(stderr, "netrekd: paranoia, no sockets to listen for\n");
       sleep(1);
       return -1;
     }
@@ -442,7 +470,7 @@
     newsock = accept (sock, (struct sockaddr*)&naddr, &len);
     if (newsock >= 0) break;
     if (errno == EINTR) continue;
-    fprintf (stderr, "port %d, %s, ", prog[i].port, prog[i].prog);
+    fprintf (stderr, "netrekd: port %d, %s, ", prog[i].port, prog[i].prog);
     perror ("accept");
     sleep (1);
     return -1;
@@ -607,7 +635,7 @@
 {
   FILE *file;
 
-  file = fopen(LIBDIR"/.newstartd.pid", "w");
+  file = fopen(N_NETREKDPID, "w");
   if (file == NULL) return;
   fprintf (file, "%d\n", (int) getpid());
   fclose (file);