NNTPC: -e and setproctitle.

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

 



When running "nntpcache -e" the configuration file isn't read so if you
override the values of something like maxArtAge it has no effect.
The following patch fixes.

Also the current support for setproctitle only works if your OS provides the
routine which many don't so I've lifted the relevant code out of sendmail and
put it in a setproctitle.c.  I haven't made the required change to the Makefile
and configure to automatically integrate this but that shouldn't be too hard.
If your system provides a setproctitle() then you need to define SPT_TYPE to
SPT_BUILTIN.  The default is to define SPT_TYPE to SPT_REUSEARGV which is right
for many systems including Solaris 2.

cheers
mark

diff -c nntpcache-1.0.5/nntpcache.c nntpcache-1.0.5.new/nntpcache.c
*** nntpcache-1.0.5/nntpcache.c	Tue Mar  4 15:16:04 1997
--- nntpcache-1.0.5.new/nntpcache.c	Sat Mar 15 18:10:24 1997
***************
*** 577,583 ****
  	}
  }
  
! int main (int argc, char **argv)
  {
  	int connected = 0;
  	char buf[MAX_CMD];
--- 577,583 ----
  	}
  }
  
! int main (int argc, char **argv, char **envp)
  {
  	int connected = 0;
  	char buf[MAX_CMD];
***************
*** 586,591 ****
--- 586,592 ----
  	struct passwd *pw;
  	struct group *gr;
  	int nodetach = FALSE;
+ 	int expireonly = FALSE;
  	char *config_file = con.configFile;
  	char *access_file = con.accessFile;
  	char *bindAddr = 0;
***************
*** 614,627 ****
  			access_file = optarg;
  			break;
  		case 'e':
! 			puts ("Running expire (only)...");
! 			if (chdir (con.cacheDir) != 0)
! 			{
! 				perror (con.cacheDir);
! 				exit (1);
! 			}
! 			expire (TRUE);
! 			exit (0);
  		case 'c':
  			config_file = optarg;
  			break;
--- 615,623 ----
  			access_file = optarg;
  			break;
  		case 'e':
! 		        expireonly = TRUE;
! 			nodetach = TRUE;
! 			break;
  		case 'c':
  			config_file = optarg;
  			break;
***************
*** 656,661 ****
--- 652,658 ----
  		}
  	umask (022);
  #ifdef HAVE_SETPROCTITLE
+ 	initsetproctitle(argc, argv, envp);
  	setproctitle("initialising");
  #endif
  	if (!sig_hup && Daemon && !nodetach)
***************
*** 708,713 ****
--- 705,721 ----
  	}
  	if (!load_config (config_file))
  		Exit (1);
+ 	if (expireonly)
+ 	{
+ 		puts ("Running expire (only)...");
+ 		if (chdir (con.cacheDir) != 0)
+ 		{
+ 			perror (con.cacheDir);
+ 			exit (1);
+ 		}
+ 		expire (TRUE);
+ 		exit (0);
+ 	}
  	if (bindAddr)
  	{
  		if (con.bindAddr) free(con.bindAddr);
*** /dev/null	Tue Mar 18 20:40:27 1997
--- nntpcache-1.0.5.new/setproctitle.c	Sat Mar 15 18:13:29 1997
***************
*** 0 ****
--- 1,598 ----
+ /*
+  * Copyright (c) 1983, 1995, 1996 Eric P. Allman
+  * Copyright (c) 1988, 1993
+  *	The Regents of the University of California.  All rights reserved.
+  *
+  * Redistribution and use in source and binary forms, with or without
+  * modification, are permitted provided that the following conditions
+  * are met:
+  * 1. Redistributions of source code must retain the above copyright
+  *    notice, this list of conditions and the following disclaimer.
+  * 2. Redistributions in binary form must reproduce the above copyright
+  *    notice, this list of conditions and the following disclaimer in the
+  *    documentation and/or other materials provided with the distribution.
+  * 3. All advertising materials mentioning features or use of this software
+  *    must display the following acknowledgement:
+  *	This product includes software developed by the University of
+  *	California, Berkeley and its contributors.
+  * 4. Neither the name of the University nor the names of its contributors
+  *    may be used to endorse or promote products derived from this software
+  *    without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  * SUCH DAMAGE.
+  */
+ 
+ #ifndef lint
+ static char sccsid[] = "@(#)conf.c	8.333 (Berkeley) 1/21/97";
+ #endif /* not lint */
+ 
+ # include <unistd.h>
+ # include <stddef.h>
+ # include <stdlib.h>
+ # include <stdio.h>
+ # include <ctype.h>
+ # include <string.h>
+ # include <errno.h>
+ 
+ # include <sys/ioctl.h>
+ # include <sys/param.h>
+ 
+ /* make a copy of a string */
+ #define newstr(s)       strcpy(malloc(strlen(s) + 1), s)
+ #define SPACELEFT(buf, ptr)  (sizeof buf - ((ptr) - buf))
+ #define MAXLINE        2048            /* max line length */
+ 
+ 
+ # ifdef __STDC__
+ 
+ # include <stdarg.h>
+ 
+ # define VA_LOCAL_DECL  va_list ap;
+ # define VA_START(f)    va_start(ap, f)
+ # define VA_END         va_end(ap)
+ 
+ # else
+ 
+ # include <varargs.h>
+ 
+ # define VA_LOCAL_DECL  va_list ap;
+ # define VA_START(f)    va_start(ap)
+ # define VA_END         va_end(ap)
+ 
+ # endif
+ 
+ #ifndef __P
+ # include "cdefs.h"
+ #endif
+ 
+ #if !HASSNPRINTF
+ # ifdef __STDC__
+ extern int              snprintf(char *, size_t, const char *, ...);
+ extern int              vsnprintf(char *, size_t, const char *, va_list);
+ # else
+ extern int              snprintf();
+ extern int              vsnprintf();
+ # endif
+ # endif
+ 
+ /*
+ **  SETPROCTITLE -- set process title for ps
+ **
+ **	Parameters:
+ **		fmt -- a printf style format string.
+ **		a, b, c -- possible parameters to fmt.
+ **
+ **	Returns:
+ **		none.
+ **
+ **	Side Effects:
+ **		Clobbers argv of our main procedure so ps(1) will
+ **		display the title.
+ */
+ 
+ #define SPT_NONE	0	/* don't use it at all */
+ #define SPT_REUSEARGV	1	/* cover argv with title information */
+ #define SPT_BUILTIN	2	/* use libc builtin */
+ #define SPT_PSTAT	3	/* use pstat(PSTAT_SETCMD, ...) */
+ #define SPT_PSSTRINGS	4	/* use PS_STRINGS->... */
+ #define SPT_SYSMIPS	5	/* use sysmips() supported by NEWS-OS 6 */
+ #define SPT_SCO		6	/* write kernel u. area */
+ 
+ #ifndef SPT_TYPE
+ # define SPT_TYPE	SPT_REUSEARGV
+ #endif
+ 
+ #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN
+ 
+ # if SPT_TYPE == SPT_PSTAT
+ #  include <sys/pstat.h>
+ # endif
+ # if SPT_TYPE == SPT_PSSTRINGS
+ #  include <machine/vmparam.h>
+ #  include <sys/exec.h>
+ #  ifndef PS_STRINGS	/* hmmmm....  apparently not available after all */
+ #   undef SPT_TYPE
+ #   define SPT_TYPE	SPT_REUSEARGV
+ #  else
+ #   ifndef NKPDE			/* FreeBSD 2.0 */
+ #    define NKPDE 63
+ typedef unsigned int	*pt_entry_t;
+ #   endif
+ #  endif
+ # endif
+ 
+ # if SPT_TYPE == SPT_PSSTRINGS
+ #  define SETPROC_STATIC	static
+ # else
+ #  define SETPROC_STATIC
+ # endif
+ 
+ # if SPT_TYPE == SPT_SYSMIPS
+ #  include <sys/sysmips.h>
+ #  include <sys/sysnews.h>
+ # endif
+ 
+ # if SPT_TYPE == SPT_SCO
+ #  include <sys/immu.h>
+ #  include <sys/dir.h>
+ #  include <sys/user.h>
+ #  include <sys/fs/s5param.h>
+ #  if PSARGSZ > MAXLINE
+ #   define SPT_BUFSIZE	PSARGSZ
+ #  endif
+ # endif
+ 
+ # ifndef SPT_PADCHAR
+ #  define SPT_PADCHAR	' '
+ # endif
+ 
+ # ifndef SPT_BUFSIZE
+ #  define SPT_BUFSIZE	MAXLINE
+ # endif
+ 
+ #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */
+ 
+ /*
+ **  Pointers for setproctitle.
+ **	This allows "ps" listings to give more useful information.
+ */
+ 
+ char		**Argv = NULL;		/* pointer to argument vector */
+ char		*LastArgv = NULL;	/* end of argv */
+ 
+ void
+ initsetproctitle(argc, argv, envp)
+ 	int argc;
+ 	char **argv;
+ 	char **envp;
+ {
+ 	register int i;
+ 	extern char **environ;
+ 
+ 	/*
+         **  Move the environment so setproctitle can use the space at
+ 	**  the top of memory.
+ 	*/
+ 
+ 	for (i = 0; envp[i] != NULL; i++)
+ 		continue;
+ 	environ = (char **) malloc(sizeof (char *) * (i + 1));
+ 	for (i = 0; envp[i] != NULL; i++)
+ 		environ[i] = newstr(envp[i]);
+ 	environ[i] = NULL;
+ 
+ 	/*
+ 	**  Save start and extent of argv for setproctitle.
+ 	*/
+ 
+ 	Argv = argv;
+ 	if (i > 0)
+ 		LastArgv = envp[i - 1] + strlen(envp[i - 1]);
+ 	else
+ 		LastArgv = argv[argc - 1] + strlen(argv[argc - 1]);
+ }
+ 
+ #if SPT_TYPE != SPT_BUILTIN
+ 
+ 
+ /*VARARGS1*/
+ void
+ # ifdef __STDC__
+ setproctitle(const char *fmt, ...)
+ # else
+ setproctitle(fmt, va_alist)
+ 	const char *fmt;
+ 	va_dcl
+ # endif
+ {
+ # if SPT_TYPE != SPT_NONE
+ 	register char *p;
+ 	register int i;
+ 	SETPROC_STATIC char buf[SPT_BUFSIZE];
+ 	VA_LOCAL_DECL
+ #  if SPT_TYPE == SPT_PSTAT
+ 	union pstun pst;
+ #  endif
+ #  if SPT_TYPE == SPT_SCO
+ 	off_t seek_off;
+ 	static int kmem = -1;
+ 	static int kmempid = -1;
+ 	struct user u;
+ #  endif
+ 
+ 	p = buf;
+ 
+ 	/* print sendmail: heading for grep */
+ 	(void) strcpy(p, "nntpcache: ");
+ 	p += strlen(p);
+ 
+ 	/* print the argument string */
+ 	VA_START(fmt);
+ 	(void) vsnprintf(p, SPACELEFT(buf, p), fmt, ap);
+ 	VA_END;
+ 
+ 	i = strlen(buf);
+ 
+ #  if SPT_TYPE == SPT_PSTAT
+ 	pst.pst_command = buf;
+ 	pstat(PSTAT_SETCMD, pst, i, 0, 0);
+ #  endif
+ #  if SPT_TYPE == SPT_PSSTRINGS
+ 	PS_STRINGS->ps_nargvstr = 1;
+ 	PS_STRINGS->ps_argvstr = buf;
+ #  endif
+ #  if SPT_TYPE == SPT_SYSMIPS
+ 	sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf);
+ #  endif
+ #  if SPT_TYPE == SPT_SCO
+ 	if (kmem < 0 || kmempid != getpid())
+ 	{
+ 		if (kmem >= 0)
+ 			close(kmem);
+ 		kmem = open(_PATH_KMEM, O_RDWR, 0);
+ 		if (kmem < 0)
+ 			return;
+ 		(void) fcntl(kmem, F_SETFD, 1);
+ 		kmempid = getpid();
+ 	}
+ 	buf[PSARGSZ - 1] = '\0';
+ 	seek_off = UVUBLK + (off_t) u.u_psargs - (off_t) &u;
+ 	if (lseek(kmem, (off_t) seek_off, SEEK_SET) == seek_off)
+ 		(void) write(kmem, buf, PSARGSZ);
+ #  endif
+ #  if SPT_TYPE == SPT_REUSEARGV
+ 	if (i > LastArgv - Argv[0] - 2)
+ 	{
+ 		i = LastArgv - Argv[0] - 2;
+ 		buf[i] = '\0';
+ 	}
+ 	(void) strcpy(Argv[0], buf);
+ 	p = &Argv[0][i];
+ 	while (p < LastArgv)
+ 		*p++ = SPT_PADCHAR;
+ 	Argv[1] = NULL;
+ #  endif
+ # endif /* SPT_TYPE != SPT_NONE */
+ }
+ 
+ #endif /* SPT_TYPE != SPT_BUILTIN */
+ /*
+ **  SNPRINTF, VSNPRINT -- counted versions of printf
+ **
+ **	These versions have been grabbed off the net.  They have been
+ **	cleaned up to compile properly and support for .precision and
+ **	%lx has been added.
+ */
+ 
+ #if !HASSNPRINTF
+ 
+ /**************************************************************
+  * Original:
+  * Patrick Powell Tue Apr 11 09:48:21 PDT 1995
+  * A bombproof version of doprnt (dopr) included.
+  * Sigh.  This sort of thing is always nasty do deal with.  Note that
+  * the version here does not include floating point...
+  *
+  * snprintf() is used instead of sprintf() as it does limit checks
+  * for string length.  This covers a nasty loophole.
+  *
+  * The other functions are there to prevent NULL pointers from
+  * causing nast effects.
+  **************************************************************/
+ 
+ /*static char _id[] = "$Id: snprintf.c,v 1.2 1995/10/09 11:19:47 roberto Exp $";*/
+ static void dopr();
+ static char *end;
+ static int	SnprfOverflow;
+ 
+ /* VARARGS3 */
+ int
+ # ifdef __STDC__
+ snprintf(char *str, size_t count, const char *fmt, ...)
+ # else
+ snprintf(str, count, fmt, va_alist)
+ 	char *str;
+ 	size_t count;
+ 	const char *fmt;
+ 	va_dcl
+ #endif
+ {
+ 	int len;
+ 	VA_LOCAL_DECL
+ 
+ 	VA_START(fmt);
+ 	len = vsnprintf(str, count, fmt, ap);
+ 	VA_END;
+ 	return len;
+ }
+ 
+ 
+ # ifndef luna2
+ int
+ vsnprintf(str, count, fmt, args)
+ 	char *str;
+ 	size_t count;
+ 	const char *fmt;
+ 	va_list args;
+ {
+ 	str[0] = 0;
+ 	end = str + count - 1;
+ 	SnprfOverflow = 0;
+ 	dopr( str, fmt, args );
+ 	if (count > 0)
+ 		end[0] = 0;
+ #if 0
+ 	if (SnprfOverflow && tTd(57, 2))
+ 		printf("\nvsnprintf overflow, len = %d, str = %s",
+ 			count, shortenstring(str, 203));
+ #endif
+ 	return strlen(str);
+ }
+ 
+ /*
+  * dopr(): poor man's version of doprintf
+  */
+ 
+ static void fmtstr __P((char *value, int ljust, int len, int zpad, int maxwidth));
+ static void fmtnum __P((long value, int base, int dosign, int ljust, int len, int zpad));
+ static void dostr __P(( char * , int ));
+ static char *output;
+ static void dopr_outch __P(( int c ));
+ 
+ static void
+ dopr( buffer, format, args )
+        char *buffer;
+        const char *format;
+        va_list args;
+ {
+        int ch;
+        long value;
+        int longflag  = 0;
+        int pointflag = 0;
+        int maxwidth  = 0;
+        char *strvalue;
+        int ljust;
+        int len;
+        int zpad;
+ 
+        output = buffer;
+        while( (ch = *format++) ){
+                switch( ch ){
+                case '%':
+                        ljust = len = zpad = maxwidth = 0;
+                        longflag = pointflag = 0;
+                nextch:
+                        ch = *format++;
+                        switch( ch ){
+                        case 0:
+                                dostr( "**end of format**" , 0);
+                                return;
+                        case '-': ljust = 1; goto nextch;
+                        case '0': /* set zero padding if len not set */
+                                if(len==0 && !pointflag) zpad = '0';
+                        case '1': case '2': case '3':
+                        case '4': case '5': case '6':
+                        case '7': case '8': case '9':
+ 			       if (pointflag)
+ 				 maxwidth = maxwidth*10 + ch - '0';
+ 			       else
+ 				 len = len*10 + ch - '0';
+                                goto nextch;
+ 		       case '*': 
+ 			       if (pointflag)
+ 				 maxwidth = va_arg( args, int );
+ 			       else
+ 				 len = va_arg( args, int );
+ 			       goto nextch;
+ 		       case '.': pointflag = 1; goto nextch;
+                        case 'l': longflag = 1; goto nextch;
+                        case 'u': case 'U':
+                                /*fmtnum(value,base,dosign,ljust,len,zpad) */
+                                if( longflag ){
+                                        value = va_arg( args, long );
+                                } else {
+                                        value = va_arg( args, int );
+                                }
+                                fmtnum( value, 10,0, ljust, len, zpad ); break;
+                        case 'o': case 'O':
+                                /*fmtnum(value,base,dosign,ljust,len,zpad) */
+                                if( longflag ){
+                                        value = va_arg( args, long );
+                                } else {
+                                        value = va_arg( args, int );
+                                }
+                                fmtnum( value, 8,0, ljust, len, zpad ); break;
+                        case 'd': case 'D':
+                                if( longflag ){
+                                        value = va_arg( args, long );
+                                } else {
+                                        value = va_arg( args, int );
+                                }
+                                fmtnum( value, 10,1, ljust, len, zpad ); break;
+                        case 'x':
+                                if( longflag ){
+                                        value = va_arg( args, long );
+                                } else {
+                                        value = va_arg( args, int );
+                                }
+                                fmtnum( value, 16,0, ljust, len, zpad ); break;
+                        case 'X':
+                                if( longflag ){
+                                        value = va_arg( args, long );
+                                } else {
+                                        value = va_arg( args, int );
+                                }
+                                fmtnum( value,-16,0, ljust, len, zpad ); break;
+                        case 's':
+                                strvalue = va_arg( args, char *);
+ 			       if (maxwidth > 0 || !pointflag) {
+ 				 if (pointflag && len > maxwidth)
+ 				   len = maxwidth; /* Adjust padding */
+ 				 fmtstr( strvalue,ljust,len,zpad, maxwidth);
+ 			       }
+ 			       break;
+                        case 'c':
+                                ch = va_arg( args, int );
+                                dopr_outch( ch ); break;
+                        case '%': dopr_outch( ch ); continue;
+                        default:
+                                dostr(  "???????" , 0);
+                        }
+                        break;
+                default:
+                        dopr_outch( ch );
+                        break;
+                }
+        }
+        *output = 0;
+ }
+ 
+ static void
+ fmtstr(  value, ljust, len, zpad, maxwidth )
+        char *value;
+        int ljust, len, zpad, maxwidth;
+ {
+        int padlen, strlen;     /* amount to pad */
+ 
+        if( value == 0 ){
+                value = "<NULL>";
+        }
+        for( strlen = 0; value[strlen]; ++ strlen ); /* strlen */
+        if (strlen > maxwidth && maxwidth)
+ 	 strlen = maxwidth;
+        padlen = len - strlen;
+        if( padlen < 0 ) padlen = 0;
+        if( ljust ) padlen = -padlen;
+        while( padlen > 0 ) {
+                dopr_outch( ' ' );
+                --padlen;
+        }
+        dostr( value, maxwidth );
+        while( padlen < 0 ) {
+                dopr_outch( ' ' );
+                ++padlen;
+        }
+ }
+ 
+ static void
+ fmtnum(  value, base, dosign, ljust, len, zpad )
+        long value;
+        int base, dosign, ljust, len, zpad;
+ {
+        int signvalue = 0;
+        unsigned long uvalue;
+        char convert[20];
+        int place = 0;
+        int padlen = 0; /* amount to pad */
+        int caps = 0;
+ 
+        /* DEBUGP(("value 0x%x, base %d, dosign %d, ljust %d, len %d, zpad %d\n",
+                value, base, dosign, ljust, len, zpad )); */
+        uvalue = value;
+        if( dosign ){
+                if( value < 0 ) {
+                        signvalue = '-';
+                        uvalue = -value;
+                }
+        }
+        if( base < 0 ){
+                caps = 1;
+                base = -base;
+        }
+        do{
+                convert[place++] =
+                        (caps? "0123456789ABCDEF":"0123456789abcdef")
+                         [uvalue % (unsigned)base  ];
+                uvalue = (uvalue / (unsigned)base );
+        }while(uvalue);
+        convert[place] = 0;
+        padlen = len - place;
+        if( padlen < 0 ) padlen = 0;
+        if( ljust ) padlen = -padlen;
+        /* DEBUGP(( "str '%s', place %d, sign %c, padlen %d\n",
+                convert,place,signvalue,padlen)); */
+        if( zpad && padlen > 0 ){
+                if( signvalue ){
+                        dopr_outch( signvalue );
+                        --padlen;
+                        signvalue = 0;
+                }
+                while( padlen > 0 ){
+                        dopr_outch( zpad );
+                        --padlen;
+                }
+        }
+        while( padlen > 0 ) {
+                dopr_outch( ' ' );
+                --padlen;
+        }
+        if( signvalue ) dopr_outch( signvalue );
+        while( place > 0 ) dopr_outch( convert[--place] );
+        while( padlen < 0 ){
+                dopr_outch( ' ' );
+                ++padlen;
+        }
+ }
+ 
+ static void
+ dostr( str , cut)
+      char *str;
+      int cut;
+ {
+   if (cut) {
+     while(*str && cut-- > 0) dopr_outch(*str++);
+   } else {
+     while(*str) dopr_outch(*str++);
+   }
+ }
+ 
+ static void
+ dopr_outch( c )
+        int c;
+ {
+ #if 0
+        if( iscntrl(c) && c != '\n' && c != '\t' ){
+                c = '@' + (c & 0x1F);
+                if( end == 0 || output < end )
+                        *output++ = '^';
+        }
+ #endif
+        if( end == 0 || output < end )
+                *output++ = c;
+        else
+ 		SnprfOverflow++;
+ }
+ 
+ # endif /* !luna2 */
+ 
+ #endif /* !HASSNPRINTF */



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

Powered by Linux