1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00
samba-mirror/source3/tests/unixsock.c
Derrell Lipman 3a9a3ad8f9 r22731: - Fix bug #4594.
configure.in determines if -Werror-implicit-function-declaration is
  available, and if so it enables that flag if --enable-developer is
  specified.  Since the configure tests themselves did not use that flag, it
  was possible for a configure test to succeed, followed by a failed
  compilation due to a facility being available but not having a proper
  declaration in a header file.  (This bit me with readahead().)  This patch
  ensures that if implicit function declarations will kill the build, the
  feature being tested is deselected so the build will succeed.

  The autoconf manual suggests using return instead of exit in configure
  tests because the declaration for exit is often missing.  We require this
  now, since we error if prototypes are missing.  See section 5.5.1 of
  http://www.gnu.org/software/autoconf/manual/autoconf.html.  This patch makes
  these changes, because in fact, an external declaration for exit is missing
  here (and likely elsewhere).

  I've verified that the features selected (here) with the original
  configure.in and the new one are the same except for, in my case,
  readahead.  I've also confirmed that the generated Makefile is identical.

  These changes are not being applied to the 3.0.26 branch because it does not
  exhibit the initial problem this patch is supposed to solve since it doesn't
  attempt to use -Werror-implicit-function-declaration.
(This used to be commit 4d42720915)
2007-10-10 12:21:51 -05:00

97 lines
2.0 KiB
C

/*
* -*- c-file-style: "linux" -*-
*
* Try creating a Unix-domain socket, opening it, and reading from it.
* The POSIX name for these is AF_LOCAL/PF_LOCAL.
*
* This is used by the Samba autoconf scripts to detect systems which
* don't have Unix-domain sockets, such as (probably) VMS, or systems
* on which they are broken under some conditions, such as RedHat 7.0
* (unpatched). We can't build WinBind there at the moment.
*
* Martin Pool <mbp@samba.org>, June 2000.
*/
/* TODO: Look for AF_LOCAL (most standard), AF_UNIX, and AF_FILE. */
#include <stdio.h>
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_SYS_UN_H
# include <sys/un.h>
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#if HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#if HAVE_ERRNO_DECL
# include <errno.h>
#else
extern int errno;
#endif
static int bind_socket(char const *filename)
{
int sock_fd;
struct sockaddr_un name;
size_t size;
/* Create the socket. */
if ((sock_fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) {
perror ("socket(PF_LOCAL, SOCK_STREAM)");
return 1;
}
/* Bind a name to the socket. */
name.sun_family = AF_LOCAL;
strncpy(name.sun_path, filename, sizeof (name.sun_path));
/* The size of the address is
the offset of the start of the filename,
plus its length,
plus one for the terminating null byte.
Alternatively you can just do:
size = SUN_LEN (&name);
*/
size = SUN_LEN(&name);
/* XXX: This probably won't work on unfriendly libcs */
if (bind(sock_fd, (struct sockaddr *) &name, size) < 0) {
perror ("bind");
return 1;
}
return sock_fd;
}
int main(void)
{
int sock_fd;
int kid;
char const *filename = "conftest.unixsock.sock";
/* abolish hanging */
alarm(15); /* secs */
if ((sock_fd = bind_socket(filename)) < 0)
return 1;
/* the socket will be deleted when autoconf cleans up these
files. */
return 0;
}