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

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

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: Re: [Xen-devel] Re: [Xen-changelog] Make xenstored reopen its trace file on SIGHUP. This allows one to rotate the
From: Hollis Blanchard <hollisb@xxxxxxxxxx>
Date: Mon, 7 Nov 2005 11:24:02 -0600
Cc: Ewan Mellor <ewan@xxxxxxxxxxxxx>
Delivery-date: Mon, 07 Nov 2005 17:25:03 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <436F8BB6.1090207@xxxxxxxxxx>
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>
Organization: IBM Linux Technology Center
References: <E1EZ6jH-0002pi-4u@xxxxxxxxxxxxxxxxxxxxx> <436F8BB6.1090207@xxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: KMail/1.8.2
On Monday 07 November 2005 11:15, Anthony Liguori 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.

I'm really not sure how strlen could be non-threadsafe. I don't care if it's 
not in your list; your list doesn't include strtok_r either, and that is 
explicitly thread-safe. :-P

However, in addition to perror, another thread could try to use tracefd 
between the close and the open. You'd probably want to do something like:
        oldfd = tracefd;
        newfd = open();
        if (newfd < 0) {
                ...
        }
        tracefd = newfd;
        close(oldfd);

Finally, you really should do error-checking on close(). See the close(2) man 
page...

-- 
Hollis Blanchard
IBM Linux Technology Center

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