* Re: [Xen-changelog] Make xenstored reopen its trace file on SIGHUP. This allows one to rotate the
[not found] <E1EZ6jH-0002pi-4u@xenbits.xensource.com>
@ 2005-11-07 17:15 ` Anthony Liguori
2005-11-07 17:23 ` Ewan Mellor
2005-11-07 17:24 ` Hollis Blanchard
0 siblings, 2 replies; 4+ messages in thread
From: Anthony Liguori @ 2005-11-07 17:15 UTC (permalink / raw)
To: xen-devel; +Cc: Ewan Mellor
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@lists.xensource.com
>http://lists.xensource.com/xen-changelog
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xen-changelog] Make xenstored reopen its trace file on SIGHUP. This allows one to rotate the
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
1 sibling, 0 replies; 4+ messages in thread
From: Ewan Mellor @ 2005-11-07 17:23 UTC (permalink / raw)
To: Anthony Liguori; +Cc: xen-devel
On Mon, Nov 07, 2005 at 11:15:34AM -0600, Anthony Liguori wrote:
> 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.
OK, I'll believe you about perror - thanks for spotting that.
Why, though, should strlen not be safe? Even if strlen(constant) doesn't turn
into a constant integer at compile-time, which I rather hope that it would,
why in any case would strlen be a problem?
Ewan.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Re: [Xen-changelog] Make xenstored reopen its trace file on SIGHUP. This allows one to rotate the
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
2005-11-07 17:36 ` Anthony Liguori
1 sibling, 1 reply; 4+ messages in thread
From: Hollis Blanchard @ 2005-11-07 17:24 UTC (permalink / raw)
To: xen-devel; +Cc: Ewan Mellor
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Re: [Xen-changelog] Make xenstored reopen its trace file on SIGHUP. This allows one to rotate the
2005-11-07 17:24 ` Hollis Blanchard
@ 2005-11-07 17:36 ` Anthony Liguori
0 siblings, 0 replies; 4+ messages in thread
From: Anthony Liguori @ 2005-11-07 17:36 UTC (permalink / raw)
To: Hollis Blanchard; +Cc: xen-devel, Ewan Mellor
Hollis Blanchard wrote:
>On Monday 07 November 2005 11:15, Anthony Liguori wrote:
>
>
>>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
>
>
So re-reading the manpage, the list of safe functions is a POSIX-ism.
That's perhaps why the thread-safe string functions aren't there since
those are defined by ANSI not POSIX.
Regards,
Anthony Liguori
>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...
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-11-07 17:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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
2005-11-07 17:36 ` Anthony Liguori
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.