instead of mkstemp.
* misc/Makefile (routines): Add mkostemp and mkostemp64.
* misc/Versions: Export mkostemp and mkostemp64 for GLIBC_2.7.
* misc/mkostemp.c: New file.
* misc/mkostemp64.c: New file.
* stdlib/stdlib.h: Declare the new functions.
* sysdeps/posix/tempname.c: Add new parameter which is added to
the flags for open. Remove __GT_BIGFILE handling.
* stdio-common/tempname.c: Likewise.
* include/stdio.h: Adjust __gen_tempname prototype.
Renumber __GT_* constants.
* libio/oldtmpfile.c: Adjust for __gen_tempname interface change.
* misc/mkdtemp.c: Likewise.
* misc/mkstemp.c: Likewise.
* misc/mkstemp64.c: Likewise.
* misc/mktemp.c: Likewise.
* stdio-common/tempnam.c: Likewise.
* stdio-common/tmpfile.c: Likewise.
* stdio-common/tmpfile64.c: Likewise.
* stdio-common/tmpnam.c: Likewise.
* stdio-common/tmpnam_r.c: Likewise.
+2007-08-10 Ulrich Drepper <drepper@redhat.com>
+
+ * nscd/connections.c: Use O_CLOEXEC is possible. Use mkostemp
+ instead of mkstemp.
+
+ * misc/Makefile (routines): Add mkostemp and mkostemp64.
+ * misc/Versions: Export mkostemp and mkostemp64 for GLIBC_2.7.
+ * misc/mkostemp.c: New file.
+ * misc/mkostemp64.c: New file.
+ * stdlib/stdlib.h: Declare the new functions.
+ * sysdeps/posix/tempname.c: Add new parameter which is added to
+ the flags for open. Remove __GT_BIGFILE handling.
+ * stdio-common/tempname.c: Likewise.
+ * include/stdio.h: Adjust __gen_tempname prototype.
+ Renumber __GT_* constants.
+ * libio/oldtmpfile.c: Adjust for __gen_tempname interface change.
+ * misc/mkdtemp.c: Likewise.
+ * misc/mkstemp.c: Likewise.
+ * misc/mkstemp64.c: Likewise.
+ * misc/mktemp.c: Likewise.
+ * stdio-common/tempnam.c: Likewise.
+ * stdio-common/tmpfile.c: Likewise.
+ * stdio-common/tmpfile64.c: Likewise.
+ * stdio-common/tmpnam.c: Likewise.
+ * stdio-common/tmpnam_r.c: Likewise.
+
2007-08-10 Roland McGrath <roland@frob.com>
* sysdeps/mach/hurd/bits/ioctls.h (NLDLY, TABDLY, BSDLY, VTDLY):
__const char *__dir, __const char *__pfx,
int __try_tempdir);
-extern int __gen_tempname (char *__tmpl, int __kind);
+extern int __gen_tempname (char *__tmpl, int __flags, int __kind);
/* The __kind argument to __gen_tempname may be one of: */
# define __GT_FILE 0 /* create a file */
-# define __GT_BIGFILE 1 /* create a file, using open64 */
-# define __GT_DIR 2 /* create a directory */
-# define __GT_NOCREATE 3 /* just find a name not currently in use */
+# define __GT_DIR 1 /* create a directory */
+# define __GT_NOCREATE 2 /* just find a name not currently in use */
/* Print out MESSAGE on the error output and abort. */
extern void __libc_fatal (__const char *__message)
-/* Copyright (C) 1991,1993,1996-2000,2003,2004 Free Software Foundation, Inc.
+/* Copyright (C) 1991,1993,1996-2000,2003,2004,2007
+ Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0))
return NULL;
- fd = __gen_tempname (buf, __GT_FILE);
+ fd = __gen_tempname (buf, 0, __GT_FILE);
if (fd < 0)
return NULL;
-# Copyright (C) 1991-2002,2003,2004,2005,2006 Free Software Foundation, Inc.
+# Copyright (C) 1991-2006, 2007 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
gethostid sethostid \
revoke vhangup \
swapon swapoff mktemp mkstemp mkstemp64 mkdtemp \
+ mkostemp mkostemp64 \
ualarm usleep \
gtty stty \
ptrace \
futimesat;
__syslog_chk; __vsyslog_chk;
}
+ GLIBC_2.7 {
+ mkostemp; mkostemp64;
+ }
}
-/* Copyright (C) 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1999, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
mkdtemp (template)
char *template;
{
- if (__gen_tempname (template, __GT_DIR))
+ if (__gen_tempname (template, 0, __GT_DIR))
return NULL;
else
return template;
--- /dev/null
+/* Copyright (C) 1998, 1999, 2001, 2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef __GT_FILE
+# define __GT_FILE 0
+#endif
+
+/* Generate a unique temporary file name from TEMPLATE.
+ The last six characters of TEMPLATE must be "XXXXXX";
+ they are replaced with a string that makes the filename unique.
+ Then open the file and return a fd. */
+int
+mkostemp (template, flags)
+ char *template;
+ int flags;
+{
+ return __gen_tempname (template, flags, __GT_FILE);
+}
--- /dev/null
+/* Copyright (C) 2000, 2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/* Generate a unique temporary file name from TEMPLATE.
+ The last six characters of TEMPLATE must be "XXXXXX";
+ they are replaced with a string that makes the filename unique.
+ Then open the file and return a fd. */
+int
+mkostemp64 (template, flags)
+ char *template;
+ int flags;
+{
+ return __gen_tempname (template, flags | O_LARGEFILE, __GT_FILE);
+}
-/* Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2001, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
mkstemp (template)
char *template;
{
- return __gen_tempname (template, __GT_FILE);
+ return __gen_tempname (template, 0, __GT_FILE);
}
-/* Copyright (C) 2000 Free Software Foundation, Inc.
+/* Copyright (C) 2000, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
mkstemp64 (template)
char *template;
{
- return __gen_tempname (template, __GT_BIGFILE);
+ return __gen_tempname (template, O_LARGEFILE, __GT_FILE);
}
-/* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2000, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
mktemp (template)
char *template;
{
- if (__gen_tempname (template, __GT_NOCREATE) < 0)
+ if (__gen_tempname (template, 0, __GT_NOCREATE) < 0)
/* We return the null string if we can't find a unique file name. */
template[0] = '\0';
}
+#ifdef O_CLOEXEC
+# define EXTRA_O_FLAGS O_CLOEXEC
+#else
+# define EXTRA_O_FLAGS 0
+#endif
+
+
/* Initialize database information structures. */
void
nscd_init (void)
if (dbs[cnt].persistent)
{
/* Try to open the appropriate file on disk. */
- int fd = open (dbs[cnt].db_filename, O_RDWR);
+ int fd = open (dbs[cnt].db_filename, O_RDWR | EXTRA_O_FLAGS);
if (fd != -1)
{
struct stat64 st;
/* We also need a read-only descriptor. */
if (dbs[cnt].shared)
{
- dbs[cnt].ro_fd = open (dbs[cnt].db_filename, O_RDONLY);
+ dbs[cnt].ro_fd = open (dbs[cnt].db_filename,
+ O_RDONLY | EXTRA_O_FLAGS);
if (dbs[cnt].ro_fd == -1)
dbg_log (_("\
cannot create read-only descriptor for \"%s\"; no mmap"),
if (dbs[cnt].persistent)
{
fd = open (dbs[cnt].db_filename,
- O_RDWR | O_CREAT | O_EXCL | O_TRUNC,
+ O_RDWR | O_CREAT | O_EXCL | O_TRUNC | EXTRA_O_FLAGS,
S_IRUSR | S_IWUSR);
if (fd != -1 && dbs[cnt].shared)
- ro_fd = open (dbs[cnt].db_filename, O_RDONLY);
+ ro_fd = open (dbs[cnt].db_filename,
+ O_RDONLY | EXTRA_O_FLAGS);
}
else
{
char fname[] = _PATH_NSCD_XYZ_DB_TMP;
- fd = mkstemp (fname);
+ fd = mkostemp (fname, EXTRA_O_FLAGS);
/* We do not need the file name anymore after we
opened another file descriptor in read-only mode. */
if (fd != -1)
{
if (dbs[cnt].shared)
- ro_fd = open (fname, O_RDONLY);
+ ro_fd = open (fname, O_RDONLY | EXTRA_O_FLAGS);
unlink (fname);
}
}
}
+#if !defined O_CLOEXEC || !defined __ASSUME_O_CLOEXEC
+ /* We do not check here whether the O_CLOEXEC provided to the
+ open call was successful or not. The two fcntl calls are
+ only performed once each per process start-up and therefore
+ is not noticeable at all. */
if (paranoia
&& ((dbs[cnt].wr_fd != -1
&& fcntl (dbs[cnt].wr_fd, F_SETFD, FD_CLOEXEC) == -1)
strerror (errno));
paranoia = 0;
}
+#endif
if (dbs[cnt].head == NULL)
{
-/* Copyright (C) 1991,1993,1996-1999,2000 Free Software Foundation, Inc.
+/* Copyright (C) 1991,1993,1996-2000,2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
if (__path_search (buf, FILENAME_MAX, dir, pfx, 1))
return NULL;
- if (__gen_tempname (buf, __GT_NOCREATE))
+ if (__gen_tempname (buf, 0, __GT_NOCREATE))
return NULL;
return __strdup (buf);
-/* Copyright (C) 1991, 92, 93, 95-98, 99 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 93, 95-98, 99, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
*/
int
-__gen_tempname (tmpl, kind)
+__gen_tempname (tmpl, flags, kind)
char *tmpl;
+ int flags;
int kind;
{
__set_errno (ENOSYS);
/* Open a stdio stream on an anonymous temporary file. Generic/POSIX version.
- Copyright (C) 1991,93,1996-2000,2002,2003 Free Software Foundation, Inc.
+ Copyright (C) 1991,1993,1996-2000,2002,2003,2007
+ Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
# endif
#endif
-#ifndef GEN_THIS
-# define GEN_THIS __GT_FILE
-#endif
/* This returns a new stream opened on a temporary file (generated
by tmpnam). The file is opened with mode "w+b" (binary read/write).
if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0))
return NULL;
- fd = __gen_tempname (buf, GEN_THIS);
+ int flags = 0;
+#ifdef FLAGS
+ flags = FLAGS;
+#endif
+ fd = __gen_tempname (buf, flags, __GT_FILE);
if (fd < 0)
return NULL;
return f;
}
-#if defined USE_IN_LIBIO && GEN_THIS == __GT_FILE /* Not for tmpfile64. */
+#if defined USE_IN_LIBIO && !defined FLAGS /* Not for tmpfile64. */
# undef tmpfile
# include <shlib-compat.h>
versioned_symbol (libc, __new_tmpfile, tmpfile, GLIBC_2_1);
-#define GEN_THIS __GT_BIGFILE
-#define tmpfile tmpfile64
+#define FLAGS O_LARGEFILE
+#define tmpfile tmpfile64
#include <tmpfile.c>
-/* Copyright (C) 1991,1993,1996-1999,2000 Free Software Foundation, Inc.
+/* Copyright (C) 1991,1993,1996-1999,2000,2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
0))
return NULL;
- if (__builtin_expect (__gen_tempname (tmpbuf, __GT_NOCREATE), 0))
+ if (__builtin_expect (__gen_tempname (tmpbuf, 0, __GT_NOCREATE), 0))
return NULL;
if (s == NULL)
-/* Copyright (C) 1991,1993,1996-1999,2000 Free Software Foundation, Inc.
+/* Copyright (C) 1991,1993,1996-1999,2000,2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
if (__path_search (s, L_tmpnam, NULL, NULL, 0))
return NULL;
- if (__gen_tempname (s, __GT_NOCREATE))
+ if (__gen_tempname (s, 0, __GT_NOCREATE))
return NULL;
return s;
extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
#endif
+#ifdef __USE_GNU
+/* Generate a unique temporary file name from TEMPLATE similar to
+ mkstemp. But allow the caller to pass additional flags which are
+ used in the open call to create the file..
+
+ This function is a possible cancellation points and therefore not
+ marked with __THROW. */
+# ifndef __USE_FILE_OFFSET64
+extern int mkostemp (char *__template, int __flags) __nonnull ((1)) __wur;
+# else
+# ifdef __REDIRECT
+extern int __REDIRECT (mkostemp, (char *__template, int __flags), mkostemp64)
+ __nonnull ((1)) __wur;
+# else
+# define mkostemp mkostemp64
+# endif
+# endif
+# ifdef __USE_LARGEFILE64
+extern int mkostemp64 (char *__template, int __flags) __nonnull ((1)) __wur;
+# endif
+#endif
+
__BEGIN_NAMESPACE_STD
/* Execute the given line as a shell command.
-/* Copyright (C) 1991-1999, 2000, 2001, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2001, 2006, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
#endif
#ifndef __GT_FILE
# define __GT_FILE 0
-# define __GT_BIGFILE 1
-# define __GT_DIR 2
-# define __GT_NOCREATE 3
+# define __GT_DIR 1
+# define __GT_NOCREATE 2
#endif
#if STDC_HEADERS || _LIBC
at the time of the call.
__GT_FILE: create the file using open(O_CREAT|O_EXCL)
and return a read-write fd. The file is mode 0600.
- __GT_BIGFILE: same as __GT_FILE but use open64().
__GT_DIR: create a directory, which will be mode 0700.
We use a clever algorithm to get hard-to-predict names. */
int
-__gen_tempname (char *tmpl, int kind)
+__gen_tempname (char *tmpl, int flags, int kind)
{
int len;
char *XXXXXX;
switch (kind)
{
case __GT_FILE:
- fd = __open (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
- break;
-
- case __GT_BIGFILE:
- fd = __open64 (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
+ fd = __open (tmpl,
+ (flags & ~ACCESSPERMS)
+ | O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
break;
case __GT_DIR: