WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] Re: [Xen-changelog] Make xenstored reopen its trace file on

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] Re: [Xen-changelog] Make xenstored reopen its trace file on SIGHUP. This allows one to rotate the
From: Anthony Liguori <aliguori@xxxxxxxxxx>
Date: Mon, 07 Nov 2005 11:15:34 -0600
Cc: Ewan Mellor <ewan@xxxxxxxxxxxxx>
Delivery-date: Mon, 07 Nov 2005 17:16:00 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <E1EZ6jH-0002pi-4u@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <E1EZ6jH-0002pi-4u@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla Thunderbird 1.0.7 (X11/20051013)
Xen patchbot -unstable wrote:


+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"));
+}
+
perror and strlen are not safe to call from a signal handler.

I suggest just removing the perror call altogether and replacing strlen with sizeof() - 1.

Regards,

Anthony Liguori

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



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