#include <errno.h>
#include <string.h>
#include <netdb.h>
+#include <netinet/tcp.h>
+#include <stdlib.h>
#if SIZEOF_UNSIGNED_SHORT_INT==4
typedef unsigned short u32;
#include "nbd.h"
#endif
+#if NBD_LFS==1
+#define _LARGEFILE_SOURCE
+#define _FILE_OFFSET_BITS=64
+#endif
+
u64 cliserv_magic = 0x00420281861253LL;
#define INIT_PASSWD "NBDMAGIC"
/* config.h.in. Generated from configure.in by autoheader. */
+/* Define to 1 if you have the `alarm' function. */
+#undef HAVE_ALARM
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+#undef HAVE_ARPA_INET_H
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#undef HAVE_FCNTL_H
+
+/* Define to 1 if you have the `fork' function. */
+#undef HAVE_FORK
+
+/* Define to 1 if you have the `gethostbyname' function. */
+#undef HAVE_GETHOSTBYNAME
+
+/* Define to 1 if you have the `inet_ntoa' function. */
+#undef HAVE_INET_NTOA
+
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `llseek' function. */
#undef HAVE_LLSEEK
+/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
+ to 0 otherwise. */
+#undef HAVE_MALLOC
+
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
+/* Define to 1 if you have the `memset' function. */
+#undef HAVE_MEMSET
+
+/* Define to 1 if you have the <netdb.h> header file. */
+#undef HAVE_NETDB_H
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#undef HAVE_NETINET_IN_H
+
+/* Define to 1 if your system has a GNU libc compatible `realloc' function,
+ and to 0 otherwise. */
+#undef HAVE_REALLOC
+
+/* Define to 1 if you have the `socket' function. */
+#undef HAVE_SOCKET
+
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
+/* Define to 1 if you have the `strerror' function. */
+#undef HAVE_STRERROR
+
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
+/* Define to 1 if you have the `strstr' function. */
+#undef HAVE_STRSTR
+
+/* Define to 1 if you have the <syslog.h> header file. */
+#undef HAVE_SYSLOG_H
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#undef HAVE_SYS_IOCTL_H
+
+/* Define to 1 if you have the <sys/mount.h> header file. */
+#undef HAVE_SYS_MOUNT_H
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#undef HAVE_SYS_SOCKET_H
+
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
+/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
+#undef HAVE_SYS_WAIT_H
+
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
+/* Define to 1 if you have the `vfork' function. */
+#undef HAVE_VFORK
+
+/* Define to 1 if you have the <vfork.h> header file. */
+#undef HAVE_VFORK_H
+
+/* Define to 1 if `fork' works. */
+#undef HAVE_WORKING_FORK
+
+/* Define to 1 if `vfork' works. */
+#undef HAVE_WORKING_VFORK
+
+/* Define to 1 if Large File Support should be enabled */
+#undef NBD_LFS
+
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the version of this package. */
#undef PACKAGE_VERSION
+/* Define to 1 if the C compiler supports function prototypes. */
+#undef PROTOTYPES
+
+/* Define to 1 if the `setvbuf' function takes the buffering type as its
+ second argument and the buffer pointer as the third, as on System V before
+ release 3. */
+#undef SETVBUF_REVERSED
+
/* The size of a `unsigned int', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_INT
first (like Motorola and SPARC, unlike Intel and VAX). */
#undef WORDS_BIGENDIAN
+/* Define like PROTOTYPES; this can be used by system headers. */
+#undef __PROTOTYPES
+
+/* Define to empty if `const' does not conform to ANSI C. */
+#undef const
+
/* Define as `__inline' if that's what the C compiler calls it, or to nothing
if it is not supported. */
#undef inline
+
+/* Define to rpl_malloc if the replacement function should be used. */
+#undef malloc
+
+/* Define to `long' if <sys/types.h> does not define. */
+#undef off_t
+
+/* Define to `int' if <sys/types.h> does not define. */
+#undef pid_t
+
+/* Define to rpl_realloc if the replacement function should be used. */
+#undef realloc
+
+/* Define as `fork' if `vfork' does not work. */
+#undef vfork
dnl Configure script for NBD system
dnl (c) 1998 Martin Mares <mj@ucw.cz>, (c) 2000 Pavel Machek <pavel@ucw.cz>
AC_INIT(nbd, 2.5, wouter@debian.org)
-
+AC_ARG_ENABLE(lfs, AC_HELP_STRING([--enable-lfs],[Enable Large File Support (default is no)]), [NBD_LFS=1], [NBD_LFS=0])
+AC_MSG_CHECKING([whether Large File Support should be enabled])
+if test $NBD_LFS -eq 1; then
+ AC_DEFINE(NBD_LFS,1, [Define to 1 if Large File Support should be enabled])
+ AC_MSG_RESULT([yes])
+else
+ AC_DEFINE(NBD_LFS,0)
+ AC_MSG_RESULT([no])
+fi
AC_PROG_CC
AC_MSG_CHECKING(whether warnings should be enabled)
if test -n "$GCC" ; then
#AC_PROG_INSTALL
AC_C_BIGENDIAN
AC_C_INLINE
+AC_C_CONST
AC_CHECK_SIZEOF(unsigned short int)
AC_CHECK_SIZEOF(unsigned int)
AC_CHECK_SIZEOF(unsigned long int)
AC_CHECK_SIZEOF(unsigned long long int)
-AC_CHECK_FUNCS(llseek)
+AC_CHECK_FUNCS([llseek alarm gethostbyname inet_ntoa memset socket strerror strstr])
+AC_FUNC_FORK
+AC_FUNC_MALLOC
+AC_FUNC_REALLOC
+AC_FUNC_SETVBUF_REVERSED
AC_MSG_CHECKING(whether client should be built)
case "`uname`" in
*Linux*) BUILD_CLIENT=nbd-client
;;
*) AC_MSG_RESULT(no) ;;
esac
-AC_CHECK_HEADERS([linux/nbd.h])
+AC_CHECK_HEADERS([linux/nbd.h arpa/inet.h fcntl.h netdb.h netinet/in.h sys/ioctl.h sys/mount.h sys/socket.h syslog.h])
+AC_HEADER_SYS_WAIT
+AC_TYPE_OFF_T
+AC_TYPE_PID_T
AC_SUBST(BUILD_CLIENT)
AC_CONFIG_HEADER(config.h)
AC_OUTPUT(Makefile)
* so that processes don't think they have to wait for us, which is
* interesting for initscripts as well. Wouter Verhelst
* <wouter@debian.org>
+ * Version 2.5 - Bugfix release: forgot to reset child_arraysize to
+ * zero after fork()ing, resulting in nbd-server going berserk
+ * when it receives a signal with at least one child open. Wouter
+ * Verhelst <wouter@debian.org>
+ * 10/10/2003 - Added socket option SO_KEEPALIVE (sf.net bug 819235);
+ * rectified type of mainloop::size_host (sf.net bugs 814435 and
+ * 817385); close the PID file after writing to it, so that the
+ * daemon can actually be found. Wouter Verhelst
+ * <wouter@debian.org>
*/
#define VERSION PACKAGE_VERSION
pidf=fopen(pidfname, "w");
if(pidf) {
fprintf(pidf,"%d", (int)getpid());
+ fclose(pidf);
} else {
perror("fopen");
fprintf(stderr, "Not fatal; continuing");
/* lose the pesky "Address already in use" error message */
if (setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1) {
- err("setsockopt");
+ err("setsockopt SO_REUSEADDR");
+ }
+ if (setsockopt(sock,SOL_SOCKET,SO_KEEPALIVE,&yes,sizeof(int)) == -1) {
+ err("setsockopt SO_KEEPALIVE");
}
DEBUG("Waiting for connections... bind, ");
struct nbd_reply reply;
char zeros[300];
int i = 0;
- off_t size_host;
+ u64 size_host;
memset(zeros, 0, 290);
if (write(net, INIT_PASSWD, 8) < 0)
cliserv_magic = htonll(cliserv_magic);
if (write(net, &cliserv_magic, sizeof(cliserv_magic)) < 0)
err("Negotiation failed: %m");
- size_host = htonll(exportsize);
+ size_host = htonll((u64)exportsize);
if (write(net, &size_host, 8) < 0)
err("Negotiation failed: %m");
if (write(net, zeros, 128) < 0)