bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new gnulib module 'fcntl' to detect O_NOFOLLOW problem etc.


From: Paul Eggert
Subject: new gnulib module 'fcntl' to detect O_NOFOLLOW problem etc.
Date: Mon, 28 Aug 2006 16:01:38 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

Bruno Haible <address@hidden> writes:

> So it appears that O_NOFOLLOW exists but has no effect.
> Shouldn't be too hard to write a configure against it.

OK, I installed this into gnulib to address the gnulib part of the
problem.  I'll send the coreutils changes via another email.

2006-08-28  Paul Eggert  <address@hidden>

        * lib/fcntl_.h: New file.
        * lib/chdir-safer.c (O_DIRECTORY, O_NOFOLLOW): Remove, now that we have
        the fcntl module.
        * lib/dirchownmod.c: Likewise.
        * lib/fts.c: Likewise.
        * m4/fcntl_h.m4: New file.
        * modules/fcntl: New file.
        * modules/chdir-safer (Depends-on): Add fcntl.
        * modules/fts: Likewise.
        * modules/mkdir-p: Likewise.

--- /dev/null   2005-09-24 22:00:15.000000000 -0700
+++ lib/fcntl_.h        2006-08-28 15:52:05.000000000 -0700
@@ -0,0 +1,100 @@
+/* Like <fcntl.h>, but with non-working flags defined to 0.
+
+   Copyright (C) 2006 Free Software Foundation, Inc.
+
+   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 2, 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, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* written by Paul Eggert */
+
+#ifndef _GL_FCNTL_H
+#define _GL_FCNTL_H
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include @ABSOLUTE_FCNTL_H@
+
+#if !defined O_DIRECT && defined O_DIRECTIO
+/* Tru64 spells it `O_DIRECTIO'.  */
+# define O_DIRECT O_DIRECTIO
+#endif
+
+#ifndef O_DIRECT
+# define O_DIRECT 0
+#endif
+
+#ifndef O_DIRECTORY
+# define O_DIRECTORY 0
+#endif
+
+#ifndef O_DSYNC
+# define O_DSYNC 0
+#endif
+
+#ifndef O_NDELAY
+# define O_NDELAY 0
+#endif
+
+#ifndef O_NOATIME
+# define O_NOATIME 0
+#endif
+
+#ifndef O_NONBLOCK
+# define O_NONBLOCK O_NDELAY
+#endif
+
+#ifndef O_NOCTTY
+# define O_NOCTTY 0
+#endif
+
+#ifdef O_NOFOLLOW_IS_INEFFECTIVE
+# undef O_NOFOLLOW
+#endif
+#ifndef O_NOFOLLOW
+# define O_NOFOLLOW 0
+#endif
+
+#ifndef O_NOLINKS
+# define O_NOLINKS 0
+#endif
+
+#ifndef O_RSYNC
+# define O_RSYNC 0
+#endif
+
+#ifndef O_SYNC
+# define O_SYNC 0
+#endif
+
+/* For systems that distinguish between text and binary I/O.
+   O_BINARY is usually declared in fcntl.h  */
+#if !defined O_BINARY && defined _O_BINARY
+  /* For MSC-compatible compilers.  */
+# define O_BINARY _O_BINARY
+# define O_TEXT _O_TEXT
+#endif
+
+#ifdef __BEOS__
+  /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect.  */
+# undef O_BINARY
+# undef O_TEXT
+#endif
+
+#ifndef O_BINARY
+# define O_BINARY 0
+# define O_TEXT 0
+#endif
+
+#endif
--- /dev/null   2005-09-24 22:00:15.000000000 -0700
+++ m4/fcntl_h.m4       2006-08-28 15:47:21.000000000 -0700
@@ -0,0 +1,50 @@
+# Configure fcntl.h.
+dnl Copyright (C) 2006 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.
+
+dnl Written by Paul Eggert.
+
+AC_DEFUN([gl_FCNTL_H],
+[
+  AC_CACHE_CHECK([for working fcntl.h], gl_cv_header_working_fcntl_h,
+    [AC_RUN_IFELSE(
+       [AC_LANG_PROGRAM(
+         [[#include <sys/types.h>
+          #include <sys/stat.h>
+          #include <unistd.h>
+          #include <fcntl.h>
+          #ifndef O_NOFOLLOW
+           #define O_NOFOLLOW 0
+          #endif
+          static int const constants[] =
+           {
+             O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
+             O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY
+           };
+         ]],
+         [[static char const sym[] = "conftest.sym";
+           if (O_NOFOLLOW)
+             {
+               if (symlink (".", sym) != 0)
+                 return 1;
+               if (open (sym, O_RDONLY | O_NOFOLLOW) == 0)
+                 return 1;
+             }
+           return !constants;]])],
+       [gl_cv_header_working_fcntl_h=yes],
+       [gl_cv_header_working_fcntl_h=no],
+       [gl_cv_header_working_fcntl_h=cross-compiling])])
+
+  if test $gl_cv_header_working_fcntl_h != yes; then
+    AC_DEFINE([O_NOFOLLOW_IS_INEFFECTIVE], 1,
+      [Define to 1 if O_NOFOLLOW is ineffective.])
+  fi
+
+  gl_ABSOLUTE_HEADER([fcntl.h])
+  ABSOLUTE_FCNTL_H=\"$gl_cv_absolute_fcntl_h\"
+  AC_SUBST([ABSOLUTE_FCNTL_H])
+  FCNTL_H='fcntl.h'
+  AC_SUBST([FCNTL_H])
+])
--- /dev/null   2005-09-24 22:00:15.000000000 -0700
+++ modules/fcntl       2006-08-28 15:52:54.000000000 -0700
@@ -0,0 +1,34 @@
+Description:
+Like <fcntl.h>, but with non-working flags defined to 0.
+
+Files:
+lib/fcntl_.h
+m4/absolute-header.m4
+m4/fcntl_h.m4
+
+Depends-on:
+unistd
+
+configure.ac:
+gl_FCNTL_H
+
+Makefile.am:
+BUILT_SOURCES += $(FCNTL_H)
+EXTRA_DIST += fcntl_.h
+
+# We need the following in order to create <fcntl.h> when the system
+# doesn't have one that works with the given compiler.
+fcntl.h: fcntl_.h
+       sed -e 's|@''ABSOLUTE_FCNTL_H''@|$(ABSOLUTE_FCNTL_H)|g' \
+           < $(srcdir)/fcntl_.h > address@hidden
+       mv address@hidden $@
+MOSTLYCLEANFILES += fcntl.h fcntl.h-t
+
+Include:
+#include <fcntl.h>
+
+License:
+LGPL
+
+Maintainer:
+all
Index: lib/chdir-safer.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/chdir-safer.c,v
retrieving revision 1.2
diff -p -u -r1.2 chdir-safer.c
--- lib/chdir-safer.c   3 Jul 2006 08:32:46 -0000       1.2
+++ lib/chdir-safer.c   28 Aug 2006 22:56:35 -0000
@@ -32,14 +32,6 @@
 #include <sys/stat.h>
 #include "same-inode.h"
 
-#ifndef O_DIRECTORY
-# define O_DIRECTORY 0
-#endif
-
-#ifndef O_NOFOLLOW
-# define O_NOFOLLOW 0
-#endif
-
 /* Like chdir, but fail if DIR is a symbolic link to a directory (or
    similar funny business), or if DIR is not readable.  This avoids a
    minor race condition between when a directory is created or statted
Index: lib/dirchownmod.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/dirchownmod.c,v
retrieving revision 1.2
diff -p -u -r1.2 dirchownmod.c
--- lib/dirchownmod.c   21 Aug 2006 22:05:23 -0000      1.2
+++ lib/dirchownmod.c   28 Aug 2006 22:56:35 -0000
@@ -33,13 +33,6 @@
 #include "lchmod.h"
 #include "stat-macros.h"
 
-#ifndef O_DIRECTORY
-# define O_DIRECTORY 0
-#endif
-#ifndef O_NOFOLLOW
-# define O_NOFOLLOW 0
-#endif
-
 #ifndef HAVE_FCHMOD
 # define HAVE_FCHMOD 0
 # undef fchmod
Index: lib/fts.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/fts.c,v
retrieving revision 1.14
diff -p -u -r1.14 fts.c
--- lib/fts.c   17 Aug 2006 20:34:21 -0000      1.14
+++ lib/fts.c   28 Aug 2006 22:56:35 -0000
@@ -115,10 +115,6 @@ static char sccsid[] = "@(#)fts.c  8.6 (B
 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
 #endif
 
-#if !defined O_NOFOLLOW
-# define O_NOFOLLOW 0
-#endif
-
 /* If this host provides the openat function, then we can avoid
    attempting to open "." in some initialization code below.  */
 #ifdef HAVE_OPENAT
Index: modules/chdir-safer
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/chdir-safer,v
retrieving revision 1.2
diff -p -u -r1.2 chdir-safer
--- modules/chdir-safer 21 Aug 2006 21:46:31 -0000      1.2
+++ modules/chdir-safer 28 Aug 2006 22:56:35 -0000
@@ -7,6 +7,7 @@ lib/chdir-safer.c
 m4/chdir-safer.m4
 
 Depends-on:
+fcntl
 same-inode
 stdbool
 
Index: modules/fts
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/fts,v
retrieving revision 1.6
diff -p -u -r1.6 fts
--- modules/fts 21 Aug 2006 21:46:31 -0000      1.6
+++ modules/fts 28 Aug 2006 22:56:35 -0000
@@ -10,6 +10,7 @@ m4/fts.m4
 Depends-on:
 cycle-check
 dirfd
+fcntl
 hash
 lstat
 openat
Index: modules/mkdir-p
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/mkdir-p,v
retrieving revision 1.8
diff -p -u -r1.8 mkdir-p
--- modules/mkdir-p     22 Aug 2006 12:26:39 -0000      1.8
+++ modules/mkdir-p     28 Aug 2006 22:56:35 -0000
@@ -10,6 +10,7 @@ m4/mkdir-p.m4
 
 Depends-on:
 error
+fcntl
 gettext-h
 lchmod
 lchown




reply via email to

[Prev in Thread] Current Thread [Next in Thread]