From: <ca...@us...> - 2009-04-06 02:22:08
|
Revision: 1990 http://ganglia.svn.sourceforge.net/ganglia/?rev=1990&view=rev Author: carenas Date: 2009-04-06 01:32:42 +0000 (Mon, 06 Apr 2009) Log Message: ----------- gmetad: daemon_init moved from libganglia daemon_init is only used by gmetad and once umask restrictions were added makes more sense as an internal object Modified Paths: -------------- trunk/monitor-core/gmetad/Makefile.am trunk/monitor-core/lib/Makefile.am Added Paths: ----------- trunk/monitor-core/gmetad/daemon_init.c trunk/monitor-core/gmetad/daemon_init.h Removed Paths: ------------- trunk/monitor-core/lib/daemon_init.c trunk/monitor-core/lib/daemon_init.h Modified: trunk/monitor-core/gmetad/Makefile.am =================================================================== --- trunk/monitor-core/gmetad/Makefile.am 2009-04-06 00:50:42 UTC (rev 1989) +++ trunk/monitor-core/gmetad/Makefile.am 2009-04-06 01:32:42 UTC (rev 1990) @@ -13,7 +13,7 @@ sbin_PROGRAMS = gmetad gmetad_SOURCES = gmetad.c cmdline.c cmdline.h gmetad.h data_thread.c \ server.c process_xml.c rrd_helpers.c conf.c conf.h type_hash.c \ - xml_hash.c cleanup.c rrd_helpers.h + xml_hash.c cleanup.c rrd_helpers.h daemon_init.c daemon_init.h gmetad_LDADD = $(top_builddir)/lib/libganglia.la -lrrd -lm \ $(GLDADD) Copied: trunk/monitor-core/gmetad/daemon_init.c (from rev 1989, trunk/monitor-core/lib/daemon_init.c) =================================================================== --- trunk/monitor-core/gmetad/daemon_init.c (rev 0) +++ trunk/monitor-core/gmetad/daemon_init.c 2009-04-06 01:32:42 UTC (rev 1990) @@ -0,0 +1,54 @@ +/** + * @file daemon_init.c Functions for standalone daemons + */ +/* $Id$ */ +#include <sys/types.h> +#include <sys/stat.h> +#include <stdlib.h> +#include <unistd.h> +#include <signal.h> +#include <syslog.h> +#include "daemon_init.h" + +#define MAXFD 64 + +extern int daemon_proc; /* defined in error_msg.c */ + +/** + * @fn void daemon_init (const char *pname, int facility) + * @param pname The name of your program + * @param facility See the openlog() manpage for details + */ +void +daemon_init (const char *pname, int facility) +{ + int i; + pid_t pid; + mode_t prev_umask; + + pid = fork(); + + if (pid != 0) + exit (0); /* parent terminates */ + + /* 41st child continues */ + setsid (); /* become session leader */ + + signal (SIGHUP, SIG_IGN); + if ((pid = fork ()) != 0) + exit (0); /* 1st child terminates */ + + /* 42nd child continues */ + daemon_proc = 1; /* for our err_XXX() functions */ + + i = chdir ("/"); /* change working directory */ + + /* set our file mode creation mask */ + prev_umask = umask(022); + umask( prev_umask | 022); + + for (i = 0; i < MAXFD; i++) + close (i); + + openlog (pname, LOG_PID, facility); +} Copied: trunk/monitor-core/gmetad/daemon_init.h (from rev 1989, trunk/monitor-core/lib/daemon_init.h) =================================================================== --- trunk/monitor-core/gmetad/daemon_init.h (rev 0) +++ trunk/monitor-core/gmetad/daemon_init.h 2009-04-06 01:32:42 UTC (rev 1990) @@ -0,0 +1,6 @@ +#ifndef DAEMON_INIT_H +#define DAEMON_INIT_H 1 + +void daemon_init (const char *pname, int facility); + +#endif Modified: trunk/monitor-core/lib/Makefile.am =================================================================== --- trunk/monitor-core/lib/Makefile.am 2009-04-06 00:50:42 UTC (rev 1989) +++ trunk/monitor-core/lib/Makefile.am 2009-04-06 01:32:42 UTC (rev 1990) @@ -23,8 +23,7 @@ lib_LTLIBRARIES = libganglia.la libganglia_la_SOURCES = gm_protocol_xdr.c gm_protocol.h \ become_a_nobody.c become_a_nobody.h \ -debug_msg.c daemon_init.c daemon_init.h update_pidfile.c update_pidfile.h \ -file.c file.h \ +debug_msg.c update_pidfile.c update_pidfile.h file.c file.h \ dotconf.c dotconf.h error_msg.c ganglia_priv.h \ ganglia.c hash.c hash.h inetaddr.c llist.c llist.h \ my_inet_ntop.c my_inet_ntop.h net.h rdwr.c rdwr.h readdir.c readdir.h tcp.c \ Deleted: trunk/monitor-core/lib/daemon_init.c =================================================================== --- trunk/monitor-core/lib/daemon_init.c 2009-04-06 00:50:42 UTC (rev 1989) +++ trunk/monitor-core/lib/daemon_init.c 2009-04-06 01:32:42 UTC (rev 1990) @@ -1,54 +0,0 @@ -/** - * @file daemon_init.c Functions for standalone daemons - */ -/* $Id$ */ -#include <sys/types.h> -#include <sys/stat.h> -#include <stdlib.h> -#include <unistd.h> -#include <signal.h> -#include <syslog.h> -#include "daemon_init.h" - -#define MAXFD 64 - -extern int daemon_proc; /* defined in error_msg.c */ - -/** - * @fn void daemon_init (const char *pname, int facility) - * @param pname The name of your program - * @param facility See the openlog() manpage for details - */ -void -daemon_init (const char *pname, int facility) -{ - int i; - pid_t pid; - mode_t prev_umask; - - pid = fork(); - - if (pid != 0) - exit (0); /* parent terminates */ - - /* 41st child continues */ - setsid (); /* become session leader */ - - signal (SIGHUP, SIG_IGN); - if ((pid = fork ()) != 0) - exit (0); /* 1st child terminates */ - - /* 42nd child continues */ - daemon_proc = 1; /* for our err_XXX() functions */ - - i = chdir ("/"); /* change working directory */ - - /* set our file mode creation mask */ - prev_umask = umask(022); - umask( prev_umask | 022); - - for (i = 0; i < MAXFD; i++) - close (i); - - openlog (pname, LOG_PID, facility); -} Deleted: trunk/monitor-core/lib/daemon_init.h =================================================================== --- trunk/monitor-core/lib/daemon_init.h 2009-04-06 00:50:42 UTC (rev 1989) +++ trunk/monitor-core/lib/daemon_init.h 2009-04-06 01:32:42 UTC (rev 1990) @@ -1,6 +0,0 @@ -#ifndef DAEMON_INIT_H -#define DAEMON_INIT_H 1 - -void daemon_init (const char *pname, int facility); - -#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |