[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Make xenstored reopen its trace file on SIGHUP. This allows one to rotate the



# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID 19a226d8db165868406ba983b0bae60b9e80f14d
# Parent  1f57d567cf4b4d7d7f53bf2bb8bb11168840298b
Make xenstored reopen its trace file on SIGHUP.  This allows one to rotate the
logs beneath the daemon.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r 1f57d567cf4b -r 19a226d8db16 tools/xenstore/xenstored_core.c
--- a/tools/xenstore/xenstored_core.c   Mon Nov  7 11:05:15 2005
+++ b/tools/xenstore/xenstored_core.c   Mon Nov  7 11:28:53 2005
@@ -56,6 +56,7 @@
 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 @@
        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 @@
                        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;
@@ -1511,6 +1523,8 @@
        }
        if (optind != argc)
                barf("%s: No arguments desired", argv[0]);
+
+       reopen_log();
 
        if (dofork) {
                openlog("xenstored", 0, LOG_DAEMON);
@@ -1577,6 +1591,8 @@
                close(STDOUT_FILENO);
                close(STDERR_FILENO);
        }
+
+       signal(SIGHUP, reopen_log);
 
 #ifdef TESTING
        signal(SIGUSR1, stop_failtest);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.