NNTPC: Argument handling with 1.0.6

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The first problem that bit me was that the arguments with parameters that
are specified on the command line are trashed by proctitle.  This means
that you can't use -c, -a, or -b.

My fix for this changes it to Sstrdup(optarg) instead.  They are not
free'd at any point, as they can be reused on a reload.

The next problem is that when you use -r, the files are zorched based
on the default location, rather than that on the config file.  My fix
adds a flag, which delays the zorch until after loading the config file.
The flag is then reset, so that the zorch is not repeated on a reload
(as is currently the case).

The next problem (which I haven't addressed) is that if you specify the
bind address using -b, and there is no bind address in the configuration
file, then con.bindAddr will be the compiled in default.  This will barf
when passed to free().

Something else I have noticed is that access_file is not used.  It would
not be possible to set it via the command line, as it not included in
the getopt argument (nor included in the usage message).  This looks
like a candidate for dead code to drop.

One question I have is, why does Sstrdup (and friends) have the following
structure?

    int t = 0;
    do
    {
       ...
    } while (--t<60);

This is never going to terminate (well, it will take a long time for
the integer to wrap around).

Anyway, enough for now.  Here is my (untested) patch to try and sort out
some of the problems with argument parsing, and allow me to give 1.0.6
a shakedown tomorrow.

--- nntpcache.c~	Tue Apr  8 22:02:25 1997
+++ nntpcache.c	Tue Apr  8 22:32:23 1997
@@ -587,6 +587,7 @@
 	struct group *gr;
 	int nodetach = FALSE;
 	int expireonly = FALSE;
+	int zorch = FALSE;
 	char *config_file = con.configFile;
 	char *access_file = con.accessFile;
 	char *bindAddr = 0;
@@ -612,14 +613,14 @@
 		switch (c)
 		{
 		case 'a':
-			access_file = optarg;
+			access_file = Sstrdup(optarg);
 			break;
 		case 'e':
 		        expireonly = TRUE;
 			nodetach = TRUE;
 			break;
 		case 'c':
-			config_file = optarg;
+			config_file = Sstrdup(optarg);
 			break;
 		case 'i':
 			Daemon = FALSE;
@@ -628,17 +629,10 @@
 			nodetach = TRUE;
 			break;
 		case 'b':
-			bindAddr = optarg;
+			bindAddr = Sstrdup(optarg);
 			break;
 		case 'r':
-			printf ("zorching %s/{cache.mmap,%s.{dir,pag}}!\n", con.cacheDir, con.historyFile);
-			chdir (con.cacheDir);
-			unlink (con.mmapFile);
-			unlink (con.historyFile);
-			sprintf (buf, "%.127s.pag", con.historyFile);
-			unlink (buf);
-			sprintf (buf, "%.127s.dir", con.historyFile);
-			unlink (buf);
+			zorch = TRUE;
 			break;
 		case 's':
 			f_swap_child = TRUE;
@@ -703,6 +697,18 @@
 	}
 	if (!load_config (config_file))
 		Exit (1);
+	if (zorch)
+	{
+	    printf ("zorching %s/{cache.mmap,%s.{dir,pag}}!\n", con.cacheDir, con.historyFile);
+	    chdir (con.cacheDir);
+	    unlink (con.mmapFile);
+	    unlink (con.historyFile);
+	    sprintf (buf, "%.127s.pag", con.historyFile);
+	    unlink (buf);
+	    sprintf (buf, "%.127s.dir", con.historyFile);
+	    unlink (buf);
+	    zorch = FALSE;	/* don't zorch again on reload */
+	}
 	if (expireonly)
 	{
 		puts ("Running expire (only)...");


[Index of Archives]     [Yosemite]     [Yosemite Campsites]     [Bugtraq]     [Linux]     [Trn]

Powered by Linux