diff options
Diffstat (limited to 'contrib/csup/main.c')
-rw-r--r-- | contrib/csup/main.c | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/contrib/csup/main.c b/contrib/csup/main.c index 33f5915..7415039 100644 --- a/contrib/csup/main.c +++ b/contrib/csup/main.c @@ -66,6 +66,8 @@ usage(char *argv0) "Override supfile's \"base\" directory"); lprintf(-1, USAGE_OPTFMT, "-c collDir", "Subdirectory of \"base\" for collections (default \"sup\")"); + lprintf(-1, USAGE_OPTFMT, "-d delLimit", + "Allow at most \"delLimit\" file deletions (default unlimited)"); lprintf(-1, USAGE_OPTFMT, "-h host", "Override supfile's \"host\" name"); lprintf(-1, USAGE_OPTFMT, "-i pattern", @@ -73,6 +75,8 @@ usage(char *argv0) lprintf(-1, USAGE_OPTFMTSUB, "May be repeated for an OR operation. Default is"); lprintf(-1, USAGE_OPTFMTSUB, "to include each entire collection."); + lprintf(-1, USAGE_OPTFMT, "-k", + "Keep bad temporary files when fixups are required"); lprintf(-1, USAGE_OPTFMT, "-l lockfile", "Lock file during update; fail if already locked"); lprintf(-1, USAGE_OPTFMT, "-L n", @@ -102,13 +106,13 @@ main(int argc, char *argv[]) socklen_t laddrlen; struct stream *lock; char *argv0, *file, *lockfile; - uint16_t port; int family, error, lockfd, lflag, overridemask; - int c, i, retries, status; + int c, i, deletelim, port, retries, status; time_t nexttry; error = 0; family = PF_UNSPEC; + deletelim = -1; port = 0; lflag = 0; lockfd = 0; @@ -121,7 +125,8 @@ main(int argc, char *argv[]) override = coll_new(NULL); overridemask = 0; - while ((c = getopt(argc, argv, "146A:b:c:gh:i:l:L:p:P:r:svzZ")) != -1) { + while ((c = getopt(argc, argv, + "146A:b:c:d:gh:i:kl:L:p:P:r:svzZ")) != -1) { switch (c) { case '1': retries = 0; @@ -152,6 +157,14 @@ main(int argc, char *argv[]) case 'c': override->co_colldir = optarg; break; + case 'd': + error = asciitoint(optarg, &deletelim, 0); + if (error || deletelim < 0) { + lprintf(-1, "Invalid deletion limit\n"); + usage(argv0); + return (1); + } + break; case 'g': /* For compatibility. */ break; @@ -163,6 +176,10 @@ main(int argc, char *argv[]) case 'i': pattlist_add(override->co_accepts, optarg); break; + case 'k': + override->co_options |= CO_KEEPBADFILES; + overridemask |= CO_KEEPBADFILES; + break; case 'l': lockfile = optarg; lflag = 1; @@ -191,9 +208,8 @@ main(int argc, char *argv[]) stream_close(lock); break; case 'L': - errno = 0; - verbose = strtol(optarg, NULL, 0); - if (errno == EINVAL) { + error = asciitoint(optarg, &verbose, 0); + if (error) { lprintf(-1, "Invalid verbosity\n"); usage(argv0); return (1); @@ -201,13 +217,21 @@ main(int argc, char *argv[]) break; case 'p': /* Use specified server port. */ - errno = 0; - port = strtol(optarg, NULL, 0); - if (errno == EINVAL) { + error = asciitoint(optarg, &port, 0); + if (error) { lprintf(-1, "Invalid server port\n"); usage(argv0); return (1); } + if (port <= 0 || port >= 65536) { + lprintf(-1, "Invalid port %d\n", port); + return (1); + } + if (port < 1024) { + lprintf(-1, "Reserved port %d not permitted\n", + port); + return (1); + } break; case 'P': /* For compatibility. */ @@ -218,9 +242,8 @@ main(int argc, char *argv[]) } break; case 'r': - errno = 0; - retries = strtol(optarg, NULL, 0); - if (errno == EINVAL || retries < 0) { + error = asciitoint(optarg, &retries, 0); + if (error || retries < 0) { lprintf(-1, "Invalid retry limit\n"); usage(argv0); return (1); @@ -270,15 +293,16 @@ main(int argc, char *argv[]) if (config == NULL) return (1); - if (laddr != NULL) { - config->laddr = laddr; - config->laddrlen = laddrlen; - } if (config_checkcolls(config) == 0) { lprintf(-1, "No collections selected\n"); return (1); } + if (laddr != NULL) { + config->laddr = laddr; + config->laddrlen = laddrlen; + } + config->deletelim = deletelim; lprintf(2, "Connecting to %s\n", config->host); i = 0; |