From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11403 Path: news.gmane.org!.POSTED!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: tmpfile patch Date: Thu, 8 Jun 2017 22:15:55 +0200 Message-ID: <20170608201555.GR9350@port70.net> References: <1c4f252e-9c13-9d52-f966-a186216a8396@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1496952973 27203 195.159.176.226 (8 Jun 2017 20:16:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 8 Jun 2017 20:16:13 +0000 (UTC) User-Agent: Mutt/1.6.0 (2016-04-01) To: musl@lists.openwall.com Original-X-From: musl-return-11416-gllmg-musl=m.gmane.org@lists.openwall.com Thu Jun 08 22:16:06 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dJ3qf-0006gH-5B for gllmg-musl@m.gmane.org; Thu, 08 Jun 2017 22:16:05 +0200 Original-Received: (qmail 28133 invoked by uid 550); 8 Jun 2017 20:16:08 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 28115 invoked from network); 8 Jun 2017 20:16:07 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: <1c4f252e-9c13-9d52-f966-a186216a8396@gmail.com> Xref: news.gmane.org gmane.linux.lib.musl.general:11403 Archived-At: * Petr Sko=C4=8D=C3=ADk [2017-06-08 20:01:53 +0200]: > Hi, > I made a patch to tmpfile() to make it signal-proof and use > O_TMPFILE if it can. >=20 > Best Regards, > Petr Skocik > diff --git a/src/stdio/tmpfile.c b/src/stdio/tmpfile.c > index 525090aa..34c3d487 100644 > --- a/src/stdio/tmpfile.c > +++ b/src/stdio/tmpfile.c > @@ -1,6 +1,7 @@ > #include > #include > #include "stdio_impl.h" > +#include "pthread_impl.h" > =20 > #define MAXTRIES 100 > =20 > @@ -8,10 +9,23 @@ char *__randname(char *); > =20 > FILE *tmpfile(void) > { > +#ifdef O_TMPFILE i don't think this ifdef helps, kernel support for O_TMPFILE can only be detected at runtime, you will get ENOSYS on an old kernel. > + int fd; > + FILE *f =3D 0; > + fd =3D sys_open("/tmp", O_RDWR|O_TMPFILE); > + if (fd >=3D 0) { > + f =3D __fdopen(fd, "w+"); > + if (!f) __syscall(SYS_close, fd); > + } > + return f; > +#else > char s[] =3D "/tmp/tmpfile_XXXXXX"; > + FILE *f =3D 0; > int fd; > - FILE *f; > int try; > + sigset_t saved_mask; > + > + pthread_sigmask(SIG_SETMASK, SIGALL_SET, &saved_mask); > for (try=3D0; try __randname(s+13); > fd =3D sys_open(s, O_RDWR|O_CREAT|O_EXCL, 0600); > @@ -21,12 +35,15 @@ FILE *tmpfile(void) > #else > __syscall(SYS_unlinkat, AT_FDCWD, s, 0); > #endif > + pthread_sigmask(SIG_SETMASK, &saved_mask, 0); > f =3D __fdopen(fd, "w+"); > if (!f) __syscall(SYS_close, fd); > return f; > } > } > + pthread_sigmask(SIG_SETMASK, &saved_mask, 0); > return 0; > +#endif /*O_TMPFILE*/ > } > =20 > LFS64(tmpfile);