diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2011-04-10 15:47:29 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2011-04-10 15:47:29 +0000 |
commit | 9f456934bb9a90ca681b33e80b4019703968f08d (patch) | |
tree | 983372b04789d76ef7ae56b928a06e77fd8eb12c /usr.bin/rdistd | |
parent | 19f7d0b1c1f9a19e8c44763c05b14dfc067d4540 (diff) |
Apply some tough type-love and give rdist a chance to handle files
larger than 2GB. Diff from Stephan R. Gerber via PR#6586, tweaks
by me.
ok deraadt@
Diffstat (limited to 'usr.bin/rdistd')
-rw-r--r-- | usr.bin/rdistd/filesys.c | 10 | ||||
-rw-r--r-- | usr.bin/rdistd/server.c | 53 |
2 files changed, 31 insertions, 32 deletions
diff --git a/usr.bin/rdistd/filesys.c b/usr.bin/rdistd/filesys.c index 8c37fbd22c8..8323f98de54 100644 --- a/usr.bin/rdistd/filesys.c +++ b/usr.bin/rdistd/filesys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: filesys.c,v 1.11 2009/10/27 23:59:42 deraadt Exp $ */ +/* $OpenBSD: filesys.c,v 1.12 2011/04/10 15:47:28 krw Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -402,7 +402,7 @@ is_symlinked(char *path, struct stat *statbuf, int *isvalid) * information. */ int -getfilesysinfo(char *file, long *freespace, long *freefiles) +getfilesysinfo(char *file, int64_t *freespace, int64_t *freefiles) { #if defined(STATFS_TYPE) static statfs_t statfsbuf; @@ -449,11 +449,11 @@ getfilesysinfo(char *file, long *freespace, long *freefiles) * to < 0 if the field is unsupported for the filesystem type. */ #if defined(BROKEN_STATFS) - if (statfsbuf.f_ffree > 0) + if (statfsbuf.f_favail > 0) #else - if (statfsbuf.f_ffree >= 0) + if (statfsbuf.f_favail >= 0) #endif /* BROKEN_STATFS */ - *freefiles = statfsbuf.f_ffree; + *freefiles = statfsbuf.f_favail; #else /* !STATFS_TYPE */ diff --git a/usr.bin/rdistd/server.c b/usr.bin/rdistd/server.c index 06c95f2734d..ab4343583d2 100644 --- a/usr.bin/rdistd/server.c +++ b/usr.bin/rdistd/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.21 2009/10/27 23:59:42 deraadt Exp $ */ +/* $OpenBSD: server.c,v 1.22 2011/04/10 15:47:28 krw Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -41,8 +41,8 @@ char *ptarget; /* pointer to end of target name */ int catname = 0; /* cat name to target name */ char *sptarget[32]; /* stack of saved ptarget's for directories */ char *fromhost = NULL; /* Client hostname */ -static long min_freespace = 0; /* Minimium free space on a filesystem */ -static long min_freefiles = 0; /* Minimium free # files on a filesystem */ +static int64_t min_freespace = 0; /* Minimium free space on a filesystem */ +static int64_t min_freefiles = 0; /* Minimium free # files on a filesystem */ int oumask; /* Old umask */ static int cattarget(char *); @@ -656,8 +656,8 @@ query(char *xname) case S_IFIFO: #endif #endif - (void) sendcmd(QC_YES, "%ld %ld %o %s %s", - (long) stb.st_size, stb.st_mtime, + (void) sendcmd(QC_YES, "%lld %ld %o %s %s", + (long long) stb.st_size, stb.st_mtime, stb.st_mode & 07777, getusername(stb.st_uid, target, options), getgroupname(stb.st_gid, target, options)); @@ -794,13 +794,13 @@ recvfile(char *new, opt_t opts, int mode, char *owner, char *group, wrerr = 0; olderrno = 0; for (i = 0; i < size; i += BUFSIZ) { - int amt = BUFSIZ; + off_t amt = BUFSIZ; cp = buf; if (i + amt > size) amt = size - i; do { - int j; + ssize_t j; j = readrem(cp, amt); if (j <= 0) { @@ -1330,6 +1330,7 @@ setconfig(char *cmd) { char *cp = cmd; char *estr; + const char *errstr; switch (*cp++) { case SC_HOSTNAME: /* Set hostname */ @@ -1346,19 +1347,17 @@ setconfig(char *cmd) break; case SC_FREESPACE: /* Minimium free space */ - if (!isdigit((unsigned char)*cp)) { - fatalerr("Expected digit, got '%s'.", cp); - return; - } - min_freespace = (unsigned long) atoi(cp); + min_freespace = (int64_t)strtonum(cp, 0, LLONG_MAX, &errstr); + if (errstr) + fatalerr("Minimum free space is %s: '%s'", errstr, + optarg); break; case SC_FREEFILES: /* Minimium free files */ - if (!isdigit((unsigned char)*cp)) { - fatalerr("Expected digit, got '%s'.", cp); - return; - } - min_freefiles = (unsigned long) atoi(cp); + min_freefiles = (int64_t)strtonum(cp, 0, LLONG_MAX, &errstr); + if (errstr) + fatalerr("Minimum free files is %s: '%s'", errstr, + optarg); break; case SC_LOGGING: /* Logging options */ @@ -1396,7 +1395,7 @@ recvit(char *cmd, int type) char *owner, *group, *file; char new[MAXPATHLEN]; char fileb[MAXPATHLEN]; - long freespace = -1, freefiles = -1; + int64_t freespace = -1, freefiles = -1; char *cp = cmd; /* @@ -1420,7 +1419,7 @@ recvit(char *cmd, int type) /* * Get file size */ - size = strtol(cp, &cp, 10); + size = (off_t) strtoll(cp, &cp, 10); if (*cp++ != ' ') { error("recvit: size not delimited"); return; @@ -1429,7 +1428,7 @@ recvit(char *cmd, int type) /* * Get modification time */ - mtime = strtol(cp, &cp, 10); + mtime = (time_t) strtol(cp, &cp, 10); if (*cp++ != ' ') { error("recvit: mtime not delimited"); return; @@ -1478,8 +1477,8 @@ recvit(char *cmd, int type) file = fileb; debugmsg(DM_MISC, - "recvit: opts = %04o mode = %04o size = %d mtime = %d", - opts, mode, size, mtime); + "recvit: opts = %04o mode = %04o size = %lld mtime = %d", + opts, mode, (long long) size, mtime); debugmsg(DM_MISC, "recvit: owner = '%s' group = '%s' file = '%s' catname = %d isdir = %d", owner, group, file, catname, (type == S_IFDIR) ? 1 : 0); @@ -1523,7 +1522,7 @@ recvit(char *cmd, int type) */ if (min_freespace || min_freefiles) { /* Convert file size to kilobytes */ - long fsize = (long) (size / 1024); + int64_t fsize = (int64_t)size / 1024; if (getfilesysinfo(target, &freespace, &freefiles) != 0) return; @@ -1535,15 +1534,15 @@ recvit(char *cmd, int type) if (min_freespace && (freespace >= 0) && (freespace - fsize < min_freespace)) { error( - "%s: Not enough free space on filesystem: min %d free %d", - target, min_freespace, freespace); + "%s: Not enough free space on filesystem: min %lld " + "free %lld", target, min_freespace, freespace); return; } if (min_freefiles && (freefiles >= 0) && (freefiles - 1 < min_freefiles)) { error( - "%s: Not enough free files on filesystem: min %d free %d", - target, min_freefiles, freefiles); + "%s: Not enough free files on filesystem: min %lld free " + "%lld", target, min_freefiles, freefiles); return; } } |