bug-gnulib
[Top][All Lists]
Advanced

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

Re: truncate-fail-diag failure on Solaris


From: Bruno Haible
Subject: Re: truncate-fail-diag failure on Solaris
Date: Thu, 12 Jun 2008 02:17:50 +0200
User-agent: KMail/1.5.4

Jim Meyering wrote in
<http://lists.gnu.org/archive/html/bug-coreutils/2008-06/msg00101.html>:
> > You could see whether the file name ends in '/' before
> > you call open() on it, no?
>
> To work around such broken systems without polluting
> all application code, in the past we've used wrapper
> functions like the ones around stat, lstat and rename.
> They would be enabled (with overhead) only if a configure-time
> test detects the broken syscall.

Yes, of course, we use this methodology.

> We could probably do the
> same with open to accommodate solaris 7, but I don't think
> it's worth the effort for a system that old

It's not only Solaris 7. It's also Solaris 9 and HP-UX 11.

The right place for the wrapper is the gnulib 'open' module. I'm adding this:


2008-06-11  Bruno Haible  <address@hidden>

        * m4/open.m4 (gl_FUNC_OPEN): Add test against trailing slash bug.
        * lib/open.c: Include errno.h.
        (open): Fail when attempting to write to a file that has a trailing
        slash.
        * tests/test-open.c (main): Test against trailing slash bug.
        * doc/posix-functions/open.texi: Mention the trailing slash bug.

*** doc/posix-functions/open.texi.orig  2008-06-12 02:15:29.000000000 +0200
--- doc/posix-functions/open.texi       2008-06-12 01:53:53.000000000 +0200
***************
*** 9,14 ****
--- 9,18 ----
  Portability problems fixed by Gnulib:
  @itemize
  @item
+ This function does not fail when the file name argument ends in a slash
+ and (without the slash) names a nonexistent file, on some platforms:
+ HP-UX 11.00, Solaris 9.
+ @item
  On Windows platforms (excluding Cygwin), this function does usually not
  recognize the @file{/dev/null} filename.
  @end itemize
*** lib/open.c.orig     2008-06-12 02:15:29.000000000 +0200
--- lib/open.c  2008-06-12 02:15:27.000000000 +0200
***************
*** 1,5 ****
  /* Open a descriptor to a file.
!    Copyright (C) 2007 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
--- 1,5 ----
  /* Open a descriptor to a file.
!    Copyright (C) 2007-2008 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
***************
*** 24,29 ****
--- 24,30 ----
  /* If the fchdir replacement is used, open() is defined in fchdir.c.  */
  #ifndef FCHDIR_REPLACEMENT
  
+ # include <errno.h>
  # include <stdarg.h>
  # include <string.h>
  # include <sys/types.h>
***************
*** 51,56 ****
--- 52,69 ----
        va_end (arg);
      }
  
+ # if OPEN_TRAILING_SLASH_BUG
+   if (flags & (O_CREAT | O_WRONLY | O_RDWR))
+     {
+       size_t len = strlen (filename);
+       if (len > 0 && filename[len - 1] == '/')
+       {
+         errno = EISDIR;
+         return -1;
+       }
+     }
+ # endif
+ 
  # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
    if (strcmp (filename, "/dev/null") == 0)
      filename = "NUL";
*** m4/open.m4.orig     2008-06-12 02:15:29.000000000 +0200
--- m4/open.m4  2008-06-12 02:05:11.000000000 +0200
***************
*** 1,5 ****
! # open.m4 serial 1
! dnl Copyright (C) 2007 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.
--- 1,5 ----
! # open.m4 serial 2
! dnl Copyright (C) 2007-2008 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.
***************
*** 13,17 ****
--- 13,52 ----
        REPLACE_OPEN=1
        AC_LIBOBJ([open])
        ;;
+     *)
+       dnl open("foo/") should not create a file when the file name has a
+       dnl trailing slash.
+       AC_CACHE_CHECK([whether open recognizes a trailing slash],
+         [gl_cv_func_open_slash],
+         [
+           AC_TRY_RUN([
+ #include <fcntl.h>
+ #if HAVE_UNISTD_H
+ # include <unistd.h>
+ #endif
+ int main ()
+ {
+   return open ("conftest.sl/", O_CREAT, 0600) >= 0;
+ }], [gl_cv_func_open_slash=yes], [gl_cv_func_open_slash=no],
+             [
+ changequote(,)dnl
+              case "$host_os" in
+                solaris2.[0-9]*) gl_cv_func_open_slash="guessing no" ;;
+                hpux*)           gl_cv_func_open_slash="guessing no" ;;
+                *)               gl_cv_func_open_slash="guessing yes" ;;
+              esac
+ changequote([,])dnl
+             ])
+           rm -f conftest.sl
+         ])
+       case "$gl_cv_func_open_slash" in
+         *no)
+           AC_DEFINE([OPEN_TRAILING_SLASH_BUG], 1,
+             [Define to 1 if open() fails to recognize a trailing slash.])
+           REPLACE_OPEN=1
+           AC_LIBOBJ([open])
+           ;;
+       esac
+       ;;
    esac
  ])
*** tests/test-open.c.orig      2008-06-12 02:15:29.000000000 +0200
--- tests/test-open.c   2008-06-12 02:03:01.000000000 +0200
***************
*** 38,43 ****
--- 38,45 ----
  int
  main ()
  {
+   ASSERT (open ("nonexist.ent/", O_CREAT, 0600) < 0);
+ 
    ASSERT (open ("/dev/null", O_RDONLY) >= 0);
  
    return 0;





reply via email to

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