Commit 7a500c41 authored by Peter Pentchev's avatar Peter Pentchev
Browse files

Update upstream source from tag 'upstream/20200929+ds1'

Update to upstream version '20200929+ds1'
with Debian dir c310f0a54006b04b5ca62ba9b4c4444d27d1d07f
parents 64576139 244b140f
2020505:
20200929:
- enhancement: added option --no-direct to disable use of O_DIRECT
- defaults: raised default TCP timeout to 10ms for WAN connections
- fix: leave TCP buffer size untouched if not set
- enhancement: add option to set TCP timeout
- performance optimization: use recv with MSG_WAITALL instead of read
- configure fix: look for objdump also with target prefix
- testing: make sure to use gtar for testing to avoid unexpected failures
- portability: NetBSD compatibility fix
- build enhancement: added dependency calculation for make
- build enhancement: automatic version string generation
20200505:
- configure fix for some powerpc toolchains
- update config.sub and config.guess
- added option to perform direct I/Os on temporary file
......
#
# Copyright (C) 2000-2019, Thomas Maier-Komor
# Copyright (C) 2000-2020, Thomas Maier-Komor
#
# This is the source code of mbuffer.
#
......@@ -43,6 +43,7 @@ TAR = @TAR@
TARGET = mbuffer$(EXE)
SOURCES = log.c network.c mbuffer.c hashing.c input.c common.c settings.c globals.c
OBJECTS = $(SOURCES:%.c=build/%.o)
DEPS = $(SOURCES:%.c=build/%.d)
TESTTREE = /bin /usr/bin
......@@ -50,7 +51,7 @@ TESTTREE = /bin /usr/bin
all: $(TARGET) idev.so tapetest.so have-af
$(OBJECTS): build config.h Makefile
$(OBJECTS): config.h Makefile
build:
mkdir build
......@@ -58,6 +59,14 @@ build:
build/%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
build/%.d: %.c
$(CC) -MM -MG -MT $(@:%.d=%.o) $(CFLAGS) $< -o $@
always:
version.h: always
sh mkversion.sh
$(TARGET): $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $@
......@@ -186,3 +195,7 @@ tapetest.so: tapetest.c config.h
idev.so: idev.c config.h
$(CC) $(CFLAGS) -shared -g -fPIC idev.c -o $@ $(LIBS)
$(DEPS): | build
include $(DEPS)
......@@ -137,6 +137,8 @@ void releaseLock(void *l)
void enable_directio(int fd, const char *fn)
{
if (OptDirect == 0)
return;
#ifdef O_DIRECT
if (0 == fcntl(fd,F_SETFL,fcntl(fd,F_GETFL) | O_DIRECT))
infomsg("enabled O_DIRECT on %s\n",fn);
......@@ -146,6 +148,8 @@ void enable_directio(int fd, const char *fn)
#ifdef __sun
if (-1 == directio(fd,DIRECTIO_ON))
infomsg("direct I/O hinting failed for output %s: %s\n",fn,strerror(errno));
else
infomsg("direct I/O hinting enabled for output to %s\n",fn);
#endif
}
......
......@@ -625,9 +625,9 @@ LIBOBJS
AUTOCONF
DEBUG
ALLOCA
ac_ct_OBJDUMP
OBJDUMP
AWK
TAR
MT
CP
RM
......@@ -635,6 +635,7 @@ SH
INSTALL_DATA
INSTALL_SCRIPT
INSTALL_PROGRAM
TAR
EGREP
GREP
CPP
......@@ -3843,6 +3844,46 @@ if test "x$ac_cv_prog_cc_c99" != xno; then :
fi
# Extract the first word of "gtar tar", so it can be a program name with args.
set dummy gtar tar; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_path_TAR+:} false; then :
$as_echo_n "(cached) " >&6
else
case $TAR in
[\\/]* | ?:[\\/]*)
ac_cv_path_TAR="$TAR" # Let the user override the test with a path.
;;
*)
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_path_TAR="$as_dir/$ac_word$ac_exec_ext"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
;;
esac
fi
TAR=$ac_cv_path_TAR
if test -n "$TAR"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $TAR" >&5
$as_echo "$TAR" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C/C++ restrict keyword" >&5
$as_echo_n "checking for C/C++ restrict keyword... " >&6; }
if ${ac_cv_c_restrict+:} false; then :
......@@ -4394,51 +4435,6 @@ $as_echo "no" >&6; }
fi
for ac_prog in objdump gobjdump
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_path_OBJDUMP+:} false; then :
$as_echo_n "(cached) " >&6
else
case $OBJDUMP in
[\\/]* | ?:[\\/]*)
ac_cv_path_OBJDUMP="$OBJDUMP" # Let the user override the test with a path.
;;
*)
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_path_OBJDUMP="$as_dir/$ac_word$ac_exec_ext"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
;;
esac
fi
OBJDUMP=$ac_cv_path_OBJDUMP
if test -n "$OBJDUMP"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5
$as_echo "$OBJDUMP" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
test -n "$OBJDUMP" && break
done
# Check whether --enable-largefile was given.
if test "${enable_largefile+set}" = set; then :
enableval=$enable_largefile;
......@@ -4653,11 +4649,100 @@ fi
for ac_prog in gobjdump objdump
do
# Extract the first word of "$target_alias-$ac_prog", so it can be a program name with args.
set dummy $target_alias-$ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_OBJDUMP+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$OBJDUMP"; then
ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_OBJDUMP="$target_alias-$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
fi
fi
OBJDUMP=$ac_cv_prog_OBJDUMP
if test -n "$OBJDUMP"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5
$as_echo "$OBJDUMP" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
test -n "$OBJDUMP" && break
done
if test -z "$OBJDUMP"; then
as_fn_error $? "unable to find objdump" "$LINENO" 5
if test "$build" = "$target"; then
ac_ct_OBJDUMP=$OBJDUMP
for ac_prog in gobjdump objdump
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_OBJDUMP+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$ac_ct_OBJDUMP"; then
ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_ac_ct_OBJDUMP="$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
fi
fi
ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP
if test -n "$ac_ct_OBJDUMP"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5
$as_echo "$ac_ct_OBJDUMP" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
test -n "$ac_ct_OBJDUMP" && break
done
OBJDUMP=$ac_ct_OBJDUMP
else
OBJDUMP=""
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable assertions" >&5
$as_echo_n "checking whether to enable assertions... " >&6; }
# Check whether --enable-assert was given.
......@@ -5673,15 +5758,19 @@ fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking linking open() and write() to detect libc names" >&5
$as_echo_n "checking linking open() and write() to detect libc names... " >&6; }
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
if test -z "$OBJDUMP"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unable to find objdump, which is needed to run tests" >&5
$as_echo "$as_me: WARNING: unable to find objdump, which is needed to run tests" >&2;}
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking linking open() and write() to detect libc names" >&5
$as_echo_n "checking linking open() and write() to detect libc names... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
......@@ -5735,7 +5824,7 @@ _ACEOF
$as_echo "$libc_write" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking name of fstat() in C library" >&5
$as_echo_n "checking name of fstat() in C library... " >&6; }
libc_fstat=`$OBJDUMP -T conftest | $AWK '/\*UND\*/ && $NF ~ /^fstat/ { print $NF }'`
libc_fstat=`$OBJDUMP -T conftest | $AWK '/\*UND\*/ && $NF ~ /^_*fstat/ { print $NF }'`
cat >>confdefs.h <<_ACEOF
#define LIBC_FSTAT $libc_fstat
......@@ -5753,6 +5842,9 @@ See \`config.log' for more details" "$LINENO" 5; }
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
......
#
# Copyright (C) 2000-2019, Thomas Maier-Komor
# Copyright (C) 2000-2020, Thomas Maier-Komor
#
# This is the source code of mbuffer.
#
......@@ -45,6 +45,7 @@ USRCFLAGS=${CFLAGS}
AC_LANG_C
AC_PROG_CC_C99(cc gcc)
AC_PATH_PROG(TAR,[gtar tar])
AC_C_RESTRICT
AC_C_INLINE
......@@ -109,13 +110,10 @@ AC_PATH_PROG(CP,cp)
AC_PATH_PROG(MT,mt,AC_MSG_WARN(could not find the program mt - you might need this if you want autoloader support))
AC_PATH_PROGS(TAR,[gtar tar])
AC_PATH_PROG(AWK,awk)
AC_PATH_PROGS(OBJDUMP,objdump gobjdump)
AC_SYS_LARGEFILE
AC_STRUCT_ST_BLKSIZE
if test -z "$OBJDUMP"; then
AC_MSG_ERROR([unable to find objdump])
fi
AC_CHECK_TARGET_TOOLS(OBJDUMP,gobjdump objdump)
AC_HEADER_ASSERT
AC_CHECK_LIB(pthread, pthread_mutex_init)
......@@ -153,9 +151,12 @@ if test x$enable_md5 != xno ; then
fi
AC_MSG_CHECKING([linking open() and write() to detect libc names])
AC_LANG(C)
AC_LINK_IFELSE([
if test -z "$OBJDUMP"; then
AC_MSG_WARN([unable to find objdump, which is needed to run tests])
else
AC_MSG_CHECKING([linking open() and write() to detect libc names])
AC_LINK_IFELSE([
AC_LANG_SOURCE([[
#define _LARGEFILE64_SOURCE
#include <unistd.h>
......@@ -184,15 +185,18 @@ AC_LINK_IFELSE([
AC_DEFINE_UNQUOTED([LIBC_WRITE], $libc_write, [name of write() in libc])
AC_MSG_RESULT($libc_write)
AC_MSG_CHECKING([name of fstat() in C library])
libc_fstat=`$OBJDUMP -T conftest | $AWK '/\*UND\*/ && $NF ~ /^fstat/ { print $NF }'`
libc_fstat=`$OBJDUMP -T conftest | $AWK '/\*UND\*/ && $NF ~ /^_*fstat/ { print $NF }'`
AC_DEFINE_UNQUOTED([LIBC_FSTAT], $libc_fstat, [name of fstat() in libc])
AC_MSG_RESULT($libc_fstat)
],
[AC_MSG_FAILURE([failed to link open/write test])]
)
)
fi
AC_SUBST(DEBUG)
AC_SUBST(OBJDUMP)
AC_SUBST(TAR)
AC_SUBST(prefix)
AC_SUBST(AUTOCONF)
AC_DEFINE(_REENTRANT,1,Needed for thread safe compilation)
......
/*
* Copyright (C) 2017-2018, Thomas Maier-Komor
* Copyright (C) 2017-2020, Thomas Maier-Komor
*
* This is the source code of mbuffer.
*
......@@ -126,7 +126,7 @@ int __fxstat(int ver, int fd, struct stat *st)
Debug = strtol(d,0,0);
d_fxstat = (int (*)(int,int,struct stat *)) dlsym(RTLD_NEXT, "__fxstat");
if (Debug)
fprintf(stderr,"idev.so: d_fstat = %p\n",d_fstat);
fprintf(stderr,"idev.so: d_fstat = %p\n",d_fxstat);
}
if (Debug)
fprintf(stderr,"idev.so: __fxstat(%d,%d,%p)\n",ver,fd,st);
......
/*
* Copyright (C) 2000-2019, Thomas Maier-Komor
* Copyright (C) 2000-2020, Thomas Maier-Komor
*
* This file is part of mbuffer's source code.
*
......@@ -36,6 +36,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
......@@ -283,6 +284,8 @@ int readBlock(unsigned at)
ssize_t in;
if (IDevBSize)
in = devread(at);
else if (InSocket)
in = recv(In,Buffer[at] + num,Blocksize - num,MSG_WAITALL);
else
in = read(In,Buffer[at] + num,Blocksize - num);
debugiomsg("inputThread: read(In, Buffer[%d] + %llu, %llu) = %d\n", at, num, Blocksize - num, in);
......
......@@ -52,7 +52,7 @@ pthread_mutex_t
void setVerbose(const char *arg)
{
char c = *arg;
char c = arg[0];
if (0 == strcasecmp(arg,"fatal"))
Verbose = fatals;
else if (0 == strcasecmp(arg,"error"))
......@@ -69,7 +69,7 @@ void setVerbose(const char *arg)
Verbose = silent;
else if (0 == strcasecmp(arg,"none"))
Verbose = silent;
else if ((arg[1] == 0) && (c >= '0') && (c <= '6'))
else if ((arg[1] == '\0') && (c >= '0') && (c <= '6'))
Verbose = (verbose_t) (c-'0');
else
errormsg("Invalid argument '%s' for setting verbosity level.\n"
......
/*
* Copyright (C) 2000-2019, Thomas Maier-Komor
* Copyright (C) 2000-2020, Thomas Maier-Komor
*
* This file is part of mbuffer's source code.
*
......@@ -625,7 +625,6 @@ static void terminateOutputThread(dest_t *d, int status)
}
static void *outputThread(void *arg)
{
dest_t *dest = (dest_t *) arg;
......@@ -885,14 +884,6 @@ static void openDestinationFiles(dest_t *d)
}
if (-1 == d->fd)
d->name = 0; /* tag destination as unstartable */
#ifdef __sun
else if (d->arg) {
if (0 == directio(d->fd,DIRECTIO_ON))
infomsg("direct I/O hinting enabled for output to %s\n",d->arg);
else
infomsg("direct I/O hinting failed for output to %s: %s\n",d->arg,strerror(errno));
}
#endif
d = d->next;
}
if (ErrorOccurred != errs)
......@@ -1202,7 +1193,7 @@ int main(int argc, const char **argv)
progname = basename(argv0);
PrefixLen = strlen(progname);
Prefix = malloc(PrefixLen + 2);
(void) strncpy(Prefix,progname,PrefixLen);
memcpy(Prefix,progname,PrefixLen);
Prefix[PrefixLen++] = ':';
Prefix[PrefixLen++] = ' ';
......
......@@ -72,6 +72,13 @@
## 0 means: keep OS default
# TCPbufsize = 0
## TCP transmission timeout [msec]
# TCPtimeout = 0
## tape aware out-of-space handling
## valid values are: true, false, 0, 1, on, off
# Tapeaware = false
## Use of O_DIRECT. [boolean]
## Enabled per default. Disable to allow btrfs to use compression.
# directio = 1
#!/bin/sh
VERSION_H=${1:-version.h}
if [ -f .hg_archival.txt ]; then
HGA=.hg_archival.txt
# Gather version information from .hg_archival.txt for archives.
TAG=`awk '/^tag:/ {printf("%s",$2);}' $HGA`
LTAG=`awk '/^latesttag:/ {printf("%s",$2);}' $HGA`
TAGD=`awk '/^latesttagdistance:/ {printf("%s",$2);}' $HGA`
if [ "" != "$TAG" ]; then
VER=$TAG
elif [ "" = "$LTAG" ]; then
echo archive has no tag or latesttag
exit 1
elif [ "0" != $TAGD ]; then
VER=$LTAG.$TAGD
else
VER=$LTAG
fi
echo "#define VERSION \"$VER\"" > version.h.new
BR=`awk '/^branch:/ {printf("%s",$2);}' $HGA`
echo "#define HG_BRANCH \"$BR\"" >> version.h.new
elif [ -d .hg ]; then
HG=`which hg`
if [ "$?" != "0" ]; then
echo "error: need mecurial to determine version"
exit 1
fi
# Check if we have modified, removed, added or deleted files.
if [ `$HG st -mard | wc -l` != "0" ]; then
# add delta indicator
DELTA="+"
else
DELTA=""
fi
# Gather version information from repository and sandbox.
$HG log -r. -T"`cat version.t`" | sed "s/\$DELTA/$DELTA/" > version.h.new
else
# Bail out with an error, if no version information an be gathered.
echo "no version information available"
exit 1
fi
if [ ! -f version.h ]; then
echo creating version.h
mv version.h.new $VERSION_H
exit
fi
cmp -s $VERSION_H version.h.new
if [ "0" = "$?" ]; then
echo version.h is up-to-date
rm version.h.new
else
echo updating version.h
mv -f version.h.new $VERSION_H
fi
/*
* Copyright (C) 2000-2019, Thomas Maier-Komor
* Copyright (C) 2000-2020, Thomas Maier-Komor
*
* This file is part of mbuffer's source code.
*
......@@ -42,7 +42,7 @@
#include "settings.h"
#include "log.h"
int32_t TCPBufSize = (int32_t)1 << 20;
int32_t TCPBufSize = 0, TCPTimeout = 10000000;
#if defined(PF_INET6) && defined(PF_UNSPEC)
int AddrFam = PF_UNSPEC;
#else
......@@ -54,7 +54,7 @@ static void setTCPBufferSize(int sock, int buffer)
{
int err;
int32_t osize, size;
socklen_t bsize = sizeof(osize);
socklen_t bsize = (socklen_t)sizeof(osize);
assert(buffer == SO_RCVBUF || buffer == SO_SNDBUF);
err = getsockopt(sock,SOL_SOCKET,buffer,&osize,&bsize);
......@@ -111,7 +111,7 @@ void initNetworkInput(const char *addr)
hint.ai_family = AddrFam;
hint.ai_protocol = IPPROTO_TCP;
hint.ai_socktype = SOCK_STREAM;
#if defined __FreeBSD__ || defined __OpenBSD__
#if defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__
hint.ai_flags = AI_ADDRCONFIG;
#else
hint.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED;
......@@ -187,7 +187,13 @@ void initNetworkInput(const char *addr)
if (cinfo)
freeaddrinfo(cinfo);
debugmsg("input connection accepted\n");
setTCPBufferSize(In,SO_RCVBUF);
if (TCPBufSize)
setTCPBufferSize(In,SO_RCVBUF);
struct timeval timeo;
timeo.tv_sec = TCPTimeout/1000000;
timeo.tv_usec = TCPTimeout%1000000;
if (-1 == setsockopt(In, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo)))
warningmsg("cannot set socket send timeout: %s\n",strerror(errno));
(void) close(sock);
}
......@@ -232,13 +238,18 @@ dest_t *createNetworkOutput(const char *addr)
fd = -1;
warningmsg("error connecting to %s: %s\n",addr,strerror(errno));
}
if ((x == 0) || (fd == -1))