From: Hollis Blanchard <hollisb@us.ibm.com>
To: xen-devel@lists.xensource.com
Cc: Ewan Mellor <ewan@xensource.com>
Subject: Re: Re: [Xen-changelog] Make xenstored reopen its trace file on SIGHUP. This allows one to rotate the
Date: Mon, 7 Nov 2005 11:24:02 -0600 [thread overview]
Message-ID: <200511071124.02430.hollisb@us.ibm.com> (raw)
In-Reply-To: <436F8BB6.1090207@us.ibm.com>
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
next prev parent reply other threads:[~2005-11-07 17:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <E1EZ6jH-0002pi-4u@xenbits.xensource.com>
2005-11-07 17:15 ` [Xen-changelog] Make xenstored reopen its trace file on SIGHUP. This allows one to rotate the Anthony Liguori
2005-11-07 17:23 ` Ewan Mellor
2005-11-07 17:24 ` Hollis Blanchard [this message]
2005-11-07 17:36 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200511071124.02430.hollisb@us.ibm.com \
--to=hollisb@us.ibm.com \
--cc=ewan@xensource.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.