X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=miscutil.c;h=ed09ff8d0f53ca14740696f4d6478a907f462049;hb=caec21aaad840031cae68e8e2a6fceab731f88e6;hp=beab02b9664cab00a139d579b3e359e61a52f22b;hpb=27e7ab19921a75f023658b07d314719875be2062;p=privoxy.git diff --git a/miscutil.c b/miscutil.c index beab02b9..ed09ff8d 100644 --- a/miscutil.c +++ b/miscutil.c @@ -1,4 +1,4 @@ -const char miscutil_rcs[] = "$Id: miscutil.c,v 1.23 2001/10/29 03:48:10 david__schmidt Exp $"; +const char miscutil_rcs[] = "$Id: miscutil.c,v 1.25 2001/11/13 00:16:38 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/miscutil.c,v $ @@ -36,6 +36,19 @@ const char miscutil_rcs[] = "$Id: miscutil.c,v 1.23 2001/10/29 03:48:10 david__s * * Revisions : * $Log: miscutil.c,v $ + * Revision 1.25 2001/11/13 00:16:38 jongfoster + * Replacing references to malloc.h with the standard stdlib.h + * (See ANSI or K&R 2nd Ed) + * + * Revision 1.24 2001/11/05 21:41:43 steudten + * Add changes to be a real daemon just for unix os. + * (change cwd to /, detach from controlling tty, set + * process group and session leader to the own process. + * Add DBG() Macro. + * Add some fatal-error log message for failed malloc(). + * Add '-d' if compiled with 'configure --with-debug' to + * enable debug output. + * * Revision 1.23 2001/10/29 03:48:10 david__schmidt * OS/2 native needed a snprintf() routine. Added one to miscutil, brackedted * by and __OS2__ ifdef. @@ -149,9 +162,12 @@ const char miscutil_rcs[] = "$Id: miscutil.c,v 1.23 2001/10/29 03:48:10 david__s #include "config.h" #include +#include #include +#if !defined(_WIN32) && !defined(__OS2__) +#include +#endif /* #if !defined(_WIN32) && !defined(__OS2__) */ #include -#include #include #include @@ -185,7 +201,52 @@ void *zalloc(int size) return(ret); } +#if defined(unix) +/********************************************************************* + * + * Function : deletePidFile + * + * Description : deletes the pid file with the pid of the main process + * + * Parameters : - + * + * Returns : - + * + *********************************************************************/ +void deletePidFile( void ) +{ + char pidfile[ 64 ]; + snprintf( pidfile, sizeof(pidfile), "%s/%s", PID_FILE_PATH, PID_FILE_NAME); + unlink( pidfile ); +} +/********************************************************************* + * + * Function : writePidFile + * + * Description : writes the pid file with the pid of the main process + * + * Parameters : - + * + * Returns : - + * + *********************************************************************/ +void writePidFile( void ) +{ + FILE *fp; + char pidfile[64]; + + snprintf( pidfile, sizeof(pidfile), "%s/%s", PID_FILE_PATH, PID_FILE_NAME); + if ((fp = fopen( pidfile,"w")) == NULL ) + { + log_error(LOG_LEVEL_INFO, "can't open pidfile '%s': %E", pidfile); + return; + } + + fprintf( fp,"%u\n", (unsigned int) getpid()); + fclose ( fp ); +} +#endif /* unix */ /********************************************************************* *