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

CVS update: Vanilla/newstartd



Date:	Friday July 16, 1999 @ 8:31
Author:	cameron

Update of /home/netrek/cvsroot/Vanilla/newstartd
In directory cvs.castle.real-time.com:/var/tmp/cvs-serv12682/newstartd

Modified Files:
	Makefile newstartd.c 
Log Message:
Late night Quozl changes ...
	- make a netrekd replacement for newstartd,
	- adjust RPM build for use of netrekd,
	- remove manifest,
	- rework primary Makefile,
	- drop bzip2 for gzip.

Details in ChangeLog ... which I reckon is too big for here.


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

Index: Vanilla/newstartd/Makefile
diff -u Vanilla/newstartd/Makefile:1.12 Vanilla/newstartd/Makefile:1.13
--- Vanilla/newstartd/Makefile:1.12	Wed Mar 17 20:25:45 1999
+++ Vanilla/newstartd/Makefile	Fri Jul 16 08:31:15 1999
@@ -39,6 +39,7 @@
           /bin/mkdir $(LIBDIR); \
         fi
 	$(INSTALL) $(INSTALLOPTS) newstartd $(LIBDIR)/newstartd
+	(cd $(LIBDIR); ln -sf newstartd netrekd)
 
 depend: 
 	touch .depend
Index: Vanilla/newstartd/newstartd.c
diff -u Vanilla/newstartd/newstartd.c:1.14 Vanilla/newstartd/newstartd.c:1.15
--- Vanilla/newstartd/newstartd.c:1.14	Fri Apr 30 18:31:29 1999
+++ Vanilla/newstartd/newstartd.c	Fri Jul 16 08:31:15 1999
@@ -1,7 +1,7 @@
-/* 	$Id: newstartd.c,v 1.14 1999/04/30 23:31:29 ahn Exp $	 */
+/* 	$Id: newstartd.c,v 1.15 1999/07/16 13:31:15 cameron Exp $	 */
 
 #ifndef lint
-static char vcid[] = "$Id: newstartd.c,v 1.14 1999/04/30 23:31:29 ahn Exp $";
+static char vcid[] = "$Id: newstartd.c,v 1.15 1999/07/16 13:31:15 cameron Exp $";
 #endif /* lint */
 
 /*
@@ -126,7 +126,6 @@
 #endif
 
 void handle_reaper(void) {
-
   struct sigaction action;
 
   action.sa_flags = SA_NOCLDWAIT;
@@ -134,7 +133,6 @@
   sigemptyset(&(action.sa_mask));
   action.sa_sigaction = NULL;
   sigaction(SIGCHLD, &action, NULL);
-
 }
 
 #endif
@@ -145,6 +143,7 @@
   int port_idx = -1;
   int num_progs = 0;
   int i;
+  pid_t pid;
 
   active = 0;
   getpath ();
@@ -152,17 +151,50 @@
   /* if someone tries to ask for help, give 'em it */
   if (argc == 2 && argv[1][0] == '-') {
     fprintf (stderr, "Usage: %s [portfile] [debug]\n", argv[0] );
+    fprintf (stderr, "Usage: %s stop\n", argv[0] );
     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 (file != NULL) {
+	fscanf (file, "%d", &pid);
+	fclose (file);
+	if (kill (pid, SIGINT) == 0) {
+	  remove (LIBDIR"/.newstartd.pid");
+	  exit(0);
+	}
+	perror ("kill");
+	exit(1);
+      }
+      perror (LIBDIR"/.newstartd.pid");
+      exit(1);
+    }
+  }
+
   /* allow user to specify a port file to use */
   if (argc == 2) portfile = argv[1];
 
-  /* allow user to ask for verbose output */
+  /* allow developer to ask for verbose output */
   if (argc == 3 && !strcmp(argv[2], "debug")) debug++;
 
-  /* set up handlers for signals */
+  /* wander off to the place where we live */
+  if (chdir (LIBDIR) != 0) {
+    perror (LIBDIR);
+    exit(1);
+  }
+
+  /* check file access before forking */
+  if (access (portfile, R_OK) != 0) {
+    perror (portfile);
+    exit(1);
+  }
 
+  /* set up handlers for signals */
 #ifdef REAPER_HANDLER
   handle_reaper();
 #else
@@ -171,19 +203,41 @@
   SIGNAL (SIGHUP, hangup);
   SIGNAL (SIGUSR1, SIG_IGN);
 
-  /* detach from terminal */
-  DETACH
-
   /* open the connection log file */
   if ((fd = open (LogFile, O_CREAT | O_WRONLY | O_APPEND, 0600)) < 0) {
-    perror ("open log");
+    perror (LogFile);
   }
+
+  /* fork this as a daemon */
+  pid = fork();
+  if (pid != 0) {
+    if (pid < 0) { 
+      perror("fork"); 
+      exit(1); 
+    }
+    fprintf (stderr, "Vanilla Netrek Listener %spl%d started, pid %d,\n"
+	     "\tlogging to %s\n", 
+	     mvers, PATCHLEVEL, pid, LogFile );
+    exit(0);
+  }
+
+  /* detach from terminal */
+  DETACH
+
+  /* do not propogate the log to forked processes */
+  fcntl(fd, F_SETFD, FD_CLOEXEC);
+
+  /* close our standard file descriptors and attach them to the log */
+  (void) dup2 (fd, 0);
+  (void) dup2 (fd, 1);
+  (void) dup2 (fd, 2);
+
+  /* set the standard streams to be line buffered (ANSI C3.159-1989) */
+  setvbuf (stderr, NULL, _IOLBF, 0);
+  setvbuf (stdout, NULL, _IOLBF, 0);
 
-  /* record our process id and announce ourselves */
+  /* record our process id */
   putpid ();
-  fprintf (stderr, "Vanilla Netrek Listener %spl%d\n", mvers, PATCHLEVEL );
-  fprintf (stderr, "%s\n", vcid );
-  fprintf (stderr, "using %s\n", portfile );
 
   /* run forever */
   for (;;) {