Hey folks, I sent this patch to rsync-bugs a while back, and never got a response (other than the automated message from the bug tracking system). It might be useful to some of you. It's certainly been critical to my use of rsync. I'm not sure whether it should be included in the main rsync distribution or not...that's for the rsync maintainers to decide. ----- Forwarded message from [EMAIL PROTECTED] ----- Delivered-To: [EMAIL PROTECTED] Date: Mon, 30 Oct 2000 22:11:21 -0800 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: FIFO's and unix domain sockets under *bsd User-Agent: Mutt/1.2.5i Hey rsync folks, There seems to be a problem with rsync under NetBSD, FreeBSD, and almost surely OpenBSD (although I haven't tested the latter). Under these and possibly other systems, named pipes and unix domain sockets fail to be copied. This appears to be because mknod(2) cannot be used to create these types of files on these systems. Attached is a quick patch for this problem, which simply uses mkfifo(2) to create named pipes and a socket(2) and bind(2) to create unix domain sockets. It will not use mkfifo(2) unless autoconf detects its availability, and will not use socket(2) and bind(2) if autoconf detects that there is no <sys/un.h>. If either fail, it will fall back to using mknod(2) the old way. The patch applies cleanly to rsync 2.4.5 and 2.4.6. If this patch, or something similar, was included in future releases, it would make my life a lot easier. Andrew Flury diff -ur config.h.orig config.h --- config.h.in.orig Fri Jul 28 22:05:08 2000 +++ config.h.in Sun Oct 22 20:03:18 2000 @@ -108,6 +108,9 @@ /* Define if you have the mknod function. */ #undef HAVE_MKNOD +/* Define if you have the mkfifo function. */ +#undef HAVE_MKFIFO + /* Define if you have the readlink function. */ #undef HAVE_READLINK @@ -209,6 +212,9 @@ /* Define if you have the <sys/socket.h> header file. */ #undef HAVE_SYS_SOCKET_H + +/* Define if you have the <sys/un.h> header file. */ +#undef HAVE_SYS_UN_H /* Define if you have the <sys/time.h> header file. */ #undef HAVE_SYS_TIME_H diff -ur configure.orig configure --- configure.orig Fri Jul 28 22:05:08 2000 +++ configure Sun Oct 22 20:02:45 2000 @@ -1429,7 +1429,7 @@ fi done -for ac_hdr in sys/filio.h string.h stdlib.h sys/socket.h sys/mode.h +for ac_hdr in sys/filio.h string.h stdlib.h sys/socket.h sys/mode.h sys/un.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 @@ -2617,7 +2617,7 @@ fi -for ac_func in waitpid wait4 getcwd strdup strerror chown chmod mknod +for ac_func in waitpid wait4 getcwd strdup strerror chown chmod mknod mkfifo do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo "configure:2624: checking for $ac_func" >&5 diff -ur configure.in.orig configure.in --- configure.in.orig Fri Jul 28 22:05:08 2000 +++ configure.in Sun Oct 22 20:02:45 2000 @@ -22,7 +22,7 @@ AC_HEADER_SYS_WAIT AC_CHECK_HEADERS(sys/fcntl.h sys/select.h fcntl.h sys/time.h sys/unistd.h unistd.h utime.h grp.h) AC_CHECK_HEADERS(compat.h sys/param.h ctype.h sys/wait.h sys/ioctl.h) -AC_CHECK_HEADERS(sys/filio.h string.h stdlib.h sys/socket.h sys/mode.h) +AC_CHECK_HEADERS(sys/filio.h string.h stdlib.h sys/socket.h sys/mode.h sys/un.h) AC_CHECK_HEADERS(glob.h) AC_CHECK_SIZEOF(int) @@ -94,7 +94,7 @@ AC_FUNC_MEMCMP AC_FUNC_UTIME_NULL -AC_CHECK_FUNCS(waitpid wait4 getcwd strdup strerror chown chmod mknod) +AC_CHECK_FUNCS(waitpid wait4 getcwd strdup strerror chown chmod mknod mkfifo) AC_CHECK_FUNCS(fchmod fstat strchr readlink link utime utimes strftime) AC_CHECK_FUNCS(memmove lchown vsnprintf snprintf setsid glob strpbrk) AC_CHECK_FUNCS(strlcat strlcpy) diff -ur rsync.h.orig rsync --- rsync.h.orig Sat Aug 19 06:10:39 2000 +++ rsync.h Sun Oct 22 20:02:45 2000 @@ -101,6 +101,10 @@ #include <sys/socket.h> #endif +#ifdef HAVE_SYS_UN_H +#include <sys/un.h> +#endif + #ifdef HAVE_STRING_H #include <string.h> #endif diff -ur syscall.c.orig syscall.c --- syscall.c.orig Sat Jan 29 03:35:03 2000 +++ syscall.c Sun Oct 22 20:02:45 2000 @@ -63,6 +63,35 @@ { if (dry_run) return 0; CHECK_RO + +#if HAVE_MKFIFO + if (S_ISFIFO(mode)) { + return mkfifo(pathname, mode); + } +#endif + +#if HAVE_SYS_UN_H + if (S_ISSOCK(mode)) { + int sock; + struct sockaddr_un saddr; + int len = strlen(pathname) + 1; /* include null */ + + saddr.sun_family = AF_UNIX; + strncpy(saddr.sun_path, pathname, sizeof(saddr.sun_path)); + saddr.sun_len = len > sizeof(saddr.sun_path) ? sizeof(saddr.sun_path) +: len; + + if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { + return -1; + } + unlink(pathname); + if ((bind(sock, (struct sockaddr*)&saddr, sizeof(saddr))) < 0) { + return -1; + } + close(sock); + return do_chmod(pathname, mode); + } +#endif + return mknod(pathname, mode, dev); } #endif ----- End forwarded message -----