Re: bug#8230: touch dumps core on solaris 10

2011-03-13 Thread Jim Meyering
Ben Walton wrote:
> Thanks for saving me the legwork on this.  The patch does correct the
> problem.  I appreciate the quick turnaround on this.

Thanks to both of you.
I've just updated coreutils to use the latest from gnulib,
so this will be fixed in coreutils-8.11.

However, contrary to most NEWS-worthy bugs, I have not tried
to determine when this one was introduced.  From the initial report,
I'm assuming it was introduced in coreutils-8.8, and wrote that in NEWS.

Ben, can you confirm that touch from coreutils-8.7 did not have this problem?
I'll wait for confirmation before pushing.


>From d8ed00cb61fede223b1450e53b7d6c21edff4b43 Mon Sep 17 00:00:00 2001
From: Jim Meyering 
Date: Sun, 13 Mar 2011 09:56:53 +0100
Subject: [PATCH] touch: update to latest gnulib to fix Solaris 10 touch segfault

* gnulib: Update to latest, to address http://debbugs.gnu.org/8230.
When built on Solaris 9 and run on Solaris 10, touch would segfault.
Reported by Ben Walton.
* bootstrap: Resync from gnulib.
* tests/init.sh: Likewise.
* NEWS (Bug fixes): Mention this.
---
 NEWS  |3 +++
 THANKS.in |1 +
 bootstrap |6 +++---
 gnulib|2 +-
 tests/init.sh |   34 +-
 5 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/NEWS b/NEWS
index 5770410..9ceaa06 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,9 @@ GNU coreutils NEWS-*- 
outline -*-
   sort no longer spawns 7 worker threads to sort 16 lines
   [bug introduced in coreutils-8.6]

+  touch built on Solaris 9 would segfault when run on Solaris 10
+  [bug introduced in coreutils-8.8]
+
   wc would dereference a NULL pointer upon an early out-of-memory error
   [bug introduced in coreutils-7.1]

diff --git a/THANKS.in b/THANKS.in
index fe53c44..fbc4153 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -71,6 +71,7 @@ Barry Kelly 
http://barrkel.blogspot.com/
 Bauke Jan Douma bjdo...@xs4all.nl
 Ben Ellistonb...@air.net.au
 Ben Harris  bj...@netbsd.org
+Ben Walton  bwal...@artsci.utoronto.ca
 Bengt Martenssonbe...@mathematik.uni-bremen.de
 Benjamin Cutler cutle...@simla.colostate.edu
 Bernard Giroud  bernard.gir...@creditlyonnais.ch
diff --git a/bootstrap b/bootstrap
index e9ec11e..f004ad3 100755
--- a/bootstrap
+++ b/bootstrap
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Print a version string.
-scriptversion=2011-01-21.16; # UTC
+scriptversion=2011-03-03.12; # UTC

 # Bootstrap this package from checked-out sources.

@@ -874,7 +874,7 @@ grep -E '^[  ]*AC_CONFIG_HEADERS?\>' configure.ac 
>/dev/null ||

 for command in \
   libtool \
-  "${ACLOCAL-aclocal} --force -I m4 $ACLOCAL_FLAGS" \
+  "${ACLOCAL-aclocal} --force -I '$m4_base' $ACLOCAL_FLAGS" \
   "${AUTOCONF-autoconf} --force" \
   "${AUTOHEADER-autoheader} --force" \
   "${AUTOMAKE-automake} --add-missing --copy --force-missing"
@@ -885,7 +885,7 @@ do
 command="${LIBTOOLIZE-libtoolize} -c -f"
   fi
   echo "$0: $command ..."
-  $command || exit
+  eval "$command" || exit
 done


diff --git a/gnulib b/gnulib
index 6f0680e..68d757e 16
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit 6f0680eb29a1737d704a1df26aafc00490cd34d8
+Subproject commit 68d757e2cb228590d46961cbf3e9ec7d4460e335
diff --git a/tests/init.sh b/tests/init.sh
index 44be35b..71c6516 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -74,10 +74,10 @@ Exit () { set +e; (exit $1); exit $1; }
 # the reason for skip/failure to console, rather than to the .log files.
 : ${stderr_fileno_=2}

-warn_() { echo "$@" 1>&$stderr_fileno_; }
-fail_() { warn_ "$ME_: failed test: $@"; Exit 1; }
-skip_() { warn_ "$ME_: skipped test: $@"; Exit 77; }
-framework_failure_() { warn_ "$ME_: set-up failure: $@"; Exit 99; }
+warn_ () { echo "$@" 1>&$stderr_fileno_; }
+fail_ () { warn_ "$ME_: failed test: $@"; Exit 1; }
+skip_ () { warn_ "$ME_: skipped test: $@"; Exit 77; }
+framework_failure_ () { warn_ "$ME_: set-up failure: $@"; Exit 99; }

 # Sanitize this shell to POSIX mode, if possible.
 DUALCASE=1; export DUALCASE
@@ -193,7 +193,7 @@ fi
 test -n "$EXEEXT" && shopt -s expand_aliases

 # Enable glibc's malloc-perturbing option.
-# This is cheap and useful for exposing code that depends on the fact that
+# This is useful for exposing code that depends on the fact that
 # malloc-related functions often return memory that is mostly zeroed.
 # If you have the time and cycles, use valgrind to do an even better job.
 : ${MALLOC_PERTURB_=87}
@@ -202,22 +202,22 @@ export MALLOC_PERTURB_
 # This is a stub function that is run upon trap (upon regular exit and
 # interrupt).  Override it with a per-test function, e.g., to unmount
 # a partition, or to undo any other global state changes.
-cleanup_() { :; }
+cleanup_ () { :; }

 if ( diff --version < /dev/null 2>&1 | grep GNU ) > /dev/null 2>&1; then
-  compare() { diff -

Re: bug#8230: touch dumps core on solaris 10

2011-03-13 Thread Ben Walton
Excerpts from Jim Meyering's message of Sun Mar 13 05:11:33 -0400 2011:

Hi Jim,

> I've just updated coreutils to use the latest from gnulib, so this
> will be fixed in coreutils-8.11.

Great!

> Ben, can you confirm that touch from coreutils-8.7 did not have this
> problem?  I'll wait for confirmation before pushing.

I just built 8.7 (I skipped from 8.4 -> 8.8) with my build script and
tested it.  It works correctly, so I'd say that yes, the problem was
introduced in 8.8.  This was on sparc, I didn't make the verification
on i386, but I will if you'd like.

Thanks
-Ben
--
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302




STREQ/STRNEQ

2011-03-13 Thread Reuben Thomas
I was a bit perplexed to find that one of the tests in maint.mk
instructs me to use STREQ/STRNEQ instead of strcmp, but, while this is
eminently sensible, not only is no definition of STRNEQ provided, but
that of STREQ isn't the one meant, but rather an optimised 11-argument
horror for short literal string comparisons.

I can find a definition of STREQ in some of the lib/*.c files, and
extrapolate STRNEQ from it, but it seems nonetheless that the doctor
is prescribing a medicine that the pharmacist doesn't stock.

-- 
http://rrt.sc3d.org



test: -a and -o not portable? Since when?

2011-03-13 Thread Reuben Thomas
They're specified in POSIX, so if that doesn't count as portable, it'd
be nice to have a little more explanation in the comment in maint.mk.

-- 
http://rrt.sc3d.org



Re: test: -a and -o not portable? Since when?

2011-03-13 Thread Paul Eggert
On 03/13/2011 07:30 AM, Reuben Thomas wrote:
> They're specified in POSIX

They're marked as an obsolescent XSI extension in POSIX.1-2008.
That is, they're not required by POSIX, and even as an
optional extension they may go away in future versions.

The rationale explains why -a and -o are deprecated.
One thing that the rationale doesn't fully go into, though,
is that -a and -o are syntactically ambiguous in some
cases.



Re: [PATCH 3/4] Add a CLOEXEC recvfd

2011-03-13 Thread Bruno Haible
Hi Bastien,

> In order to avoid a race add a recvfd(int fd, int flags). flags could be 
> O_CLOEXEC.
> ---
>  lib/passfd.c   |   58 
> +++-
>  lib/passfd.h   |1 +
>  m4/afunix.m4   |   22 +
>  modules/passfd |1 +

This is pretty good as well. But there's no need for two functions recvfd and
recvfd2. Better merge them into a single function. It's easy for the callers
to pass a 0 flags argument. In the POSIX API, a separate function was
introduced only when the previous function already existed for a long time,
like pipe()/pipe2() and accept()/accept4().

Also, it is better to test 'flags & O_CLOEXEC' instead of 'flags == O_CLOEXEC'
because
  - The flags argument is conceptually a bit mask.
  - O_CLOEXEC is 0 on some platforms (that don't support this flag), and
passing a 0 flags argument ought to _not_ set the close-on-exec flag.

Other than this, I applied the usual untabification and .m4 file indentation.

A possible simplification would be to assume that MSG_CMSG_CLOEXEC is a macro
when it exists, and thus simplify "#if HAVE_MSG_CMSG_CLOEXEC" to
"#if defined MSG_CMSG_CLOEXEC".


2011-03-13  Bastien Roucariès  
Bruno Haible  

passfd module, part 3.
* lib/passfd.h (recvfd): Add a flags argument.
* lib/passfd.c: Include , cloexec.h.
(recvfd): Add a flags argument.
* m4/afunix.m4 (gl_SOCKET_AFUNIX): Test whether MSG_CMSG_CLOEXEC
exists.
* modules/passfd (Depends-on): Add cloexec.
Suggested by Eric Blake.

--- lib/passfd.c.orig   Sun Mar 13 16:26:20 2011
+++ lib/passfd.cSun Mar 13 15:53:28 2011
@@ -19,6 +19,7 @@
 #include "passfd.h"
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -35,6 +36,8 @@
 # include 
 #endif
 
+#include "cloexec.h"
+
 /* sendfd sends the file descriptor fd along the socket
to a process calling recvfd on the other end.
 
@@ -84,11 +87,12 @@
 }
 
 /* recvfd receives a file descriptor through the socket.
+   The flags are a bitmask, possibly including O_CLOEXEC (defined in 
).
 
Return 0 on success, or -1 with errno set in case of error.
 */
 int
-recvfd (int sock)
+recvfd (int sock, int flags)
 {
   char recv = 0;
   const int mone = -1;
@@ -96,6 +100,12 @@
   struct iovec iov[1];
   struct msghdr msg;
 
+  if ((flags & ~O_CLOEXEC) != 0)
+{
+  errno = EINVAL;
+  return -1;
+}
+
   /* send at least one char */
   iov[0].iov_base = &recv;
   iov[0].iov_len = 1;
@@ -108,6 +118,11 @@
 #if HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
 struct cmsghdr *cmsg;
 char buf[CMSG_SPACE (sizeof (fd))];
+# if HAVE_MSG_CMSG_CLOEXEC
+int flags_recvmsg = (flags & O_CLOEXEC ? MSG_CMSG_CLOEXEC : 0);
+# else
+int flags_recvmsg = 0;
+# endif
 
 msg.msg_control = buf;
 msg.msg_controllen = sizeof (buf);
@@ -119,7 +134,7 @@
 memcpy (CMSG_DATA (cmsg), &mone, sizeof (mone));
 msg.msg_controllen = cmsg->cmsg_len;
 
-if (recvmsg (sock, &msg, 0) < 0)
+if (recvmsg (sock, &msg, flags_recvmsg) < 0)
   return -1;
 
 cmsg = CMSG_FIRSTHDR (&msg);
@@ -133,13 +148,43 @@
   }
 
 memcpy (&fd, CMSG_DATA (cmsg), sizeof (fd));
+
+# if !HAVE_MSG_CMSG_CLOEXEC
+/* set close-on-exec flag */
+if (flags & O_CLOEXEC)
+  {
+if (set_cloexec_flag (fd, true) < 0)
+  {
+int saved_errno = errno;
+(void) close (fd);
+errno = saved_errno;
+return -1;
+  }
+  }
+# endif
+
 return fd;
+
 #elif HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY
 msg.msg_accrights = &fd;
 msg.msg_accrightslen = sizeof (fd);
 if (recvmsg (sock, &msg, 0) < 0)
   return -1;
+
+/* set close-on-exec flag */
+if (flags & O_CLOEXEC)
+  {
+if (set_cloexec_flag (fd, true) < 0)
+  {
+int saved_errno = errno;
+(void) close (fd);
+errno = saved_errno;
+return -1;
+  }
+  }
+
 return fd;
+
 #else
 errno = ENOSYS;
 return -1;
--- lib/passfd.h.orig   Sun Mar 13 16:26:20 2011
+++ lib/passfd.hSun Mar 13 15:43:03 2011
@@ -23,7 +23,7 @@
 #endif
 
 extern int sendfd (int sock, int fd);
-extern int recvfd (int sock);
+extern int recvfd (int sock, int flags);
 
 #ifdef __cplusplus
 }
--- m4/afunix.m4.orig   Sun Mar 13 16:26:20 2011
+++ m4/afunix.m4Sun Mar 13 15:58:06 2011
@@ -1,4 +1,4 @@
-# afunix.m4 serial 2
+# afunix.m4 serial 3
 dnl Copyright (C) 2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -109,4 +109,31 @@
 AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY], [1],
   [Define to 1 if fd can be sent/received in the BSD4.3 way.])
   fi
+
+  AC_MSG_CHECKING([for UNIX domain sockets recvmsg() MSG_CMSG_CLOEXEC flag])
+  AC_CACHE_VAL([gl_cv_socket_unix_msg_cmsg_cloexec],
+[AC_COMPILE_IFELSE(
+   [AC_LANG_P

Re: [PATCH 2/4] sendfd, recvf pass file descriptors along Unix domain sockets

2011-03-13 Thread Bruno Haible
Hi Bastien,

>  lib/passfd.c   |  147 
> 
>  lib/passfd.h   |   21 
>  modules/passfd |   30 +++

This code looked nearly fine as well (at least superficially), so I've
committed it in your name with this ChangeLog entry:

2011-03-07  Bastien Roucariès  

passfd module, part 2.
* modules/passfd: New file.
* lib/passfd.h: New file.
* lib/passfd.c: New file.

and added some tweaks:
- In the module description, section "Include", you should mention only the
  header files the programmer needs to use for your module.
- In the lib/ source files, we use the GPLv3+ copyright header normally.
  The real license terms are in the modules file, however.
- We avoid tabs in gnulib source code. See the README file, section
  "Indent with spaces, not TABs", for a recipe that makes sure not to introduce
  tabs accidentally.
- We use #if, not #ifdef, to test the value of HAVE_... macros defined in
  config.h.
- Specify the functions unambiguously: If a function is expected to set errno
  when it fails (and your unit test in part 4 apparently expects this), then
  the function's specification should say so.
- The specification of recvfd was merely a copy&paste of the specification of
  sendfd.
- Once you depend on module 'sys_socket', you can include 
  unconditionally and don't need , because the 'sys_socket' module
  deals with all this.
- Reduce the scope of the variables 'fd' and 'mone', so as to avoid gcc warnings
  like "warning: unused variable ‘mone’".
- The dependency to module 'errno' is not needed, since the only errno values
  that you use are ENOSYS and EACCES. (See doc/posix-headers/errno.texi.)


2011-03-13  Bruno Haible  

passfd module, part 2, tweaks.
* modules/passfd (Files): Reorder.
(Depends-on): Remove errno.
(Include): Remove , .
* lib/passfd.h: Use a GPLv3+ header. Make C++ safe.
* lib/passfd.c: Untabify. Use a GPLv3+ header. Really include the
specification header. Include  always. Don't include
. Use "#if HAVE_..." instead of "#ifdef HAVE_...".
(sendfd): Clarify that it sets errno when it fails.
(recvfd): Fix specification.

--- modules/passfd.orig Sun Mar 13 15:16:08 2011
+++ modules/passfd  Sun Mar 13 15:09:09 2011
@@ -2,13 +2,12 @@
 Passfile descriptors along Unix (socket/stream) file descriptors
 
 Files:
-m4/sockpfaf.m4
-m4/afunix.m4
-lib/passfd.c
 lib/passfd.h
+lib/passfd.c
+m4/afunix.m4
+m4/sockpfaf.m4
 
 Depends-on:
-errno
 sys_socket
 extensions
 
@@ -19,8 +19,6 @@
 lib_SOURCES += passfd.c
 
 Include:
-
-
 "passfd.h"
 
 License:
--- lib/passfd.h.orig   Sun Mar 13 15:16:08 2011
+++ lib/passfd.hSun Mar 13 15:12:04 2011
@@ -4,7 +4,7 @@
 
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 of the License, or
+   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,
@@ -14,8 +14,19 @@
 
You should have received a copy of the GNU General Public License
along with this program.  If not, see .  */
+
 #ifndef PASSFD_H_
 #define PASSFD_H_ 1
-int sendfd (int sock, int fd);
-int recvfd (int sock);
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int sendfd (int sock, int fd);
+extern int recvfd (int sock);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif
--- lib/passfd.c.orig   Sun Mar 13 15:16:07 2011
+++ lib/passfd.cSun Mar 13 15:15:19 2011
@@ -2,7 +2,7 @@
 
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 of the License, or
+   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,
@@ -16,6 +16,8 @@
 #include 
 
 /* Specification.  */
+#include "passfd.h"
+
 #include 
 #include 
 #include 
@@ -23,20 +25,15 @@
 #include 
 #include 
 
-#ifdef HAVE_SYS_SOCKET_H
 #include 
-#endif
-#ifdef HAVE_SYS_UN_H
-#include 
-#endif
-#ifdef HAVE_WINSOCK2_H
-#include 
+#if HAVE_SYS_UN_H
+# include 
 #endif
 
-/* Sendfd sends the file descriptor fd along the socket
+/* sendfd sends the file descriptor fd along the socket
to a process calling recvfd on the other end.
-   
-   return -1 in case of error, 0 on success
+
+   Return 0 on success, or -1 with errno set in case of error.
 */
 int
 sendfd (int sock, int fd)
@@ -54,7 +51,7 @@ sendfd (int sock, int fd)
   msg.msg_namelen = 0;
 
   {
-#ifdef HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
+#if HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
 struct cmsghdr *cmsg;
 char buf[CMSG_SPACE (sizeof (fd))];
 
@@ -81,

Re: [PATCH] maint: adjust cpp indentation for my modules, as well

2011-03-13 Thread Jim Meyering
Bruno Haible wrote:
> Eric Blake wrote:
>> > This Makefile is so specialized that I think it can assume GNU make.
>> > Does anyone prefer not to do that?
>>
>> No complaint by me, although we might want to 'git mv {,GNU}Makefile' to
>> make the change obvious.
>
> When a newbie looks whether there is a Makefile, he looks for 'Makefile'.
> I therefore find it preferable to not rename 'Makefile' to 'GNUmakefile',
> and instead add a comment such as "This Makefile assumes GNU make, git,
> and makeinfo for the documentation."

I've pushed this:

>From ca56fa858e1d4499a1b4483fae0b60294115cdfc Mon Sep 17 00:00:00 2001
From: Jim Meyering 
Date: Sun, 13 Mar 2011 18:45:33 +0100
Subject: [PATCH] Makefile: rely on GNU make; derive syntax-check rule names

Rather than requiring that each sc_ rule be listed as a dependent
of "check", use features of GNU make to derive the list.
* Makefile (syntax-check-rules): Define.
(check): Depend on the new variable, not the hard-coded list.
Add a comment listing a few requirements.
---
 ChangeLog |8 
 Makefile  |   14 +-
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 74afdbb..693f4cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-03-13  Jim Meyering  
+
+   Makefile: rely on GNU make; derive syntax-check rule names
+   Rather than requiring that each sc_ rule be listed as a dependent
+   of "check", use features of GNU make to derive the list.
+   * Makefile (syntax-check-rules): Define.
+   (check): Depend on the new variable, not the hard-coded list.
+
 2011-03-13  Bastien Roucariès  
 Bruno Haible  

diff --git a/Makefile b/Makefile
index 9c0d0c3..c9bfc16 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,13 @@
-# Makefile for gnulib central.
+# GNU Makefile for gnulib central.
 # Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
 #
 # Copying and distribution of this file, with or without modification,
 # in any medium, are permitted without royalty provided the copyright
 # notice and this notice are preserved.

+# This Makefile requires the use of GNU make.  Some targets require
+# that you have tools like git, makeinfo and cppi installed.
+
 # Produce some files that are not stored in the repository.
 all:

@@ -12,11 +15,12 @@ all:
 info html dvi pdf:
cd doc && $(MAKE) $@ && $(MAKE) mostlyclean

+# Collect the names of rules starting with `sc_'.
+syntax-check-rules := $(sort $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p'\
+   Makefile))
+
 # Perform some platform independent checks on the gnulib code.
-check: \
-  sc_prohibit_augmenting_PATH_via_TESTS_ENVIRONMENT\
-  sc_pragma_columns\
-  sc_prefer_ac_check_funcs_once
+check: $(syntax-check-rules)

 sc_prefer_ac_check_funcs_once:
if test -d .git; then   \
--
1.7.4.1.408.gb6b16



Re: bug#8230: touch dumps core on solaris 10

2011-03-13 Thread Jim Meyering
Ben Walton wrote:
>> Ben, can you confirm that touch from coreutils-8.7 did not have this
>> problem?  I'll wait for confirmation before pushing.
>
> I just built 8.7 (I skipped from 8.4 -> 8.8) with my build script and
> tested it.  It works correctly, so I'd say that yes, the problem was
> introduced in 8.8.  This was on sparc, I didn't make the verification
> on i386, but I will if you'd like.

Thanks for confirming.  That should be enough.
I've pushed that change to coreutils, and am marking this issue as closed.



Re: [PATCH 4/4] Add test for passfd

2011-03-13 Thread Bruno Haible
Hello Bastien,

> Add simple testing for passfd
> ---
>  modules/passfd-tests |   11 +
>  tests/test-passfd.c  |  112 
> ++

I added this too, untabified, and with this ChangeLog entry and tweaks:


2011-03-07  Bastien Roucariès  

passfd module, part 4.
* modules/passfd-tests: New file.
* tests/test-passfd.c: New file.

2011-03-13  Bruno Haible  

passfd module, part 4, tweaks.
* tests/test-passfd.c: Reorder includes.
(main): Fix perror and printf calls.

--- tests/test-passfd.c.origSun Mar 13 20:18:22 2011
+++ tests/test-passfd.c Sun Mar 13 19:55:45 2011
@@ -1,5 +1,5 @@
-/* Test of terminating the current process.
-   Copyright (C) 2010-2011 Free Software Foundation, Inc.
+/* Test of passing file descriptors.
+   Copyright (C) 2011 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
@@ -14,18 +14,17 @@
You should have received a copy of the GNU General Public License
along with this program.  If not, see .  */
 
-/* Written by Bruno Haible , 2010.  */
-
 #include 
+
+#include "passfd.h"
+
+#include 
 #include 
 #include 
 #include 
-#include "passfd.h"
 #include 
 #include 
 #include 
-#include 
-
 
 #include "macros.h"
 
@@ -57,7 +56,7 @@
   pid = fork ();
   if (pid == -1)
 {
-  perror ("fork:");
+  perror ("fork");
   return 3;
 }
   if (pid == 0)
@@ -65,7 +64,7 @@
   ret = sendfd (pair[1], fdnull);
   if (ret == -1)
 {
-  perror ("sendfd:");
+  perror ("sendfd");
   return 64;
 }
   return 0;
@@ -82,7 +81,7 @@
   ret = waitpid (pid, &status, 0);
   if (ret == -1)
 {
-  perror ("waitpid:");
+  perror ("waitpid");
   return 17;
 }
   ASSERT (ret == pid);
@@ -96,7 +95,7 @@
   ret = WEXITSTATUS (status);
   if (ret != 0)
 {
-  fprintf (stderr, "Send fd fail");
+  fprintf (stderr, "Send fd fail\n");
   return ret;
 }
 
@@ -104,7 +103,7 @@
   ret == fstat (fd, &st);
   if (0 != ret)
 {
-  perror("fstat:");
+  perror ("fstat");
   return 80;
 }
   return 0;

-- 
In memoriam Odette Sansom 



test-ignore-value.c warnings

2011-03-13 Thread Bruno Haible
Hi Eric,

On OpenBSD 4.4, which uses a gcc version 3.3.5, I get these warnings:

test-ignore-value.c:35: warning: `__warn_unused_result__' attribute directive 
ignored
test-ignore-value.c:36: warning: `__warn_unused_result__' attribute directive 
ignored
test-ignore-value.c:37: warning: `__warn_unused_result__' attribute directive 
ignored
test-ignore-value.c:38: warning: `__warn_unused_result__' attribute directive 
ignored
test-ignore-value.c:39: warning: `__warn_unused_result__' attribute directive 
ignored

The reason is that __warn_unused_result__ was introduced in gcc 3.4, not
in gcc 3.1, as the code appears to assume. OK to fix this?


2011-03-13  Bruno Haible  

ignore-value tests: Avoid warnings.
* tests/test-ignore-value.c (_GL_ATTRIBUTE_RETURN_CHECK): Define to
empty for gcc < 3.4.

--- tests/test-ignore-value.c.orig  Sun Mar 13 20:55:04 2011
+++ tests/test-ignore-value.c   Sun Mar 13 20:50:28 2011
@@ -24,7 +24,7 @@
 #include 
 
 #ifndef _GL_ATTRIBUTE_RETURN_CHECK
-# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1)
+# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
 #  define _GL_ATTRIBUTE_RETURN_CHECK
 # else
 #  define _GL_ATTRIBUTE_RETURN_CHECK __attribute__((__warn_unused_result__))

-- 
In memoriam Odette Sansom 



Re: test: -a and -o not portable? Since when?

2011-03-13 Thread Reuben Thomas
On 13 March 2011 15:22, Paul Eggert  wrote:
> On 03/13/2011 07:30 AM, Reuben Thomas wrote:
>> They're specified in POSIX
>
> They're marked as an obsolescent XSI extension in POSIX.1-2008.

Pity that the POSIX man pages say none of this (but I don't know that
they even mention 2008).

Thanks for the explanation. A one-line explanation such as:

# (syntactically ambiguous in some cases; deprecated by POSIX)

would be nice to see in maint.mk, given that the audience for the
checks there is likely to be quite pedantic in the first place.

-- 
http://rrt.sc3d.org



Exception to space-tab rule

2011-03-13 Thread Reuben Thomas
make syntax-check is complaining about space-tabs (sc_space_tab) in a
sort of file where this is perfectly permissable: a .diff file. Why do
I have a diff file in version control? Because I'm patching gnulib.

Of course, I can add this to VC_LIST_ALWAYS_EXCLUDE_REGEX, but maybe
.diff files should be excluded from this check anyway?

-- 
http://rrt.sc3d.org



Read GNULIB_SRCDIR in maint.mk?

2011-03-13 Thread Reuben Thomas
i.e. just before

gnulib_dir ?= $(srcdir)/gnulib

have

gnulib_dir ?= $(GNULIB_SRCDIR)

?

-- 
http://rrt.sc3d.org



passfd on glibc

2011-03-13 Thread Bruno Haible
After the passfd source code is written and polished and has a unit test,
now comes testing on various platforms.

The first one is a glibc system.  I get these warnings:

test-passfd.c: In function ‘main’:
test-passfd.c:81: warning: implicit declaration of function ‘waitpid’
test-passfd.c:103: warning: value computed is not used

This fixes it:


2011-03-13  Bruno Haible  

passfd test: Fix warnings.
* tests/test-passfd.c: Include .
(main): Fix typo.

--- tests/test-passfd.c.origSun Mar 13 23:34:20 2011
+++ tests/test-passfd.c Sun Mar 13 20:36:56 2011
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "macros.h"
 
@@ -86,8 +87,7 @@
 }
   ASSERT (ret == pid);
 
-  ret = WIFEXITED (status);
-  if (ret == 0)
+  if (!WIFEXITED (status))
 {
   fprintf (stderr, "Child does not normally exit\n");
   return 65;
@@ -100,8 +100,8 @@
 }
 
   /* try to stat new fd */
-  ret == fstat (fd, &st);
-  if (0 != ret)
+  ret = fstat (fd, &st);
+  if (ret < 0)
 {
   perror ("fstat");
   return 80;
-- 
In memoriam Odette Sansom 



passfd on OpenBSD

2011-03-13 Thread Bruno Haible
On OpenBSD 4.4, I get this compilation error:

passfd.c: In function `sendfd':
passfd.c:45: error: storage size of `iov' isn't known

The reason is that for 'struct iovec' you need , not only
 (look in POSIX!). This fixes it:


2011-03-13  Bruno Haible  

passfd: Fix compilation error on OpenBSD.
* lib/passfd.c: Include .

--- lib/passfd.c.orig   Sun Mar 13 23:34:19 2011
+++ lib/passfd.cSun Mar 13 21:30:49 2011
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
-- 
In memoriam Odette Sansom 



gnu_key_ID setup

2011-03-13 Thread Reuben Thomas
Currently, maint.mk has the line (1077):

  $$(git cat-file tag v$(VERSION) > .ann-sig \

Is this v$(VERSION) somehow different from the one that is the
definition of this-vc-tag for the git case? i.e. why's $(this-vc-tag)
not used here instead of v$(VERSION)?

-- 
http://rrt.sc3d.org



passfd on FreeBSD

2011-03-13 Thread Bruno Haible
On FreeBSD 6.4, the compilation succeeds but the test fails:

recvfd: Function not implemented
sendfd: Function not implemented
FAIL: test-passfd

config.log shows this:

configure:7701: checking for UNIX domain sockets SCM_RIGHTS that behave in BSD4.
4 way
configure:7744: gcc -c -g -O2 -Wall conftest.c >&5
conftest.c: In function `main':
conftest.c:98: error: `NULL' undeclared (first use in this function)
conftest.c:98: error: (Each undeclared identifier is reported only once
conftest.c:98: error: for each function it appears in.)
conftest.c:94: warning: unused variable `fdptr'

The reason is that the expansion of CMSG_FIRSTHDR (...) contains a reference to 
NULL.

In :
#define CMSG_NXTHDR(mhdr, cmsg) \
((char *)(cmsg) == NULL ? CMSG_FIRSTHDR(mhdr) : \
...


2011-03-13  Bruno Haible  

passfd: Work around bug with CMSG_FIRSTHDR on FreeBSD 6.4.
* lib/sys_socket.in.h: Include .
* m4/afunix.m4 (gl_SOCKET_AFUNIX): Include  before using
CMSG_FIRSTHDR. Remove unused variable.

--- lib/sys_socket.in.h.origSun Mar 13 23:51:21 2011
+++ lib/sys_socket.in.h Sun Mar 13 23:50:39 2011
@@ -50,6 +50,10 @@
.  */
 # include 
 
+/* On FreeBSD 6.4,  defines some macros that assume that NULL
+   is defined.  */
+# include 
+
 /* The include_next requires a split double-inclusion guard.  */
 # @INCLUDE_NEXT@ @NEXT_SYS_SOCKET_H@
 
--- m4/afunix.m4.orig   Sun Mar 13 23:51:21 2011
+++ m4/afunix.m4Sun Mar 13 23:51:11 2011
@@ -1,4 +1,4 @@
-# afunix.m4 serial 3
+# afunix.m4 serial 4
 dnl Copyright (C) 2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -43,6 +43,7 @@
 [AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
   [[#include 
+#include 
 #ifdef HAVE_SYS_SOCKET_H
 #include 
 #endif
@@ -57,7 +58,6 @@
   struct cmsghdr *cmsg;
   int myfds[1] = {0};
   char buf[CMSG_SPACE (sizeof (myfds))];
-  int *fdptr;
 
   msg.msg_control = buf;
   msg.msg_controllen = sizeof buf;

-- 
In memoriam Odette Sansom 



passfd on AIX 5.2

2011-03-13 Thread Bruno Haible
On AIX 5.1 and likely also 5.2, I get these warnings

passfd.c: In function 'sendfd':
passfd.c:60: warning: implicit declaration of function 'CMSG_SPACE'
passfd.c:67: warning: implicit declaration of function 'CMSG_LEN'

and later on link errors because CMSG_SPACE and CMSG_LEN are not functions.

The reason is that  defines these two macros only if
_LINUX_SOURCE_COMPAT is defined. This fixes it:


2011-03-13  Bruno Haible  

passfd: Fix link error on AIX 5.2.
* m4/afunix.m4 (gl_SOCKET_AFUNIX): Define _LINUX_SOURCE_COMPAT.

--- m4/afunix.m4.orig   Sun Mar 13 23:59:07 2011
+++ m4/afunix.m4Sun Mar 13 23:59:05 2011
@@ -1,4 +1,4 @@
-# afunix.m4 serial 4
+# afunix.m4 serial 5
 dnl Copyright (C) 2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -38,6 +38,10 @@
   [Define to 1 if  defines SCM_RIGHTS.])
   fi
 
+  dnl Persuade AIX 5.2  to declare CMSG_SPACE, CMSG_LEN.
+  AC_DEFINE([_LINUX_SOURCE_COMPAT], [1],
+[Define in order to get some macros on AIX systems.])
+
   AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHTS that behave in BSD4.4 
way])
   AC_CACHE_VAL([gl_cv_socket_unix_scm_rights_bsd44_way],
 [AC_COMPILE_IFELSE(
-- 
In memoriam Odette Sansom 



passfd on Solaris

2011-03-13 Thread Bruno Haible
On Solaris, I get a link error:

gcc  -g -O2   -o test-passfd test-passfd.o ../gllib/libgnu.a 
Undefined   first referenced
 symbol in file
socketpair  test-passfd.o
recvmsg ../gllib/libgnu.a(passfd.o)
sendmsg ../gllib/libgnu.a(passfd.o)


This fixes it, and also fixes the module description.


2011-03-13  Bruno Haible  

passfd: Fix link error on Solaris.
* modules/passfd (Description): Correct.
(Depends-on): Add socketlib.
(Link): New section.
* modules/passfd-tests (Makefile.am): Link test-passfd with LIBSOCKET.

--- modules/passfd.orig Sun Mar 13 23:59:07 2011
+++ modules/passfd  Sun Mar 13 23:55:25 2011
@@ -1,5 +1,5 @@
 Description:
-Passfile descriptors along Unix (socket/stream) file descriptors
+Pass file descriptors along Unix domain sockets
 
 Files:
 lib/passfd.h
@@ -10,6 +10,7 @@
 Depends-on:
 cloexec
 sys_socket
+socketlib
 extensions
 
 configure.ac:
@@ -21,6 +22,9 @@
 Include:
 "passfd.h"
 
+Link:
+$(LIBSOCKET)
+
 License:
 LGPLv2+
 
--- modules/passfd-tests.orig   Sun Mar 13 23:59:07 2011
+++ modules/passfd-testsSun Mar 13 23:55:25 2011
@@ -9,3 +9,4 @@
 Makefile.am:
 TESTS += test-passfd
 check_PROGRAMS += test-passfd
+test_passfd_LDADD = $(LDADD) @LIBSOCKET@

-- 
In memoriam Odette Sansom 



passfd on more platforms

2011-03-13 Thread Bruno Haible
Here's the result of testing passfd:

Linux  OK  BSD4.4 way, MSG_CMSG_CLOEXEC
FreeBSDOK  BSD4.4 way
OpenBSDOK  BSD4.4 way
NetBSD FAILBSD4.4 way
AIXOK  BSD4.4 way
HP-UX  OK  BSD4.3 way
IRIX   OK  BSD4.3 way
OSF/1  OK  BSD4.4 way
SolarisOK  BSD4.3 way
Cygwin FAILBSD4.4 way

It is a bit surprising that Solaris 10 says that it doesn't support the
BSD4.4 way. That is because
  checking for UNIX domain sockets SCM_RIGHTS that behave in BSD4.4 way... no
because CMSG_SPACE etc. are not declared by  by default.
I'm not sure whether gnulib should define _XOPEN_SOURCE, _XOPEN_SOURCE_EXTENDED,
or _POSIX_C_SOURCE. But's let's leave it as is for now, since the BSD4.3 way
works.

On NetBSD 5.0, the test reports
  sendfd: Invalid argument
and then hangs.

On Cygwin, the test fails:
  recvfd: Permission denied
  FAIL: test-passfd.exe

On mingw, I haven't even tried the module. It first requires
  - a 'socketpair' module for the test,
  - to rewrite the test to use the 'execute' module instead of fork().

Bruno
-- 
In memoriam Odette Sansom 



VC-tag

2011-03-13 Thread Reuben Thomas
What's the intended use of VC-tag in maint.mk? I can't seem to find
anything on this in the manual, or in the code, and only a short note
when it was added in the ChangeLog. $(VC-tag) doesn't seem to be used
anywhere. This seems to be connected with the comment:

# If it's not already specified, derive the GPG key ID from
# the signed tag we've just applied to mark this release.

I'd like indeed to have just applied that signed tag, but I can't see
how to do it via a make target.

-- 
http://rrt.sc3d.org




Re: test: -a and -o not portable? Since when?

2011-03-13 Thread Ben Pfaff
Reuben Thomas  writes:

> On 13 March 2011 15:22, Paul Eggert  wrote:
>> On 03/13/2011 07:30 AM, Reuben Thomas wrote:
>>> They're specified in POSIX
>>
>> They're marked as an obsolescent XSI extension in POSIX.1-2008.
>
> Pity that the POSIX man pages say none of this (but I don't know that
> they even mention 2008).

I do see the mention of obsolescence:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
-- 
Ben Pfaff 
http://benpfaff.org