ia64/xen-unstable

changeset 7643:19a226d8db16

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>
author emellor@leeni.uk.xensource.com
date Mon Nov 07 12:28:53 2005 +0100 (2005-11-07)
parents 1f57d567cf4b
children 43fbea30b5c8
files tools/xenstore/xenstored_core.c
line diff
     1.1 --- a/tools/xenstore/xenstored_core.c	Mon Nov 07 12:05:15 2005 +0100
     1.2 +++ b/tools/xenstore/xenstored_core.c	Mon Nov 07 12:28:53 2005 +0100
     1.3 @@ -56,6 +56,7 @@ extern int eventchn_fd; /* in xenstored_
     1.4  static bool verbose;
     1.5  LIST_HEAD(connections);
     1.6  static int tracefd = -1;
     1.7 +static char *tracefile = NULL;
     1.8  static TDB_CONTEXT *tdb_ctx;
     1.9  
    1.10  #ifdef TESTING
    1.11 @@ -242,6 +243,21 @@ void trace(const char *fmt, ...)
    1.12  	talloc_free(str);
    1.13  }
    1.14  
    1.15 +void reopen_log()
    1.16 +{
    1.17 +	if (!tracefile)
    1.18 +		return;
    1.19 +
    1.20 +	if (tracefd > 0)
    1.21 +		close(tracefd);
    1.22 +	tracefd = open(tracefile, O_WRONLY|O_CREAT|O_APPEND, 0600);
    1.23 +	if (tracefd < 0) {
    1.24 +		perror("Could not open tracefile");
    1.25 +		return;
    1.26 +	}
    1.27 +	write(tracefd, "\n***\n", strlen("\n***\n"));
    1.28 +}
    1.29 +
    1.30  static bool write_messages(struct connection *conn)
    1.31  {
    1.32  	int ret;
    1.33 @@ -1498,11 +1514,7 @@ int main(int argc, char *argv[])
    1.34  			outputpid = true;
    1.35  			break;
    1.36  		case 'T':
    1.37 -			tracefd = open(optarg, O_WRONLY|O_CREAT|O_APPEND, 0600);
    1.38 -			if (tracefd < 0)
    1.39 -				barf_perror("Could not open tracefile %s",
    1.40 -					    optarg);
    1.41 -                        write(tracefd, "\n***\n", strlen("\n***\n"));
    1.42 +			tracefile = optarg;
    1.43  			break;
    1.44  		case 'V':
    1.45  			verbose = true;
    1.46 @@ -1512,6 +1524,8 @@ int main(int argc, char *argv[])
    1.47  	if (optind != argc)
    1.48  		barf("%s: No arguments desired", argv[0]);
    1.49  
    1.50 +	reopen_log();
    1.51 +
    1.52  	if (dofork) {
    1.53  		openlog("xenstored", 0, LOG_DAEMON);
    1.54  		daemonize();
    1.55 @@ -1578,6 +1592,8 @@ int main(int argc, char *argv[])
    1.56  		close(STDERR_FILENO);
    1.57  	}
    1.58  
    1.59 +	signal(SIGHUP, reopen_log);
    1.60 +
    1.61  #ifdef TESTING
    1.62  	signal(SIGUSR1, stop_failtest);
    1.63  #endif