From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hollis Blanchard 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 Message-ID: <200511071124.02430.hollisb@us.ibm.com> References: <436F8BB6.1090207@us.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <436F8BB6.1090207@us.ibm.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Ewan Mellor List-Id: xen-devel@lists.xenproject.org On Monday 07 November 2005 11:15, Anthony Liguori wrote: > >+void reopen_log() > >+{ > >+=A0=A0=A0=A0=A0=A0if (!tracefile) > >+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0return; > >+ > >+=A0=A0=A0=A0=A0=A0if (tracefd > 0) > >+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0close(tracefd); > >+=A0=A0=A0=A0=A0=A0tracefd =3D open(tracefile, O_WRONLY|O_CREAT|O_APPEND= , 0600); > >+=A0=A0=A0=A0=A0=A0if (tracefd < 0) { > >+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0perror("Could not open tracef= ile"); > >+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0return; > >+=A0=A0=A0=A0=A0=A0} > >+=A0=A0=A0=A0=A0=A0write(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=20 not in your list; your list doesn't include strtok_r either, and that is=20 explicitly thread-safe. :-P However, in addition to perror, another thread could try to use tracefd=20 between the close and the open. You'd probably want to do something like: oldfd =3D tracefd; newfd =3D open(); if (newfd < 0) { ... } tracefd =3D newfd; close(oldfd); =46inally, you really should do error-checking on close(). See the close(2)= man=20 page... =2D-=20 Hollis Blanchard IBM Linux Technology Center