=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rsync/sender.c,v retrieving revision 1.21 retrieving revision 1.22 diff -c -r1.21 -r1.22 *** src/usr.bin/rsync/sender.c 2019/04/02 11:05:55 1.21 --- src/usr.bin/rsync/sender.c 2019/05/08 20:00:25 1.22 *************** *** 1,4 **** ! /* $Id: sender.c,v 1.21 2019/04/02 11:05:55 deraadt Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * --- 1,4 ---- ! /* $Id: sender.c,v 1.22 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * *************** *** 119,130 **** sz = MINIMUM(MAX_CHUNK, up->stat.curlen - up->stat.curpos); if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { ! ERRX1(sess, "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"); return 0; } io_lowbuffer_buf(sess, *wb, &pos, *wbsz, --- 119,130 ---- sz = MINIMUM(MAX_CHUNK, up->stat.curlen - up->stat.curpos); if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { ! ERRX1("io_lowbuffer_alloc"); return 0; } io_lowbuffer_int(sess, *wb, &pos, *wbsz, sz); if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, sz)) { ! ERRX1("io_lowbuffer_alloc"); return 0; } io_lowbuffer_buf(sess, *wb, &pos, *wbsz, *************** *** 144,150 **** */ if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { ! ERRX1(sess, "io_lowbuffer_alloc"); return 0; } io_lowbuffer_int(sess, *wb, --- 144,150 ---- */ if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { ! ERRX1("io_lowbuffer_alloc"); return 0; } io_lowbuffer_int(sess, *wb, *************** *** 161,167 **** hash_file(up->stat.map, up->stat.mapsz, fmd, sess); if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, dsz)) { ! ERRX1(sess, "io_lowbuffer_alloc"); return 0; } io_lowbuffer_buf(sess, *wb, &pos, *wbsz, fmd, dsz); --- 161,167 ---- hash_file(up->stat.map, up->stat.mapsz, fmd, sess); if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, dsz)) { ! ERRX1("io_lowbuffer_alloc"); return 0; } io_lowbuffer_buf(sess, *wb, &pos, *wbsz, fmd, dsz); *************** *** 175,181 **** */ if (!sess->opts->dry_run) ! LOG3(sess, "%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); --- 175,181 ---- */ if (!sess->opts->dry_run) ! 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,225 **** if (up->cur->idx < 0) { if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { ! ERRX1(sess, "io_lowbuffer_alloc"); return 0; } io_lowbuffer_int(sess, *wb, &pos, *wbsz, -1); --- 219,225 ---- if (up->cur->idx < 0) { if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { ! ERRX1("io_lowbuffer_alloc"); return 0; } io_lowbuffer_int(sess, *wb, &pos, *wbsz, -1); *************** *** 227,233 **** if (sess->opts->server && sess->rver > 27) { if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { ! ERRX1(sess, "io_lowbuffer_alloc"); return 0; } io_lowbuffer_int(sess, *wb, &pos, *wbsz, -1); --- 227,233 ---- if (sess->opts->server && sess->rver > 27) { if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { ! ERRX1("io_lowbuffer_alloc"); return 0; } io_lowbuffer_int(sess, *wb, &pos, *wbsz, -1); *************** *** 235,244 **** up->stat.curst = BLKSTAT_PHASE; } else if (sess->opts->dry_run) { if (!sess->opts->server) ! LOG1(sess, "%s", fl[up->cur->idx].wpath); if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { ! ERRX1(sess, "io_lowbuffer_alloc"); return 0; } io_lowbuffer_int(sess, *wb, &pos, *wbsz, up->cur->idx); --- 235,244 ---- up->stat.curst = BLKSTAT_PHASE; } else if (sess->opts->dry_run) { if (!sess->opts->server) ! LOG1("%s", fl[up->cur->idx].wpath); if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, isz)) { ! ERRX1("io_lowbuffer_alloc"); return 0; } io_lowbuffer_int(sess, *wb, &pos, *wbsz, up->cur->idx); *************** *** 253,269 **** */ if (!sess->opts->server) ! LOG1(sess, "%s", fl[up->cur->idx].wpath); if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, 20)) { ! ERRX1(sess, "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", fl[up->cur->idx].path, (intmax_t)up->cur->blks->size); up->stat.curst = BLKSTAT_NEXT; } --- 253,269 ---- */ if (!sess->opts->server) ! LOG1("%s", fl[up->cur->idx].wpath); if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, 20)) { ! 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("%s: primed for %jd B total", fl[up->cur->idx].path, (intmax_t)up->cur->blks->size); up->stat.curst = BLKSTAT_NEXT; } *************** *** 289,295 **** if (idx == -1) { if ((s = calloc(1, sizeof(struct send_dl))) == NULL) { ! ERR(sess, "calloc"); return 0; } s->idx = -1; --- 289,295 ---- if (idx == -1) { if ((s = calloc(1, sizeof(struct send_dl))) == NULL) { ! ERR("calloc"); return 0; } s->idx = -1; *************** *** 301,325 **** /* Validate the index. */ if (idx < 0 || (uint32_t)idx >= flsz) { ! ERRX(sess, "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 " "directory: %s", fl[idx].path); return 0; } else if (S_ISLNK(fl[idx].st.mode)) { ! ERRX(sess, "blocks requested for " "symlink: %s", fl[idx].path); return 0; } else if (!S_ISREG(fl[idx].st.mode)) { ! ERRX(sess, "blocks requested for " "special: %s", fl[idx].path); return 0; } if ((s = calloc(1, sizeof(struct send_dl))) == NULL) { ! ERR(sess, "callloc"); return 0; } s->idx = idx; --- 301,325 ---- /* Validate the index. */ if (idx < 0 || (uint32_t)idx >= flsz) { ! ERRX("file index out of bounds: invalid %d out of %zu", idx, flsz); return 0; } else if (S_ISDIR(fl[idx].st.mode)) { ! ERRX("blocks requested for " "directory: %s", fl[idx].path); return 0; } else if (S_ISLNK(fl[idx].st.mode)) { ! ERRX("blocks requested for " "symlink: %s", fl[idx].path); return 0; } else if (!S_ISREG(fl[idx].st.mode)) { ! ERRX("blocks requested for " "special: %s", fl[idx].path); return 0; } if ((s = calloc(1, sizeof(struct send_dl))) == NULL) { ! ERR("callloc"); return 0; } s->idx = idx; *************** *** 335,341 **** if (!sess->opts->dry_run) { s->blks = blk_recv(sess, fd, fl[idx].path); if (s->blks == NULL) { ! ERRX1(sess, "blk_recv"); return 0; } } --- 335,341 ---- if (!sess->opts->dry_run) { s->blks = blk_recv(sess, fd, fl[idx].path); if (s->blks == NULL) { ! ERRX1("blk_recv"); return 0; } } *************** *** 371,377 **** ssize_t ssz; if (pledge("stdio getpw rpath unveil", NULL) == -1) { ! ERR(sess, "pledge"); return 0; } --- 371,377 ---- ssize_t ssz; if (pledge("stdio getpw rpath unveil", NULL) == -1) { ! ERR("pledge"); return 0; } *************** *** 387,393 **** */ if (!flist_gen(sess, argc, argv, &fl, &flsz)) { ! ERRX1(sess, "flist_gen"); goto out; } --- 387,393 ---- */ if (!flist_gen(sess, argc, argv, &fl, &flsz)) { ! ERRX1("flist_gen"); goto out; } *************** *** 395,401 **** if (!sess->opts->server && sess->opts->del && !io_write_int(sess, fdout, 0)) { ! ERRX1(sess, "io_write_int"); goto out; } --- 395,401 ---- if (!sess->opts->server && sess->opts->del && !io_write_int(sess, fdout, 0)) { ! ERRX1("io_write_int"); goto out; } *************** *** 405,425 **** */ if (!flist_send(sess, fdin, fdout, fl, flsz)) { ! ERRX1(sess, "flist_send"); goto out; } else if (!io_write_int(sess, fdout, 0)) { ! ERRX1(sess, "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"); rc = 1; goto out; } else if (!sess->opts->server) ! LOG1(sess, "Transfer starting: %zu files", flsz); /* * If we're the server, read our exclusion list. --- 405,425 ---- */ if (!flist_send(sess, fdin, fdout, fl, flsz)) { ! ERRX1("flist_send"); goto out; } else if (!io_write_int(sess, fdout, 0)) { ! ERRX1("io_write_int"); goto out; } /* Exit if we're the server with zero files. */ if (flsz == 0 && sess->opts->server) { ! WARNX("sender has empty file list: exiting"); rc = 1; goto out; } else if (!sess->opts->server) ! LOG1("Transfer starting: %zu files", flsz); /* * If we're the server, read our exclusion list. *************** *** 428,437 **** if (sess->opts->server) { if (!io_read_size(sess, fdin, &excl)) { ! ERRX1(sess, "io_read_size"); goto out; } else if (excl != 0) { ! ERRX1(sess, "exclusion list is non-empty"); goto out; } } --- 428,437 ---- if (sess->opts->server) { if (!io_read_size(sess, fdin, &excl)) { ! ERRX1("io_read_size"); goto out; } else if (excl != 0) { ! ERRX1("exclusion list is non-empty"); goto out; } } *************** *** 452,469 **** for (;;) { assert(pfd[0].fd != -1); if ((c = poll(pfd, 3, POLL_TIMEOUT)) == -1) { ! ERR(sess, "poll"); goto out; } else if (c == 0) { ! ERRX(sess, "poll: timeout"); goto out; } for (i = 0; i < 3; i++) if (pfd[i].revents & (POLLERR|POLLNVAL)) { ! ERRX(sess, "poll: bad fd"); goto out; } else if (pfd[i].revents & POLLHUP) { ! ERRX(sess, "poll: hangup"); goto out; } --- 452,469 ---- for (;;) { assert(pfd[0].fd != -1); if ((c = poll(pfd, 3, POLL_TIMEOUT)) == -1) { ! ERR("poll"); goto out; } else if (c == 0) { ! ERRX("poll: timeout"); goto out; } for (i = 0; i < 3; i++) if (pfd[i].revents & (POLLERR|POLLNVAL)) { ! ERRX("poll: bad fd"); goto out; } else if (pfd[i].revents & POLLHUP) { ! ERRX("poll: hangup"); goto out; } *************** *** 477,488 **** if (sess->mplex_reads && (pfd[0].revents & POLLIN)) { if (!io_read_flush(sess, fdin)) { ! ERRX1(sess, "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"); goto out; } else if (c > 0) continue; --- 477,488 ---- if (sess->mplex_reads && (pfd[0].revents & POLLIN)) { if (!io_read_flush(sess, fdin)) { ! ERRX1("io_read_flush"); goto out; } else if (sess->mplex_read_remain == 0) { c = io_read_check(sess, fdin); if (c < 0) { ! ERRX1("io_read_check"); goto out; } else if (c > 0) continue; *************** *** 499,515 **** if (pfd[0].revents & POLLIN) { if (!io_read_int(sess, fdin, &idx)) { ! ERRX1(sess, "io_read_int"); goto out; } if (!send_dl_enqueue(sess, &sdlq, idx, fl, flsz, fdin)) { ! ERRX1(sess, "send_dl_enqueue"); goto out; } c = io_read_check(sess, fdin); if (c < 0) { ! ERRX1(sess, "io_read_check"); goto out; } else if (c > 0) continue; --- 499,515 ---- if (pfd[0].revents & POLLIN) { if (!io_read_int(sess, fdin, &idx)) { ! ERRX1("io_read_int"); goto out; } if (!send_dl_enqueue(sess, &sdlq, idx, fl, flsz, fdin)) { ! ERRX1("send_dl_enqueue"); goto out; } c = io_read_check(sess, fdin); if (c < 0) { ! ERRX1("io_read_check"); goto out; } else if (c > 0) continue; *************** *** 531,537 **** f = &fl[up.cur->idx]; if (fstat(up.stat.fd, &st) == -1) { ! ERR(sess, "%s: fstat", f->path); goto out; } --- 531,537 ---- f = &fl[up.cur->idx]; if (fstat(up.stat.fd, &st) == -1) { ! ERR("%s: fstat", f->path); goto out; } *************** *** 547,553 **** up.stat.mapsz, PROT_READ, MAP_SHARED, up.stat.fd, 0); if (up.stat.map == MAP_FAILED) { ! ERR(sess, "%s: mmap", f->path); goto out; } } --- 547,553 ---- up.stat.mapsz, PROT_READ, MAP_SHARED, up.stat.fd, 0); if (up.stat.map == MAP_FAILED) { ! ERR("%s: mmap", f->path); goto out; } } *************** *** 570,576 **** ssz = write(fdout, wbuf + wbufpos, wbufsz - wbufpos); if (ssz < 0) { ! ERR(sess, "write"); goto out; } wbufpos += ssz; --- 570,576 ---- ssz = write(fdout, wbuf + wbufpos, wbufsz - wbufpos); if (ssz < 0) { ! ERR("write"); goto out; } wbufpos += ssz; *************** *** 593,599 **** assert(wbufpos == 0 && wbufsz == 0); if (!send_up_fsm(sess, &phase, &up, &wbuf, &wbufsz, &wbufmax, fl)) { ! ERRX1(sess, "send_up_fsm"); goto out; } else if (phase > 1) break; --- 593,599 ---- assert(wbufpos == 0 && wbufsz == 0); if (!send_up_fsm(sess, &phase, &up, &wbuf, &wbufsz, &wbufmax, fl)) { ! ERRX1("send_up_fsm"); goto out; } else if (phase > 1) break; *************** *** 645,651 **** 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); goto out; } pfd[2].fd = up.stat.fd; --- 645,651 ---- up.stat.fd = open(fl[up.cur->idx].path, O_RDONLY|O_NONBLOCK, 0); if (up.stat.fd == -1) { ! ERR("%s: open", fl[up.cur->idx].path); goto out; } pfd[2].fd = up.stat.fd; *************** *** 653,678 **** } if (!TAILQ_EMPTY(&sdlq)) { ! ERRX(sess, "phases complete with files still queued"); goto out; } if (!sess_stats_send(sess, fdout)) { ! ERRX1(sess, "sess_stats_end"); goto out; } /* Final "goodbye" message. */ if (!io_read_int(sess, fdin, &idx)) { ! ERRX1(sess, "io_read_int"); goto out; } else if (idx != -1) { ! ERRX(sess, "read incorrect update complete ack"); goto out; } ! LOG2(sess, "sender finished updating"); rc = 1; out: send_up_reset(&up); --- 653,678 ---- } if (!TAILQ_EMPTY(&sdlq)) { ! ERRX("phases complete with files still queued"); goto out; } if (!sess_stats_send(sess, fdout)) { ! ERRX1("sess_stats_end"); goto out; } /* Final "goodbye" message. */ if (!io_read_int(sess, fdin, &idx)) { ! ERRX1("io_read_int"); goto out; } else if (idx != -1) { ! ERRX("read incorrect update complete ack"); goto out; } ! LOG2("sender finished updating"); rc = 1; out: send_up_reset(&up);