aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenstore/xenstored_core.c
diff options
context:
space:
mode:
authoremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>2005-11-07 12:28:53 +0100
committeremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>2005-11-07 12:28:53 +0100
commit0fad7c81521a6052b5328c87f3c41e4e4d066c51 (patch)
tree97155ad71fcd8633a54b6073935fb917248521e2 /tools/xenstore/xenstored_core.c
parent12f3d679c665c0145021da0ca29e1b6de0447d9e (diff)
downloadxen-0fad7c81521a6052b5328c87f3c41e4e4d066c51.tar.gz
xen-0fad7c81521a6052b5328c87f3c41e4e4d066c51.tar.bz2
xen-0fad7c81521a6052b5328c87f3c41e4e4d066c51.zip
Make xenstored reopen its trace file on SIGHUP. This allows one to rotate the
logs beneath the daemon. Signed-off-by: Ewan Mellor <ewan@xensource.com>
Diffstat (limited to 'tools/xenstore/xenstored_core.c')
-rw-r--r--tools/xenstore/xenstored_core.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 4dcdb52ef4..268e859108 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -56,6 +56,7 @@ extern int eventchn_fd; /* in xenstored_domain.c */
static bool verbose;
LIST_HEAD(connections);
static int tracefd = -1;
+static char *tracefile = NULL;
static TDB_CONTEXT *tdb_ctx;
#ifdef TESTING
@@ -242,6 +243,21 @@ void trace(const char *fmt, ...)
talloc_free(str);
}
+void reopen_log()
+{
+ if (!tracefile)
+ return;
+
+ if (tracefd > 0)
+ close(tracefd);
+ tracefd = open(tracefile, O_WRONLY|O_CREAT|O_APPEND, 0600);
+ if (tracefd < 0) {
+ perror("Could not open tracefile");
+ return;
+ }
+ write(tracefd, "\n***\n", strlen("\n***\n"));
+}
+
static bool write_messages(struct connection *conn)
{
int ret;
@@ -1498,11 +1514,7 @@ int main(int argc, char *argv[])
outputpid = true;
break;
case 'T':
- tracefd = open(optarg, O_WRONLY|O_CREAT|O_APPEND, 0600);
- if (tracefd < 0)
- barf_perror("Could not open tracefile %s",
- optarg);
- write(tracefd, "\n***\n", strlen("\n***\n"));
+ tracefile = optarg;
break;
case 'V':
verbose = true;
@@ -1512,6 +1524,8 @@ int main(int argc, char *argv[])
if (optind != argc)
barf("%s: No arguments desired", argv[0]);
+ reopen_log();
+
if (dofork) {
openlog("xenstored", 0, LOG_DAEMON);
daemonize();
@@ -1578,6 +1592,8 @@ int main(int argc, char *argv[])
close(STDERR_FILENO);
}
+ signal(SIGHUP, reopen_log);
+
#ifdef TESTING
signal(SIGUSR1, stop_failtest);
#endif