diff options
author | Wayne Davison <wayned@samba.org> | 2004-10-01 06:56:14 +0000 |
---|---|---|
committer | Wayne Davison <wayned@samba.org> | 2004-10-01 06:56:14 +0000 |
commit | da6eb9d123caf52640ae0cd6017fb0b657188c89 (patch) | |
tree | 978f9bd67b2e84395e1ed35664b86a91c815181e /syscall.c | |
parent | 1b15e07e99bd50df0fb95b0678a19634cbe11da5 (diff) | |
download | rsync-da6eb9d123caf52640ae0cd6017fb0b657188c89.tar.gz rsync-da6eb9d123caf52640ae0cd6017fb0b657188c89.tar.bz2 rsync-da6eb9d123caf52640ae0cd6017fb0b657188c89.zip |
Improved do_mknod() so that it handles creating a fifo file
and a socket file when mknod() itself does not.
Diffstat (limited to 'syscall.c')
-rw-r--r-- | syscall.c | 35 |
1 files changed, 33 insertions, 2 deletions
@@ -26,6 +26,10 @@ #include "rsync.h" +#if !MKNOD_CREATES_SOCKETS && HAVE_SYS_UN_H +#include <sys/un.h> +#endif + extern int dry_run; extern int read_only; extern int list_only; @@ -71,14 +75,41 @@ int do_lchown(const char *path, uid_t owner, gid_t group) return lchown(path, owner, group); } -#if HAVE_MKNOD int do_mknod(char *pathname, mode_t mode, dev_t dev) { if (dry_run) return 0; RETURN_ERROR_IF_RO_OR_LO; +#if !MKNOD_CREATES_FIFOS && HAVE_MKFIFO + if (S_ISFIFO(mode)) + return mkfifo(pathname, mode); +#endif +#if !MKNOD_CREATES_SOCKETS && HAVE_SYS_UN_H + if (S_ISSOCK(mode)) { + int sock; + struct sockaddr_un saddr; + unsigned int len; + + saddr.sun_family = AF_UNIX; + len = strlcpy(saddr.sun_path, pathname, sizeof saddr.sun_path); +#if HAVE_SOCKADDR_UN_LEN + saddr.sun_len = len >= sizeof saddr.sun_path + ? sizeof saddr.sun_path : len + 1; +#endif + + if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0 + || (unlink(pathname) < 0 && errno != ENOENT) + || (bind(sock, (struct sockaddr*)&saddr, sizeof saddr)) < 0) + return -1; + close(sock); + return do_chmod(pathname, mode); + } +#endif +#if HAVE_MKNOD return mknod(pathname, mode, dev); -} +#else + return -1; #endif +} int do_rmdir(char *pathname) { |