Re: uninorm/nfc - Unicode version?

2011-03-30 Thread Simon Josefsson
First thanks for the relicensing!

Bruno Haible  writes:

> Simon Josefsson wrote on 2011-01-19:
>> OTOH, by only relicensing some modules, I don't think I can use an
>> installed libunistring shared library, which would contain LGPLv3+ code
>> too.
>
> Yes, I agree, this would be too hairy from a legal point of view. You can
> explain to a lawyer which .so file requires which .so file (via "ldd" or
> "readelf"), but it's too hard to explain that a .so file consists of
> two parts, one part under LGPLv2+ and one part under LGPLv3+ and that
> they should be considered as independent "works" although no tool exists
> that can separate the two parts.

Right.  And I don't think that is essential -- I see the LGPLv2+ part as
mostly for glibc, which likely will not want to link to libunistring but
to a self-contained "libcidn2.so" like it is done today for libidn.

/Simon



Re: [PATCH] maint: stop using .x-sc_* files to list syntax-check exemptions

2011-03-30 Thread Paolo Bonzini

On 03/19/2011 06:35 PM, Jim Meyering wrote:

+exclude_file_name_regexp--sc_space_tab = ^gl/lib/.*\.c\.diff$$


.diff and .patch files should probably be exempted from this rule at the 
gnulib level, no?


Paolo



Re: [PATCH] maint: stop using .x-sc_* files to list syntax-check exemptions

2011-03-30 Thread Jim Meyering
Paolo Bonzini wrote:
> On 03/19/2011 06:35 PM, Jim Meyering wrote:
>> +exclude_file_name_regexp--sc_space_tab = ^gl/lib/.*\.c\.diff$$
>
> .diff and .patch files should probably be exempted from this rule at
> the gnulib level, no?

Hi Paolo,

I debated that.
However, a patch will contain a space-TAB only if the original source
contains a leading TAB in a context line, and with the no-leading-TAB
policy used by a few projects, such a diff would only apply to exempt
files, like Makefile.am.

Always exempting .diff and .patch files would let those files
introduce inadvertent space-TAB.  In some projects, those
files we need to exempt (and patches applying to them)
are truly exceptional, so it makes sense to have to list them.
The exempted .diff files referred to above apply to C source files
from glibc; they contain lines starting with TAB.

As such, I would prefer not to always exempt them.



Re: [PATCH] Fix a typo

2011-03-30 Thread Bastien ROUCARIES
Any news ?

On Mon, Mar 28, 2011 at 1:41 PM, Bastien ROUCARIES
 wrote:
> Fix a typo in passfd code
> ---
>  lib/passfd.c |    1 -
>  1 files changed, 0 insertions(+), 1 deletions(-)
>
> diff --git a/lib/passfd.c b/lib/passfd.c
> index 573b80e..ae716a6 100644
> --- a/lib/passfd.c
> +++ b/lib/passfd.c
> @@ -67,7 +67,6 @@ sendfd (int sock, int fd)
>     cmsg->cmsg_len = CMSG_LEN (sizeof (int));
>     /* Initialize the payload: */
>     memcpy (CMSG_DATA (cmsg), &fd, sizeof (fd));
> -    msg.msg_controllen = cmsg->cmsg_len;
>  #elif HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY
>     msg.msg_accrights = &fd;
>     msg.msg_accrightslen = sizeof (fd);
> --
> 1.7.4.1
>
>



Re: [PATCH] tests: readlink* ("", ... fails with EINVAL on newer kernels

2011-03-30 Thread Eric Blake
On 03/30/2011 12:49 AM, Jim Meyering wrote:
> coreutils' "make check" failed on rawhide due to a kernel change
> in how readlink and readlinkat treat the empty file name.
> Before, they'd fail with ENOENT.  Now, it's EINVAL.

That's unfortunate, because it violates POSIX.  Is it worth filing a bug
against glibc to avoid exposing the kernel's choice to the user?

But I agree with the patch.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] tests: readlink* ("", ... fails with EINVAL on newer kernels

2011-03-30 Thread Jim Meyering
Eric Blake wrote:
> On 03/30/2011 12:49 AM, Jim Meyering wrote:
>> coreutils' "make check" failed on rawhide due to a kernel change
>> in how readlink and readlinkat treat the empty file name.
>> Before, they'd fail with ENOENT.  Now, it's EINVAL.
>
> That's unfortunate, because it violates POSIX.

Good point.

> Is it worth filing a bug
> against glibc to avoid exposing the kernel's choice to the user?

Actually I don't *know* that this changed in the kernel.
It might have been in glibc.  I didn't look.

In any case, it'd be good to know what motivated the change,
so if no one else gets to it first, I'll track that down tomorrow.



Re: non-blocking I/O

2011-03-30 Thread Eric Blake
On 03/29/2011 09:16 AM, Bruno Haible wrote:
> Paolo Bonzini wrote:
>> Without guessing what your bias is, I also :) prefer to implement 
>> {g,s}et_nonblock_flag functions.  It would use either 
>> SetNamedPipeHandleState or ioctlsocket (using the socket detection trick 
>> in sockets.c to detect sockets, and then GetFileType to detect pipes if 
>> it fails).
> 
> Here's proposed code to that effect.

Let's get it checked in.

>  Note that the getter function cannot
> be implemented: How to determine whether a Woe32 socket is non-blocking?

I don't know.

> /* Non-blocking I/O is an I/O mode by which read(), write() calls avoid
>blocking the current thread.  When non-blocking is enabled:
>- A read() call returns -1 with errno set to EAGAIN when no data or EOF
>  information is immediately available.
>- A write() call returns -1 with errno set to EAGAIN when it cannot
>  transport the requested amount of data (but at most one pipe buffer)
>  without blocking.
> 
>There are two modern alternatives to non-blocking I/O:

three

>  - use select() or poll() followed by read() or write() if the descriptor
>is ready,
>  - call read() or write() in separate threads.  */

- use aio_*, although that is not as widely portable

> 
> #if 0 /* cannot be portably implemented */
> /* Return true if I/O to the descriptor DESC is currently non-blocking,
>or false if it is blocking.  */
> extern bool get_nonblocking_flag (int desc);
> #endif

Should we make this tri-state?

-1 for unable to determine (such as mingw sockets for now), 0 for
blocking (such as mingw regular files, or Unix platforms where
fcntl(F_GETFL) works), 1 for non-blocking.

> /* Specify the non-blocking flag for the descriptor DESC.
>Return 0 upon success, or -1 with errno set upon failure.
>The default depends on the presence of the O_NONBLOCK flag for files
>or pipes opened with open() or on the presence of the SOCK_NONBLOCK
>flag for pipes.  */
> extern int set_nonblocking_flag (int desc, bool value);

Should we document this function's behavior on fd's exempt by POSIX?
For regular files and directories, non-blocking has no effect, but it is
implementation-defined whether fcntl(F_SETFL) can modify the O_NONBLOCK
flag or whether the flag is silently ignored.  Having consistent
behavior (such as making this function always return -1 EBADF on a
non-pipe non-socket, rather than triggering implementation-defined
behavior with subtle differences across platforms) might be worth the
extra effort of an fstat().  I'm not sure whether block and character
special devices can usefully be set non-blocking, or whether that is a
per-device setting.

> #else
> /* Unix API.  */
> 
> # include 
> 
> /* We don't need the gnulib replacement of fcntl() here.  */
> # undef fcntl
> 
> # if 0
> bool
> get_nonblocking_flag (int desc)
> {
>   int fcntl_flags;
> 
>   fcntl_flags = fcntl (desc, F_GETFL, 0);
>   if (fcntl_flags < 0)
> return false;

This would be a case for returning -1 in a tri-state implementation.

>   return (fcntl_flags & O_NONBLOCK) != 0;
> }
> # endif
> 
> int
> set_nonblocking_flag (int desc, bool value)
> {
>   int fcntl_flags;
> 
>   fcntl_flags = fcntl (desc, F_GETFL, 0);
>   if (fcntl_flags < 0)
> return -1;
>   if ((O_NONBLOCK & ~fcntl_flags) == 0)
> return 0;
>   return fcntl (desc, F_SETFL, fcntl_flags | O_NONBLOCK);

This doesn't honor the 'value' parameter, but blindly assumes it was
true.  Sometimes it is also desirable to clear non-blocking, by passing
false.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: non-blocking I/O

2011-03-30 Thread Eric Blake
On 03/30/2011 11:46 AM, Eric Blake wrote:
> On 03/29/2011 09:16 AM, Bruno Haible wrote:
>> Paolo Bonzini wrote:
>>> Without guessing what your bias is, I also :) prefer to implement 
>>> {g,s}et_nonblock_flag functions.  It would use either 
>>> SetNamedPipeHandleState or ioctlsocket (using the socket detection trick 
>>> in sockets.c to detect sockets, and then GetFileType to detect pipes if 
>>> it fails).
>>
>> Here's proposed code to that effect.
> 
> Let's get it checked in.
> 
>>  Note that the getter function cannot
>> be implemented: How to determine whether a Woe32 socket is non-blocking?
> 
> I don't know.

Then again, since gnulib is _already_ wrapping all Woe32 sockets into a
nicer fd, we could maintain an external table of the blocking status of
all sockets that we have created (similar to how we already create an
external table of directory fds for emulating fchdir()).  [Or even
modify the existing fchdir table to serve multiple purposes, since we've
already hooked dup(), fcntl(), and other functions into updating that
table as necessary]

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


license of c-strcasestr

2011-03-30 Thread Eric Blake
libvirt just started using strcasestr() since it is LGPLv2+, but I would
rather it used c_strcasestr() to avoid problems with locales and
multi-byte characters.  Any chance we can get the c-strcasestr module
relicensed to LGPLv2+ instead of its current LGPLv3+?

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


[PATCH] doc: update users.txt

2011-03-30 Thread Simon Josefsson
* users.txt: Add libidn2.  Fix libtasn1 link.
---
 ChangeLog |4 
 users.txt |4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 09a5810..c262f06 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2011-03-30  Simon Josefsson  
+
+   * users.txt: Add libidn2.  Fix libtasn1 link.
+
 2011-03-30  Jim Meyering  
 
tests: readlink* ("",... fails with EINVAL on newer kernels
diff --git a/users.txt b/users.txt
index 61c4a91..7151184 100644
--- a/users.txt
+++ b/users.txt
@@ -47,12 +47,12 @@ The following packages appear to be using gnulib and 
gnulib-tool:
   libguestfs  http://libguestfs.org/
   libiconvhttp://libiconv.cvs.sourceforge.net/libiconv/libiconv/
   libidn  http://git.sv.gnu.org/gitweb/?p=libidn.git
+  libidn2 http://josefsson.org/libidn2/
   libksba http://cvs.gnupg.org/cgi-bin/viewcvs.cgi/trunk/?root=KSBA
   libntlm http://git.josefsson.org/?p=libntlm.git;a=summary
   libprelude  https://trac.prelude-ids.org/browser/trunk/libprelude/
   libpreludedbhttps://trac.prelude-ids.org/browser/trunk/libpreludedb/
-  libtasn1
http://cvs.gnupg.org/cgi-bin/viewcvs.cgi/libtasn1/?root=GNU+TLS+Library
-  http://repo.or.cz/w/libtasn1.git
+  libtasn1http://git.savannah.gnu.org/gitweb/?p=libtasn1.git
   libunistringhttp://git.sv.gnu.org/gitweb/?p=libunistring.git
   libvirt http://libvirt.org/
   http://git.et.redhat.com/?p=libvirt.git;a=summary
-- 
1.7.2.5




Re: Confusion about gnulib asprintf attribute annotation...

2011-03-30 Thread Eric Blake
[adding bug-gnulib, to get Bruno's take on this]

On 03/29/2011 05:14 AM, Daniel P. Berrange wrote:
> Hey Eric,
> 
> In libvirt we annotate virAsprintf() with '__gnu_printf__' to ensure
> gcc uses the GNU printf specifiers to get %lld support.
> 
> I've just noticed that the actual GNULIB  asprintf() function though
> is only using '__printf__' which means it will use the Win32 specifiers
> on GCC >= 4.4. This seems not right to me, since IIRC asprintf() is
> providing a full GNU compatible implementation AFAIK (libvirt certainly
> thinks it is, hence  our virAsprintf annotation).

I see this in 'info gcc':

 The parameter ARCHETYPE determines how the format string is
 interpreted, and should be `printf', `scanf', `strftime',
 `gnu_printf', `gnu_scanf', `gnu_strftime' or `strfmon'.  (You can
 also use `__printf__', `__scanf__', `__strftime__' or
 `__strfmon__'.)  On MinGW targets, `ms_printf', `ms_scanf', and
 `ms_strftime' are also present.  ARCHTYPE values such as `printf'
 refer to the formats accepted by the system's C run-time library,
 while `gnu_' values always refer to the formats accepted by the
 GNU C Library.  On Microsoft Windows targets, `ms_' values refer
 to the formats accepted by the `msvcrt.dll' library.

We only accept a subset of __gnu_printf__ in the gnulib replacement (for
example, gnulib supports %Id on glibc, but not elsewhere, even though
using attribute __gnu_printf__ would not warn about use of %Id).  But
you are also right that __printf__ devolves to __gnu_printf__ on glibc
and to __ms_printf__ on mingw, and that __ms_printf__ warns for %lld
even though the gnulib replacements guarantee that it is valid.  I'd
rather go for __gnu_printf__ everywhere (at the expense of missed
warnings) than going for __printf__ and getting spurious warnings on
mingw about the very things that the gnulib *printf modules end up
working around.

> The thing I'm looking at is gnulib/lib/stdio.h.in which has:
> 
>   #define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) 
> \
> _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, 
> first_argument))
> 
> Whereas I'd expect it to look more like this if gnulib has a GNU compatible
> replacement asprintf()
> 
>   #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
>   # define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, 
> first_argument) \
>  _GL_ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, 
> first_argument))
>   #else
>   # define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, 
> first_argument) \
>  _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, 
> first_argument))
>   #endif
> 
> Except this affects all the *printf() variants listed in stdio.h.in, and
> from previous discussions, only asprintf() seemed to be GNU compatible
> 
>   http://www.redhat.com/archives/libvir-list/2010-August/msg00447.html

Right; the various *printf-posix modules provide everything, but the
*printf counterparts vary in how much they provide (asprintf pretty much
provides everything, since mingw lacks it to begin with, but printf and
sprintf still don't understand %lld because they didn't need to pull in
the full asprintf).

> 
> So maybe it instead needs a _GL_ATTRIBUTE_FORMAT_GNU_PRINTF like
> 
>   #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
>   # define _GL_ATTRIBUTE_FORMAT_GNU_PRINTF(formatstring_parameter, 
> first_argument) \
>  _GL_ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, 
> first_argument))
>   #else
>   # define _GL_ATTRIBUTE_FORMAT_GNU_PRINTF(formatstring_parameter, 
> first_argument) \
>  _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, 
> first_argument))
>   #endif
> 
> and then change asprintf() to use _GL_ATTRIBUTE_FORMAT_GNU_PRINTF ?

Hmm, sounds like we might really want an explicit __gnu_printf__ on
asprintf, regardless of whether it was asprintf or asprintf-posix
module; whereas the printf declaration gets __printf__ for the printf
module and __gnu_printf__ for the printf-posix module.  Which means
_GL_ATTRIBUTE_FORMAT_GNU_PRINTF has to be defined first, then something
like:

#if posix-modules
# define _GL_ATTRIBUTE_FORMAT_PRINTF _GL_ATTRIBUTE_FORMAT_GNU_PRINTF
#else
# define _GL_ATTRIBUTE_FORMAT_PRINTF __printf__
#endif

But I agree that it could use some cleanup.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


GPLv3 blobs in C

2011-03-30 Thread Simon Josefsson
I recently wrote an interactive tool licensed under GPLv3, and you may
recall that GPLv3 says this:

  If the program does terminal interaction, make it output a short
  notice like this when it starts in an interactive mode:

  Copyright (C)   
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.

  The hypothetical commands `show w' and `show c' should show the appropriate
  parts of the General Public License.  Of course, your program's commands
  might be different; for a GUI interface, you would use an "about box".

I put what I believe are the "appropriate parts" of the GPLv3 text into
a .h file, see below.  It occured to me now that this may be useful to
have in gnulib -- other applications may want to be able to output the
same information.  Thoughts?  Is #define's the best approach?  Do we
want another #define for the entire GPLv3 license text?

Finally, what is the appropriate license for this file?  The license of
GPLv3 doesn't permit modifications, and I'm not sure removing some parts
of the file and keeping others, and modifying the content to work in a
#define string, is OK.  Maybe this is a question for the FSF legal.

/Simon

/* blurbs.h - warranty and conditions blurbs
   Copyright (C) 2011 Simon Josefsson

   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 .
*/

#define WARRANTY\
  "THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\n"  \
  "APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\n" \
  "HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT 
WARRANTY\n" \
  "OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\n" \
  "THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n" \
  "PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 
PROGRAM\n" \
  "IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\n" \
  "ALL NECESSARY SERVICING, REPAIR OR CORRECTION."

#define CONDITIONS  \
  "   TERMS AND CONDITIONS\n"   \
  "\n"  \
  "  0. Definitions.\n" \
  "\n"  \
  "  \"This License\" refers to version 3 of the GNU General Public License.\n" 
\
  "\n"  \
  "  \"Copyright\" also means copyright-like laws that apply to other kinds 
of\n" \
  "works, such as semiconductor masks.\n"   \
  "\n"  \
  "  \"The Program\" refers to any copyrightable work licensed under this\n" \
  "License.  Each licensee is addressed as \"you\".  \"Licensees\" and\n" \
  "\"recipients\" may be individuals or organizations.\n"   \
  "\n"  \
  "  To \"modify\" a work means to copy from or adapt all or part of the 
work\n" \
  "in a fashion requiring copyright permission, other than the making of an\n" \
  "exact copy.  The resulting work is called a \"modified version\" of the\n" \
  "earlier work or a work \"based on\" the earlier work.\n" \
  "\n"  \
  "  A \"covered work\" means either the unmodified Program or a work based\n" \
  "on the Program.\n"   \
  "\n"  \
  "  To \"propagate\" a work means to do anything with it that, without\n" \
  "permission, would make you directly or secondarily liable for\n" \
  "infringement under applicable copyright law, except executing it on a\n" \
  "computer or modifying a private copy.  Propagation includes copying,\n" \
  "distribution (with or without modification), making available to the\n" \
  "public, and in some countries other activities as well.\n"   \
  "\n"  \
  "  To \"convey\" a work means any kind of propaga

Re: GPLv3 blobs in C

2011-03-30 Thread Mike Frysinger
On Wed, Mar 30, 2011 at 5:25 PM, Simon Josefsson wrote:
> I put what I believe are the "appropriate parts" of the GPLv3 text into
> a .h file, see below.  It occured to me now that this may be useful to
> have in gnulib -- other applications may want to be able to output the
> same information.  Thoughts?  Is #define's the best approach?  Do we
> want another #define for the entire GPLv3 license text?

seems like you'd want to have the module auto generate the header from
an actual COPYING file rather than hardcoding the strings yourself ...
-mike



Re: [PATCH] Fix a typo

2011-03-30 Thread Eric Blake
On 03/28/2011 05:41 AM, Bastien ROUCARIES wrote:
> Fix a typo in passfd code
> ---
>  lib/passfd.c |1 -
>  1 files changed, 0 insertions(+), 1 deletions(-)
> 
> diff --git a/lib/passfd.c b/lib/passfd.c
> index 573b80e..ae716a6 100644
> --- a/lib/passfd.c
> +++ b/lib/passfd.c
> @@ -67,7 +67,6 @@ sendfd (int sock, int fd)
>  cmsg->cmsg_len = CMSG_LEN (sizeof (int));
>  /* Initialize the payload: */
>  memcpy (CMSG_DATA (cmsg), &fd, sizeof (fd));
> -msg.msg_controllen = cmsg->cmsg_len;
>  #elif HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY
>  msg.msg_accrights = &fd;
>  msg.msg_accrightslen = sizeof (fd);

Hmm, both before and after this patch of yours, I get things to compile
on NetBSD 5.0.2, but the test hangs in both cases, after printing:

sendfd: Invalid argument

Hanging a unit test is bad; so I'm also going to check in a followup
that does an alarm(5) to the self-test (we've done it elsewhere, so I
have precedence).  However, I also concur that your patch is reasonable,
as you already assigned msg_controllen earlier in the function.  I
guessed that the reason for the failure is that you forgot to assign
msg_flags, and NetBSD was rejecting uninitialized data as invalid flags.
 However, after pushing this patch, things still fail, so I'm still
investigating.

From cc0745fc8e17997b71a1e021ca15c0b95ba779b9 Mon Sep 17 00:00:00 2001
From: Eric Blake 
Date: Wed, 30 Mar 2011 14:46:02 -0600
Subject: [PATCH] passfd: fix incorrect sendmsg arguments

The unit test hung on NetBSD, which pointed out a couple of bugs.

* lib/passfd.c (sendfd): Avoid uninitialized msg_flags field, and
incorrect msg_controllen value.
* modules/passfd-tests (Depends-on): Check for alarm.
* tests/test-passfd.c (main) [HAVE_DECL_ALARM]: Avoid hanging test.
Reported by Bastien ROUCARIES.
---
 ChangeLog|9 +
 lib/passfd.c |2 +-
 modules/passfd-tests |1 +
 tests/test-passfd.c  |7 +++
 4 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 09a5810..ec324a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-03-30  Eric Blake  
+
+   passfd: fix incorrect sendmsg arguments
+   * lib/passfd.c (sendfd): Avoid uninitialized msg_flags field, and
+   incorrect msg_controllen value.
+   * modules/passfd-tests (Depends-on): Check for alarm.
+   * tests/test-passfd.c (main) [HAVE_DECL_ALARM]: Avoid hanging test.
+   Reported by Bastien ROUCARIES.
+
 2011-03-30  Jim Meyering  

tests: readlink* ("",... fails with EINVAL on newer kernels
diff --git a/lib/passfd.c b/lib/passfd.c
index 573b80e..5bf400d 100644
--- a/lib/passfd.c
+++ b/lib/passfd.c
@@ -47,6 +47,7 @@ sendfd (int sock, int fd)
   struct msghdr msg;

   /* send at least one char */
+  memset (&msg, 0, sizeof msg);
   iov[0].iov_base = &send;
   iov[0].iov_len = 1;
   msg.msg_iov = iov;
@@ -67,7 +68,6 @@ sendfd (int sock, int fd)
 cmsg->cmsg_len = CMSG_LEN (sizeof (int));
 /* Initialize the payload: */
 memcpy (CMSG_DATA (cmsg), &fd, sizeof (fd));
-msg.msg_controllen = cmsg->cmsg_len;
 #elif HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY
 msg.msg_accrights = &fd;
 msg.msg_accrightslen = sizeof (fd);
diff --git a/modules/passfd-tests b/modules/passfd-tests
index 132679c..477754b 100644
--- a/modules/passfd-tests
+++ b/modules/passfd-tests
@@ -5,6 +5,7 @@ tests/macros.h
 Depends-on:

 configure.ac:
+AC_CHECK_DECLS_ONCE([alarm])

 Makefile.am:
 TESTS += test-passfd
diff --git a/tests/test-passfd.c b/tests/test-passfd.c
index 2048934..d657ad9 100644
--- a/tests/test-passfd.c
+++ b/tests/test-passfd.c
@@ -19,6 +19,7 @@
 #include "passfd.h"

 #include 
+#include 
 #include 
 #include 
 #include 
@@ -40,6 +41,12 @@ main ()
   int fd;
   struct stat st;

+#if HAVE_DECL_ALARM
+  /* Avoid hanging on failure.  */
+  signal (SIGALRM, SIG_DFL);
+  alarm (5);
+#endif
+
   fdnull = open ("/dev/null", O_RDWR);
   if (fdnull < 0)
 {
-- 
1.7.4



I'm also pushing this followup, which reduces the code size a bit (we
prefer sizeof variable over sizeof (type), NULL over 0 for null
pointers, there's no need to make a one-element array, and we prefer to
avoid in-function #ifdefs when possible).

From aeea9482713470cd1e4cd78b39c8d87841c62b2f Mon Sep 17 00:00:00 2001
From: Eric Blake 
Date: Wed, 30 Mar 2011 15:30:13 -0600
Subject: [PATCH] passfd: standardize coding conventions

* m4/afunix.m4 (gl_SOCKET_AFUNIX): Drop check for something that
can be learned at compile time.
* lib/passfd.c (MSG_CMSG_CLOEXEC): Reduce number of in-function
ifdefs.
(passfd, recvfd): Follow gnulib code conventions.

Signed-off-by: Eric Blake 
---
 ChangeLog|7 +++
 lib/passfd.c |   48 +++-
 m4/afunix.m4 |   29 +
 3 files changed, 31 insertions(+), 53 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ec324a0..5d4dc84 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2011-03-30  Eric Blake 

Re: GPLv3 blobs in C

2011-03-30 Thread Karl Berry
Finally, what is the appropriate license for this file?  

Can you check how gdb's source files are set up?
(show copying, show warranty)
Sorry, I can't easily do so myself just now.

GPLv3 doesn't permit modifications, and I'm not sure removing some
parts of the file and keeping others, and modifying the content to
work in a #define string, is OK.

You aren't modifying the GPL's words.  That's the important thing.  Not
how you chop them up.

karl



Re: license of c-strcasestr

2011-03-30 Thread Bruno Haible
Eric Blake wrote:
> libvirt just started using strcasestr() since it is LGPLv2+, but I would
> rather it used c_strcasestr() to avoid problems with locales and
> multi-byte characters.  Any chance we can get the c-strcasestr module
> relicensed to LGPLv2+ instead of its current LGPLv3+?

Fine with me, since the code is very similar to code in glibc. The other
copyright holder of this module are you yourself. So I'm applying this change:


2011-03-30  Bruno Haible  

c-strcasestr: Relicense under LGPLv2+.
* modules/c-strcasestr (License): Change to LGPLv2+.
Requested by Eric Blake, for libvirt.

--- modules/c-strcasestr.orig   Thu Mar 31 01:38:09 2011
+++ modules/c-strcasestrWed Mar 30 22:09:51 2011
@@ -22,7 +22,7 @@
 "c-strcasestr.h"
 
 License:
-LGPL
+LGPLv2+
 
 Maintainer:
 Bruno Haible

-- 
In memoriam Airey Neave 



fix passfd [was: [PATCH] Fix a typo]

2011-03-30 Thread Eric Blake
On 03/30/2011 03:36 PM, Eric Blake wrote:
>  However, after pushing this patch, things still fail, so I'm still
> investigating.

Found it, thanks to ktrace/kdump and tedious comparison against a sample
program from
http://mail-index.netbsd.org/netbsd-bugs/2009/02/20/msg009294.html.  buf
goes out of scope before you call sendmsg(); and NetBSD's compiler took
advantage of that to pass garbage to the syscall.  I'm impressed that
the test even passed on other systems.

From f711a2d501b4cdf6f096a76d5e050bb14d67e513 Mon Sep 17 00:00:00 2001
From: Eric Blake 
Date: Wed, 30 Mar 2011 18:15:33 -0600
Subject: [PATCH] passfd: fix scoping bug

The scoping bug was the cause of the NetBSD hang.

* lib/passfd.c (sendfd, passfd): Don't let buf go out of scope
before sendmsg/recvmsg.

Signed-off-by: Eric Blake 
---
 ChangeLog|4 ++
 lib/passfd.c |  158
+++--
 2 files changed, 79 insertions(+), 83 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 79e70fc..07abca6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-03-30  Eric Blake  

+   passfd: fix scoping bug
+   * lib/passfd.c (sendfd, passfd): Don't let buf go out of scope
+   before sendmsg/recvmsg.
+
passfd: standardize coding conventions
* m4/afunix.m4 (gl_SOCKET_AFUNIX): Drop check for something that
can be learned at compile time.
diff --git a/lib/passfd.c b/lib/passfd.c
index 6784659..1ab94b4 100644
--- a/lib/passfd.c
+++ b/lib/passfd.c
@@ -49,6 +49,10 @@ sendfd (int sock, int fd)
   char send = 0;
   struct iovec iov;
   struct msghdr msg;
+#if HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
+  struct cmsghdr *cmsg;
+  char buf[CMSG_SPACE (sizeof fd)];
+#endif

   /* send at least one char */
   memset (&msg, 0, sizeof msg);
@@ -59,27 +63,22 @@ sendfd (int sock, int fd)
   msg.msg_name = NULL;
   msg.msg_namelen = 0;

-  {
 #if HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
-struct cmsghdr *cmsg;
-char buf[CMSG_SPACE (sizeof fd)];
-
-msg.msg_control = buf;
-msg.msg_controllen = sizeof buf;
-cmsg = CMSG_FIRSTHDR (&msg);
-cmsg->cmsg_level = SOL_SOCKET;
-cmsg->cmsg_type = SCM_RIGHTS;
-cmsg->cmsg_len = CMSG_LEN (sizeof fd);
-/* Initialize the payload: */
-memcpy (CMSG_DATA (cmsg), &fd, sizeof fd);
+  msg.msg_control = buf;
+  msg.msg_controllen = sizeof buf;
+  cmsg = CMSG_FIRSTHDR (&msg);
+  cmsg->cmsg_level = SOL_SOCKET;
+  cmsg->cmsg_type = SCM_RIGHTS;
+  cmsg->cmsg_len = CMSG_LEN (sizeof fd);
+  /* Initialize the payload: */
+  memcpy (CMSG_DATA (cmsg), &fd, sizeof fd);
 #elif HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY
-msg.msg_accrights = &fd;
-msg.msg_accrightslen = sizeof fd;
+  msg.msg_accrights = &fd;
+  msg.msg_accrightslen = sizeof fd;
 #else
-errno = ENOSYS;
-return -1;
+  errno = ENOSYS;
+  return -1;
 #endif
-  }

   if (sendmsg (sock, &msg, 0) != iov.iov_len)
 return -1;
@@ -97,6 +96,12 @@ recvfd (int sock, int flags)
   char recv = 0;
   struct iovec iov;
   struct msghdr msg;
+  int fd = -1;
+#if HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
+  struct cmsghdr *cmsg;
+  char buf[CMSG_SPACE (sizeof fd)];
+  int flags_recvmsg = flags & O_CLOEXEC ? MSG_CMSG_CLOEXEC : 0;
+#endif

   if ((flags & ~O_CLOEXEC) != 0)
 {
@@ -105,6 +110,7 @@ recvfd (int sock, int flags)
 }

   /* send at least one char */
+  memset (&msg, 0, sizeof msg);
   iov.iov_base = &recv;
   iov.iov_len = 1;
   msg.msg_iov = &iov;
@@ -112,78 +118,64 @@ recvfd (int sock, int flags)
   msg.msg_name = NULL;
   msg.msg_namelen = 0;

-  {
 #if HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
-int fd;
-struct cmsghdr *cmsg;
-char buf[CMSG_SPACE (sizeof fd)];
-const int mone = -1;
-int flags_recvmsg = flags & O_CLOEXEC ? MSG_CMSG_CLOEXEC : 0;
-
-msg.msg_control = buf;
-msg.msg_controllen = sizeof buf;
-cmsg = CMSG_FIRSTHDR (&msg);
-cmsg->cmsg_level = SOL_SOCKET;
-cmsg->cmsg_type = SCM_RIGHTS;
-cmsg->cmsg_len = CMSG_LEN (sizeof mone);
-/* Initialize the payload: */
-memcpy (CMSG_DATA (cmsg), &mone, sizeof mone);
-msg.msg_controllen = cmsg->cmsg_len;
-
-if (recvmsg (sock, &msg, flags_recvmsg) < 0)
-  return -1;
-
-cmsg = CMSG_FIRSTHDR (&msg);
-/* be paranoiac */
-if (cmsg == NULL || cmsg->cmsg_len != CMSG_LEN (sizeof fd)
-|| cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS)
-  {
-/* fake errno: at end the file is not available */
-errno = EACCES;
-return -1;
-  }
-
-memcpy (&fd, CMSG_DATA (cmsg), sizeof fd);
-
-/* set close-on-exec flag */
-if (!MSG_CMSG_CLOEXEC && (flags & O_CLOEXEC))
-  {
-if (set_cloexec_flag (fd, true) < 0)
-  {
-int saved_errno = errno;
-(void) close (fd);
-errno = saved_errno;
-return -1;
-  }
-  }
-
-return fd;
-
-#elif HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY
-int fd;
+  msg.msg_control = buf;
+  msg.msg_controllen = size

Re: Confusion about gnulib asprintf attribute annotation...

2011-03-30 Thread Bruno Haible
Eric Blake wrote:
> We only accept a subset of __gnu_printf__ in the gnulib replacement (for
> example, gnulib supports %Id on glibc, but not elsewhere, even though
> using attribute __gnu_printf__ would not warn about use of %Id).

GCC calls it "gnu_printf" but it actually denotes the C90 or C99 syntax
of printf format strings, depending on the -std option. And the syntax
checks are the same on glibc systems (which support the 'I' flag) and
on platforms other than glibc and mingw (which don't support the 'I' flag).
To demonstrate this: The program

 foo.c 
extern int pf (const char *, ...) __attribute__ ((__format__ (__printf__, 1, 
2)));
extern int gpf (const char *, ...) __attribute__ ((__format__ (__gnu_printf__, 
1, 2)));

void foo (long long x)
{
  pf ("%Id", (int)x);
  gpf ("%Id", (int)x);
}
===

yields the following warnings with GCC 4.4.5, both on a glibc system and on an
AIX 7.1 system:

$ gcc -Wall -S foo.c -std=gnu99
[no warning]
$ gcc -Wall -pedantic -S foo.c -std=gnu99
foo.c: In function 'foo':
foo.c:6: warning: ISO C does not support the 'I' printf flag
foo.c:7: warning: ISO C does not support the 'I' printf flag

Eric Blake wrote:
> sounds like we might really want an explicit __gnu_printf__ on
> asprintf, regardless of whether it was asprintf or asprintf-posix
> module

Yes, because our implementation of asprintf calls vasnprintf.

> whereas the printf declaration gets __printf__ for the printf 
> module and __gnu_printf__ for the printf-posix module.

Yes, except that when the printf and vfprintf-posix module is used,
we need __gnu_printf__ as well.

This patch should fix it all. I've committed it. Can you please report if
it doesn't work for you?


2011-03-30  Bruno Haible  

stdio: Avoid GCC >= 4.4 warnings when using %lld and similar on mingw.
* lib/stdio.in.h (_GL_ATTRIBUTE_FORMAT_PRINTF): Use 'gnu_printf' format
instead of 'printf' format for GCC >= 4.4.
(_GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM): New macro.
(fprintf, printf, vfprintf, vprintf): Declare with
_GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM when the function ends up calling
the system's vfprintf() function.
Reported by Daniel P. Berrange  via Eric Blake.

--- lib/stdio.in.h.orig Thu Mar 31 02:50:04 2011
+++ lib/stdio.in.h  Thu Mar 31 02:49:58 2011
@@ -67,7 +67,24 @@
 #else
 # define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
 #endif
-#define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \
+
+/* _GL_ATTRIBUTE_FORMAT_PRINTF
+   indicates to GCC that the function takes a format string and arguments,
+   where the format string directives are the ones standardized by ISO C99
+   and POSIX.  */
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \
+   _GL_ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, 
first_argument))
+#else
+# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \
+   _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument))
+#endif
+
+/* _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_PRINTF,
+   except that it indicates to GCC that the supported format string directives
+   are the ones of the system printf(), rather than the ones standardized by
+   ISO C99 and POSIX.  */
+#define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, 
first_argument) \
   _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument))
 
 /* Solaris 10 declares renameat in , not in .  */
@@ -191,9 +208,15 @@
 #   define fprintf rpl_fprintf
 #  endif
 #  define GNULIB_overrides_fprintf 1
+#  if @GNULIB_FPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
 _GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...)
 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3)
 _GL_ARG_NONNULL ((1, 2)));
+#  else
+_GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...)
+_GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 3)
+_GL_ARG_NONNULL ((1, 2)));
+#  endif
 _GL_CXXALIAS_RPL (fprintf, int, (FILE *fp, const char *format, ...));
 # else
 _GL_CXXALIAS_SYS (fprintf, int, (FILE *fp, const char *format, ...));
@@ -694,12 +717,21 @@
 /* Don't break __attribute__((format(printf,M,N))).  */
 #define printf __printf__
 #   endif
+#   if @GNULIB_PRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
 _GL_FUNCDECL_RPL_1 (__printf__, int,
 (const char *format, ...)
 __asm__ (@ASM_SYMBOL_PREFIX@
  _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf))
 _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2)
 _GL_ARG_NONNULL ((1)));
+#   else
+_GL_FUNCDECL_RPL_1 (__printf__, int,
+

[PATCH] nonblocking: new module

2011-03-30 Thread Eric Blake
This still lacks the ability to query non-blocking status of mingw
sockets; but that should be possible in a future patch in much the
same manner as fchdir.

* modules/nonblocking: New module.
* modules/nonblocking-tests: Likewise.
* lib/nonblocking.h: New file.
* lib/nonblocking.c: Likewise.
* tests/test-nonblocking.c: New test.
* lib/ioctl.c (ioctl) [mingw]: Update comment.

Signed-off-by: Eric Blake 
---

I've touched up your proposal, and done more testing with this.
I'll probably commit this tomorrow.

 ChangeLog |   11 
 lib/ioctl.c   |4 +
 lib/nonblocking.c |  137 +
 lib/nonblocking.h |   60 
 modules/nonblocking   |   26 +
 modules/nonblocking-tests |   16 +
 tests/test-nonblocking.c  |  115 +
 7 files changed, 369 insertions(+), 0 deletions(-)
 create mode 100644 lib/nonblocking.c
 create mode 100644 lib/nonblocking.h
 create mode 100644 modules/nonblocking
 create mode 100644 modules/nonblocking-tests
 create mode 100644 tests/test-nonblocking.c

diff --git a/ChangeLog b/ChangeLog
index 5bc9b73..daaf7bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,15 @@
 2011-03-30  Bruno Haible  
+   and Eric Blake  
+
+   nonblocking: new module
+   * modules/nonblocking: New module.
+   * modules/nonblocking-tests: Likewise.
+   * lib/nonblocking.h: New file.
+   * lib/nonblocking.c: Likewise.
+   * tests/test-nonblocking.c: New test.
+   * lib/ioctl.c (ioctl) [mingw]: Update comment.
+
+2011-03-30  Bruno Haible  

stdio: Avoid GCC >= 4.4 warnings when using %lld and similar on mingw.
* lib/stdio.in.h (_GL_ATTRIBUTE_FORMAT_PRINTF): Use 'gnu_printf' format
diff --git a/lib/ioctl.c b/lib/ioctl.c
index 7c09d95..4bbed76 100644
--- a/lib/ioctl.c
+++ b/lib/ioctl.c
@@ -63,6 +63,10 @@ ioctl (int fd, int req, ...)
   buf = va_arg (args, void *);
   va_end (args);

+  /* We don't support FIONBIO on pipes here.  If you want to make pipe
+ fds non-blocking, use the gnulib 'nonblocking' module, until
+ gnulib implements fcntl F_GETFL / F_SETFL with O_NONBLOCK.  */
+
   sock = FD_TO_SOCKET (fd);
   r = ioctlsocket (sock, req, buf);
   if (r < 0)
diff --git a/lib/nonblocking.c b/lib/nonblocking.c
new file mode 100644
index 000..61ea3ca
--- /dev/null
+++ b/lib/nonblocking.c
@@ -0,0 +1,137 @@
+/* Non-blocking I/O for pipe or socket 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
+   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 .  */
+
+#include 
+
+/* Specification.  */
+#include "nonblocking.h"
+
+#include 
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* Native Woe32 API.  */
+
+# include 
+# include 
+
+/* Get declarations of the Win32 API functions.  */
+# define WIN32_LEAN_AND_MEAN
+# include 
+
+int
+get_nonblocking_flag (int desc)
+{
+  HANDLE h = (HANDLE) _get_osfhandle (desc);
+  if (GetFileType (h) == FILE_TYPE_PIPE)
+{
+  /* h is a pipe or socket.  */
+  DWORD state;
+  if (GetNamedPipeHandleState (h, &state, NULL, NULL, NULL, NULL, 0))
+/* h is a pipe.  */
+return (state & PIPE_NOWAIT) != 0;
+  else
+/* h is a socket.  */
+errno = ENOSYS;
+return -1;
+}
+  else
+return 0;
+}
+
+int
+set_nonblocking_flag (int desc, bool value)
+{
+  HANDLE h = (HANDLE) _get_osfhandle (desc);
+  if (GetFileType (h) == FILE_TYPE_PIPE)
+{
+  /* h is a pipe or socket.  */
+  DWORD state;
+  if (GetNamedPipeHandleState (h, &state, NULL, NULL, NULL, NULL, 0))
+{
+  /* h is a pipe.  */
+  if ((state & PIPE_NOWAIT) != 0)
+{
+  if (value)
+return 0;
+  state &= ~PIPE_NOWAIT;
+}
+  else
+{
+  if (!value)
+return 0;
+  state |= PIPE_NOWAIT;
+}
+  if (SetNamedPipeHandleState (h, &state, NULL, NULL))
+return 0;
+  errno = EINVAL;
+  return -1;
+}
+  else
+{
+  /* h is a socket.  */
+  int v = value;
+  return ioctl (desc, FIONBIO, &v);
+}
+}
+  else
+{
+  /* Win32 does not support non-blocking on regular files.  */
+  errno = ENOTSUP;
+

Re: non-blocking I/O

2011-03-30 Thread Paolo Bonzini

On 03/30/2011 07:46 PM, Eric Blake wrote:

I'm not sure whether block and character
special devices can usefully be set non-blocking


I believe at least /dev/random supports it:

#include 
#include 
#include 
#include 
int main()
{
  char buf[256];
  int fd = open ("/dev/random", O_RDONLY | O_NONBLOCK);
  if (fd == -1) {
perror ("/dev/random");
exit (1);
  }
  alarm (5);
  while (read (fd, buf, 256) != -1 || errno != EAGAIN)
;
  puts ("works");
  exit (0);
}

Paolo