bug-gnulib
[Top][All Lists]
Advanced

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

Re: declare sethostname if unistd.h doesn't


From: Bruno Haible
Subject: Re: declare sethostname if unistd.h doesn't
Date: Sun, 20 Nov 2011 15:12:55 +0100
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

Hi Ben,

> When testing the pending release of inetutils on solaris 9/10, I
> discovered that sethostname isn't declared in unistd.h on Solaris.
> The following patch adds handling for this although I'm not positive
> that it's the best way to do it.  At the very least it's a starting
> point for discussing the best way to add the required support.
> 
> Based on the 'not corrected by' section in
> glibc-functions/sethostname.texi, I was tempted to make this a
> separate module but decided not to go that far yet.  If that's the
> better or more proper solution, I don't mind resubmitting.

Yes, the declaration is missing in the Solaris 10 header files, but also
on other platforms that have the function: AIX and OSF/1.

The usual approach in gnulib is to have the header file module ('unistd'
in this case) provide the types and C macros that ought to be present in
that header file, while functions declarations and function definitions
go into a module per function.

And when we provide the function module, we try to fix as many problems
as reasonably possible. This would mean, provide code for the function
on Minix 3.1.8, AIX 5.1, Cygwin, mingw, MSVC 9, Interix 3.5, BeOS.
Even if, in the worst case, the function just sets errno to ENOSYS.

> --- a/doc/glibc-functions/sethostname.texi
> +++ b/doc/glibc-functions/sethostname.texi
> @@ -6,6 +6,8 @@ Gnulib module: ---
>  
>  Portability problems fixed by Gnulib:
>  @itemize
> +Some platforms provide the function but not the prototype:
> +Solaris 9 and 10.
>  @end itemize
>  
>  Portability problems not fixed by Gnulib:

It would not make sense to say that we fix a problem in Gnulib but
don't say in which module.

Also, mentioning Solaris 9 is redundant when we mention Solaris 10.
In most cases, from the fact that a bug exists in Solaris 10 you can
also conclude that it exists in older Solaris versions. In other words,
here we mention the newest OS release that is known to have the bug.
Since Solaris 11 2011-10 _does_ have the declaration, we need to mention
Solaris 10.

While you can ponder how to define a sethostname() replacement, I'm
already adding this to the doc:


2011-11-20  Bruno Haible  <address@hidden>

        sethostname: Mention more portability problems.
        * doc/glibc-functions/sethostname.texi: Mention the missing declaration
        problem.
        Reported by Ben Walton <address@hidden>.

--- doc/glibc-functions/sethostname.texi.orig   Sun Nov 20 14:19:27 2011
+++ doc/glibc-functions/sethostname.texi        Sun Nov 20 14:19:16 2011
@@ -13,4 +13,7 @@
 @item
 This function is missing on some platforms:
 Minix 3.1.8, AIX 5.1, Cygwin, mingw, MSVC 9, Interix 3.5, BeOS.
address@hidden
+This function is not declared on some platforms:
+AIX 7.1, OSF/1 5.1, Solaris 10.
 @end itemize

> diff --git a/lib/unistd.in.h b/lib/unistd.in.h
> index f53f34b..057eaab 100644
> --- a/lib/unistd.in.h
> +++ b/lib/unistd.in.h
> @@ -683,6 +683,10 @@ _GL_WARN_ON_USE (getgroups, "getgroups is unportable - "
>  # endif
>  #endif
>  
> +#if HAVE_SETHOSTNAME && !HAVE_DECL_SETHOSTNAME
> +_GL_FUNCDECL_SYS (sethostname, int, (const char *name, size_t len)
> +               _GL_ARG_NONNULL ((1)));
> +#endif
>  
>  #if @GNULIB_GETHOSTNAME@
>  /* Return the standard host name of the machine.

Here, please use one of the templates from build-aux/snippet/c++defs.h.
These templates make sure that C++ programs will see the right declarations
too.

Also, please, Gnulib uses spaces for indentation in most files. Exceptions
are ChangeLog, Makefile snippets in module descriptions, and Makefiles.

> diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4
> index 57c8094..8b5cf6f 100644
> --- a/m4/unistd_h.m4
> +++ b/m4/unistd_h.m4
> @@ -21,6 +21,12 @@ AC_DEFUN([gl_UNISTD_H],
>    fi
>    AC_SUBST([HAVE_UNISTD_H])
>  
> +  dnl Ensure there is a prototype for sethostname
> +  AC_CHECK_DECLS([sethostname])
> +  dnl Detect the function too as we don't need the prototype if the function
> +  dnl isn't available.
> +  AC_CHECK_FUNCS([sethostname])
> +
>    dnl Ensure the type pid_t gets defined.
>    AC_REQUIRE([AC_TYPE_PID_T])

This would belong in a file sethostname.m4.


Now, how to implement sethostname() on platforms that don't have it?

- On Cygwin and native Windows, SetComputerNameEx [1] seems to be the
  best suited primitive.

- On AIX 5.1, sethostname() actually exists; only this can't be seen by using
  "nm /lib/libc.a" as I had done.

- On Minix 3.1.8, sethostname() should write the hostname into 
/etc/hostname.file,
  followed by a newline.

- On other systems, just use errno = ENOSYS; as fallback.

Can you implement this?

Bruno

[1] 
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724931%28v=vs.85%29.aspx
-- 
In memoriam Kerem Yılmazer <http://en.wikipedia.org/wiki/Kerem_Yılmazer>



reply via email to

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