[2036] in Moira Commits
/svn/moira r4178 - trunk/moira/server
daemon@ATHENA.MIT.EDU (Garry Zacheiss)
Wed Aug 27 18:59:30 2014
Date: Wed, 27 Aug 2014 18:59:24 -0400
From: Garry Zacheiss <zacheiss@mit.edu>
Message-Id: <201408272259.s7RMxOUZ029257@drugstore.mit.edu>
To: moira-commits@mit.edu
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Author: zacheiss
Date: 2014-08-27 18:59:23 -0400 (Wed, 27 Aug 2014)
New Revision: 4178
Modified:
trunk/moira/server/startmoira.c
Log:
reopen log file on SIGHUP.
Modified: trunk/moira/server/startmoira.c
===================================================================
--- trunk/moira/server/startmoira.c 2014-08-22 15:47:44 UTC (rev 4177)
+++ trunk/moira/server/startmoira.c 2014-08-27 22:59:23 UTC (rev 4178)
@@ -26,10 +26,13 @@
RCSID("$HeadURL$ $Id$");
#define PROG "moirad"
+#define MOIRAD_LOG MOIRA_DIR "/moira.log"
int rdpipe[2];
+static volatile int do_reopen;
char *whoami;
void cleanup(int signal);
+void reopen_logfile(int signal);
void cleanup(int signal)
{
@@ -61,6 +64,11 @@
errno = serrno;
}
+void reopen_logfile(int signal)
+{
+ do_reopen = 1;
+}
+
int main(int argc, char *argv[])
{
char buf[BUFSIZ];
@@ -76,13 +84,15 @@
getrlimit(RLIMIT_NOFILE, &rl);
nfds = rl.rlim_cur;
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = 0;
action.sa_handler = cleanup;
- action.sa_flags = 0;
- sigemptyset(&action.sa_mask);
sigaction(SIGCHLD, &action, NULL);
+ action.sa_flags = SA_RESTART;
+ action.sa_handler = reopen_logfile;
+ sigaction(SIGHUP, &action, NULL);
- sprintf(buf, "%s/moira.log", MOIRA_DIR);
- logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640);
+ logf = open(MOIRAD_LOG, O_CREAT|O_WRONLY|O_APPEND, 0640);
if (logf < 0)
{
perror(buf);
@@ -135,6 +145,21 @@
done = 0;
errno = 0;
+
+ if (do_reopen)
+ {
+ fclose(log);
+ close(logf);
+ logf = open(MOIRAD_LOG, O_CREAT|O_WRONLY|O_APPEND, 0640);
+ if (logf < 0)
+ {
+ perror(buf);
+ exit(1);
+ }
+ log = fdopen(logf, "w");
+ do_reopen = 0;
+ }
+
if (!fgets(buf, BUFSIZ, prog))
{
if (errno && errno != EINTR)
@@ -146,6 +171,7 @@
else
break;
}
+
time(&now);
time_s = ctime(&now) + 4;
time_s[strlen(time_s) - 6] = '\0';