I noticed that gdb could leak file descriptors coming from mkstemp.
This patch fixes the problem by importing the gnulib mkostemp instead,
and then changing gdb to pass O_CLOEXEC.
A small gnulib patch was needed. This has already been accepted
upstream.
gdb/ChangeLog
2018-10-27 Tom Tromey <tom@tromey.com>
* unittests/scoped_mmap-selftests.c (test_normal): Use
gdb_mkostemp_cloexec.
* unittests/scoped_fd-selftests.c (test_destroy, test_release):
Use gdb_mkostemp_cloexec.
* gnulib/aclocal-m4-deps.mk, gnulib/aclocal.m4,
gnulib/config.in, gnulib/configure,
gnulib/import/Makefile.am, gnulib/import/Makefile.in,
gnulib/import/m4/gnulib-cache.m4,
gnulib/import/m4/gnulib-comp.m4: Update.
* gnulib/import/m4/mkostemp.m4: New file.
* gnulib/import/m4/mkstemp.m4: Remove.
* gnulib/import/mkostemp.c: New file.
* gnulib/import/mkstemp.m4: Remove.
* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Remove
mkstemp, add mkostemp. Apply new patch.
* gnulib/import/stdlib.in.h: Apply patch.
* gnulib/patches/0002-mkostemp-mkostemps-Fix-compilation-error-in-C-mode-o.patch:
New file.
* dwarf-index-write.c (write_psymtabs_to_index): Use
gdb_mkostemp_cloexec.
* common/filestuff.h (gdb_mkostemp_cloexec): New function.
+2018-10-27 Tom Tromey <tom@tromey.com>
+
+ * unittests/scoped_mmap-selftests.c (test_normal): Use
+ gdb_mkostemp_cloexec.
+ * unittests/scoped_fd-selftests.c (test_destroy, test_release):
+ Use gdb_mkostemp_cloexec.
+ * gnulib/aclocal-m4-deps.mk, gnulib/aclocal.m4,
+ gnulib/config.in, gnulib/configure,
+ gnulib/import/Makefile.am, gnulib/import/Makefile.in,
+ gnulib/import/m4/gnulib-cache.m4,
+ gnulib/import/m4/gnulib-comp.m4: Update.
+ * gnulib/import/m4/mkostemp.m4: New file.
+ * gnulib/import/m4/mkstemp.m4: Remove.
+ * gnulib/import/mkostemp.c: New file.
+ * gnulib/import/mkstemp.m4: Remove.
+ * gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Remove
+ mkstemp, add mkostemp. Apply new patch.
+ * gnulib/import/stdlib.in.h: Apply patch.
+ * gnulib/patches/0002-mkostemp-mkostemps-Fix-compilation-error-in-C-mode-o.patch:
+ New file.
+ * dwarf-index-write.c (write_psymtabs_to_index): Use
+ gdb_mkostemp_cloexec.
+ * common/filestuff.h (gdb_mkostemp_cloexec): New function.
+
2018-10-27 Tom Tromey <tom@tromey.com>
* unittests/mkdir-recursive-selftests.c: New file.
#define FILESTUFF_H
#include <dirent.h>
+#include <fcntl.h>
/* Note all the file descriptors which are open when this is called.
These file descriptors will not be closed by close_most_fds. */
extern int gdb_open_cloexec (const char *filename, int flags,
/* mode_t */ unsigned long mode);
+/* Like mkstemp, but ensures that the file descriptor is
+ close-on-exec. */
+
+static inline int
+gdb_mkostemp_cloexec (char *name_template, int flags = 0)
+{
+ /* gnulib provides a mkostemp replacement if needed. */
+ return mkostemp (name_template, flags | O_CLOEXEC);
+}
+
/* Convenience wrapper for the above, which takes the filename as an
std::string. */
gdb::char_vector filename_temp = make_temp_filename (filename);
gdb::optional<scoped_fd> out_file_fd
- (gdb::in_place, mkstemp (filename_temp.data ()));
+ (gdb::in_place, gdb_mkostemp_cloexec (filename_temp.data (), O_BINARY));
if (out_file_fd->get () == -1)
perror_with_name (("mkstemp"));
gdb::char_vector filename_str_temp = make_temp_filename (filename_str);
gdb::optional<scoped_fd> out_file_str_fd
- (gdb::in_place, mkstemp (filename_str_temp.data ()));
+ (gdb::in_place, gdb_mkostemp_cloexec (filename_str_temp.data (),
+ O_BINARY));
if (out_file_str_fd->get () == -1)
perror_with_name (("mkstemp"));
import/m4/mempcpy.m4 \
import/m4/memrchr.m4 \
import/m4/mkdir.m4 \
- import/m4/mkstemp.m4 \
+ import/m4/mkostemp.m4 \
import/m4/mmap-anon.m4 \
import/m4/mode_t.m4 \
import/m4/msvc-inval.m4 \
m4_include([import/m4/mempcpy.m4])
m4_include([import/m4/memrchr.m4])
m4_include([import/m4/mkdir.m4])
-m4_include([import/m4/mkstemp.m4])
+m4_include([import/m4/mkostemp.m4])
m4_include([import/m4/mmap-anon.m4])
m4_include([import/m4/mode_t.m4])
m4_include([import/m4/msvc-inval.m4])
whether the gnulib module getcwd shall be considered present. */
#undef GNULIB_GETCWD
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module mkostemp shall be considered present. */
+#undef GNULIB_MKOSTEMP
+
/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
whether the gnulib module openat shall be considered present. */
#undef GNULIB_OPENAT
/* Define to 1 when the gnulib module memrchr should be tested. */
#undef GNULIB_TEST_MEMRCHR
-/* Define to 1 when the gnulib module mkstemp should be tested. */
-#undef GNULIB_TEST_MKSTEMP
+/* Define to 1 when the gnulib module mkostemp should be tested. */
+#undef GNULIB_TEST_MKOSTEMP
/* Define to 1 when the gnulib module open should be tested. */
#undef GNULIB_TEST_OPEN
when it succeeds. */
#undef HAVE_MINIMALLY_WORKING_GETCWD
-/* Define to 1 if you have the 'mkstemp' function. */
-#undef HAVE_MKSTEMP
+/* Define to 1 if you have the 'mkostemp' function. */
+#undef HAVE_MKOSTEMP
/* Define to 1 if you have the 'mprotect' function. */
#undef HAVE_MPROTECT
gl_func_list="$gl_func_list mbrtowc"
gl_header_list="$gl_header_list sys/mman.h"
gl_func_list="$gl_func_list mprotect"
-gl_func_list="$gl_func_list mkstemp"
+gl_func_list="$gl_func_list mkostemp"
gl_func_list="$gl_func_list openat"
gl_func_list="$gl_func_list link"
gl_func_list="$gl_func_list secure_getenv"
# Code from module mempcpy:
# Code from module memrchr:
# Code from module mkdir:
- # Code from module mkstemp:
+ # Code from module mkostemp:
# Code from module msvc-inval:
# Code from module msvc-nothrow:
# Code from module multiarch:
+
+
:
- if test $ac_cv_func_mkstemp = yes; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working mkstemp" >&5
-$as_echo_n "checking for working mkstemp... " >&6; }
-if ${gl_cv_func_working_mkstemp+:} false; then :
- $as_echo_n "(cached) " >&6
-else
+ if test $ac_cv_func_mkostemp != yes; then
+ HAVE_MKOSTEMP=0
+ fi
- mkdir conftest.mkstemp
- if test "$cross_compiling" = yes; then :
- case "$host_os" in
- # Guess yes on glibc systems.
- *-gnu*) gl_cv_func_working_mkstemp="guessing yes" ;;
- # If we don't know, assume the worst.
- *) gl_cv_func_working_mkstemp="guessing no" ;;
- esac
+ if test $HAVE_MKOSTEMP = 0; then
-else
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-$ac_includes_default
-int
-main ()
-{
-int result = 0;
- int i;
- off_t large = (off_t) 4294967295u;
- if (large < 0)
- large = 2147483647;
- umask (0);
- for (i = 0; i < 70; i++)
- {
- char templ[] = "conftest.mkstemp/coXXXXXX";
- int (*mkstemp_function) (char *) = mkstemp;
- int fd = mkstemp_function (templ);
- if (fd < 0)
- result |= 1;
- else
- {
- struct stat st;
- if (lseek (fd, large, SEEK_SET) != large)
- result |= 2;
- if (fstat (fd, &st) < 0)
- result |= 4;
- else if (st.st_mode & 0077)
- result |= 8;
- if (close (fd))
- result |= 16;
- }
- }
- return result;
- ;
- return 0;
-}
-_ACEOF
-if ac_fn_c_try_run "$LINENO"; then :
- gl_cv_func_working_mkstemp=yes
-else
- gl_cv_func_working_mkstemp=no
-fi
-rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
- conftest.$ac_objext conftest.beam conftest.$ac_ext
-fi
- rm -rf conftest.mkstemp
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_working_mkstemp" >&5
-$as_echo "$gl_cv_func_working_mkstemp" >&6; }
- case "$gl_cv_func_working_mkstemp" in
- *yes) ;;
- *)
- REPLACE_MKSTEMP=1
- ;;
- esac
- else
- HAVE_MKSTEMP=0
- fi
- if test $HAVE_MKSTEMP = 0 || test $REPLACE_MKSTEMP = 1; then
+ gl_LIBOBJS="$gl_LIBOBJS mkostemp.$ac_objext"
+ fi
- gl_LIBOBJS="$gl_LIBOBJS mkstemp.$ac_objext"
+cat >>confdefs.h <<_ACEOF
+#define GNULIB_MKOSTEMP 1
+_ACEOF
- fi
- GNULIB_MKSTEMP=1
+ GNULIB_MKOSTEMP=1
-$as_echo "#define GNULIB_TEST_MKSTEMP 1" >>confdefs.h
+$as_echo "#define GNULIB_TEST_MKOSTEMP 1" >>confdefs.h
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl getcwd glob inet_ntop inttypes limits-h lstat memchr memmem mkdir mkstemp pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h
+# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl getcwd glob inet_ntop inttypes limits-h lstat memchr memmem mkdir mkostemp pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h
AUTOMAKE_OPTIONS = 1.9.6 gnits
## end gnulib module mkdir
-## begin gnulib module mkstemp
+## begin gnulib module mkostemp
-EXTRA_DIST += mkstemp.c
+EXTRA_DIST += mkostemp.c
-EXTRA_libgnu_a_SOURCES += mkstemp.c
+EXTRA_libgnu_a_SOURCES += mkostemp.c
-## end gnulib module mkstemp
+## end gnulib module mkostemp
## begin gnulib module msvc-inval
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl getcwd glob inet_ntop inttypes limits-h lstat memchr memmem mkdir mkstemp pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h
+# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl getcwd glob inet_ntop inttypes limits-h lstat memchr memmem mkdir mkostemp pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h
$(top_srcdir)/import/m4/mempcpy.m4 \
$(top_srcdir)/import/m4/memrchr.m4 \
$(top_srcdir)/import/m4/mkdir.m4 \
- $(top_srcdir)/import/m4/mkstemp.m4 \
+ $(top_srcdir)/import/m4/mkostemp.m4 \
$(top_srcdir)/import/m4/mmap-anon.m4 \
$(top_srcdir)/import/m4/mode_t.m4 \
$(top_srcdir)/import/m4/msvc-inval.m4 \
malloca.valgrind math.in.h mbrtowc.c mbsinit.c \
mbsrtowcs-impl.h mbsrtowcs-state.c mbsrtowcs.c memchr.c \
memchr.valgrind memmem.c str-two-way.h mempcpy.c memrchr.c \
- mkdir.c mkstemp.c msvc-inval.c msvc-inval.h msvc-nothrow.c \
+ mkdir.c mkostemp.c msvc-inval.c msvc-inval.h msvc-nothrow.c \
msvc-nothrow.h netinet_in.in.h open.c openat.c openat.h \
dirent-private.h opendir.c pathmax.h rawmemchr.c \
rawmemchr.valgrind dirent-private.h readdir.c readlink.c \
gettimeofday.c glob.c inet_ntop.c isnan.c isnand.c isnan.c \
isnanl.c lstat.c malloc.c mbrtowc.c mbsinit.c \
mbsrtowcs-state.c mbsrtowcs.c memchr.c memmem.c mempcpy.c \
- memrchr.c mkdir.c mkstemp.c msvc-inval.c msvc-nothrow.c open.c \
- openat.c opendir.c rawmemchr.c readdir.c readlink.c realloc.c \
- rename.c rewinddir.c rmdir.c secure_getenv.c setenv.c stat.c \
- strchrnul.c strdup.c strerror.c strerror-override.c strstr.c \
- strtok_r.c unsetenv.c
+ memrchr.c mkdir.c mkostemp.c msvc-inval.c msvc-nothrow.c \
+ open.c openat.c opendir.c rawmemchr.c readdir.c readlink.c \
+ realloc.c rename.c rewinddir.c rmdir.c secure_getenv.c \
+ setenv.c stat.c strchrnul.c strdup.c strerror.c \
+ strerror-override.c strstr.c strtok_r.c unsetenv.c
# Use this preprocessor expression to decide whether #include_next works.
# Do not rely on a 'configure'-time test for this, since the expression
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mempcpy.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memrchr.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mkdir.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mkstemp.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mkostemp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msvc-inval.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msvc-nothrow.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/open.Po@am__quote@
# Specification in the form of a command-line invocation:
-# gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl getcwd glob inet_ntop inttypes limits-h lstat memchr memmem mkdir mkstemp pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h
+# gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl getcwd glob inet_ntop inttypes limits-h lstat memchr memmem mkdir mkostemp pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h
# Specification in the form of a few gnulib-tool.m4 macro invocations:
gl_LOCAL_DIR([])
memchr
memmem
mkdir
- mkstemp
+ mkostemp
pathmax
rawmemchr
readlink
# Code from module mempcpy:
# Code from module memrchr:
# Code from module mkdir:
- # Code from module mkstemp:
+ # Code from module mkostemp:
# Code from module msvc-inval:
# Code from module msvc-nothrow:
# Code from module multiarch:
if test $REPLACE_MKDIR = 1; then
AC_LIBOBJ([mkdir])
fi
- gl_FUNC_MKSTEMP
- if test $HAVE_MKSTEMP = 0 || test $REPLACE_MKSTEMP = 1; then
- AC_LIBOBJ([mkstemp])
- gl_PREREQ_MKSTEMP
+ gl_FUNC_MKOSTEMP
+ if test $HAVE_MKOSTEMP = 0; then
+ AC_LIBOBJ([mkostemp])
+ gl_PREREQ_MKOSTEMP
fi
- gl_STDLIB_MODULE_INDICATOR([mkstemp])
+ gl_MODULE_INDICATOR([mkostemp])
+ gl_STDLIB_MODULE_INDICATOR([mkostemp])
AC_REQUIRE([gl_MSVC_INVAL])
if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
AC_LIBOBJ([msvc-inval])
lib/mempcpy.c
lib/memrchr.c
lib/mkdir.c
- lib/mkstemp.c
+ lib/mkostemp.c
lib/msvc-inval.c
lib/msvc-inval.h
lib/msvc-nothrow.c
m4/mempcpy.m4
m4/memrchr.m4
m4/mkdir.m4
- m4/mkstemp.m4
+ m4/mkostemp.m4
m4/mmap-anon.m4
m4/mode_t.m4
m4/msvc-inval.m4
--- /dev/null
+# mkostemp.m4 serial 2
+dnl Copyright (C) 2009-2016 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_MKOSTEMP],
+[
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+
+ dnl Persuade glibc <stdlib.h> to declare mkostemp().
+ AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+ AC_CHECK_FUNCS_ONCE([mkostemp])
+ if test $ac_cv_func_mkostemp != yes; then
+ HAVE_MKOSTEMP=0
+ fi
+])
+
+# Prerequisites of lib/mkostemp.c.
+AC_DEFUN([gl_PREREQ_MKOSTEMP],
+[
+])
+++ /dev/null
-#serial 23
-
-# Copyright (C) 2001, 2003-2007, 2009-2016 Free Software Foundation, Inc.
-# This file is free software; the Free Software Foundation
-# gives unlimited permission to copy and/or distribute it,
-# with or without modifications, as long as this notice is preserved.
-
-# On some hosts (e.g., HP-UX 10.20, SunOS 4.1.4, Solaris 2.5.1), mkstemp has a
-# silly limit that it can create no more than 26 files from a given template.
-# Other systems lack mkstemp altogether.
-# On OSF1/Tru64 V4.0F, the system-provided mkstemp function can create
-# only 32 files per process.
-# On some hosts, mkstemp creates files with mode 0666, which is a security
-# problem and a violation of POSIX 2008.
-# On systems like the above, arrange to use the replacement function.
-AC_DEFUN([gl_FUNC_MKSTEMP],
-[
- AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
- AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
-
- AC_CHECK_FUNCS_ONCE([mkstemp])
- if test $ac_cv_func_mkstemp = yes; then
- AC_CACHE_CHECK([for working mkstemp],
- [gl_cv_func_working_mkstemp],
- [
- mkdir conftest.mkstemp
- AC_RUN_IFELSE(
- [AC_LANG_PROGRAM(
- [AC_INCLUDES_DEFAULT],
- [[int result = 0;
- int i;
- off_t large = (off_t) 4294967295u;
- if (large < 0)
- large = 2147483647;
- umask (0);
- for (i = 0; i < 70; i++)
- {
- char templ[] = "conftest.mkstemp/coXXXXXX";
- int (*mkstemp_function) (char *) = mkstemp;
- int fd = mkstemp_function (templ);
- if (fd < 0)
- result |= 1;
- else
- {
- struct stat st;
- if (lseek (fd, large, SEEK_SET) != large)
- result |= 2;
- if (fstat (fd, &st) < 0)
- result |= 4;
- else if (st.st_mode & 0077)
- result |= 8;
- if (close (fd))
- result |= 16;
- }
- }
- return result;]])],
- [gl_cv_func_working_mkstemp=yes],
- [gl_cv_func_working_mkstemp=no],
- [case "$host_os" in
- # Guess yes on glibc systems.
- *-gnu*) gl_cv_func_working_mkstemp="guessing yes" ;;
- # If we don't know, assume the worst.
- *) gl_cv_func_working_mkstemp="guessing no" ;;
- esac
- ])
- rm -rf conftest.mkstemp
- ])
- case "$gl_cv_func_working_mkstemp" in
- *yes) ;;
- *)
- REPLACE_MKSTEMP=1
- ;;
- esac
- else
- HAVE_MKSTEMP=0
- fi
-])
-
-# Prerequisites of lib/mkstemp.c.
-AC_DEFUN([gl_PREREQ_MKSTEMP],
-[
-])
--- /dev/null
+/* Copyright (C) 1998-1999, 2001, 2005-2007, 2009-2016 Free Software
+ Foundation, Inc.
+ This file is derived from the one in the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if !_LIBC
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+
+#if !_LIBC
+# include "tempname.h"
+# define __gen_tempname gen_tempname
+# ifndef __GTFILE
+# define __GT_FILE GT_FILE
+# endif
+#endif
+
+#include <stdio.h>
+
+#ifndef __GT_FILE
+# define __GT_FILE 0
+#endif
+
+/* Generate a unique temporary file name from XTEMPLATE.
+ The last six characters of XTEMPLATE must be "XXXXXX";
+ they are replaced with a string that makes the file name unique.
+ Then open the file and return a fd. */
+int
+mkostemp (char *xtemplate, int flags)
+{
+ return __gen_tempname (xtemplate, 0, flags, __GT_FILE);
+}
+++ /dev/null
-/* Copyright (C) 1998-1999, 2001, 2005-2007, 2009-2016 Free Software
- Foundation, Inc.
- This file is derived from the one in the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#if !_LIBC
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-
-#if !_LIBC
-# include "tempname.h"
-# define __gen_tempname gen_tempname
-# ifndef __GT_FILE
-# define __GT_FILE GT_FILE
-# endif
-#endif
-
-#include <stdio.h>
-
-#ifndef __GT_FILE
-# define __GT_FILE 0
-#endif
-
-/* Generate a unique temporary file name from XTEMPLATE.
- The last six characters of XTEMPLATE must be "XXXXXX";
- they are replaced with a string that makes the file name unique.
- Then open the file and return a fd.
-
- If you are creating temporary files which will later be removed,
- consider using the clean-temp module, which avoids several pitfalls
- of using mkstemp directly. */
-int
-mkstemp (char *xtemplate)
-{
- return __gen_tempname (xtemplate, 0, 0, __GT_FILE);
-}
# endif
#endif
-#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_MKOSTEMP@ || @GNULIB_MKOSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
/* On Mac OS X 10.3, only <unistd.h> declares mkstemp. */
/* On Mac OS X 10.5, only <unistd.h> declares mkstemps. */
+/* On Mac OS X 10.13, only <unistd.h> declares mkostemp and mkostemps. */
/* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */
/* But avoid namespace pollution on glibc systems and native Windows. */
# include <unistd.h>
--- /dev/null
+From 6954995dd32ea98a1973df31f411f3996bb47dfb Mon Sep 17 00:00:00 2001
+From: Tom Tromey <tom@tromey.com>
+Date: Mon, 1 Oct 2018 14:57:45 -0600
+Subject: [PATCH] mkostemp, mkostemps: Fix compilation error in C++ mode on Mac
+ OS X.
+
+Attempting to use the mkostemp module in gdb caused a build failure
+when using the C++ namespace feature, because mkostemp was not
+declared. On OS X, mkostemp is declared in unistd.h, so this patch
+extends the existing special case in stdlib.in.h to cover mkostemp and
+mkostemps.
+
+* lib/stdlib.in.h: Include <unistd.h> for mkostemp and mkostemps
+on OS X.
+---
+ ChangeLog | 6 ++++++
+ lib/stdlib.in.h | 3 ++-
+ 2 files changed, 8 insertions(+), 1 deletion(-)
+
+diff --git a/gdb/gnulib/import/stdlib.in.h b/gdb/gnulib/import/stdlib.in.h
+index db3253bd97..8f803a2ea3 100644
+--- a/gdb/gnulib/import/stdlib.in.h
++++ b/gdb/gnulib/import/stdlib.in.h
+@@ -87,9 +87,10 @@ struct random_data
+ # endif
+ #endif
+
+-#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
++#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_MKOSTEMP@ || @GNULIB_MKOSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+ /* On Mac OS X 10.3, only <unistd.h> declares mkstemp. */
+ /* On Mac OS X 10.5, only <unistd.h> declares mkstemps. */
++/* On Mac OS X 10.13, only <unistd.h> declares mkostemp and mkostemps. */
+ /* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */
+ /* But avoid namespace pollution on glibc systems and native Windows. */
+ # include <unistd.h>
+--
+2.19.0
+
memchr \
memmem \
mkdir \
- mkstemp \
+ mkostemp \
pathmax \
rawmemchr \
readlink \
}
apply_patches "patches/0001-Fix-PR-gdb-23558-Use-system-s-getcwd-when-cross-comp.patch"
+apply_patches "patches/0002-mkostemp-mkostemps-Fix-compilation-error-in-C-mode-o.patch"
# Regenerate all necessary files...
aclocal -Iimport/m4 &&
#include "defs.h"
+#include "common/filestuff.h"
#include "common/scoped_fd.h"
#include "config.h"
#include "selftest.h"
test_destroy ()
{
char filename[] = "scoped_fd-selftest-XXXXXX";
- int fd = mkstemp (filename);
+ int fd = gdb_mkostemp_cloexec (filename);
SELF_CHECK (fd >= 0);
unlink (filename);
test_release ()
{
char filename[] = "scoped_fd-selftest-XXXXXX";
- int fd = mkstemp (filename);
+ int fd = gdb_mkostemp_cloexec (filename);
SELF_CHECK (fd >= 0);
unlink (filename);
#include "defs.h"
+#include "common/filestuff.h"
#include "common/scoped_mmap.h"
#include "config.h"
test_normal ()
{
char filename[] = "scoped_mmapped_file-selftest-XXXXXX";
- int fd = mkstemp (filename);
+ int fd = gdb_mkostemp_cloexec (filename);
SELF_CHECK (fd >= 0);
SELF_CHECK (write (fd, "Hello!", 7) == 7);