diff options
author | Sebastian Benoit <benno@cvs.openbsd.org> | 2019-05-08 20:00:26 +0000 |
---|---|---|
committer | Sebastian Benoit <benno@cvs.openbsd.org> | 2019-05-08 20:00:26 +0000 |
commit | b4256882c089ac90d3bb031d8ce47cdba65dfbde (patch) | |
tree | 2d667020a5b80e86130ae4790023a0749dc20000 /usr.bin | |
parent | 73985a2cfa723d90e961688552fb3eb605909877 (diff) |
remove sess argument from log functions. ok deraadt@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/rsync/blocks.c | 59 | ||||
-rw-r--r-- | usr.bin/rsync/client.c | 23 | ||||
-rw-r--r-- | usr.bin/rsync/downloader.c | 69 | ||||
-rw-r--r-- | usr.bin/rsync/extern.h | 86 | ||||
-rw-r--r-- | usr.bin/rsync/fargs.c | 12 | ||||
-rw-r--r-- | usr.bin/rsync/flist.c | 232 | ||||
-rw-r--r-- | usr.bin/rsync/ids.c | 38 | ||||
-rw-r--r-- | usr.bin/rsync/io.c | 88 | ||||
-rw-r--r-- | usr.bin/rsync/log.c | 28 | ||||
-rw-r--r-- | usr.bin/rsync/main.c | 18 | ||||
-rw-r--r-- | usr.bin/rsync/mkpath.c | 6 | ||||
-rw-r--r-- | usr.bin/rsync/mktemp.c | 6 | ||||
-rw-r--r-- | usr.bin/rsync/receiver.c | 102 | ||||
-rw-r--r-- | usr.bin/rsync/sender.c | 96 | ||||
-rw-r--r-- | usr.bin/rsync/server.c | 37 | ||||
-rw-r--r-- | usr.bin/rsync/session.c | 22 | ||||
-rw-r--r-- | usr.bin/rsync/socket.c | 76 | ||||
-rw-r--r-- | usr.bin/rsync/symlinks.c | 14 | ||||
-rw-r--r-- | usr.bin/rsync/uploader.c | 124 |
19 files changed, 561 insertions, 575 deletions
diff --git a/usr.bin/rsync/blocks.c b/usr.bin/rsync/blocks.c index d02f4f40b4b..603a7b4a971 100644 --- a/usr.bin/rsync/blocks.c +++ b/usr.bin/rsync/blocks.c @@ -1,4 +1,4 @@ -/* $Id: blocks.c,v 1.14 2019/03/23 16:04:28 deraadt Exp $ */ +/* $Id: blocks.c,v 1.15 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -68,7 +68,7 @@ blk_find(struct sess *sess, const void *buf, off_t size, off_t offs, hash_slow(buf + offs, (size_t)osz, md, sess); have_md = 1; if (memcmp(md, blks->blks[hint].chksum_long, blks->csum) == 0) { - LOG4(sess, "%s: found matching hinted match: " + LOG4("%s: found matching hinted match: " "position %jd, block %zu (position %jd, size %zu)", path, (intmax_t)offs, blks->blks[hint].idx, @@ -89,7 +89,7 @@ blk_find(struct sess *sess, const void *buf, off_t size, off_t offs, if ((size_t)osz != blks->blks[i].len) continue; - LOG4(sess, "%s: found matching fast match: " + LOG4("%s: found matching fast match: " "position %jd, block %zu (position %jd, size %zu)", path, (intmax_t)offs, blks->blks[i].idx, @@ -106,7 +106,7 @@ blk_find(struct sess *sess, const void *buf, off_t size, off_t offs, if (memcmp(md, blks->blks[i].chksum_long, blks->csum)) continue; - LOG4(sess, "%s: sender verifies slow match", path); + LOG4("%s: sender verifies slow match", path); return &blks->blks[i]; } @@ -155,8 +155,7 @@ blk_match(struct sess *sess, const struct blkset *blks, sz = st->offs - last; st->dirty += sz; st->total += sz; - LOG4(sess, - "%s: flushing %jd B before %zu B block %zu", + LOG4("%s: flushing %jd B before %zu B block %zu", path, (intmax_t)sz, blk->len, blk->idx); tok = -(blk->idx + 1); @@ -180,7 +179,7 @@ blk_match(struct sess *sess, const struct blkset *blks, /* Emit remaining data and send terminator token. */ sz = st->mapsz - last; - LOG4(sess, "%s: flushing remaining %jd B", + LOG4("%s: flushing remaining %jd B", path, (intmax_t)sz); st->total += sz; @@ -196,7 +195,7 @@ blk_match(struct sess *sess, const struct blkset *blks, st->curst = st->mapsz ? BLKSTAT_DATA : BLKSTAT_TOK; st->dirty = st->total = st->mapsz; - LOG4(sess, "%s: flushing whole file %zu B", + LOG4("%s: flushing whole file %zu B", path, st->mapsz); } } @@ -241,7 +240,7 @@ blk_recv(struct sess *sess, int fd, const char *path) off_t offs = 0; if ((s = calloc(1, sizeof(struct blkset))) == NULL) { - ERR(sess, "calloc"); + ERR("calloc"); return NULL; } @@ -252,31 +251,31 @@ blk_recv(struct sess *sess, int fd, const char *path) */ if (!io_read_size(sess, fd, &s->blksz)) { - ERRX1(sess, "io_read_size"); + ERRX1("io_read_size"); goto out; } else if (!io_read_size(sess, fd, &s->len)) { - ERRX1(sess, "io_read_size"); + ERRX1("io_read_size"); goto out; } else if (!io_read_size(sess, fd, &s->csum)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } else if (!io_read_size(sess, fd, &s->rem)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } else if (s->rem && s->rem >= s->len) { - ERRX(sess, "block remainder is " + ERRX("block remainder is " "greater than block size"); goto out; } - LOG3(sess, "%s: read block prologue: %zu blocks of " + LOG3("%s: read block prologue: %zu blocks of " "%zu B, %zu B remainder, %zu B checksum", path, s->blksz, s->len, s->rem, s->csum); if (s->blksz) { s->blks = calloc(s->blksz, sizeof(struct blk)); if (s->blks == NULL) { - ERR(sess, "calloc"); + ERR("calloc"); goto out; } } @@ -289,7 +288,7 @@ blk_recv(struct sess *sess, int fd, const char *path) for (j = 0; j < s->blksz; j++) { b = &s->blks[j]; if (!io_read_int(sess, fd, &i)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } b->chksum_short = i; @@ -297,7 +296,7 @@ blk_recv(struct sess *sess, int fd, const char *path) assert(s->csum <= sizeof(b->chksum_long)); if (!io_read_buf(sess, fd, b->chksum_long, s->csum)) { - ERRX1(sess, "io_read_buf"); + ERRX1("io_read_buf"); goto out; } @@ -312,12 +311,12 @@ blk_recv(struct sess *sess, int fd, const char *path) s->rem : s->len; offs += b->len; - LOG4(sess, "%s: read block %zu, length %zu B", + LOG4("%s: read block %zu, length %zu B", path, b->idx, b->len); } s->size = offs; - LOG3(sess, "%s: read blocks: %zu blocks, %jd B total blocked data", + LOG3("%s: read blocks: %zu blocks, %jd B total blocked data", path, s->blksz, (intmax_t)s->size); return s; out: @@ -345,22 +344,22 @@ blk_send_ack(struct sess *sess, int fd, struct blkset *p) assert(sz <= sizeof(buf)); if (!io_read_buf(sess, fd, buf, sz)) { - ERRX1(sess, "io_read_buf"); + ERRX1("io_read_buf"); return 0; } if (!io_unbuffer_size(sess, buf, &pos, sz, &p->blksz)) - ERRX1(sess, "io_unbuffer_size"); + ERRX1("io_unbuffer_size"); else if (!io_unbuffer_size(sess, buf, &pos, sz, &p->len)) - ERRX1(sess, "io_unbuffer_size"); + ERRX1("io_unbuffer_size"); else if (!io_unbuffer_size(sess, buf, &pos, sz, &p->csum)) - ERRX1(sess, "io_unbuffer_size"); + ERRX1("io_unbuffer_size"); else if (!io_unbuffer_size(sess, buf, &pos, sz, &p->rem)) - ERRX1(sess, "io_unbuffer_size"); + ERRX1("io_unbuffer_size"); else if (p->len && p->rem >= p->len) - ERRX1(sess, "non-zero length is less than remainder"); + ERRX1("non-zero length is less than remainder"); else if (p->csum == 0 || p->csum > 16) - ERRX1(sess, "inappropriate checksum length"); + ERRX1("inappropriate checksum length"); else return 1; @@ -391,7 +390,7 @@ blk_send(struct sess *sess, int fd, size_t idx, p->csum); /* long checksum */ if ((buf = malloc(sz)) == NULL) { - ERR(sess, "malloc"); + ERR("malloc"); return 0; } @@ -411,11 +410,11 @@ blk_send(struct sess *sess, int fd, size_t idx, assert(pos == sz); if (!io_write_buf(sess, fd, buf, sz)) { - ERRX1(sess, "io_write_buf"); + ERRX1("io_write_buf"); goto out; } - LOG3(sess, "%s: sent block prologue: %zu blocks of %zu B, " + LOG3("%s: sent block prologue: %zu blocks of %zu B, " "%zu B remainder, %zu B checksum", path, p->blksz, p->len, p->rem, p->csum); rc = 1; diff --git a/usr.bin/rsync/client.c b/usr.bin/rsync/client.c index ba32e88e7e8..42e2628573b 100644 --- a/usr.bin/rsync/client.c +++ b/usr.bin/rsync/client.c @@ -1,4 +1,4 @@ -/* $Id: client.c,v 1.14 2019/03/23 16:04:28 deraadt Exp $ */ +/* $Id: client.c,v 1.15 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -50,25 +50,24 @@ rsync_client(const struct opts *opts, int fd, const struct fargs *f) sess.lver = RSYNC_PROTOCOL; if (!io_write_int(&sess, fd, sess.lver)) { - ERRX1(&sess, "io_write_int"); + ERRX1("io_write_int"); goto out; } else if (!io_read_int(&sess, fd, &sess.rver)) { - ERRX1(&sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } else if (!io_read_int(&sess, fd, &sess.seed)) { - ERRX1(&sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } if (sess.rver < sess.lver) { - ERRX(&sess, - "remote protocol %d is older than our own %d: unsupported", + ERRX("remote protocol %d is older than our own %d: unsupported", sess.rver, sess.lver); rc = 2; goto out; } - LOG2(&sess, "client detected client version %d, server version %d, seed %d", + LOG2("client detected client version %d, server version %d, seed %d", sess.lver, sess.rver, sess.seed); sess.mplex_reads = 1; @@ -79,18 +78,18 @@ rsync_client(const struct opts *opts, int fd, const struct fargs *f) */ if (f->mode != FARGS_RECEIVER) { - LOG2(&sess, "client starting sender: %s", + LOG2("client starting sender: %s", f->host == NULL ? "(local)" : f->host); if (!rsync_sender(&sess, fd, fd, f->sourcesz, f->sources)) { - ERRX1(&sess, "rsync_sender"); + ERRX1("rsync_sender"); goto out; } } else { - LOG2(&sess, "client starting receiver: %s", + LOG2("client starting receiver: %s", f->host == NULL ? "(local)" : f->host); if (!rsync_receiver(&sess, fd, fd, f->sink)) { - ERRX1(&sess, "rsync_receiver"); + ERRX1("rsync_receiver"); goto out; } } @@ -98,7 +97,7 @@ rsync_client(const struct opts *opts, int fd, const struct fargs *f) #if 0 /* Probably the EOF. */ if (io_read_check(&sess, fd)) - WARNX(&sess, "data remains in read pipe"); + WARNX("data remains in read pipe"); #endif rc = 0; diff --git a/usr.bin/rsync/downloader.c b/usr.bin/rsync/downloader.c index 405f7623759..918272e1e29 100644 --- a/usr.bin/rsync/downloader.c +++ b/usr.bin/rsync/downloader.c @@ -1,4 +1,4 @@ -/* $Id: downloader.c,v 1.19 2019/04/02 11:05:55 deraadt Exp $ */ +/* $Id: downloader.c,v 1.20 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -102,7 +102,7 @@ log_file(struct sess *sess, unit = "KB"; } - LOG1(sess, "%s (%.*f %s, %.1f%% downloaded)", + LOG1("%s (%.*f %s, %.1f%% downloaded)", f->path, prec, tot, unit, frac); } @@ -177,7 +177,7 @@ download_alloc(struct sess *sess, int fdin, struct download *p; if ((p = malloc(sizeof(struct download))) == NULL) { - ERR(sess, "malloc"); + ERR("malloc"); return NULL; } @@ -191,7 +191,7 @@ download_alloc(struct sess *sess, int fdin, p->obuf = NULL; p->obufmax = OBUF_SIZE; if (p->obufmax && (p->obuf = malloc(p->obufmax)) == NULL) { - ERR(sess, "malloc"); + ERR("malloc"); free(p); return NULL; } @@ -258,10 +258,10 @@ buf_copy(struct sess *sess, assert(p->obufsz <= p->obufmax); assert(p->obuf != NULL); if ((ssz = write(p->fd, p->obuf, p->obufsz)) < 0) { - ERR(sess, "%s: write", p->fname); + ERR("%s: write", p->fname); return 0; } else if ((size_t)ssz != p->obufsz) { - ERRX(sess, "%s: short write", p->fname); + ERRX("%s: short write", p->fname); return 0; } p->obufsz = 0; @@ -274,10 +274,10 @@ buf_copy(struct sess *sess, if (sz) { if ((ssz = write(p->fd, buf, sz)) < 0) { - ERR(sess, "%s: write", p->fname); + ERR("%s: write", p->fname); return 0; } else if ((size_t)ssz != sz) { - ERRX(sess, "%s: short write", p->fname); + ERRX("%s: short write", p->fname); return 0; } } @@ -313,13 +313,13 @@ rsync_downloader(struct download *p, struct sess *sess, int *ofd) if (p->state == DOWNLOAD_READ_NEXT) { if (!io_read_int(sess, p->fdin, &idx)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); return -1; } else if (idx >= 0 && (size_t)idx >= p->flsz) { - ERRX(sess, "index out of bounds"); + ERRX("index out of bounds"); return -1; } else if (idx < 0) { - LOG3(sess, "downloader: phase complete"); + LOG3("downloader: phase complete"); return 0; } @@ -336,7 +336,7 @@ rsync_downloader(struct download *p, struct sess *sess, int *ofd) download_reinit(sess, p, idx); if (!blk_send_ack(sess, p->fdin, &p->blk)) { - ERRX1(sess, "blk_send_ack"); + ERRX1("blk_send_ack"); goto out; } @@ -354,7 +354,7 @@ rsync_downloader(struct download *p, struct sess *sess, int *ofd) p->ofd = openat(p->rootfd, f->path, O_RDONLY | O_NONBLOCK, 0); if (p->ofd == -1 && errno != ENOENT) { - ERR(sess, "%s: openat", f->path); + ERR("%s: openat", f->path); goto out; } else if (p->ofd != -1) { *ofd = p->ofd; @@ -391,10 +391,10 @@ rsync_downloader(struct download *p, struct sess *sess, int *ofd) if (p->ofd != -1 && fstat(p->ofd, &st) == -1) { - ERR(sess, "%s: fstat", f->path); + ERR("%s: fstat", f->path); goto out; } else if (p->ofd != -1 && !S_ISREG(st.st_mode)) { - WARNX(sess, "%s: not regular", f->path); + WARNX("%s: not regular", f->path); goto out; } @@ -403,7 +403,7 @@ rsync_downloader(struct download *p, struct sess *sess, int *ofd) p->map = mmap(NULL, p->mapsz, PROT_READ, MAP_SHARED, p->ofd, 0); if (p->map == MAP_FAILED) { - ERR(sess, "%s: mmap", f->path); + ERR("%s: mmap", f->path); goto out; } } @@ -416,12 +416,12 @@ rsync_downloader(struct download *p, struct sess *sess, int *ofd) if (mktemplate(sess, &p->fname, f->path, sess->opts->recursive) == -1) { - ERRX1(sess, "mktemplate"); + ERRX1("mktemplate"); goto out; } if ((p->fd = mkstempat(p->rootfd, p->fname)) == -1) { - ERR(sess, "mkstempat"); + ERR("mkstempat"); goto out; } @@ -433,7 +433,7 @@ rsync_downloader(struct download *p, struct sess *sess, int *ofd) * memory beforehand. */ - LOG3(sess, "%s: temporary: %s", f->path, p->fname); + LOG3("%s: temporary: %s", f->path, p->fname); p->state = DOWNLOAD_READ_REMOTE; return 1; } @@ -454,33 +454,33 @@ again: assert(p->fdin != -1); if (!io_read_int(sess, p->fdin, &rawtok)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } if (rawtok > 0) { sz = rawtok; if ((buf = malloc(sz)) == NULL) { - ERR(sess, "realloc"); + ERR("realloc"); goto out; } if (!io_read_buf(sess, p->fdin, buf, sz)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } else if (!buf_copy(sess, buf, sz, p)) { - ERRX1(sess, "buf_copy"); + ERRX1("buf_copy"); goto out; } p->total += sz; p->downloaded += sz; - LOG4(sess, "%s: received %zu B block", p->fname, sz); + LOG4("%s: received %zu B block", p->fname, sz); MD4_Update(&p->ctx, buf, sz); free(buf); /* Fast-track more reads as they arrive. */ if ((c = io_read_check(sess, p->fdin)) < 0) { - ERRX1(sess, "io_read_check"); + ERRX1("io_read_check"); goto out; } else if (c > 0) goto again; @@ -489,8 +489,7 @@ again: } else if (rawtok < 0) { tok = -rawtok - 1; if (tok >= p->blk.blksz) { - ERRX(sess, - "%s: token not in block set: %zu (have %zu blocks)", + ERRX("%s: token not in block set: %zu (have %zu blocks)", p->fname, tok, p->blk.blksz); goto out; } @@ -509,17 +508,17 @@ again: assert(p->map != MAP_FAILED); if (!buf_copy(sess, buf, sz, p)) { - ERRX1(sess, "buf_copy"); + ERRX1("buf_copy"); goto out; } p->total += sz; - LOG4(sess, "%s: copied %zu B", p->fname, sz); + LOG4("%s: copied %zu B", p->fname, sz); MD4_Update(&p->ctx, buf, sz); /* Fast-track more reads as they arrive. */ if ((c = io_read_check(sess, p->fdin)) < 0) { - ERRX1(sess, "io_read_check"); + ERRX1("io_read_check"); goto out; } else if (c > 0) goto again; @@ -528,7 +527,7 @@ again: } if (!buf_copy(sess, NULL, 0, p)) { - ERRX1(sess, "buf_copy"); + ERRX1("buf_copy"); goto out; } @@ -546,24 +545,24 @@ again: MD4_Final(ourmd, &p->ctx); if (!io_read_buf(sess, p->fdin, md, MD4_DIGEST_LENGTH)) { - ERRX1(sess, "io_read_buf"); + ERRX1("io_read_buf"); goto out; } else if (memcmp(md, ourmd, MD4_DIGEST_LENGTH)) { - ERRX(sess, "%s: hash does not match", p->fname); + ERRX("%s: hash does not match", p->fname); goto out; } /* Adjust our file metadata (uid, mode, etc.). */ if (!rsync_set_metadata(sess, 1, p->fd, f, p->fname)) { - ERRX1(sess, "rsync_set_metadata"); + ERRX1("rsync_set_metadata"); goto out; } /* Finally, rename the temporary to the real file. */ if (renameat(p->rootfd, p->fname, p->rootfd, f->path) == -1) { - ERR(sess, "%s: renameat: %s", p->fname, f->path); + ERR("%s: renameat: %s", p->fname, f->path); goto out; } diff --git a/usr.bin/rsync/extern.h b/usr.bin/rsync/extern.h index 305821be579..a615cbb6b03 100644 --- a/usr.bin/rsync/extern.h +++ b/usr.bin/rsync/extern.h @@ -1,4 +1,4 @@ -/* $Id: extern.h,v 1.28 2019/04/04 04:19:54 bket Exp $ */ +/* $Id: extern.h,v 1.29 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -106,7 +106,6 @@ struct opts { int sender; /* --sender */ int server; /* --server */ int recursive; /* -r */ - int verbose; /* -v */ int dry_run; /* -n */ int preserve_times; /* -t */ int preserve_perms; /* -p */ @@ -213,54 +212,49 @@ void freeargs(arglist *); struct download; struct upload; +extern int verbose; + #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) -#define LOG0(_sess, _fmt, ...) \ - rsync_log((_sess), __FILE__, __LINE__, -1, (_fmt), ##__VA_ARGS__) -#define LOG1(_sess, _fmt, ...) \ - rsync_log((_sess), __FILE__, __LINE__, 0, (_fmt), ##__VA_ARGS__) -#define LOG2(_sess, _fmt, ...) \ - rsync_log((_sess), __FILE__, __LINE__, 1, (_fmt), ##__VA_ARGS__) -#define LOG3(_sess, _fmt, ...) \ - rsync_log((_sess), __FILE__, __LINE__, 2, (_fmt), ##__VA_ARGS__) -#define LOG4(_sess, _fmt, ...) \ - rsync_log((_sess), __FILE__, __LINE__, 3, (_fmt), ##__VA_ARGS__) -#define ERRX1(_sess, _fmt, ...) \ - rsync_errx1((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__) -#define WARNX(_sess, _fmt, ...) \ - rsync_warnx((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__) -#define WARN(_sess, _fmt, ...) \ - rsync_warn((_sess), 0, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__) -#define WARN1(_sess, _fmt, ...) \ - rsync_warn((_sess), 1, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__) -#define WARN2(_sess, _fmt, ...) \ - rsync_warn((_sess), 2, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__) -#define ERR(_sess, _fmt, ...) \ - rsync_err((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__) -#define ERRX(_sess, _fmt, ...) \ - rsync_errx((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__) - -void rsync_log(struct sess *, - const char *, size_t, int, const char *, ...) - __attribute__((format(printf, 5, 6))); -void rsync_warnx1(struct sess *, - const char *, size_t, const char *, ...) - __attribute__((format(printf, 4, 5))); -void rsync_warn(struct sess *, int, - const char *, size_t, const char *, ...) - __attribute__((format(printf, 5, 6))); -void rsync_warnx(struct sess *, const char *, - size_t, const char *, ...) - __attribute__((format(printf, 4, 5))); -void rsync_err(struct sess *, const char *, - size_t, const char *, ...) - __attribute__((format(printf, 4, 5))); -void rsync_errx(struct sess *, const char *, - size_t, const char *, ...) +#define LOG0(_fmt, ...) \ + rsync_log(__FILE__, __LINE__, -1, (_fmt), ##__VA_ARGS__) +#define LOG1(_fmt, ...) \ + rsync_log(__FILE__, __LINE__, 0, (_fmt), ##__VA_ARGS__) +#define LOG2(_fmt, ...) \ + rsync_log(__FILE__, __LINE__, 1, (_fmt), ##__VA_ARGS__) +#define LOG3(_fmt, ...) \ + rsync_log(__FILE__, __LINE__, 2, (_fmt), ##__VA_ARGS__) +#define LOG4(_fmt, ...) \ + rsync_log(__FILE__, __LINE__, 3, (_fmt), ##__VA_ARGS__) +#define ERRX1(_fmt, ...) \ + rsync_errx1(__FILE__, __LINE__, (_fmt), ##__VA_ARGS__) +#define WARNX(_fmt, ...) \ + rsync_warnx(__FILE__, __LINE__, (_fmt), ##__VA_ARGS__) +#define WARN(_fmt, ...) \ + rsync_warn(0, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__) +#define WARN1(_fmt, ...) \ + rsync_warn(1, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__) +#define WARN2(_fmt, ...) \ + rsync_warn(2, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__) +#define ERR(_fmt, ...) \ + rsync_err(__FILE__, __LINE__, (_fmt), ##__VA_ARGS__) +#define ERRX(_fmt, ...) \ + rsync_errx(__FILE__, __LINE__, (_fmt), ##__VA_ARGS__) + +void rsync_log(const char *, size_t, int, const char *, ...) __attribute__((format(printf, 4, 5))); -void rsync_errx1(struct sess *, const char *, - size_t, const char *, ...) +void rsync_warnx1(const char *, size_t, const char *, ...) + __attribute__((format(printf, 3, 4))); +void rsync_warn(int, const char *, size_t, const char *, ...) __attribute__((format(printf, 4, 5))); +void rsync_warnx(const char *, size_t, const char *, ...) + __attribute__((format(printf, 3, 4))); +void rsync_err(const char *, size_t, const char *, ...) + __attribute__((format(printf, 3, 4))); +void rsync_errx(const char *, size_t, const char *, ...) + __attribute__((format(printf, 3, 4))); +void rsync_errx1(const char *, size_t, const char *, ...) + __attribute__((format(printf, 3, 4))); int flist_del(struct sess *, int, const struct flist *, size_t); diff --git a/usr.bin/rsync/fargs.c b/usr.bin/rsync/fargs.c index 59dadc856c7..bb7123717d1 100644 --- a/usr.bin/rsync/fargs.c +++ b/usr.bin/rsync/fargs.c @@ -1,4 +1,4 @@ -/* $Id: fargs.c,v 1.16 2019/04/04 04:19:54 bket Exp $ */ +/* $Id: fargs.c,v 1.17 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -98,13 +98,13 @@ fargs_cmdline(struct sess *sess, const struct fargs *f, size_t *skip) addargs(&args, "-r"); if (sess->opts->preserve_times) addargs(&args, "-t"); - if (sess->opts->verbose > 3) + if (verbose > 3) addargs(&args, "-v"); - if (sess->opts->verbose > 2) + if (verbose > 2) addargs(&args, "-v"); - if (sess->opts->verbose > 1) + if (verbose > 1) addargs(&args, "-v"); - if (sess->opts->verbose > 0) + if (verbose > 0) addargs(&args, "-v"); if (sess->opts->one_file_system > 1) addargs(&args, "-x"); @@ -129,6 +129,6 @@ fargs_cmdline(struct sess *sess, const struct fargs *f, size_t *skip) return args.list; out: freeargs(&args); - ERR(sess, "calloc"); + ERR("calloc"); return NULL; } diff --git a/usr.bin/rsync/flist.c b/usr.bin/rsync/flist.c index ac29ad47098..0c2fd17237b 100644 --- a/usr.bin/rsync/flist.c +++ b/usr.bin/rsync/flist.c @@ -1,4 +1,4 @@ -/* $Id: flist.c,v 1.24 2019/04/04 04:19:54 bket Exp $ */ +/* $Id: flist.c,v 1.25 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2019 Florian Obser <florian@openbsd.org> @@ -81,7 +81,7 @@ flist_dedupe(struct sess *sess, struct flist **fl, size_t *sz) new = calloc(*sz, sizeof(struct flist)); if (new == NULL) { - ERR(sess, "calloc"); + ERR("calloc"); return 0; } @@ -106,7 +106,7 @@ flist_dedupe(struct sess *sess, struct flist **fl, size_t *sz) if (strcmp(f->path, fnext->path) == 0) { new[j++] = *f; i++; - WARNX(sess, "%s: duplicate path: %s", + WARNX("%s: duplicate path: %s", f->wpath, f->path); free(fnext->path); free(fnext->link); @@ -114,7 +114,7 @@ flist_dedupe(struct sess *sess, struct flist **fl, size_t *sz) continue; } - ERRX(sess, "%s: duplicate working path for " + ERRX("%s: duplicate working path for " "possibly different file: %s, %s", f->wpath, f->path, fnext->path); free(new); @@ -166,11 +166,11 @@ flist_topdirs(struct sess *sess, struct flist *fl, size_t flsz) if (cp != NULL && cp[1] != '\0') continue; fl[i].st.flags |= FLSTAT_TOP_DIR; - LOG4(sess, "%s: top-level", fl[i].wpath); + LOG4("%s: top-level", fl[i].wpath); } } else if (flsz) { fl[0].st.flags |= FLSTAT_TOP_DIR; - LOG4(sess, "%s: top-level", fl[0].wpath); + LOG4("%s: top-level", fl[0].wpath); } } @@ -191,15 +191,15 @@ flist_fts_check(struct sess *sess, FTSENT *ent) return 1; if (ent->fts_info == FTS_DC) { - WARNX(sess, "%s: directory cycle", ent->fts_path); + WARNX("%s: directory cycle", ent->fts_path); } else if (ent->fts_info == FTS_DNR) { errno = ent->fts_errno; - WARN(sess, "%s: unreadable directory", ent->fts_path); + WARN("%s: unreadable directory", ent->fts_path); } else if (ent->fts_info == FTS_DOT) { - WARNX(sess, "%s: skipping dot-file", ent->fts_path); + WARNX("%s: skipping dot-file", ent->fts_path); } else if (ent->fts_info == FTS_ERR) { errno = ent->fts_errno; - WARN(sess, "%s", ent->fts_path); + WARN("%s", ent->fts_path); } else if (ent->fts_info == FTS_DEFAULT) { if ((sess->opts->devices && (S_ISBLK(ent->fts_statp->st_mode) || S_ISCHR(ent->fts_statp->st_mode))) || @@ -208,10 +208,10 @@ flist_fts_check(struct sess *sess, FTSENT *ent) S_ISSOCK(ent->fts_statp->st_mode)))) { return 1; } - WARNX(sess, "%s: skipping special", ent->fts_path); + WARNX("%s: skipping special", ent->fts_path); } else if (ent->fts_info == FTS_NS) { errno = ent->fts_errno; - WARN(sess, "%s: could not stat", ent->fts_path); + WARN("%s: could not stat", ent->fts_path); } return 0; @@ -265,7 +265,7 @@ flist_send(struct sess *sess, int fdin, int fdout, const struct flist *fl, /* Double-check that we've no pending multiplexed data. */ - LOG2(sess, "sending file metadata list: %zu", flsz); + LOG2("sending file metadata list: %zu", flsz); for (i = 0; i < flsz; i++) { f = &fl[i]; @@ -284,7 +284,7 @@ flist_send(struct sess *sess, int fdin, int fdout, const struct flist *fl, if (sess->mplex_reads && io_read_check(sess, fdin) && !io_read_flush(sess, fdin)) { - ERRX1(sess, "io_read_flush"); + ERRX1("io_read_flush"); goto out; } @@ -299,7 +299,7 @@ flist_send(struct sess *sess, int fdin, int fdout, const struct flist *fl, if ((FLSTAT_TOP_DIR & f->st.flags)) flag |= FLIST_TOP_LEVEL; - LOG3(sess, "%s: sending file metadata: " + LOG3("%s: sending file metadata: " "size %jd, mtime %jd, mode %o", fn, (intmax_t)f->st.size, (intmax_t)f->st.mtime, f->st.mode); @@ -308,22 +308,22 @@ flist_send(struct sess *sess, int fdin, int fdout, const struct flist *fl, /* FIXME: buffer this. */ if (!io_write_byte(sess, fdout, flag)) { - ERRX1(sess, "io_write_byte"); + ERRX1("io_write_byte"); goto out; } else if (!io_write_int(sess, fdout, sz)) { - ERRX1(sess, "io_write_int"); + ERRX1("io_write_int"); goto out; } else if (!io_write_buf(sess, fdout, fn, sz)) { - ERRX1(sess, "io_write_buf"); + ERRX1("io_write_buf"); goto out; } else if (!io_write_long(sess, fdout, f->st.size)) { - ERRX1(sess, "io_write_long"); + ERRX1("io_write_long"); goto out; } else if (!io_write_uint(sess, fdout, (uint32_t)f->st.mtime)) { - ERRX1(sess, "io_write_uint"); + ERRX1("io_write_uint"); goto out; } else if (!io_write_uint(sess, fdout, f->st.mode)) { - ERRX1(sess, "io_write_uint"); + ERRX1("io_write_uint"); goto out; } @@ -331,11 +331,11 @@ flist_send(struct sess *sess, int fdin, int fdout, const struct flist *fl, if (sess->opts->preserve_uids) { if (!io_write_uint(sess, fdout, f->st.uid)) { - ERRX1(sess, "io_write_uint"); + ERRX1("io_write_uint"); goto out; } if (!idents_add(sess, 0, &uids, &uidsz, f->st.uid)) { - ERRX1(sess, "idents_add"); + ERRX1("idents_add"); goto out; } } @@ -344,11 +344,11 @@ flist_send(struct sess *sess, int fdin, int fdout, const struct flist *fl, if (sess->opts->preserve_gids) { if (!io_write_uint(sess, fdout, f->st.gid)) { - ERRX1(sess, "io_write_uint"); + ERRX1("io_write_uint"); goto out; } if (!idents_add(sess, 1, &gids, &gidsz, f->st.gid)) { - ERRX1(sess, "idents_add"); + ERRX1("idents_add"); goto out; } } @@ -360,7 +360,7 @@ flist_send(struct sess *sess, int fdin, int fdout, const struct flist *fl, (sess->opts->specials && (S_ISFIFO(f->st.mode) || S_ISSOCK(f->st.mode)))) { if (!io_write_int(sess, fdout, f->st.rdev)) { - ERRX1(sess, "io_write_int"); + ERRX1("io_write_int"); goto out; } } @@ -373,11 +373,11 @@ flist_send(struct sess *sess, int fdin, int fdout, const struct flist *fl, sz = strlen(f->link); assert(sz < INT32_MAX); if (!io_write_int(sess, fdout, sz)) { - ERRX1(sess, "io_write_int"); + ERRX1("io_write_int"); goto out; } if (!io_write_buf(sess, fdout, fn, sz)) { - ERRX1(sess, "io_write_buf"); + ERRX1("io_write_buf"); goto out; } } @@ -389,24 +389,24 @@ flist_send(struct sess *sess, int fdin, int fdout, const struct flist *fl, /* Signal end of file list. */ if (!io_write_byte(sess, fdout, 0)) { - ERRX1(sess, "io_write_byte"); + ERRX1("io_write_byte"); goto out; } /* Conditionally write identifier lists. */ if (sess->opts->preserve_uids && !sess->opts->numeric_ids) { - LOG2(sess, "sending uid list: %zu", uidsz); + LOG2("sending uid list: %zu", uidsz); if (!idents_send(sess, fdout, uids, uidsz)) { - ERRX1(sess, "idents_send"); + ERRX1("idents_send"); goto out; } } if (sess->opts->preserve_gids && !sess->opts->numeric_ids) { - LOG2(sess, "sending gid list: %zu", gidsz); + LOG2("sending gid list: %zu", gidsz); if (!idents_send(sess, fdout, gids, gidsz)) { - ERRX1(sess, "idents_send"); + ERRX1("idents_send"); goto out; } } @@ -444,7 +444,7 @@ flist_recv_name(struct sess *sess, int fd, struct flist *f, uint8_t flags, if (FLIST_NAME_SAME & flags) { if (!io_read_byte(sess, fd, &bval)) { - ERRX1(sess, "io_read_byte"); + ERRX1("io_read_byte"); return 0; } partial = bval; @@ -454,12 +454,12 @@ flist_recv_name(struct sess *sess, int fd, struct flist *f, uint8_t flags, if (FLIST_NAME_LONG & flags) { if (!io_read_size(sess, fd, &pathlen)) { - ERRX1(sess, "io_read_size"); + ERRX1("io_read_size"); return 0; } } else { if (!io_read_byte(sess, fd, &bval)) { - ERRX1(sess, "io_read_byte"); + ERRX1("io_read_byte"); return 0; } pathlen = bval; @@ -469,12 +469,12 @@ flist_recv_name(struct sess *sess, int fd, struct flist *f, uint8_t flags, /* FIXME: maximum pathname length. */ if ((len = pathlen + partial) == 0) { - ERRX(sess, "security violation: zero-length pathname"); + ERRX("security violation: zero-length pathname"); return 0; } if ((f->path = malloc(len + 1)) == NULL) { - ERR(sess, "malloc"); + ERR("malloc"); return 0; } f->path[len] = '\0'; @@ -483,12 +483,12 @@ flist_recv_name(struct sess *sess, int fd, struct flist *f, uint8_t flags, memcpy(f->path, last, partial); if (!io_read_buf(sess, fd, f->path + partial, pathlen)) { - ERRX1(sess, "io_read_buf"); + ERRX1("io_read_buf"); return 0; } if (f->path[0] == '/') { - ERRX(sess, "security violation: absolute pathname: %s", + ERRX("security violation: absolute pathname: %s", f->path); return 0; } @@ -497,7 +497,7 @@ flist_recv_name(struct sess *sess, int fd, struct flist *f, uint8_t flags, (len > 2 && strcmp(f->path + len - 3, "/..") == 0) || (len > 2 && strncmp(f->path, "../", 3) == 0) || strcmp(f->path, "..") == 0) { - ERRX(sess, "%s: security violation: backtracking pathname", + ERRX("%s: security violation: backtracking pathname", f->path); return 0; } @@ -526,7 +526,7 @@ flist_realloc(struct sess *sess, struct flist **fl, size_t *sz, size_t *max) pp = recallocarray(*fl, *max, *max + FLIST_CHUNK_SIZE, sizeof(struct flist)); if (pp == NULL) { - ERR(sess, "recallocarray"); + ERR("recallocarray"); return 0; } *fl = pp; @@ -551,7 +551,7 @@ flist_append(struct sess *sess, struct flist *f, struct stat *st, */ if ((f->path = strdup(path)) == NULL) { - ERR(sess, "strdup"); + ERR("strdup"); return 0; } @@ -573,7 +573,7 @@ flist_append(struct sess *sess, struct flist *f, struct stat *st, if (S_ISLNK(st->st_mode)) { f->link = symlink_read(sess, f->path); if (f->link == NULL) { - ERRX1(sess, "symlink_read"); + ERRX1("symlink_read"); return 0; } } @@ -604,13 +604,13 @@ flist_recv(struct sess *sess, int fd, struct flist **flp, size_t *sz) for (;;) { if (!io_read_byte(sess, fd, &flag)) { - ERRX1(sess, "io_read_byte"); + ERRX1("io_read_byte"); goto out; } else if (flag == 0) break; if (!flist_realloc(sess, &fl, &flsz, &flmax)) { - ERRX1(sess, "flist_realloc"); + ERRX1("flist_realloc"); goto out; } @@ -620,14 +620,14 @@ flist_recv(struct sess *sess, int fd, struct flist **flp, size_t *sz) /* Filename first. */ if (!flist_recv_name(sess, fd, ff, flag, last)) { - ERRX1(sess, "flist_recv_name"); + ERRX1("flist_recv_name"); goto out; } /* Read the file size. */ if (!io_read_long(sess, fd, &lval)) { - ERRX1(sess, "io_read_long"); + ERRX1("io_read_long"); goto out; } ff->st.size = lval; @@ -636,12 +636,12 @@ flist_recv(struct sess *sess, int fd, struct flist **flp, size_t *sz) if (!(FLIST_TIME_SAME & flag)) { if (!io_read_uint(sess, fd, &uival)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } ff->st.mtime = uival; /* beyond 2038 */ } else if (fflast == NULL) { - ERRX(sess, "same time without last entry"); + ERRX("same time without last entry"); goto out; } else ff->st.mtime = fflast->st.mtime; @@ -650,12 +650,12 @@ flist_recv(struct sess *sess, int fd, struct flist **flp, size_t *sz) if (!(FLIST_MODE_SAME & flag)) { if (!io_read_uint(sess, fd, &uival)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } ff->st.mode = uival; } else if (fflast == NULL) { - ERRX(sess, "same mode without last entry"); + ERRX("same mode without last entry"); goto out; } else ff->st.mode = fflast->st.mode; @@ -665,12 +665,12 @@ flist_recv(struct sess *sess, int fd, struct flist **flp, size_t *sz) if (sess->opts->preserve_uids) { if (!(FLIST_UID_SAME & flag)) { if (!io_read_uint(sess, fd, &uival)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } ff->st.uid = uival; } else if (fflast == NULL) { - ERRX(sess, "same uid without last entry"); + ERRX("same uid without last entry"); goto out; } else ff->st.uid = fflast->st.uid; @@ -681,12 +681,12 @@ flist_recv(struct sess *sess, int fd, struct flist **flp, size_t *sz) if (sess->opts->preserve_gids) { if (!(FLIST_GID_SAME & flag)) { if (!io_read_uint(sess, fd, &uival)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } ff->st.gid = uival; } else if (fflast == NULL) { - ERRX(sess, "same gid without last entry"); + ERRX("same gid without last entry"); goto out; } else ff->st.gid = fflast->st.gid; @@ -700,12 +700,12 @@ flist_recv(struct sess *sess, int fd, struct flist **flp, size_t *sz) S_ISSOCK(ff->st.mode)))) { if (!(FLIST_RDEV_SAME & flag)) { if (!io_read_int(sess, fd, &ival)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } ff->st.rdev = ival; } else if (fflast == NULL) { - ERRX(sess, "same device without last entry"); + ERRX("same device without last entry"); goto out; } else ff->st.rdev = fflast->st.rdev; @@ -716,24 +716,24 @@ flist_recv(struct sess *sess, int fd, struct flist **flp, size_t *sz) if (S_ISLNK(ff->st.mode) && sess->opts->preserve_links) { if (!io_read_size(sess, fd, &lsz)) { - ERRX1(sess, "io_read_size"); + ERRX1("io_read_size"); goto out; } else if (lsz == 0) { - ERRX(sess, "empty link name"); + ERRX("empty link name"); goto out; } ff->link = calloc(lsz + 1, 1); if (ff->link == NULL) { - ERR(sess, "calloc"); + ERR("calloc"); goto out; } if (!io_read_buf(sess, fd, ff->link, lsz)) { - ERRX1(sess, "io_read_buf"); + ERRX1("io_read_buf"); goto out; } } - LOG3(sess, "%s: received file metadata: " + LOG3("%s: received file metadata: " "size %jd, mtime %jd, mode %o, rdev (%d, %d)", ff->path, (intmax_t)ff->st.size, (intmax_t)ff->st.mtime, ff->st.mode, @@ -747,23 +747,23 @@ flist_recv(struct sess *sess, int fd, struct flist **flp, size_t *sz) if (sess->opts->preserve_uids && !sess->opts->numeric_ids) { if (!idents_recv(sess, fd, &uids, &uidsz)) { - ERRX1(sess, "idents_recv"); + ERRX1("idents_recv"); goto out; } - LOG2(sess, "received uid list: %zu", uidsz); + LOG2("received uid list: %zu", uidsz); } if (sess->opts->preserve_gids && !sess->opts->numeric_ids) { if (!idents_recv(sess, fd, &gids, &gidsz)) { - ERRX1(sess, "idents_recv"); + ERRX1("idents_recv"); goto out; } - LOG2(sess, "received gid list: %zu", gidsz); + LOG2("received gid list: %zu", gidsz); } /* Remember to order the received list. */ - LOG2(sess, "received file metadata list: %zu", flsz); + LOG2("received file metadata list: %zu", flsz); qsort(fl, flsz, sizeof(struct flist), flist_cmp); flist_topdirs(sess, fl, flsz); *sz = flsz; @@ -821,47 +821,47 @@ flist_gen_dirent(struct sess *sess, char *root, struct flist **fl, size_t *sz, */ if (lstat(root, &st) == -1) { - ERR(sess, "%s: lstat", root); + ERR("%s: lstat", root); return 0; } else if (S_ISREG(st.st_mode)) { if (!flist_realloc(sess, fl, sz, max)) { - ERRX1(sess, "flist_realloc"); + ERRX1("flist_realloc"); return 0; } f = &(*fl)[(*sz) - 1]; assert(f != NULL); if (!flist_append(sess, f, &st, root)) { - ERRX1(sess, "flist_append"); + ERRX1("flist_append"); return 0; } if (unveil(root, "r") == -1) { - ERR(sess, "%s: unveil", root); + ERR("%s: unveil", root); return 0; } return 1; } else if (S_ISLNK(st.st_mode)) { if (!sess->opts->preserve_links) { - WARNX(sess, "%s: skipping symlink", root); + WARNX("%s: skipping symlink", root); return 1; } else if (!flist_realloc(sess, fl, sz, max)) { - ERRX1(sess, "flist_realloc"); + ERRX1("flist_realloc"); return 0; } f = &(*fl)[(*sz) - 1]; assert(f != NULL); if (!flist_append(sess, f, &st, root)) { - ERRX1(sess, "flist_append"); + ERRX1("flist_append"); return 0; } if (unveil(root, "r") == -1) { - ERR(sess, "%s: unveil", root); + ERR("%s: unveil", root); return 0; } return 1; } else if (!S_ISDIR(st.st_mode)) { - WARNX(sess, "%s: skipping special", root); + WARNX("%s: skipping special", root); return 1; } @@ -894,7 +894,7 @@ flist_gen_dirent(struct sess *sess, char *root, struct flist **fl, size_t *sz, */ if ((fts = fts_open(cargv, FTS_PHYSICAL, NULL)) == NULL) { - ERR(sess, "fts_open"); + ERR("fts_open"); return 0; } @@ -910,7 +910,7 @@ flist_gen_dirent(struct sess *sess, char *root, struct flist **fl, size_t *sz, assert(ent->fts_statp != NULL); if (S_ISLNK(ent->fts_statp->st_mode) && !sess->opts->preserve_links) { - WARNX(sess, "%s: skipping symlink", ent->fts_path); + WARNX("%s: skipping symlink", ent->fts_path); continue; } @@ -933,7 +933,7 @@ flist_gen_dirent(struct sess *sess, char *root, struct flist **fl, size_t *sz, continue; if ((xdev = malloc(sizeof(dev_t))) == NULL) { - ERRX1(sess, "malloc"); + ERRX1("malloc"); goto out; } @@ -949,7 +949,7 @@ flist_gen_dirent(struct sess *sess, char *root, struct flist **fl, size_t *sz, if (nxdev) if ((xdev = realloc(xdev, sizeof(dev_t))) == NULL) { - ERRX1(sess, "realloc"); + ERRX1("realloc"); goto out; } xdev[nxdev] = ent->fts_statp->st_dev; @@ -959,7 +959,7 @@ flist_gen_dirent(struct sess *sess, char *root, struct flist **fl, size_t *sz, /* Allocate a new file entry. */ if (!flist_realloc(sess, fl, sz, max)) { - ERRX1(sess, "flist_realloc"); + ERRX1("flist_realloc"); goto out; } flsz++; @@ -969,13 +969,13 @@ flist_gen_dirent(struct sess *sess, char *root, struct flist **fl, size_t *sz, if (ent->fts_path[stripdir] == '\0') { if (asprintf(&f->path, "%s.", ent->fts_path) < 0) { - ERR(sess, "asprintf"); + ERR("asprintf"); f->path = NULL; goto out; } } else { if ((f->path = strdup(ent->fts_path)) == NULL) { - ERR(sess, "strdup"); + ERR("strdup"); goto out; } } @@ -988,7 +988,7 @@ flist_gen_dirent(struct sess *sess, char *root, struct flist **fl, size_t *sz, if (S_ISLNK(ent->fts_statp->st_mode)) { f->link = symlink_read(sess, f->path); if (f->link == NULL) { - ERRX1(sess, "symlink_read"); + ERRX1("symlink_read"); goto out; } } @@ -997,15 +997,15 @@ flist_gen_dirent(struct sess *sess, char *root, struct flist **fl, size_t *sz, errno = 0; } if (errno) { - ERR(sess, "fts_read"); + ERR("fts_read"); goto out; } if (unveil(root, "r") == -1) { - ERR(sess, "%s: unveil", root); + ERR("%s: unveil", root); goto out; } - LOG3(sess, "generated %zu filenames: %s", flsz, root); + LOG3("generated %zu filenames: %s", flsz, root); rc = 1; out: fts_close(fts); @@ -1032,11 +1032,11 @@ flist_gen_dirs(struct sess *sess, size_t argc, char **argv, struct flist **flp, break; if (i == argc) { - LOG2(sess, "recursively generated %zu filenames", *sz); + LOG2("recursively generated %zu filenames", *sz); return 1; } - ERRX1(sess, "flist_gen_dirent"); + ERRX1("flist_gen_dirent"); flist_free(*flp, max); *flp = NULL; *sz = 0; @@ -1060,7 +1060,7 @@ flist_gen_files(struct sess *sess, size_t argc, char **argv, assert(argc); if ((fl = calloc(argc, sizeof(struct flist))) == NULL) { - ERR(sess, "calloc"); + ERR("calloc"); return 0; } @@ -1068,7 +1068,7 @@ flist_gen_files(struct sess *sess, size_t argc, char **argv, if (argv[i][0] == '\0') continue; if (lstat(argv[i], &st) == -1) { - ERR(sess, "%s: lstat", argv[i]); + ERR("%s: lstat", argv[i]); goto out; } @@ -1080,15 +1080,15 @@ flist_gen_files(struct sess *sess, size_t argc, char **argv, */ if (S_ISDIR(st.st_mode)) { - WARNX(sess, "%s: skipping directory", argv[i]); + WARNX("%s: skipping directory", argv[i]); continue; } else if (S_ISLNK(st.st_mode)) { if (!sess->opts->preserve_links) { - WARNX(sess, "%s: skipping symlink", argv[i]); + WARNX("%s: skipping symlink", argv[i]); continue; } } else if (!S_ISREG(st.st_mode)) { - WARNX(sess, "%s: skipping special", argv[i]); + WARNX("%s: skipping special", argv[i]); continue; } @@ -1099,16 +1099,16 @@ flist_gen_files(struct sess *sess, size_t argc, char **argv, /* Add this file to our file-system worldview. */ if (unveil(argv[i], "r") == -1) { - ERR(sess, "%s: unveil", argv[i]); + ERR("%s: unveil", argv[i]); goto out; } if (!flist_append(sess, f, &st, argv[i])) { - ERRX1(sess, "flist_append"); + ERRX1("flist_append"); goto out; } } - LOG2(sess, "non-recursively generated %zu filenames", flsz); + LOG2("non-recursively generated %zu filenames", flsz); *sz = flsz; *flp = fl; return 1; @@ -1141,7 +1141,7 @@ flist_gen(struct sess *sess, size_t argc, char **argv, struct flist **flp, /* After scanning, lock our file-system view. */ if (unveil(NULL, NULL) == -1) { - ERR(sess, "unveil"); + ERR("unveil"); return 0; } if (!rc) @@ -1154,7 +1154,7 @@ flist_gen(struct sess *sess, size_t argc, char **argv, struct flist **flp, return 1; } - ERRX1(sess, "flist_dedupe"); + ERRX1("flist_dedupe"); flist_free(*flp, *sz); *flp = NULL; *sz = 0; @@ -1206,7 +1206,7 @@ flist_gen_dels(struct sess *sess, const char *root, struct flist **fl, return 1; if ((cargv = calloc(cargvs + 1, sizeof(char *))) == NULL) { - ERR(sess, "calloc"); + ERR("calloc"); return 0; } @@ -1221,7 +1221,7 @@ flist_gen_dels(struct sess *sess, const char *root, struct flist **fl, assert(cargvs == 1); assert(S_ISDIR(wfl[0].st.mode)); if (asprintf(&cargv[0], "%s/", root) < 0) { - ERR(sess, "asprintf"); + ERR("asprintf"); cargv[0] = NULL; goto out; } @@ -1234,18 +1234,18 @@ flist_gen_dels(struct sess *sess, const char *root, struct flist **fl, assert(strcmp(wfl[i].wpath, ".")); c = asprintf(&cargv[j], "%s/%s", root, wfl[i].wpath); if (c < 0) { - ERR(sess, "asprintf"); + ERR("asprintf"); cargv[j] = NULL; goto out; } - LOG4(sess, "%s: will scan for deletions", cargv[j]); + LOG4("%s: will scan for deletions", cargv[j]); j++; } assert(j == cargvs); cargv[j] = NULL; } - LOG2(sess, "delete from %zu directories", cargvs); + LOG2("delete from %zu directories", cargvs); /* * Next, use the standard hcreate(3) hashtable interface to hash @@ -1257,21 +1257,21 @@ flist_gen_dels(struct sess *sess, const char *root, struct flist **fl, */ if (!hcreate(wflsz)) { - ERR(sess, "hcreate"); + ERR("hcreate"); goto out; } for (i = 0; i < wflsz; i++) { memset(&hent, 0, sizeof(ENTRY)); if ((hent.key = strdup(wfl[i].wpath)) == NULL) { - ERR(sess, "strdup"); + ERR("strdup"); goto out; } if ((hentp = hsearch(hent, ENTER)) == NULL) { - ERR(sess, "hsearch"); + ERR("hsearch"); goto out; } else if (hentp->key != hent.key) { - ERRX(sess, "%s: duplicate", wfl[i].wpath); + ERRX("%s: duplicate", wfl[i].wpath); free(hent.key); goto out; } @@ -1284,7 +1284,7 @@ flist_gen_dels(struct sess *sess, const char *root, struct flist **fl, */ if ((fts = fts_open(cargv, FTS_PHYSICAL, NULL)) == NULL) { - ERR(sess, "fts_open"); + ERR("fts_open"); goto out; } @@ -1312,7 +1312,7 @@ flist_gen_dels(struct sess *sess, const char *root, struct flist **fl, flag = 0; for (i = 0; i < wflsz; i++) { if (stat(wfl[i].path, &st) == -1) { - ERR(sess, "%s: stat", wfl[i].path); + ERR("%s: stat", wfl[i].path); goto out; } if (ent->fts_statp->st_dev == st.st_dev) { @@ -1334,13 +1334,13 @@ flist_gen_dels(struct sess *sess, const char *root, struct flist **fl, /* Not found: we'll delete it. */ if (!flist_realloc(sess, fl, sz, &max)) { - ERRX1(sess, "flist_realloc"); + ERRX1("flist_realloc"); goto out; } f = &(*fl)[*sz - 1]; if ((f->path = strdup(ent->fts_path)) == NULL) { - ERR(sess, "strdup"); + ERR("strdup"); goto out; } f->wpath = f->path + stripdir; @@ -1349,7 +1349,7 @@ flist_gen_dels(struct sess *sess, const char *root, struct flist **fl, } if (errno) { - ERR(sess, "fts_read"); + ERR("fts_read"); goto out; } @@ -1384,14 +1384,14 @@ flist_del(struct sess *sess, int root, const struct flist *fl, size_t flsz) assert(sess->opts->recursive); for (i = flsz - 1; i >= 0; i--) { - LOG1(sess, "%s: deleting", fl[i].wpath); + LOG1("%s: deleting", fl[i].wpath); if (sess->opts->dry_run) continue; assert(root != -1); flag = S_ISDIR(fl[i].st.mode) ? AT_REMOVEDIR : 0; if (unlinkat(root, fl[i].wpath, flag) == -1 && errno != ENOENT) { - ERR(sess, "%s: unlinkat", fl[i].wpath); + ERR("%s: unlinkat", fl[i].wpath); return 0; } } diff --git a/usr.bin/rsync/ids.c b/usr.bin/rsync/ids.c index b946dd33ceb..3ab46125f82 100644 --- a/usr.bin/rsync/ids.c +++ b/usr.bin/rsync/ids.c @@ -1,4 +1,4 @@ -/* $Id: ids.c,v 1.11 2019/03/31 09:26:05 deraadt Exp $ */ +/* $Id: ids.c,v 1.12 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -142,7 +142,7 @@ idents_remap(struct sess *sess, int isgid, struct ident *ids, size_t idsz) else ids[i].mapped = id; - LOG4(sess, "remapped identifier %s: %d -> %d", + LOG4("remapped identifier %s: %d -> %d", ids[i].name, ids[i].id, ids[i].mapped); } } @@ -180,23 +180,23 @@ idents_add(struct sess *sess, int isgid, assert(i == *idsz); if (isgid) { if ((grp = getgrgid((gid_t)id)) == NULL) { - ERR(sess, "%d: unknown gid", id); + ERR("%d: unknown gid", id); return 0; } name = grp->gr_name; } else { if ((usr = getpwuid((uid_t)id)) == NULL) { - ERR(sess, "%d: unknown uid", id); + ERR("%d: unknown uid", id); return 0; } name = usr->pw_name; } if ((sz = strlen(name)) > UINT8_MAX) { - ERRX(sess, "%d: name too long: %s", id, name); + ERRX("%d: name too long: %s", id, name); return 0; } else if (sz == 0) { - ERRX(sess, "%d: zero-length name", id); + ERRX("%d: zero-length name", id); return 0; } @@ -204,18 +204,18 @@ idents_add(struct sess *sess, int isgid, pp = reallocarray(*ids, *idsz + 1, sizeof(struct ident)); if (pp == NULL) { - ERR(sess, "reallocarray"); + ERR("reallocarray"); return 0; } *ids = pp; (*ids)[*idsz].id = id; (*ids)[*idsz].name = strdup(name); if ((*ids)[*idsz].name == NULL) { - ERR(sess, "strdup"); + ERR("strdup"); return 0; } - LOG4(sess, "adding identifier to list: %s (%u)", + LOG4("adding identifier to list: %s (%u)", (*ids)[*idsz].name, (*ids)[*idsz].id); (*idsz)++; return 1; @@ -239,19 +239,19 @@ idents_send(struct sess *sess, sz = strlen(ids[i].name); assert(sz > 0 && sz <= UINT8_MAX); if (!io_write_uint(sess, fd, ids[i].id)) { - ERRX1(sess, "io_write_uint"); + ERRX1("io_write_uint"); return 0; } else if (!io_write_byte(sess, fd, sz)) { - ERRX1(sess, "io_write_byte"); + ERRX1("io_write_byte"); return 0; } else if (!io_write_buf(sess, fd, ids[i].name, sz)) { - ERRX1(sess, "io_write_buf"); + ERRX1("io_write_buf"); return 0; } } if (!io_write_int(sess, fd, 0)) { - ERRX1(sess, "io_write_int"); + ERRX1("io_write_int"); return 0; } @@ -274,7 +274,7 @@ idents_recv(struct sess *sess, for (;;) { if (!io_read_uint(sess, fd, &id)) { - ERRX1(sess, "io_read_uint"); + ERRX1("io_read_uint"); return 0; } else if (id == 0) break; @@ -282,7 +282,7 @@ idents_recv(struct sess *sess, pp = reallocarray(*ids, *idsz + 1, sizeof(struct ident)); if (pp == NULL) { - ERR(sess, "reallocarray"); + ERR("reallocarray"); return 0; } *ids = pp; @@ -295,19 +295,19 @@ idents_recv(struct sess *sess, */ if (!io_read_byte(sess, fd, &sz)) { - ERRX1(sess, "io_read_byte"); + ERRX1("io_read_byte"); return 0; } else if (sz == 0) - WARNX(sess, "zero-length name in identifier list"); + WARNX("zero-length name in identifier list"); (*ids)[*idsz].id = id; (*ids)[*idsz].name = calloc(sz + 1, 1); if ((*ids)[*idsz].name == NULL) { - ERR(sess, "calloc"); + ERR("calloc"); return 0; } if (!io_read_buf(sess, fd, (*ids)[*idsz].name, sz)) { - ERRX1(sess, "io_read_buf"); + ERRX1("io_read_buf"); return 0; } (*idsz)++; diff --git a/usr.bin/rsync/io.c b/usr.bin/rsync/io.c index 0e451226d31..be6dc4f0ecc 100644 --- a/usr.bin/rsync/io.c +++ b/usr.bin/rsync/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.15 2019/03/31 09:26:05 deraadt Exp $ */ +/* $Id: io.c,v 1.16 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -41,7 +41,7 @@ io_read_check(struct sess *sess, int fd) pfd.events = POLLIN; if (poll(&pfd, 1, 0) < 0) { - ERR(sess, "poll"); + ERR("poll"); return -1; } return (pfd.revents & POLLIN); @@ -71,26 +71,26 @@ io_write_nonblocking(struct sess *sess, int fd, const void *buf, size_t bsz, /* Poll and check for all possible errors. */ if ((c = poll(&pfd, 1, POLL_TIMEOUT)) == -1) { - ERR(sess, "poll"); + ERR("poll"); return 0; } else if (c == 0) { - ERRX(sess, "poll: timeout"); + ERRX("poll: timeout"); return 0; } else if ((pfd.revents & (POLLERR|POLLNVAL))) { - ERRX(sess, "poll: bad fd"); + ERRX("poll: bad fd"); return 0; } else if ((pfd.revents & POLLHUP)) { - ERRX(sess, "poll: hangup"); + ERRX("poll: hangup"); return 0; } else if (!(pfd.revents & POLLOUT)) { - ERRX(sess, "poll: unknown event"); + ERRX("poll: unknown event"); return 0; } /* Now the non-blocking write. */ if ((wsz = write(fd, buf, bsz)) < 0) { - ERR(sess, "write"); + ERR("write"); return 0; } @@ -111,10 +111,10 @@ io_write_blocking(struct sess *sess, int fd, const void *buf, size_t sz) while (sz > 0) { c = io_write_nonblocking(sess, fd, buf, sz, &wsz); if (!c) { - ERRX1(sess, "io_write_nonblocking"); + ERRX1("io_write_nonblocking"); return 0; } else if (wsz == 0) { - ERRX(sess, "io_write_nonblocking: short write"); + ERRX("io_write_nonblocking: short write"); return 0; } buf += wsz; @@ -147,11 +147,11 @@ io_write_buf(struct sess *sess, int fd, const void *buf, size_t sz) tag = (7 << 24) + wsz; tagbuf = htole32(tag); if (!io_write_blocking(sess, fd, &tagbuf, sizeof(tagbuf))) { - ERRX1(sess, "io_write_blocking"); + ERRX1("io_write_blocking"); return 0; } if (!io_write_blocking(sess, fd, buf, wsz)) { - ERRX1(sess, "io_write_blocking"); + ERRX1("io_write_blocking"); return 0; } sess->total_write += wsz; @@ -171,9 +171,9 @@ io_write_line(struct sess *sess, int fd, const char *line) { if (!io_write_buf(sess, fd, line, strlen(line))) - ERRX1(sess, "io_write_buf"); + ERRX1("io_write_buf"); else if (!io_write_byte(sess, fd, '\n')) - ERRX1(sess, "io_write_byte"); + ERRX1("io_write_byte"); else return 1; @@ -203,26 +203,26 @@ io_read_nonblocking(struct sess *sess, /* Poll and check for all possible errors. */ if ((c = poll(&pfd, 1, POLL_TIMEOUT)) == -1) { - ERR(sess, "poll"); + ERR("poll"); return 0; } else if (c == 0) { - ERRX(sess, "poll: timeout"); + ERRX("poll: timeout"); return 0; } else if ((pfd.revents & (POLLERR|POLLNVAL))) { - ERRX(sess, "poll: bad fd"); + ERRX("poll: bad fd"); return 0; } else if (!(pfd.revents & (POLLIN|POLLHUP))) { - ERRX(sess, "poll: unknown event"); + ERRX("poll: unknown event"); return 0; } /* Now the non-blocking read, checking for EOF. */ if ((rsz = read(fd, buf, bsz)) < 0) { - ERR(sess, "read"); + ERR("read"); return 0; } else if (rsz == 0) { - ERRX(sess, "unexpected end of file"); + ERRX("unexpected end of file"); return 0; } @@ -246,10 +246,10 @@ io_read_blocking(struct sess *sess, while (sz > 0) { c = io_read_nonblocking(sess, fd, buf, sz, &rsz); if (!c) { - ERRX1(sess, "io_read_nonblocking"); + ERRX1("io_read_nonblocking"); return 0; } else if (rsz == 0) { - ERRX(sess, "io_read_nonblocking: short read"); + ERRX("io_read_nonblocking: short read"); return 0; } buf += rsz; @@ -287,7 +287,7 @@ io_read_flush(struct sess *sess, int fd) */ if (!io_read_blocking(sess, fd, &tagbuf, sizeof(tagbuf))) { - ERRX1(sess, "io_read_blocking"); + ERRX1("io_read_blocking"); return 0; } tag = le32toh(tagbuf); @@ -299,13 +299,13 @@ io_read_flush(struct sess *sess, int fd) tag -= 7; if (sess->mplex_read_remain > sizeof(mpbuf)) { - ERRX(sess, "multiplex buffer overflow"); + ERRX("multiplex buffer overflow"); return 0; } else if (sess->mplex_read_remain == 0) return 1; if (!io_read_blocking(sess, fd, mpbuf, sess->mplex_read_remain)) { - ERRX1(sess, "io_read_blocking"); + ERRX1("io_read_blocking"); return 0; } if (mpbuf[sess->mplex_read_remain - 1] == '\n') @@ -316,7 +316,7 @@ io_read_flush(struct sess *sess, int fd) * will control its own log levelling. */ - LOG0(sess, "%.*s", (int)sess->mplex_read_remain, mpbuf); + LOG0("%.*s", (int)sess->mplex_read_remain, mpbuf); sess->mplex_read_remain = 0; /* @@ -325,7 +325,7 @@ io_read_flush(struct sess *sess, int fd) */ if (tag == 1) { - ERRX1(sess, "error from remote host"); + ERRX1("error from remote host"); return 0; } return 1; @@ -364,7 +364,7 @@ io_read_buf(struct sess *sess, int fd, void *buf, size_t sz) rsz = sess->mplex_read_remain < sz ? sess->mplex_read_remain : sz; if (!io_read_blocking(sess, fd, buf, rsz)) { - ERRX1(sess, "io_read_blocking"); + ERRX1("io_read_blocking"); return 0; } sz -= rsz; @@ -376,7 +376,7 @@ io_read_buf(struct sess *sess, int fd, void *buf, size_t sz) assert(sess->mplex_read_remain == 0); if (!io_read_flush(sess, fd)) { - ERRX1(sess, "io_read_flush"); + ERRX1("io_read_flush"); return 0; } } @@ -398,7 +398,7 @@ io_write_ulong(struct sess *sess, int fd, uint64_t val) if (sval <= INT32_MAX && sval >= 0) { if (!io_write_int(sess, fd, (int32_t)val)) { - ERRX1(sess, "io_write_int"); + ERRX1("io_write_int"); return 0; } return 1; @@ -409,9 +409,9 @@ io_write_ulong(struct sess *sess, int fd, uint64_t val) nv = htole64(val); if (!io_write_int(sess, fd, -1)) - ERRX1(sess, "io_write_int"); + ERRX1("io_write_int"); else if (!io_write_buf(sess, fd, &nv, sizeof(int64_t))) - ERRX1(sess, "io_write_buf"); + ERRX1("io_write_buf"); else return 1; @@ -436,7 +436,7 @@ io_write_uint(struct sess *sess, int fd, uint32_t val) nv = htole32(val); if (!io_write_buf(sess, fd, &nv, sizeof(uint32_t))) { - ERRX1(sess, "io_write_buf"); + ERRX1("io_write_buf"); return 0; } return 1; @@ -518,7 +518,7 @@ io_lowbuffer_alloc(struct sess *sess, void **buf, if (*bufsz + sz + extra > *bufmax) { pp = realloc(*buf, *bufsz + sz + extra); if (pp == NULL) { - ERR(sess, "realloc"); + ERR("realloc"); return 0; } *buf = pp; @@ -562,12 +562,12 @@ io_read_long(struct sess *sess, int fd, int64_t *val) uint64_t uoval; if (!io_read_ulong(sess, fd, &uoval)) { - ERRX1(sess, "io_read_long"); + ERRX1("io_read_long"); return 0; } *val = (int64_t)uoval; if (*val < 0) { - ERRX1(sess, "io_read_long negative"); + ERRX1("io_read_long negative"); return 0; } return 1; @@ -586,7 +586,7 @@ io_read_ulong(struct sess *sess, int fd, uint64_t *val) /* Start with the short-circuit: read as an int. */ if (!io_read_int(sess, fd, &sval)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); return 0; } else if (sval != -1) { *val = (uint64_t)le32toh(sval); @@ -596,7 +596,7 @@ io_read_ulong(struct sess *sess, int fd, uint64_t *val) /* If the int is -1, read as 64 bits. */ if (!io_read_buf(sess, fd, &oval, sizeof(uint64_t))) { - ERRX1(sess, "io_read_buf"); + ERRX1("io_read_buf"); return 0; } @@ -617,10 +617,10 @@ io_read_size(struct sess *sess, int fd, size_t *val) int32_t oval; if (!io_read_int(sess, fd, &oval)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); return 0; } else if (oval < 0) { - ERRX(sess, "io_read_size: negative value"); + ERRX("io_read_size: negative value"); return 0; } @@ -638,7 +638,7 @@ io_read_uint(struct sess *sess, int fd, uint32_t *val) uint32_t oval; if (!io_read_buf(sess, fd, &oval, sizeof(uint32_t))) { - ERRX1(sess, "io_read_buf"); + ERRX1("io_read_buf"); return 0; } @@ -692,7 +692,7 @@ io_unbuffer_size(struct sess *sess, const void *buf, io_unbuffer_int(sess, buf, bufpos, bufsz, &oval); if (oval < 0) { - ERRX(sess, "io_unbuffer_size: negative value"); + ERRX("io_unbuffer_size: negative value"); return 0; } *val = oval; @@ -708,7 +708,7 @@ io_read_byte(struct sess *sess, int fd, uint8_t *val) { if (!io_read_buf(sess, fd, val, sizeof(uint8_t))) { - ERRX1(sess, "io_read_buf"); + ERRX1("io_read_buf"); return 0; } return 1; @@ -723,7 +723,7 @@ io_write_byte(struct sess *sess, int fd, uint8_t val) { if (!io_write_buf(sess, fd, &val, sizeof(uint8_t))) { - ERRX1(sess, "io_write_buf"); + ERRX1("io_write_buf"); return 0; } return 1; diff --git a/usr.bin/rsync/log.c b/usr.bin/rsync/log.c index 5f522e0f2af..1babed65a25 100644 --- a/usr.bin/rsync/log.c +++ b/usr.bin/rsync/log.c @@ -1,4 +1,4 @@ -/* $Id: log.c,v 1.6 2019/02/18 22:47:34 benno Exp $ */ +/* $Id: log.c,v 1.7 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -23,19 +23,20 @@ #include "extern.h" +extern int verbose; + /* * Log a message at level "level", starting at zero, which corresponds * to the current verbosity level opts->verbose (whose verbosity starts * at one). */ void -rsync_log(struct sess *sess, const char *fname, - size_t line, int level, const char *fmt, ...) +rsync_log(const char *fname, size_t line, int level, const char *fmt, ...) { char *buf = NULL; va_list ap; - if (sess->opts->verbose < level + 1) + if (verbose < level + 1) return; if (fmt != NULL) { @@ -61,8 +62,7 @@ rsync_log(struct sess *sess, const char *fname, * However, it is not like errx(3) in that it does not exit. */ void -rsync_errx(struct sess *sess, const char *fname, - size_t line, const char *fmt, ...) +rsync_errx(const char *fname, size_t line, const char *fmt, ...) { char *buf = NULL; va_list ap; @@ -87,8 +87,7 @@ rsync_errx(struct sess *sess, const char *fname, * However, it is not like err(3) in that it does not exit. */ void -rsync_err(struct sess *sess, const char *fname, - size_t line, const char *fmt, ...) +rsync_err(const char *fname, size_t line, const char *fmt, ...) { char *buf = NULL; va_list ap; @@ -114,13 +113,12 @@ rsync_err(struct sess *sess, const char *fname, * chain of functions from which the actual warning occurred. */ void -rsync_errx1(struct sess *sess, const char *fname, - size_t line, const char *fmt, ...) +rsync_errx1(const char *fname, size_t line, const char *fmt, ...) { char *buf = NULL; va_list ap; - if (sess->opts->verbose < 1) + if (verbose < 1) return; if (fmt != NULL) { @@ -142,8 +140,7 @@ rsync_errx1(struct sess *sess, const char *fname, * Prints a warning message. */ void -rsync_warnx(struct sess *sess, const char *fname, - size_t line, const char *fmt, ...) +rsync_warnx(const char *fname, size_t line, const char *fmt, ...) { char *buf = NULL; va_list ap; @@ -168,14 +165,13 @@ rsync_warnx(struct sess *sess, const char *fname, * It uses a level detector for when to inhibit printing. */ void -rsync_warn(struct sess *sess, int level, - const char *fname, size_t line, const char *fmt, ...) +rsync_warn(int level, const char *fname, size_t line, const char *fmt, ...) { char *buf = NULL; va_list ap; int er = errno; - if (sess->opts->verbose < level) + if (verbose < level) return; if (fmt != NULL) { diff --git a/usr.bin/rsync/main.c b/usr.bin/rsync/main.c index 4f0b386e0bf..967e6528bc2 100644 --- a/usr.bin/rsync/main.c +++ b/usr.bin/rsync/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.44 2019/04/04 04:19:54 bket Exp $ */ +/* $Id: main.c,v 1.45 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -29,6 +29,8 @@ #include "extern.h" +int verbose; + /* * A remote host is has a colon before the first path separator. * This works for rsh remote hosts (host:/foo/bar), implicit rsync @@ -303,8 +305,8 @@ main(int argc, char *argv[]) { "no-specials", no_argument, &opts.specials, 0 }, { "times", no_argument, &opts.preserve_times, 1 }, { "no-times", no_argument, &opts.preserve_times, 0 }, - { "verbose", no_argument, &opts.verbose, 1 }, - { "no-verbose", no_argument, &opts.verbose, 0 }, + { "verbose", no_argument, &verbose, 1 }, + { "no-verbose", no_argument, &verbose, 0 }, { NULL, 0, NULL, 0 }}; /* Global pledge. */ @@ -357,7 +359,7 @@ main(int argc, char *argv[]) opts.preserve_times = 1; break; case 'v': - opts.verbose++; + verbose++; break; case 'x': opts.one_file_system++; @@ -454,20 +456,20 @@ main(int argc, char *argv[]) sess.opts = &opts; if ((args = fargs_cmdline(&sess, fargs, NULL)) == NULL) { - ERRX1(&sess, "fargs_cmdline"); + ERRX1("fargs_cmdline"); _exit(1); } for (i = 0; args[i] != NULL; i++) - LOG2(&sess, "exec[%d] = %s", i, args[i]); + LOG2("exec[%d] = %s", i, args[i]); /* Make sure the child's stdin is from the sender. */ if (dup2(fds[1], STDIN_FILENO) == -1) { - ERR(&sess, "dup2"); + ERR("dup2"); _exit(1); } if (dup2(fds[1], STDOUT_FILENO) == -1) { - ERR(&sess, "dup2"); + ERR("dup2"); _exit(1); } execvp(args[0], args); diff --git a/usr.bin/rsync/mkpath.c b/usr.bin/rsync/mkpath.c index 2555a81558b..f27e031290c 100644 --- a/usr.bin/rsync/mkpath.c +++ b/usr.bin/rsync/mkpath.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkpath.c,v 1.2 2019/02/10 23:24:14 benno Exp $ */ +/* $OpenBSD: mkpath.c,v 1.3 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 1983, 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -60,12 +60,12 @@ mkpath(struct sess *sess, char *path) if (stat(path, &sb)) { if (errno != ENOENT || (mkdir(path, 0777) && errno != EEXIST)) { - ERR(sess, "%s: stat", path); + ERR("%s: stat", path); return (-1); } } else if (!S_ISDIR(sb.st_mode)) { errno = ENOTDIR; - ERR(sess, "%s: stat", path); + ERR("%s: stat", path); return (-1); } diff --git a/usr.bin/rsync/mktemp.c b/usr.bin/rsync/mktemp.c index f789b5c727f..ad95ba8bfba 100644 --- a/usr.bin/rsync/mktemp.c +++ b/usr.bin/rsync/mktemp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mktemp.c,v 1.8 2019/04/02 11:05:55 deraadt Exp $ */ +/* $OpenBSD: mktemp.c,v 1.9 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 1996-1998, 2008 Theo de Raadt * Copyright (c) 1997, 2008-2009 Todd C. Miller @@ -293,11 +293,11 @@ mktemplate(struct sess *sess, char **ret, const char *path, int recursive) n = asprintf(ret, "%.*s/.%s.XXXXXXXXXX", dirlen, path, path + dirlen + 1); if (n < 0) { - ERR(sess, "asprintf"); + ERR("asprintf"); *ret = NULL; } } else if ((n = asprintf(ret, ".%s.XXXXXXXXXX", path)) < 0) { - ERR(sess, "asprintf"); + ERR("asprintf"); *ret = NULL; } diff --git a/usr.bin/rsync/receiver.c b/usr.bin/rsync/receiver.c index c6d26cb0917..5d353e3a0c9 100644 --- a/usr.bin/rsync/receiver.c +++ b/usr.bin/rsync/receiver.c @@ -1,4 +1,4 @@ -/* $Id: receiver.c,v 1.22 2019/03/30 07:28:55 deraadt Exp $ */ +/* $Id: receiver.c,v 1.23 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> @@ -57,10 +57,10 @@ rsync_set_metadata(struct sess *sess, int newfile, ts[1].tv_sec = f->st.mtime; ts[1].tv_nsec = 0; if (futimens(fd, ts) == -1) { - ERR(sess, "%s: futimens", path); + ERR("%s: futimens", path); return 0; } - LOG4(sess, "%s: updated date", f->path); + LOG4("%s: updated date", f->path); } /* @@ -78,14 +78,14 @@ rsync_set_metadata(struct sess *sess, int newfile, if (uid != (uid_t)-1 || gid != (gid_t)-1) { if (fchown(fd, uid, gid) == -1) { if (errno != EPERM) { - ERR(sess, "%s: fchown", path); + ERR("%s: fchown", path); return 0; } if (getuid() == 0) - WARNX(sess, "%s: identity unknown or not available " + WARNX("%s: identity unknown or not available " "to user.group: %u.%u", f->path, uid, gid); } else - LOG4(sess, "%s: updated uid and/or gid", f->path); + LOG4("%s: updated uid and/or gid", f->path); mode &= ~(S_ISTXT | S_ISUID | S_ISGID); } @@ -93,10 +93,10 @@ rsync_set_metadata(struct sess *sess, int newfile, if (newfile || sess->opts->preserve_perms) { if (fchmod(fd, mode) == -1) { - ERR(sess, "%s: fchmod", path); + ERR("%s: fchmod", path); return 0; } - LOG4(sess, "%s: updated permissions", f->path); + LOG4("%s: updated permissions", f->path); } return 1; @@ -118,10 +118,10 @@ rsync_set_metadata_at(struct sess *sess, int newfile, int rootfd, ts[1].tv_sec = f->st.mtime; ts[1].tv_nsec = 0; if (utimensat(rootfd, path, ts, AT_SYMLINK_NOFOLLOW) == -1) { - ERR(sess, "%s: utimensat", path); + ERR("%s: utimensat", path); return 0; } - LOG4(sess, "%s: updated date", f->path); + LOG4("%s: updated date", f->path); } /* @@ -139,14 +139,14 @@ rsync_set_metadata_at(struct sess *sess, int newfile, int rootfd, if (uid != (uid_t)-1 || gid != (gid_t)-1) { if (fchownat(rootfd, path, uid, gid, AT_SYMLINK_NOFOLLOW) == -1) { if (errno != EPERM) { - ERR(sess, "%s: fchownat", path); + ERR("%s: fchownat", path); return 0; } if (getuid() == 0) - WARNX(sess, "%s: identity unknown or not available " + WARNX("%s: identity unknown or not available " "to user.group: %u.%u", f->path, uid, gid); } else - LOG4(sess, "%s: updated uid and/or gid", f->path); + LOG4("%s: updated uid and/or gid", f->path); mode &= ~(S_ISTXT | S_ISUID | S_ISGID); } @@ -154,10 +154,10 @@ rsync_set_metadata_at(struct sess *sess, int newfile, int rootfd, if (newfile || sess->opts->preserve_perms) { if (fchmodat(rootfd, path, mode, AT_SYMLINK_NOFOLLOW) == -1) { - ERR(sess, "%s: fchmodat", path); + ERR("%s: fchmodat", path); return 0; } - LOG4(sess, "%s: updated permissions", f->path); + LOG4("%s: updated permissions", f->path); } return 1; @@ -181,7 +181,7 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) mode_t oumask; if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", NULL) == -1) { - ERR(sess, "pledge"); + ERR("pledge"); goto out; } @@ -189,16 +189,16 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) if (!sess->opts->server && !io_write_int(sess, fdout, 0)) { - ERRX1(sess, "io_write_int"); + ERRX1("io_write_int"); goto out; } if (sess->opts->server && sess->opts->del) { if (!io_read_size(sess, fdin, &excl)) { - ERRX1(sess, "io_read_size"); + ERRX1("io_read_size"); goto out; } else if (excl != 0) { - ERRX(sess, "exclusion list is non-empty"); + ERRX("exclusion list is non-empty"); goto out; } } @@ -209,28 +209,28 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) */ if (!flist_recv(sess, fdin, &fl, &flsz)) { - ERRX1(sess, "flist_recv"); + ERRX1("flist_recv"); goto out; } /* The IO error is sent after the file list. */ if (!io_read_int(sess, fdin, &ioerror)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } else if (ioerror != 0) { - ERRX1(sess, "io_error is non-zero"); + ERRX1("io_error is non-zero"); goto out; } if (flsz == 0 && !sess->opts->server) { - WARNX(sess, "receiver has empty file list: exiting"); + WARNX("receiver has empty file list: exiting"); rc = 1; goto out; } else if (!sess->opts->server) - LOG1(sess, "Transfer starting: %zu files", flsz); + LOG1("Transfer starting: %zu files", flsz); - LOG2(sess, "%s: receiver destination", root); + LOG2("%s: receiver destination", root); /* * Create the path for our destination directory, if we're not @@ -241,10 +241,10 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) if (!sess->opts->dry_run) { if ((tofree = strdup(root)) == NULL) { - ERR(sess, "strdup"); + ERR("strdup"); goto out; } else if (mkpath(sess, tofree) < 0) { - ERRX1(sess, "%s: mkpath", root); + ERRX1("%s: mkpath", root); free(tofree); goto out; } @@ -261,7 +261,7 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) if (!sess->opts->dry_run) { dfd = open(root, O_RDONLY | O_DIRECTORY, 0); if (dfd == -1) { - ERR(sess, "%s: open", root); + ERR("%s: open", root); goto out; } } @@ -274,7 +274,7 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) if (sess->opts->del && sess->opts->recursive && !flist_gen_dels(sess, root, &dfl, &dflsz, fl, flsz)) { - ERRX1(sess, "flist_gen_local"); + ERRX1("flist_gen_local"); goto out; } @@ -286,17 +286,17 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) */ if (unveil(root, "rwc") == -1) { - ERR(sess, "%s: unveil", root); + ERR("%s: unveil", root); goto out; } else if (unveil(NULL, NULL) == -1) { - ERR(sess, "%s: unveil", root); + ERR("%s: unveil", root); goto out; } /* If we have a local set, go for the deletion. */ if (!flist_del(sess, dfd, dfl, dflsz)) { - ERRX1(sess, "flist_del"); + ERRX1("flist_del"); goto out; } @@ -315,33 +315,33 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) ul = upload_alloc(sess, root, dfd, fdout, CSUM_LENGTH_PHASE1, fl, flsz, oumask); if (ul == NULL) { - ERRX1(sess, "upload_alloc"); + ERRX1("upload_alloc"); goto out; } dl = download_alloc(sess, fdin, fl, flsz, dfd); if (dl == NULL) { - ERRX1(sess, "download_alloc"); + ERRX1("download_alloc"); goto out; } - LOG2(sess, "%s: ready for phase 1 data", root); + LOG2("%s: ready for phase 1 data", root); for (;;) { if ((c = poll(pfd, PFD__MAX, POLL_TIMEOUT)) == -1) { - ERR(sess, "poll"); + ERR("poll"); goto out; } else if (c == 0) { - ERRX(sess, "poll: timeout"); + ERRX("poll: timeout"); goto out; } for (i = 0; i < PFD__MAX; i++) if (pfd[i].revents & (POLLERR|POLLNVAL)) { - ERRX(sess, "poll: bad fd"); + ERRX("poll: bad fd"); goto out; } else if (pfd[i].revents & POLLHUP) { - ERRX(sess, "poll: hangup"); + ERRX("poll: hangup"); goto out; } @@ -357,7 +357,7 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) if (sess->mplex_reads && (POLLIN & pfd[PFD_SENDER_IN].revents)) { if (!io_read_flush(sess, fdin)) { - ERRX1(sess, "io_read_flush"); + ERRX1("io_read_flush"); goto out; } else if (sess->mplex_read_remain == 0) pfd[PFD_SENDER_IN].revents &= ~POLLIN; @@ -376,7 +376,7 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) &pfd[PFD_UPLOADER_IN].fd, sess, &pfd[PFD_SENDER_OUT].fd); if (c < 0) { - ERRX1(sess, "rsync_uploader"); + ERRX1("rsync_uploader"); goto out; } } @@ -395,14 +395,12 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) c = rsync_downloader(dl, sess, &pfd[PFD_DOWNLOADER_IN].fd); if (c < 0) { - ERRX1(sess, "rsync_downloader"); + ERRX1("rsync_downloader"); goto out; } else if (c == 0) { assert(phase == 0); phase++; - LOG2(sess, - "%s: receiver ready for phase 2 data", - root); + LOG2("%s: receiver ready for phase 2 data", root); break; } @@ -420,13 +418,13 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) if (phase == 1) { if (!io_write_int(sess, fdout, -1)) { - ERRX1(sess, "io_write_int"); + ERRX1("io_write_int"); goto out; } else if (!io_read_int(sess, fdin, &ioerror)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } else if (ioerror != -1) { - ERRX(sess, "expected phase ack"); + ERRX("expected phase ack"); goto out; } } @@ -437,21 +435,21 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) */ if (!rsync_uploader_tail(ul, sess)) { - ERRX1(sess, "rsync_uploader_tail"); + ERRX1("rsync_uploader_tail"); goto out; } /* Process server statistics and say good-bye. */ if (!sess_stats_recv(sess, fdin)) { - ERRX1(sess, "sess_stats_recv"); + ERRX1("sess_stats_recv"); goto out; } else if (!io_write_int(sess, fdout, -1)) { - ERRX1(sess, "io_write_int"); + ERRX1("io_write_int"); goto out; } - LOG2(sess, "receiver finished updating"); + LOG2("receiver finished updating"); rc = 1; out: if (dfd != -1) diff --git a/usr.bin/rsync/sender.c b/usr.bin/rsync/sender.c index ab7221a87d7..d6613daa80c 100644 --- a/usr.bin/rsync/sender.c +++ b/usr.bin/rsync/sender.c @@ -1,4 +1,4 @@ -/* $Id: sender.c,v 1.21 2019/04/02 11:05:55 deraadt Exp $ */ +/* $Id: sender.c,v 1.22 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -119,12 +119,12 @@ send_up_fsm(struct sess *sess, size_t *phase, sz = MINIMUM(MAX_CHUNK, up->stat.curlen - up->stat.curpos); if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { - ERRX1(sess, "io_lowbuffer_alloc"); + ERRX1("io_lowbuffer_alloc"); return 0; } io_lowbuffer_int(sess, *wb, &pos, *wbsz, sz); if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, sz)) { - ERRX1(sess, "io_lowbuffer_alloc"); + ERRX1("io_lowbuffer_alloc"); return 0; } io_lowbuffer_buf(sess, *wb, &pos, *wbsz, @@ -144,7 +144,7 @@ send_up_fsm(struct sess *sess, size_t *phase, */ if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { - ERRX1(sess, "io_lowbuffer_alloc"); + ERRX1("io_lowbuffer_alloc"); return 0; } io_lowbuffer_int(sess, *wb, @@ -161,7 +161,7 @@ send_up_fsm(struct sess *sess, size_t *phase, hash_file(up->stat.map, up->stat.mapsz, fmd, sess); if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, dsz)) { - ERRX1(sess, "io_lowbuffer_alloc"); + ERRX1("io_lowbuffer_alloc"); return 0; } io_lowbuffer_buf(sess, *wb, &pos, *wbsz, fmd, dsz); @@ -175,7 +175,7 @@ send_up_fsm(struct sess *sess, size_t *phase, */ if (!sess->opts->dry_run) - LOG3(sess, "%s: flushed %jd KB total, %.2f%% uploaded", + LOG3("%s: flushed %jd KB total, %.2f%% uploaded", fl[up->cur->idx].path, (intmax_t)up->stat.total / 1024, 100.0 * up->stat.dirty / up->stat.total); @@ -219,7 +219,7 @@ send_up_fsm(struct sess *sess, size_t *phase, if (up->cur->idx < 0) { if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { - ERRX1(sess, "io_lowbuffer_alloc"); + ERRX1("io_lowbuffer_alloc"); return 0; } io_lowbuffer_int(sess, *wb, &pos, *wbsz, -1); @@ -227,7 +227,7 @@ send_up_fsm(struct sess *sess, size_t *phase, if (sess->opts->server && sess->rver > 27) { if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { - ERRX1(sess, "io_lowbuffer_alloc"); + ERRX1("io_lowbuffer_alloc"); return 0; } io_lowbuffer_int(sess, *wb, &pos, *wbsz, -1); @@ -235,10 +235,10 @@ send_up_fsm(struct sess *sess, size_t *phase, up->stat.curst = BLKSTAT_PHASE; } else if (sess->opts->dry_run) { if (!sess->opts->server) - LOG1(sess, "%s", fl[up->cur->idx].wpath); + LOG1("%s", fl[up->cur->idx].wpath); if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { - ERRX1(sess, "io_lowbuffer_alloc"); + ERRX1("io_lowbuffer_alloc"); return 0; } io_lowbuffer_int(sess, *wb, &pos, *wbsz, up->cur->idx); @@ -253,17 +253,17 @@ send_up_fsm(struct sess *sess, size_t *phase, */ if (!sess->opts->server) - LOG1(sess, "%s", fl[up->cur->idx].wpath); + LOG1("%s", fl[up->cur->idx].wpath); if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, 20)) { - ERRX1(sess, "io_lowbuffer_alloc"); + ERRX1("io_lowbuffer_alloc"); return 0; } assert(sizeof(buf) == 20); blk_recv_ack(sess, buf, up->cur->blks, up->cur->idx); io_lowbuffer_buf(sess, *wb, &pos, *wbsz, buf, 20); - LOG3(sess, "%s: primed for %jd B total", + LOG3("%s: primed for %jd B total", fl[up->cur->idx].path, (intmax_t)up->cur->blks->size); up->stat.curst = BLKSTAT_NEXT; } @@ -289,7 +289,7 @@ send_dl_enqueue(struct sess *sess, struct send_dlq *q, if (idx == -1) { if ((s = calloc(1, sizeof(struct send_dl))) == NULL) { - ERR(sess, "calloc"); + ERR("calloc"); return 0; } s->idx = -1; @@ -301,25 +301,25 @@ send_dl_enqueue(struct sess *sess, struct send_dlq *q, /* Validate the index. */ if (idx < 0 || (uint32_t)idx >= flsz) { - ERRX(sess, "file index out of bounds: invalid %d out of %zu", + ERRX("file index out of bounds: invalid %d out of %zu", idx, flsz); return 0; } else if (S_ISDIR(fl[idx].st.mode)) { - ERRX(sess, "blocks requested for " + ERRX("blocks requested for " "directory: %s", fl[idx].path); return 0; } else if (S_ISLNK(fl[idx].st.mode)) { - ERRX(sess, "blocks requested for " + ERRX("blocks requested for " "symlink: %s", fl[idx].path); return 0; } else if (!S_ISREG(fl[idx].st.mode)) { - ERRX(sess, "blocks requested for " + ERRX("blocks requested for " "special: %s", fl[idx].path); return 0; } if ((s = calloc(1, sizeof(struct send_dl))) == NULL) { - ERR(sess, "callloc"); + ERR("callloc"); return 0; } s->idx = idx; @@ -335,7 +335,7 @@ send_dl_enqueue(struct sess *sess, struct send_dlq *q, if (!sess->opts->dry_run) { s->blks = blk_recv(sess, fd, fl[idx].path); if (s->blks == NULL) { - ERRX1(sess, "blk_recv"); + ERRX1("blk_recv"); return 0; } } @@ -371,7 +371,7 @@ rsync_sender(struct sess *sess, int fdin, ssize_t ssz; if (pledge("stdio getpw rpath unveil", NULL) == -1) { - ERR(sess, "pledge"); + ERR("pledge"); return 0; } @@ -387,7 +387,7 @@ rsync_sender(struct sess *sess, int fdin, */ if (!flist_gen(sess, argc, argv, &fl, &flsz)) { - ERRX1(sess, "flist_gen"); + ERRX1("flist_gen"); goto out; } @@ -395,7 +395,7 @@ rsync_sender(struct sess *sess, int fdin, if (!sess->opts->server && sess->opts->del && !io_write_int(sess, fdout, 0)) { - ERRX1(sess, "io_write_int"); + ERRX1("io_write_int"); goto out; } @@ -405,21 +405,21 @@ rsync_sender(struct sess *sess, int fdin, */ if (!flist_send(sess, fdin, fdout, fl, flsz)) { - ERRX1(sess, "flist_send"); + ERRX1("flist_send"); goto out; } else if (!io_write_int(sess, fdout, 0)) { - ERRX1(sess, "io_write_int"); + ERRX1("io_write_int"); goto out; } /* Exit if we're the server with zero files. */ if (flsz == 0 && sess->opts->server) { - WARNX(sess, "sender has empty file list: exiting"); + WARNX("sender has empty file list: exiting"); rc = 1; goto out; } else if (!sess->opts->server) - LOG1(sess, "Transfer starting: %zu files", flsz); + LOG1("Transfer starting: %zu files", flsz); /* * If we're the server, read our exclusion list. @@ -428,10 +428,10 @@ rsync_sender(struct sess *sess, int fdin, if (sess->opts->server) { if (!io_read_size(sess, fdin, &excl)) { - ERRX1(sess, "io_read_size"); + ERRX1("io_read_size"); goto out; } else if (excl != 0) { - ERRX1(sess, "exclusion list is non-empty"); + ERRX1("exclusion list is non-empty"); goto out; } } @@ -452,18 +452,18 @@ rsync_sender(struct sess *sess, int fdin, for (;;) { assert(pfd[0].fd != -1); if ((c = poll(pfd, 3, POLL_TIMEOUT)) == -1) { - ERR(sess, "poll"); + ERR("poll"); goto out; } else if (c == 0) { - ERRX(sess, "poll: timeout"); + ERRX("poll: timeout"); goto out; } for (i = 0; i < 3; i++) if (pfd[i].revents & (POLLERR|POLLNVAL)) { - ERRX(sess, "poll: bad fd"); + ERRX("poll: bad fd"); goto out; } else if (pfd[i].revents & POLLHUP) { - ERRX(sess, "poll: hangup"); + ERRX("poll: hangup"); goto out; } @@ -477,12 +477,12 @@ rsync_sender(struct sess *sess, int fdin, if (sess->mplex_reads && (pfd[0].revents & POLLIN)) { if (!io_read_flush(sess, fdin)) { - ERRX1(sess, "io_read_flush"); + ERRX1("io_read_flush"); goto out; } else if (sess->mplex_read_remain == 0) { c = io_read_check(sess, fdin); if (c < 0) { - ERRX1(sess, "io_read_check"); + ERRX1("io_read_check"); goto out; } else if (c > 0) continue; @@ -499,17 +499,17 @@ rsync_sender(struct sess *sess, int fdin, if (pfd[0].revents & POLLIN) { if (!io_read_int(sess, fdin, &idx)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } if (!send_dl_enqueue(sess, &sdlq, idx, fl, flsz, fdin)) { - ERRX1(sess, "send_dl_enqueue"); + ERRX1("send_dl_enqueue"); goto out; } c = io_read_check(sess, fdin); if (c < 0) { - ERRX1(sess, "io_read_check"); + ERRX1("io_read_check"); goto out; } else if (c > 0) continue; @@ -531,7 +531,7 @@ rsync_sender(struct sess *sess, int fdin, f = &fl[up.cur->idx]; if (fstat(up.stat.fd, &st) == -1) { - ERR(sess, "%s: fstat", f->path); + ERR("%s: fstat", f->path); goto out; } @@ -547,7 +547,7 @@ rsync_sender(struct sess *sess, int fdin, up.stat.mapsz, PROT_READ, MAP_SHARED, up.stat.fd, 0); if (up.stat.map == MAP_FAILED) { - ERR(sess, "%s: mmap", f->path); + ERR("%s: mmap", f->path); goto out; } } @@ -570,7 +570,7 @@ rsync_sender(struct sess *sess, int fdin, ssz = write(fdout, wbuf + wbufpos, wbufsz - wbufpos); if (ssz < 0) { - ERR(sess, "write"); + ERR("write"); goto out; } wbufpos += ssz; @@ -593,7 +593,7 @@ rsync_sender(struct sess *sess, int fdin, assert(wbufpos == 0 && wbufsz == 0); if (!send_up_fsm(sess, &phase, &up, &wbuf, &wbufsz, &wbufmax, fl)) { - ERRX1(sess, "send_up_fsm"); + ERRX1("send_up_fsm"); goto out; } else if (phase > 1) break; @@ -645,7 +645,7 @@ rsync_sender(struct sess *sess, int fdin, up.stat.fd = open(fl[up.cur->idx].path, O_RDONLY|O_NONBLOCK, 0); if (up.stat.fd == -1) { - ERR(sess, "%s: open", fl[up.cur->idx].path); + ERR("%s: open", fl[up.cur->idx].path); goto out; } pfd[2].fd = up.stat.fd; @@ -653,26 +653,26 @@ rsync_sender(struct sess *sess, int fdin, } if (!TAILQ_EMPTY(&sdlq)) { - ERRX(sess, "phases complete with files still queued"); + ERRX("phases complete with files still queued"); goto out; } if (!sess_stats_send(sess, fdout)) { - ERRX1(sess, "sess_stats_end"); + ERRX1("sess_stats_end"); goto out; } /* Final "goodbye" message. */ if (!io_read_int(sess, fdin, &idx)) { - ERRX1(sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } else if (idx != -1) { - ERRX(sess, "read incorrect update complete ack"); + ERRX("read incorrect update complete ack"); goto out; } - LOG2(sess, "sender finished updating"); + LOG2("sender finished updating"); rc = 1; out: send_up_reset(&up); diff --git a/usr.bin/rsync/server.c b/usr.bin/rsync/server.c index 5b0ab5cf81b..2a7fff2ac9d 100644 --- a/usr.bin/rsync/server.c +++ b/usr.bin/rsync/server.c @@ -1,4 +1,4 @@ -/* $Id: server.c,v 1.10 2019/03/23 16:04:28 deraadt Exp $ */ +/* $Id: server.c,v 1.11 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -32,9 +32,9 @@ fcntl_nonblock(struct sess *sess, int fd) int fl; if ((fl = fcntl(fd, F_GETFL, 0)) == -1) - ERR(sess, "fcntl: F_GETFL"); + ERR("fcntl: F_GETFL"); else if (fcntl(fd, F_SETFL, fl|O_NONBLOCK) == -1) - ERR(sess, "fcntl: F_SETFL"); + ERR("fcntl: F_SETFL"); else return 1; @@ -66,7 +66,7 @@ rsync_server(const struct opts *opts, size_t argc, char *argv[]) if (!fcntl_nonblock(&sess, fdin) || !fcntl_nonblock(&sess, fdout)) { - ERRX1(&sess, "fcntl_nonblock"); + ERRX1("fcntl_nonblock"); goto out; } @@ -76,31 +76,30 @@ rsync_server(const struct opts *opts, size_t argc, char *argv[]) sess.seed = arc4random(); if (!io_read_int(&sess, fdin, &sess.rver)) { - ERRX1(&sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } else if (!io_write_int(&sess, fdout, sess.lver)) { - ERRX1(&sess, "io_write_int"); + ERRX1("io_write_int"); goto out; } else if (!io_write_int(&sess, fdout, sess.seed)) { - ERRX1(&sess, "io_write_int"); + ERRX1("io_write_int"); goto out; } sess.mplex_writes = 1; if (sess.rver < sess.lver) { - ERRX(&sess, - "remote protocol %d is older than our own %d: unsupported", + ERRX("remote protocol %d is older than our own %d: unsupported", sess.rver, sess.lver); rc = 2; goto out; } - LOG2(&sess, "server detected client version %d, server version %d, seed %d", + LOG2("server detected client version %d, server version %d, seed %d", sess.rver, sess.lver, sess.seed); if (sess.opts->sender) { - LOG2(&sess, "server starting sender"); + LOG2("server starting sender"); /* * At this time, I always get a period as the first @@ -111,22 +110,22 @@ rsync_server(const struct opts *opts, size_t argc, char *argv[]) */ if (strcmp(argv[0], ".")) { - ERRX(&sess, "first argument must be a standalone period"); + ERRX("first argument must be a standalone period"); goto out; } argv++; argc--; if (argc == 0) { - ERRX(&sess, "must have arguments"); + ERRX("must have arguments"); goto out; } if (!rsync_sender(&sess, fdin, fdout, argc, argv)) { - ERRX1(&sess, "rsync_sender"); + ERRX1("rsync_sender"); goto out; } } else { - LOG2(&sess, "server starting receiver"); + LOG2("server starting receiver"); /* * I don't understand why this calling convention @@ -135,15 +134,15 @@ rsync_server(const struct opts *opts, size_t argc, char *argv[]) */ if (argc != 2) { - ERRX(&sess, "server receiver mode requires two argument"); + ERRX("server receiver mode requires two argument"); goto out; } else if (strcmp(argv[0], ".")) { - ERRX(&sess, "first argument must be a standalone period"); + ERRX("first argument must be a standalone period"); goto out; } if (!rsync_receiver(&sess, fdin, fdout, argv[1])) { - ERRX1(&sess, "rsync_receiver"); + ERRX1("rsync_receiver"); goto out; } } @@ -151,7 +150,7 @@ rsync_server(const struct opts *opts, size_t argc, char *argv[]) #if 0 /* Probably the EOF. */ if (io_read_check(&sess, fdin)) - WARNX(&sess, "data remains in read pipe"); + WARNX("data remains in read pipe"); #endif rc = 0; diff --git a/usr.bin/rsync/session.c b/usr.bin/rsync/session.c index 8d71118c011..affb4c883fc 100644 --- a/usr.bin/rsync/session.c +++ b/usr.bin/rsync/session.c @@ -1,4 +1,4 @@ -/* $Id: session.c,v 1.6 2019/03/31 09:26:05 deraadt Exp $ */ +/* $Id: session.c,v 1.7 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -36,7 +36,7 @@ stats_log(struct sess *sess, const char *tru = "B", *twu = "B", *tsu = "B"; int trsz = 0, twsz = 0, tssz = 0; - assert(sess->opts->verbose); + assert(verbose); if (sess->opts->server) return; @@ -85,7 +85,7 @@ stats_log(struct sess *sess, } else ts = tsize; - LOG1(sess, "Transfer complete: " + LOG1("Transfer complete: " "%.*lf %s sent, %.*lf %s read, %.*lf %s file size", trsz, tr, tru, twsz, tw, twu, @@ -103,7 +103,7 @@ sess_stats_send(struct sess *sess, int fd) { uint64_t tw, tr, ts; - if (sess->opts->verbose == 0) + if (verbose == 0) return 1; tw = sess->total_write; @@ -112,13 +112,13 @@ sess_stats_send(struct sess *sess, int fd) if (sess->opts->server) { if (!io_write_ulong(sess, fd, tr)) { - ERRX1(sess, "io_write_ulong"); + ERRX1("io_write_ulong"); return 0; } else if (!io_write_ulong(sess, fd, tw)) { - ERRX1(sess, "io_write_ulong"); + ERRX1("io_write_ulong"); return 0; } else if (!io_write_ulong(sess, fd, ts)) { - ERRX1(sess, "io_write_ulong"); + ERRX1("io_write_ulong"); return 0; } } @@ -139,17 +139,17 @@ sess_stats_recv(struct sess *sess, int fd) { uint64_t tr, tw, ts; - if (sess->opts->server || sess->opts->verbose == 0) + if (sess->opts->server || verbose == 0) return 1; if (!io_read_ulong(sess, fd, &tw)) { - ERRX1(sess, "io_read_ulong"); + ERRX1("io_read_ulong"); return 0; } else if (!io_read_ulong(sess, fd, &tr)) { - ERRX1(sess, "io_read_ulong"); + ERRX1("io_read_ulong"); return 0; } else if (!io_read_ulong(sess, fd, &ts)) { - ERRX1(sess, "io_read_ulong"); + ERRX1("io_read_ulong"); return 0; } diff --git a/usr.bin/rsync/socket.c b/usr.bin/rsync/socket.c index 36384d063a0..7e5dc67779e 100644 --- a/usr.bin/rsync/socket.c +++ b/usr.bin/rsync/socket.c @@ -1,4 +1,4 @@ -/* $Id: socket.c,v 1.22 2019/03/31 08:47:46 naddy Exp $ */ +/* $Id: socket.c,v 1.23 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -58,10 +58,10 @@ inet_connect(struct sess *sess, int *sd, if (*sd != -1) close(*sd); - LOG2(sess, "trying: %s, %s", src->ip, host); + LOG2("trying: %s, %s", src->ip, host); if ((*sd = socket(src->family, SOCK_STREAM, 0)) == -1) { - ERR(sess, "socket"); + ERR("socket"); return -1; } @@ -75,21 +75,21 @@ inet_connect(struct sess *sess, int *sd, c = connect(*sd, (const struct sockaddr *)&src->sa, src->salen); if (c == -1) { if (errno == ECONNREFUSED || errno == EHOSTUNREACH) { - WARNX(sess, "connect refused: %s, %s", + WARNX("connect refused: %s, %s", src->ip, host); return 0; } - ERR(sess, "connect"); + ERR("connect"); return -1; } /* Set up non-blocking mode. */ if ((flags = fcntl(*sd, F_GETFL, 0)) == -1) { - ERR(sess, "fcntl"); + ERR("fcntl"); return -1; } else if (fcntl(*sd, F_SETFL, flags|O_NONBLOCK) == -1) { - ERR(sess, "fcntl"); + ERR("fcntl"); return -1; } @@ -119,18 +119,18 @@ inet_resolve(struct sess *sess, const char *host, size_t *sz) error = getaddrinfo(host, sess->opts->port, &hints, &res0); - LOG2(sess, "resolving: %s", host); + LOG2("resolving: %s", host); if (error == EAI_AGAIN || error == EAI_NONAME) { - ERRX(sess, "could not resolve hostname %s: %s", + ERRX("could not resolve hostname %s: %s", host, gai_strerror(error)); return NULL; } else if (error == EAI_SERVICE) { - ERRX(sess, "could not resolve service rsync: %s", + ERRX("could not resolve service rsync: %s", gai_strerror(error)); return NULL; } else if (error) { - ERRX(sess, "getaddrinfo: %s: %s", host, gai_strerror(error)); + ERRX("getaddrinfo: %s: %s", host, gai_strerror(error)); return NULL; } @@ -142,14 +142,14 @@ inet_resolve(struct sess *sess, const char *host, size_t *sz) srcsz++; if (srcsz == 0) { - ERRX(sess, "no addresses resolved: %s", host); + ERRX("no addresses resolved: %s", host); freeaddrinfo(res0); return NULL; } src = calloc(srcsz, sizeof(struct source)); if (src == NULL) { - ERRX(sess, "calloc"); + ERRX("calloc"); freeaddrinfo(res0); return NULL; } @@ -181,7 +181,7 @@ inet_resolve(struct sess *sess, const char *host, size_t *sz) src[i].ip, INET6_ADDRSTRLEN); } - LOG2(sess, "hostname resolved: %s: %s", host, src[i].ip); + LOG2("hostname resolved: %s: %s", host, src[i].ip); i++; } @@ -201,7 +201,7 @@ protocol_line(struct sess *sess, const char *host, const char *cp) int major, minor; if (strncmp(cp, "@RSYNCD: ", 9)) { - LOG0(sess, "%s", cp); + LOG0("%s", cp); return 0; } @@ -227,7 +227,7 @@ protocol_line(struct sess *sess, const char *host, const char *cp) return 0; } - ERRX(sess, "rsyncd protocol error: unknown command"); + ERRX("rsyncd protocol error: unknown command"); return -1; } @@ -255,7 +255,7 @@ rsync_connect(const struct opts *opts, int *sd, const struct fargs *f) /* Resolve all IP addresses from the host. */ if ((src = inet_resolve(&sess, f->host, &srcsz)) == NULL) { - ERRX1(&sess, "inet_resolve"); + ERRX1("inet_resolve"); exit(1); } @@ -263,7 +263,7 @@ rsync_connect(const struct opts *opts, int *sd, const struct fargs *f) if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw inet unveil", NULL) == -1) { - ERR(&sess, "pledge"); + ERR("pledge"); exit(1); } @@ -276,7 +276,7 @@ rsync_connect(const struct opts *opts, int *sd, const struct fargs *f) for (i = 0; i < srcsz; i++) { c = inet_connect(&sess, sd, &src[i], f->host); if (c < 0) { - ERRX1(&sess, "inet_connect"); + ERRX1("inet_connect"); goto out; } else if (c > 0) break; @@ -285,16 +285,16 @@ rsync_connect(const struct opts *opts, int *sd, const struct fargs *f) /* Drop the inet pledge. */ if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", NULL) == -1) { - ERR(&sess, "pledge"); + ERR("pledge"); goto out; } if (i == srcsz) { - ERRX(&sess, "cannot connect to host: %s", f->host); + ERRX("cannot connect to host: %s", f->host); goto out; } - LOG2(&sess, "connected: %s, %s", src[i].ip, f->host); + LOG2("connected: %s, %s", src[i].ip, f->host); free(src); return 0; @@ -331,7 +331,7 @@ rsync_socket(const struct opts *opts, int sd, const struct fargs *f) assert(f->module != NULL); if ((args = fargs_cmdline(&sess, f, &skip)) == NULL) { - ERRX1(&sess, "fargs_cmdline"); + ERRX1("fargs_cmdline"); exit(1); } @@ -339,14 +339,14 @@ rsync_socket(const struct opts *opts, int sd, const struct fargs *f) (void)snprintf(buf, sizeof(buf), "@RSYNCD: %d", sess.lver); if (!io_write_line(&sess, sd, buf)) { - ERRX1(&sess, "io_write_line"); + ERRX1("io_write_line"); goto out; } - LOG2(&sess, "requesting module: %s, %s", f->module, f->host); + LOG2("requesting module: %s, %s", f->module, f->host); if (!io_write_line(&sess, sd, f->module)) { - ERRX1(&sess, "io_write_line"); + ERRX1("io_write_line"); goto out; } @@ -361,14 +361,14 @@ rsync_socket(const struct opts *opts, int sd, const struct fargs *f) for (;;) { for (i = 0; i < sizeof(buf); i++) { if (!io_read_byte(&sess, sd, &byte)) { - ERRX1(&sess, "io_read_byte"); + ERRX1("io_read_byte"); goto out; } if ((buf[i] = byte) == '\n') break; } if (i == sizeof(buf)) { - ERRX(&sess, "line buffer overrun"); + ERRX("line buffer overrun"); goto out; } else if (i == 0) continue; @@ -385,7 +385,7 @@ rsync_socket(const struct opts *opts, int sd, const struct fargs *f) buf[i - 1] = '\0'; if ((c = protocol_line(&sess, f->host, buf)) < 0) { - ERRX1(&sess, "protocol_line"); + ERRX1("protocol_line"); goto out; } else if (c > 0) break; @@ -402,11 +402,11 @@ rsync_socket(const struct opts *opts, int sd, const struct fargs *f) for (i = skip ; args[i] != NULL; i++) if (!io_write_line(&sess, sd, args[i])) { - ERRX1(&sess, "io_write_line"); + ERRX1("io_write_line"); goto out; } if (!io_write_byte(&sess, sd, '\n')) { - ERRX1(&sess, "io_write_line"); + ERRX1("io_write_line"); goto out; } @@ -418,14 +418,14 @@ rsync_socket(const struct opts *opts, int sd, const struct fargs *f) /* Protocol exchange: get the random seed. */ if (!io_read_int(&sess, sd, &sess.seed)) { - ERRX1(&sess, "io_read_int"); + ERRX1("io_read_int"); goto out; } /* Now we've completed the handshake. */ if (sess.rver < sess.lver) { - ERRX(&sess, "remote protocol is older than our own (%d < %d): " + ERRX("remote protocol is older than our own (%d < %d): " "this is not supported", sess.rver, sess.lver); rc = 2; @@ -433,23 +433,23 @@ rsync_socket(const struct opts *opts, int sd, const struct fargs *f) } sess.mplex_reads = 1; - LOG2(&sess, "read multiplexing enabled"); + LOG2("read multiplexing enabled"); - LOG2(&sess, "socket detected client version %d, server version %d, seed %d", + LOG2("socket detected client version %d, server version %d, seed %d", sess.lver, sess.rver, sess.seed); assert(f->mode == FARGS_RECEIVER); - LOG2(&sess, "client starting receiver: %s", f->host); + LOG2("client starting receiver: %s", f->host); if (!rsync_receiver(&sess, sd, sd, f->sink)) { - ERRX1(&sess, "rsync_receiver"); + ERRX1("rsync_receiver"); goto out; } #if 0 /* Probably the EOF. */ if (io_read_check(&sess, sd)) - WARNX(&sess, "data remains in read pipe"); + WARNX("data remains in read pipe"); #endif rc = 0; diff --git a/usr.bin/rsync/symlinks.c b/usr.bin/rsync/symlinks.c index 68265829505..5f706686b2d 100644 --- a/usr.bin/rsync/symlinks.c +++ b/usr.bin/rsync/symlinks.c @@ -1,4 +1,4 @@ -/* $Id: symlinks.c,v 1.3 2019/02/11 21:41:22 deraadt Exp $ */ +/* $Id: symlinks.c,v 1.4 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -38,18 +38,18 @@ symlink_read(struct sess *sess, const char *path) for (sz = MAXPATHLEN; ; sz *= 2) { if ((pp = realloc(buf, sz + 1)) == NULL) { - ERR(sess, "realloc"); + ERR("realloc"); free(buf); return NULL; } buf = pp; if ((nsz = readlink(path, buf, sz)) == -1) { - ERR(sess, "%s: readlink", path); + ERR("%s: readlink", path); free(buf); return NULL; } else if (nsz == 0) { - ERRX(sess, "%s: empty link", path); + ERRX("%s: empty link", path); free(buf); return NULL; } else if ((size_t)nsz < sz) @@ -77,18 +77,18 @@ symlinkat_read(struct sess *sess, int fd, const char *path) for (sz = MAXPATHLEN; ; sz *= 2) { if ((pp = realloc(buf, sz + 1)) == NULL) { - ERR(sess, "realloc"); + ERR("realloc"); free(buf); return NULL; } buf = pp; if ((nsz = readlinkat(fd, path, buf, sz)) == -1) { - ERR(sess, "%s: readlinkat", path); + ERR("%s: readlinkat", path); free(buf); return NULL; } else if (nsz == 0) { - ERRX(sess, "%s: empty link", path); + ERRX("%s: empty link", path); free(buf); return NULL; } else if ((size_t)nsz < sz) diff --git a/usr.bin/rsync/uploader.c b/usr.bin/rsync/uploader.c index 70aab10e6f5..7e283c71c33 100644 --- a/usr.bin/rsync/uploader.c +++ b/usr.bin/rsync/uploader.c @@ -1,4 +1,4 @@ -/* $Id: uploader.c,v 1.20 2019/04/02 11:05:55 deraadt Exp $ */ +/* $Id: uploader.c,v 1.21 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2019 Florian Obser <florian@openbsd.org> @@ -72,7 +72,7 @@ log_dir(struct sess *sess, const struct flist *f) return; sz = strlen(f->path); assert(sz > 0); - LOG1(sess, "%s%s", f->path, (f->path[sz - 1] == '/') ? "" : "/"); + LOG1("%s%s", f->path, (f->path[sz - 1] == '/') ? "" : "/"); } /* @@ -84,7 +84,7 @@ log_link(struct sess *sess, const struct flist *f) { if (!sess->opts->server) - LOG1(sess, "%s -> %s", f->path, f->link); + LOG1("%s -> %s", f->path, f->link); } /* @@ -95,7 +95,7 @@ log_file(struct sess *sess, const struct flist *f) { if (!sess->opts->server) - LOG1(sess, "%s", f->path); + LOG1("%s", f->path); } /* @@ -181,7 +181,7 @@ pre_link(struct upload *p, struct sess *sess) assert(S_ISLNK(f->st.mode)); if (!sess->opts->preserve_links) { - WARNX(sess, "%s: ignoring symlink", f->path); + WARNX("%s: ignoring symlink", f->path); return 0; } else if (sess->opts->dry_run) { log_link(sess, f); @@ -200,12 +200,12 @@ pre_link(struct upload *p, struct sess *sess) if (rc != -1 && !S_ISLNK(st.st_mode)) { if (S_ISDIR(st.st_mode) && unlinkat(p->rootfd, f->path, AT_REMOVEDIR) == -1) { - ERR(sess, "%s: unlinkat", f->path); + ERR("%s: unlinkat", f->path); return -1; } rc = -1; } else if (rc == -1 && errno != ENOENT) { - ERR(sess, "%s: fstatat", f->path); + ERR("%s: fstatat", f->path); return -1; } @@ -217,13 +217,13 @@ pre_link(struct upload *p, struct sess *sess) if (rc != -1) { b = symlinkat_read(sess, p->rootfd, f->path); if (b == NULL) { - ERRX1(sess, "symlinkat_read"); + ERRX1("symlinkat_read"); return -1; } if (strcmp(f->link, b)) { free(b); b = NULL; - LOG3(sess, "%s: updating symlink: %s", f->path, f->link); + LOG3("%s: updating symlink: %s", f->path, f->link); updatelink = 1; } free(b); @@ -236,14 +236,14 @@ pre_link(struct upload *p, struct sess *sess) */ if (rc == -1 || updatelink) { - LOG3(sess, "%s: creating symlink: %s", f->path, f->link); + LOG3("%s: creating symlink: %s", f->path, f->link); if (mktemplate(sess, &temp, f->path, sess->opts->recursive) == -1) { - ERRX1(sess, "mktemplate"); + ERRX1("mktemplate"); return -1; } if (mkstemplinkat(f->link, p->rootfd, temp) == NULL) { - ERR(sess, "mkstemplinkat"); + ERR("mkstemplinkat"); free(temp); return -1; } @@ -255,7 +255,7 @@ pre_link(struct upload *p, struct sess *sess) if (newlink) { if (renameat(p->rootfd, temp, p->rootfd, f->path) == -1) { - ERR(sess, "%s: renameat %s", temp, f->path); + ERR("%s: renameat %s", temp, f->path); (void)unlinkat(p->rootfd, temp, 0); free(temp); return -1; @@ -284,7 +284,7 @@ pre_dev(struct upload *p, struct sess *sess) assert(S_ISBLK(f->st.mode) || S_ISCHR(f->st.mode)); if (!sess->opts->devices || getuid() != 0) { - WARNX(sess, "skipping non-regular file %s", f->path); + WARNX("skipping non-regular file %s", f->path); return 0; } else if (sess->opts->dry_run) { log_file(sess, f); @@ -303,12 +303,12 @@ pre_dev(struct upload *p, struct sess *sess) if (rc != -1 && !(S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))) { if (S_ISDIR(st.st_mode) && unlinkat(p->rootfd, f->path, AT_REMOVEDIR) == -1) { - ERR(sess, "%s: unlinkat", f->path); + ERR("%s: unlinkat", f->path); return -1; } rc = -1; } else if (rc == -1 && errno != ENOENT) { - ERR(sess, "%s: fstatat", f->path); + ERR("%s: fstatat", f->path); return -1; } @@ -318,7 +318,7 @@ pre_dev(struct upload *p, struct sess *sess) if ((f->st.mode & (S_IFCHR|S_IFBLK)) != (st.st_mode & (S_IFCHR|S_IFBLK)) || f->st.rdev != st.st_rdev) { - LOG3(sess, "%s: updating device", f->path); + LOG3("%s: updating device", f->path); updatedev = 1; } } @@ -327,12 +327,12 @@ pre_dev(struct upload *p, struct sess *sess) newdev = 1; if (mktemplate(sess, &temp, f->path, sess->opts->recursive) == -1) { - ERRX1(sess, "mktemplate"); + ERRX1("mktemplate"); return -1; } if (mkstempnodat(p->rootfd, temp, f->st.mode & (S_IFCHR|S_IFBLK), f->st.rdev) == NULL) { - ERR(sess, "mkstempnodat"); + ERR("mkstempnodat"); free(temp); return -1; } @@ -343,7 +343,7 @@ pre_dev(struct upload *p, struct sess *sess) if (newdev) { if (renameat(p->rootfd, temp, p->rootfd, f->path) == -1) { - ERR(sess, "%s: renameat %s", temp, f->path); + ERR("%s: renameat %s", temp, f->path); (void)unlinkat(p->rootfd, temp, 0); free(temp); return -1; @@ -372,7 +372,7 @@ pre_fifo(struct upload *p, struct sess *sess) assert(S_ISFIFO(f->st.mode)); if (!sess->opts->specials) { - WARNX(sess, "skipping non-regular file %s", f->path); + WARNX("skipping non-regular file %s", f->path); return 0; } else if (sess->opts->dry_run) { log_file(sess, f); @@ -391,12 +391,12 @@ pre_fifo(struct upload *p, struct sess *sess) if (rc != -1 && !S_ISFIFO(st.st_mode)) { if (S_ISDIR(st.st_mode) && unlinkat(p->rootfd, f->path, AT_REMOVEDIR) == -1) { - ERR(sess, "%s: unlinkat", f->path); + ERR("%s: unlinkat", f->path); return -1; } rc = -1; } else if (rc == -1 && errno != ENOENT) { - ERR(sess, "%s: fstatat", f->path); + ERR("%s: fstatat", f->path); return -1; } @@ -404,11 +404,11 @@ pre_fifo(struct upload *p, struct sess *sess) newfifo = 1; if (mktemplate(sess, &temp, f->path, sess->opts->recursive) == -1) { - ERRX1(sess, "mktemplate"); + ERRX1("mktemplate"); return -1; } if (mkstempfifoat(p->rootfd, temp) == NULL) { - ERR(sess, "mkstempfifoat"); + ERR("mkstempfifoat"); free(temp); return -1; } @@ -419,7 +419,7 @@ pre_fifo(struct upload *p, struct sess *sess) if (newfifo) { if (renameat(p->rootfd, temp, p->rootfd, f->path) == -1) { - ERR(sess, "%s: renameat %s", temp, f->path); + ERR("%s: renameat %s", temp, f->path); (void)unlinkat(p->rootfd, temp, 0); free(temp); return -1; @@ -448,7 +448,7 @@ pre_sock(struct upload *p, struct sess *sess) assert(S_ISSOCK(f->st.mode)); if (!sess->opts->specials) { - WARNX(sess, "skipping non-regular file %s", f->path); + WARNX("skipping non-regular file %s", f->path); return 0; } else if (sess->opts->dry_run) { log_file(sess, f); @@ -467,12 +467,12 @@ pre_sock(struct upload *p, struct sess *sess) if (rc != -1 && !S_ISSOCK(st.st_mode)) { if (S_ISDIR(st.st_mode) && unlinkat(p->rootfd, f->path, AT_REMOVEDIR) == -1) { - ERR(sess, "%s: unlinkat", f->path); + ERR("%s: unlinkat", f->path); return -1; } rc = -1; } else if (rc == -1 && errno != ENOENT) { - ERR(sess, "%s: fstatat", f->path); + ERR("%s: fstatat", f->path); return -1; } @@ -480,11 +480,11 @@ pre_sock(struct upload *p, struct sess *sess) newsock = 1; if (mktemplate(sess, &temp, f->path, sess->opts->recursive) == -1) { - ERRX1(sess, "mktemplate"); + ERRX1("mktemplate"); return -1; } if (mkstempsock(p->root, temp) == NULL) { - ERR(sess, "mkstempsock"); + ERR("mkstempsock"); free(temp); return -1; } @@ -495,7 +495,7 @@ pre_sock(struct upload *p, struct sess *sess) if (newsock) { if (renameat(p->rootfd, temp, p->rootfd, f->path) == -1) { - ERR(sess, "%s: renameat %s", temp, f->path); + ERR("%s: renameat %s", temp, f->path); (void)unlinkat(p->rootfd, temp, 0); free(temp); return -1; @@ -523,7 +523,7 @@ pre_dir(const struct upload *p, struct sess *sess) assert(S_ISDIR(f->st.mode)); if (!sess->opts->recursive) { - WARNX(sess, "%s: ignoring directory", f->path); + WARNX("%s: ignoring directory", f->path); return 0; } else if (sess->opts->dry_run) { log_dir(sess, f); @@ -534,10 +534,10 @@ pre_dir(const struct upload *p, struct sess *sess) rc = fstatat(p->rootfd, f->path, &st, AT_SYMLINK_NOFOLLOW); if (rc == -1 && errno != ENOENT) { - ERR(sess, "%s: fstatat", f->path); + ERR("%s: fstatat", f->path); return -1; } else if (rc != -1 && !S_ISDIR(st.st_mode)) { - ERRX(sess, "%s: not a directory", f->path); + ERRX("%s: not a directory", f->path); return -1; } else if (rc != -1) { /* @@ -545,7 +545,7 @@ pre_dir(const struct upload *p, struct sess *sess) * as we may locally have shut down writing into the * directory and that doesn't work. */ - LOG3(sess, "%s: updating directory", f->path); + LOG3("%s: updating directory", f->path); return 0; } @@ -556,9 +556,9 @@ pre_dir(const struct upload *p, struct sess *sess) * case it's u-w or something. */ - LOG3(sess, "%s: creating directory", f->path); + LOG3("%s: creating directory", f->path); if (mkdirat(p->rootfd, f->path, 0777 & ~p->oumask) == -1) { - ERR(sess, "%s: mkdirat", f->path); + ERR("%s: mkdirat", f->path); return -1; } @@ -590,10 +590,10 @@ post_dir(struct sess *sess, const struct upload *u, size_t idx) return 1; if (fstatat(u->rootfd, f->path, &st, AT_SYMLINK_NOFOLLOW) == -1) { - ERR(sess, "%s: fstatat", f->path); + ERR("%s: fstatat", f->path); return 0; } else if (!S_ISDIR(st.st_mode)) { - WARNX(sess, "%s: not a directory", f->path); + WARNX("%s: not a directory", f->path); return 0; } @@ -612,10 +612,10 @@ post_dir(struct sess *sess, const struct upload *u, size_t idx) tv[1].tv_nsec = 0; rc = utimensat(u->rootfd, f->path, tv, 0); if (rc == -1) { - ERR(sess, "%s: utimensat", f->path); + ERR("%s: utimensat", f->path); return 0; } - LOG4(sess, "%s: updated date", f->path); + LOG4("%s: updated date", f->path); } /* @@ -627,10 +627,10 @@ post_dir(struct sess *sess, const struct upload *u, size_t idx) (sess->opts->preserve_perms && st.st_mode != f->st.mode)) { rc = fchmodat(u->rootfd, f->path, f->st.mode, 0); if (rc == -1) { - ERR(sess, "%s: fchmodat", f->path); + ERR("%s: fchmodat", f->path); return 0; } - LOG4(sess, "%s: updated mode", f->path); + LOG4("%s: updated mode", f->path); } return 1; @@ -653,7 +653,7 @@ pre_file(const struct upload *p, int *filefd, struct sess *sess) if (sess->opts->dry_run) { log_file(sess, f); if (!io_write_int(sess, p->fdout, p->idx)) { - ERRX1(sess, "io_write_int"); + ERRX1("io_write_int"); return -1; } return 0; @@ -672,7 +672,7 @@ pre_file(const struct upload *p, int *filefd, struct sess *sess) O_RDONLY | O_NOFOLLOW | O_NONBLOCK, 0); if (*filefd != -1 || errno == ENOENT) return 1; - ERR(sess, "%s: openat", f->path); + ERR("%s: openat", f->path); return -1; } @@ -688,7 +688,7 @@ upload_alloc(struct sess *sess, const char *root, int rootfd, int fdout, struct upload *p; if ((p = calloc(1, sizeof(struct upload))) == NULL) { - ERR(sess, "calloc"); + ERR("calloc"); return NULL; } @@ -696,7 +696,7 @@ upload_alloc(struct sess *sess, const char *root, int rootfd, int fdout, p->oumask = msk; p->root = strdup(root); if (p->root == NULL) { - ERR(sess, "strdup"); + ERR("strdup"); free(p); return NULL; } @@ -707,7 +707,7 @@ upload_alloc(struct sess *sess, const char *root, int rootfd, int fdout, p->flsz = flsz; p->newdir = calloc(flsz, sizeof(int)); if (p->newdir == NULL) { - ERR(sess, "calloc"); + ERR("calloc"); free(p->root); free(p); return NULL; @@ -782,7 +782,7 @@ rsync_uploader(struct upload *u, int *fileinfd, c = io_write_buf(sess, u->fdout, u->buf + u->bufpos, sz); if (c == 0) { - ERRX1(sess, "io_write_nonblocking"); + ERRX1("io_write_nonblocking"); return -1; } u->bufpos += sz; @@ -844,11 +844,11 @@ rsync_uploader(struct upload *u, int *fileinfd, if (u->idx == u->flsz) { assert(*fileinfd == -1); if (!io_write_int(sess, u->fdout, -1)) { - ERRX1(sess, "io_write_int"); + ERRX1("io_write_int"); return -1; } u->state = UPLOAD_FINISHED; - LOG4(sess, "uploader: finished"); + LOG4("uploader: finished"); return 0; } @@ -872,12 +872,12 @@ rsync_uploader(struct upload *u, int *fileinfd, f = &u->fl[u->idx]; if (fstat(*fileinfd, &st) == -1) { - ERR(sess, "%s: fstat", f->path); + ERR("%s: fstat", f->path); close(*fileinfd); *fileinfd = -1; return -1; } else if (!S_ISREG(st.st_mode)) { - ERRX(sess, "%s: not regular", f->path); + ERRX("%s: not regular", f->path); close(*fileinfd); *fileinfd = -1; return -1; @@ -885,10 +885,10 @@ rsync_uploader(struct upload *u, int *fileinfd, if (st.st_size == f->st.size && st.st_mtime == f->st.mtime) { - LOG3(sess, "%s: skipping: up to date", f->path); + LOG3("%s: skipping: up to date", f->path); if (!rsync_set_metadata (sess, 0, *fileinfd, f, f->path)) { - ERRX1(sess, "rsync_set_metadata"); + ERRX1("rsync_set_metadata"); close(*fileinfd); *fileinfd = -1; return -1; @@ -916,7 +916,7 @@ rsync_uploader(struct upload *u, int *fileinfd, mapsz = st.st_size; map = mmap(NULL, mapsz, PROT_READ, MAP_SHARED, *fileinfd, 0); if (map == MAP_FAILED) { - ERR(sess, "%s: mmap", u->fl[u->idx].path); + ERR("%s: mmap", u->fl[u->idx].path); close(*fileinfd); *fileinfd = -1; return -1; @@ -927,7 +927,7 @@ rsync_uploader(struct upload *u, int *fileinfd, blk.blks = calloc(blk.blksz, sizeof(struct blk)); if (blk.blks == NULL) { - ERR(sess, "calloc"); + ERR("calloc"); munmap(map, mapsz); close(*fileinfd); *fileinfd = -1; @@ -944,7 +944,7 @@ rsync_uploader(struct upload *u, int *fileinfd, munmap(map, mapsz); close(*fileinfd); *fileinfd = -1; - LOG3(sess, "%s: mapped %jd B with %zu blocks", + LOG3("%s: mapped %jd B with %zu blocks", u->fl[u->idx].path, (intmax_t)blk.size, blk.blksz); } else { @@ -953,7 +953,7 @@ rsync_uploader(struct upload *u, int *fileinfd, *fileinfd = -1; } blk.len = MAX_CHUNK; /* Doesn't matter. */ - LOG3(sess, "%s: not mapped", u->fl[u->idx].path); + LOG3("%s: not mapped", u->fl[u->idx].path); } assert(*fileinfd == -1); @@ -972,7 +972,7 @@ rsync_uploader(struct upload *u, int *fileinfd, if (u->bufsz > u->bufmax) { if ((bufp = realloc(u->buf, u->bufsz)) == NULL) { - ERR(sess, "realloc"); + ERR("realloc"); return -1; } u->buf = bufp; @@ -1019,7 +1019,7 @@ rsync_uploader_tail(struct upload *u, struct sess *sess) !sess->opts->preserve_perms) return 1; - LOG2(sess, "fixing up directory times and permissions"); + LOG2("fixing up directory times and permissions"); for (i = 0; i < u->flsz; i++) if (S_ISDIR(u->fl[i].st.mode)) |