[Initng-svn] r2667 - initng/plugins/pidfile
svn at initng.thinktux.net
svn at initng.thinktux.net
Mon Jan 2 14:13:08 CET 2006
Author: makomk
Date: Mon Jan 2 14:13:07 2006
New Revision: 2667
Modified:
initng/plugins/pidfile/initng_pidfile.c
Log:
Rate-limit pidfile warnings
Modified: initng/plugins/pidfile/initng_pidfile.c
==============================================================================
--- initng/plugins/pidfile/initng_pidfile.c (original)
+++ initng/plugins/pidfile/initng_pidfile.c Mon Jan 2 14:13:07 2006
@@ -47,6 +47,9 @@
*/
#define PID_TIMEOUT 10
+/* Rate limit on missing pidfile warnings */
+#define PID_WARN_RATE 2
+
/* The name of the process, initng should probe */
s_entry PIDOF = { "pid_of", STRING, &TYPE_DAEMON,
"When daemon exits, initng will look for a process with this name, and set daemon pid no to that pid."
@@ -68,6 +71,7 @@
*/
s_entry INTERNAL_GOT_PID = { NULL, SET, 0, NULL, NULL };
s_entry INTERNAL_PIDFILE_TIMEOUT = { NULL, INT, 0, NULL, NULL };
+s_entry INTERNAL_PID_WARN_TIME = { NULL, INT, 0, NULL, NULL };
static int clear_pidfile(active_db_h * s);
static void pid_try(active_db_h * service);
@@ -196,6 +200,7 @@
/* it doesn't fork and return, so don't wait for it to die */
initng_common_mark_service(s, &WAIT_FOR_PID_FILE);
initng_active_db_set_int(&INTERNAL_PIDFILE_TIMEOUT, s, 0);
+ initng_active_db_set_int(&INTERNAL_PID_WARN_TIME, s, (int) time(0));
return (FALSE);
}
else
@@ -212,7 +217,7 @@
* Check if a pidfile exists, if it exists, update the
* pid in the active_db entry. and return TRUE
*/
-static pid_t pid_from_file(const char *name)
+static pid_t pid_from_file(const char *name, int warn)
{
int fd = 0;
int len = 0;
@@ -226,7 +231,8 @@
/* If we cant open pidfile, this is bad */
if (fd == -1)
{
- W_("Unable to open pidfile: %s, \"%s\", it might not be created yet.\n", name, strerror(errno));
+ if(warn)
+ W_("Unable to open pidfile: %s, \"%s\", it might not be created yet.\n", name, strerror(errno));
return (-1);
}
@@ -270,7 +276,7 @@
}
/* this will get the pid of PIDFILE entry of service */
-static pid_t get_pidfile(active_db_h * s)
+static pid_t get_pidfile(active_db_h * s, int warn)
{
pid_t pid;
const char *pidfile = NULL;
@@ -287,7 +293,7 @@
return (-1);
/* get the pid from the file */
- pid = pid_from_file(pidfile_fixed);
+ pid = pid_from_file(pidfile_fixed, warn);
free(pidfile_fixed);
/* return the pid */
@@ -336,6 +342,7 @@
initng_common_mark_service(s, &WAIT_FOR_PID_FILE);
/* set the timeout also */
initng_active_db_set_int(&INTERNAL_PIDFILE_TIMEOUT, s, (int) time(0) + PID_TIMEOUT);
+ initng_active_db_set_int(&INTERNAL_PID_WARN_TIME, s, (int) time(0));
return (TRUE);
}
@@ -374,7 +381,7 @@
{
pid_t pid = -1;
process_h *p = NULL;
- int timeout = 0;
+ int timeout = 0, wt, warn = 0;
timeout = initng_active_db_get_int(&INTERNAL_PIDFILE_TIMEOUT, s);
@@ -385,6 +392,13 @@
return;
}
+ wt = initng_active_db_get_int(&INTERNAL_PID_WARN_TIME, s);
+ if(wt > time(0) || (wt + PID_WARN_RATE) < time(0))
+ {
+ warn = 1;
+ initng_active_db_set_int(&INTERNAL_PID_WARN_TIME, s, (int) time(0));
+ }
+
/* get the process to handle */
p = initng_process_db_get(&T_DAEMON, s);
if (!p)
@@ -406,7 +420,7 @@
if (initng_active_db_is(&PIDFILE, s))
{
D_("getting pid by PIDFILE!\n");
- pid = get_pidfile(s);
+ pid = get_pidfile(s, warn);
D_("result : %d\n", pid);
}
More information about the Initng-svn
mailing list