{"id":808403,"url":"http://patchwork.ozlabs.org/api/patches/808403/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/patch/1504211656-9263-1-git-send-email-adhemerval.zanella@linaro.org/","project":{"id":41,"url":"http://patchwork.ozlabs.org/api/projects/41/?format=json","name":"GNU C Library","link_name":"glibc","list_id":"libc-alpha.sourceware.org","list_email":"libc-alpha@sourceware.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1504211656-9263-1-git-send-email-adhemerval.zanella@linaro.org>","list_archive_url":null,"date":"2017-08-31T20:34:16","name":"linux: Implement tmpfile with O_TMPFILE (BZ#21530)","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"bcb29137ceeecdacbd127659ab21044c621fd5d8","submitter":{"id":66065,"url":"http://patchwork.ozlabs.org/api/people/66065/?format=json","name":"Adhemerval Zanella Netto","email":"adhemerval.zanella@linaro.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/glibc/patch/1504211656-9263-1-git-send-email-adhemerval.zanella@linaro.org/mbox/","series":[{"id":903,"url":"http://patchwork.ozlabs.org/api/series/903/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/list/?series=903","date":"2017-08-31T20:34:16","name":"linux: Implement tmpfile with O_TMPFILE (BZ#21530)","version":1,"mbox":"http://patchwork.ozlabs.org/series/903/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/808403/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/808403/checks/","tags":{},"related":[],"headers":{"Return-Path":"<libc-alpha-return-83999-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-83999-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"CuCHYJ3P\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xjvHW6XSNz9s8P\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  1 Sep 2017 06:34:31 +1000 (AEST)","(qmail 60030 invoked by alias); 31 Aug 2017 20:34:25 -0000","(qmail 60020 invoked by uid 89); 31 Aug 2017 20:34:25 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:from:to:subject:date:message-id; q=dns; s=\n\tdefault; b=Ow9VIHxkTBuSUMwNlnI77zqaznmj7dGdEOEuls+rYDJz4zFifdRIu\n\tkg2fa4q7YcWXUD1PQd4lrzHLRSjTiTQ7Bvbq8enoqjVHaPIRVwEa78fHMtek8Eo4\n\thdFAaP9d8m0W6EFxSQPzuFylJRIkMHAH4D2AX7xymDmv1/FOLUjhsA=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:from:to:subject:date:message-id; s=default;\n\tbh=u29+XIqlO7VH5JRm28nM62Gx7/c=; b=CuCHYJ3PEV81w/oO7nRk0VE2Kewa\n\tA4ZvtJdSUUgJ4bV1HIeib1OEaU/uu0sXd8j7wCuSf4urW7LlENyUcp4GTooATBxC\n\tQrE5VSxuiOOYFSXmJCMdqTcnrFPnJOgd7gh75GTF7IXYgHnSL4FD5EZDHdpb7UdC\n\txu8kpSavuAR9UQI=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0,\n\tGIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE,\n\tRCVD_IN_SORBS_SPAM,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=","X-HELO":"mail-qt0-f173.google.com","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:subject:date:message-id;\n\tbh=TRM1kyMcyf9+MfNMeRD2nZvei9tmk2X+EkOEsFaC/4Y=;\n\tb=tMfx+ccvxngsRkSL67WBnyfAe8rVOVoGdZlZiHtIQB7GMGfOtvaU6SxkvCu5t2VaIC\n\tX/enObdpqWRKcX+ctY5gp9na+8Qbxb+kfcOBfqoeKAhoXo3dTorKP2jUOk1b79TWipc4\n\tYHuF7dsuYjUtN3hH+Y0muBzqU62Xp0MgN/ttRDa8uJvagLGjbpd6YjtcgDkgKutP1H0a\n\tZC7JA3QEAZneAzwiqvQuqz1boxYg05vmHzvBimLK6CAD5fGzWfncqFs254jZjik8RbaX\n\taG0A0i7PmwAupL+sfHdbvFYwMGo0UbuwCglby1qFRR+AFAjZFzxY49YMBFkrZe4WoxRa\n\txxjg==","X-Gm-Message-State":"AHYfb5hFGNe3BMNCOE8GBVyGgTrgoCMZLWpF4lE2ZYzald/moYxmGLzu\n\tj0XBU4oaCgK2RMRzJEIs6Q==","X-Google-Smtp-Source":"ADKCNb4nMgzMWGOFqYnaeRNO1Wml6LWcCOwnle7VkqXATXqNjypQim9+xnMh7hrTcNE07wy4e0zW7Q==","X-Received":"by 10.237.51.35 with SMTP id u32mr9059829qtd.207.1504211661559; \n\tThu, 31 Aug 2017 13:34:21 -0700 (PDT)","From":"Adhemerval Zanella <adhemerval.zanella@linaro.org>","To":"libc-alpha@sourceware.org","Subject":"[PATCH] linux: Implement tmpfile with O_TMPFILE (BZ#21530)","Date":"Thu, 31 Aug 2017 17:34:16 -0300","Message-Id":"<1504211656-9263-1-git-send-email-adhemerval.zanella@linaro.org>"},"content":"This patch adds support to use O_TMPFILE on tmpfile on Linux.  This is\nsimilar previous suggestion by Andreas Schwab [1] with the difference\nthe file descriptor creation is parameterized to compartmentalize Linux\nonly open flags (O_TMPFILE) on sysdep folder.\n\nChecked on x86_64-linux-gnu.\n\n\tAdhemerval Zanella  <adhemerval.zanella@linaro.org>\n\tAndreas Schwab  <schwab@suse.de>\n\n\t[BZ #21530]\n\t* include/stdio.h (__gen_tempfd): New function.\n\t* stdio-common/Makefile (routines): Add gentempfd.\n\t* stdio-common/gentempfd.c: New file.\n\t* sysdeps/unix/sysv/linux/gentempfd.c: Likewise.\n\t* stdio-common/tmpfile.c (tmpfile): First try to use a system specific\n\tunnamed file first.\n\n[1] https://sourceware.org/ml/libc-alpha/2017-06/msg01293.html\n---\n ChangeLog                           | 11 +++++++++++\n include/stdio.h                     |  3 +++\n stdio-common/Makefile               |  2 +-\n stdio-common/gentempfd.c            | 26 ++++++++++++++++++++++++++\n stdio-common/tmpfile.c              | 29 ++++++++++++++++++++---------\n sysdeps/unix/sysv/linux/gentempfd.c | 34 ++++++++++++++++++++++++++++++++++\n 6 files changed, 95 insertions(+), 10 deletions(-)\n create mode 100644 stdio-common/gentempfd.c\n create mode 100644 sysdeps/unix/sysv/linux/gentempfd.c","diff":"diff --git a/include/stdio.h b/include/stdio.h\nindex 509447c..87e0e10 100644\n--- a/include/stdio.h\n+++ b/include/stdio.h\n@@ -191,5 +191,8 @@ libc_hidden_proto (__obstack_vprintf_chk)\n extern FILE * __fmemopen (void *buf, size_t len, const char *mode);\n libc_hidden_proto (__fmemopen)\n \n+extern int __gen_tempfd (int flags);\n+libc_hidden_proto (__gen_tempfd)\n+\n # endif /* not _ISOMAC */\n #endif /* stdio.h */\ndiff --git a/stdio-common/Makefile b/stdio-common/Makefile\nindex 397e0c2..2c3c2e5 100644\n--- a/stdio-common/Makefile\n+++ b/stdio-common/Makefile\n@@ -39,7 +39,7 @@ routines\t:=\t\t\t\t\t\t\t      \\\n \tflockfile ftrylockfile funlockfile\t\t\t\t      \\\n \tisoc99_scanf isoc99_vscanf isoc99_fscanf isoc99_vfscanf isoc99_sscanf \\\n \tisoc99_vsscanf\t\t\t\t\t\t\t      \\\n-\tpsiginfo\n+\tpsiginfo gentempfd\n \n aux\t:= errlist siglist printf-parsemb printf-parsewc fxprintf\n \ndiff --git a/stdio-common/gentempfd.c b/stdio-common/gentempfd.c\nnew file mode 100644\nindex 0000000..d40c57d\n--- /dev/null\n+++ b/stdio-common/gentempfd.c\n@@ -0,0 +1,26 @@\n+/* Generate a temporary file descriptor.  Generic/POSIX version.\n+   Copyright (C) 2017 Free Software Foundation, Inc.\n+   This file is part of the GNU C Library.\n+\n+   The GNU C Library is free software; you can redistribute it and/or\n+   modify it under the terms of the GNU Lesser General Public\n+   License as published by the Free Software Foundation; either\n+   version 2.1 of the License, or (at your option) any later version.\n+\n+   The GNU C Library is distributed in the hope that it will be useful,\n+   but WITHOUT ANY WARRANTY; without even the implied warranty of\n+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+   Lesser General Public License for more details.\n+\n+   You should have received a copy of the GNU Lesser General Public\n+   License along with the GNU C Library; if not, see\n+   <http://www.gnu.org/licenses/>.  */\n+\n+#include <stdio.h>\n+\n+int\n+__gen_tempfd (int flags)\n+{\n+  return -1;\n+}\n+libc_hidden_def (__gen_tempfd)\ndiff --git a/stdio-common/tmpfile.c b/stdio-common/tmpfile.c\nindex e6030be..3e35345 100644\n--- a/stdio-common/tmpfile.c\n+++ b/stdio-common/tmpfile.c\n@@ -34,23 +34,34 @@\n FILE *\n tmpfile (void)\n {\n-  char buf[FILENAME_MAX];\n   int fd;\n   FILE *f;\n-\n-  if (__path_search (buf, FILENAME_MAX, NULL, \"tmpf\", 0))\n-    return NULL;\n   int flags = 0;\n #ifdef FLAGS\n   flags = FLAGS;\n #endif\n-  fd = __gen_tempname (buf, 0, flags, __GT_FILE);\n+\n+  /* First try a system specific method.  */\n+  fd = __gen_tempfd (flags);\n+\n   if (fd < 0)\n-    return NULL;\n+    {\n+      char buf[FILENAME_MAX];\n \n-  /* Note that this relies on the Unix semantics that\n-     a file is not really removed until it is closed.  */\n-  (void) __unlink (buf);\n+      if (__path_search (buf, sizeof buf, NULL, \"tmpf\", 0))\n+\treturn NULL;\n+\n+      fd = __gen_tempname (buf, 0, flags, __GT_FILE);\n+      if (fd < 0)\n+\treturn NULL;\n+\n+      /* Note that this relies on the Unix semantics that\n+\t a file is not really removed until it is closed.  */\n+      (void) __unlink (buf);\n+    }\n+\n+  if (fd < 0)\n+    return NULL;\n \n   if ((f = __fdopen (fd, \"w+b\")) == NULL)\n     __close (fd);\ndiff --git a/sysdeps/unix/sysv/linux/gentempfd.c b/sysdeps/unix/sysv/linux/gentempfd.c\nnew file mode 100644\nindex 0000000..902cbe2\n--- /dev/null\n+++ b/sysdeps/unix/sysv/linux/gentempfd.c\n@@ -0,0 +1,34 @@\n+/* Generate a temporary file descriptor.  Linux version.\n+   Copyright (C) 2017 Free Software Foundation, Inc.\n+   This file is part of the GNU C Library.\n+\n+   The GNU C Library is free software; you can redistribute it and/or\n+   modify it under the terms of the GNU Lesser General Public\n+   License as published by the Free Software Foundation; either\n+   version 2.1 of the License, or (at your option) any later version.\n+\n+   The GNU C Library is distributed in the hope that it will be useful,\n+   but WITHOUT ANY WARRANTY; without even the implied warranty of\n+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+   Lesser General Public License for more details.\n+\n+   You should have received a copy of the GNU Lesser General Public\n+   License along with the GNU C Library; if not, see\n+   <http://www.gnu.org/licenses/>.  */\n+\n+#include <stdio.h>\n+#include <fcntl.h>\n+#include <errno.h>\n+\n+int\n+__gen_tempfd (int flags)\n+{\n+  int fd = __open (P_tmpdir, O_RDWR | O_TMPFILE | O_EXCL | flags,\n+\t\t   S_IRUSR | S_IWUSR);\n+  if (fd < 0 && errno == ENOENT && strcmp (P_tmpdir, \"/tmp\") != 0)\n+    fd = __open (\"/tmp\", O_RDWR | O_TMPFILE | O_EXCL | flags,\n+\t\t S_IRUSR | S_IWUSR);\n+\n+  return fd;\n+}\n+libc_hidden_def (__gen_tempfd)\n","prefixes":[]}