version 1.1, 2019/02/10 23:18:28 |
version 1.2, 2019/02/10 23:24:14 |
|
|
PFD__MAX |
PFD__MAX |
}; |
}; |
|
|
/* |
/* |
* Pledges: unveil, rpath, cpath, wpath, stdio, fattr. |
* Pledges: unveil, rpath, cpath, wpath, stdio, fattr. |
* Pledges (dry-run): -cpath, -wpath, -fattr. |
* Pledges (dry-run): -cpath, -wpath, -fattr. |
*/ |
*/ |
|
|
size_t i, flsz = 0, dflsz = 0, excl; |
size_t i, flsz = 0, dflsz = 0, excl; |
char *tofree; |
char *tofree; |
int rc = 0, dfd = -1, phase = 0, c; |
int rc = 0, dfd = -1, phase = 0, c; |
int32_t ioerror; |
int32_t ioerror; |
struct pollfd pfd[PFD__MAX]; |
struct pollfd pfd[PFD__MAX]; |
struct download *dl = NULL; |
struct download *dl = NULL; |
struct upload *ul = NULL; |
struct upload *ul = NULL; |
mode_t oumask; |
mode_t oumask; |
|
|
if (-1 == pledge("unveil rpath cpath wpath stdio fattr", NULL)) { |
if (-1 == pledge("unveil rpath cpath wpath stdio fattr", NULL)) { |
|
|
if ( ! flist_recv(sess, fdin, &fl, &flsz)) { |
if ( ! flist_recv(sess, fdin, &fl, &flsz)) { |
ERRX1(sess, "flist_recv"); |
ERRX1(sess, "flist_recv"); |
goto out; |
goto out; |
} |
} |
|
|
/* The IO error is sent after the file list. */ |
/* The IO error is sent after the file list. */ |
|
|
if ( ! io_read_int(sess, fdin, &ioerror)) { |
if ( ! io_read_int(sess, fdin, &ioerror)) { |
|
|
* unveil. |
* unveil. |
*/ |
*/ |
|
|
if (sess->opts->del && |
if (sess->opts->del && |
sess->opts->recursive && |
sess->opts->recursive && |
! flist_gen_dels(sess, root, &dfl, &dflsz, fl, flsz)) { |
! flist_gen_dels(sess, root, &dfl, &dflsz, fl, flsz)) { |
ERRX1(sess, "flist_gen_local"); |
ERRX1(sess, "flist_gen_local"); |
|
|
pfd[PFD_DOWNLOADER_IN].events = POLLIN; |
pfd[PFD_DOWNLOADER_IN].events = POLLIN; |
pfd[PFD_SENDER_OUT].events = POLLOUT; |
pfd[PFD_SENDER_OUT].events = POLLOUT; |
|
|
ul = upload_alloc(sess, dfd, fdout, |
ul = upload_alloc(sess, dfd, fdout, |
CSUM_LENGTH_PHASE1, fl, flsz, oumask); |
CSUM_LENGTH_PHASE1, fl, flsz, oumask); |
if (NULL == ul) { |
if (NULL == ul) { |
ERRX1(sess, "upload_alloc"); |
ERRX1(sess, "upload_alloc"); |
|
|
if (-1 == (c = poll(pfd, PFD__MAX, INFTIM))) { |
if (-1 == (c = poll(pfd, PFD__MAX, INFTIM))) { |
ERR(sess, "poll"); |
ERR(sess, "poll"); |
goto out; |
goto out; |
} |
} |
|
|
for (i = 0; i < PFD__MAX; i++) |
for (i = 0; i < PFD__MAX; i++) |
if (pfd[i].revents & (POLLERR|POLLNVAL)) { |
if (pfd[i].revents & (POLLERR|POLLNVAL)) { |
ERRX(sess, "poll: bad fd"); |
ERRX(sess, "poll: bad fd"); |
goto out; |
goto out; |
|
|
|
|
if ((POLLIN & pfd[PFD_UPLOADER_IN].revents) || |
if ((POLLIN & pfd[PFD_UPLOADER_IN].revents) || |
(POLLOUT & pfd[PFD_SENDER_OUT].revents)) { |
(POLLOUT & pfd[PFD_SENDER_OUT].revents)) { |
c = rsync_uploader(ul, |
c = rsync_uploader(ul, |
&pfd[PFD_UPLOADER_IN].fd, |
&pfd[PFD_UPLOADER_IN].fd, |
sess, &pfd[PFD_SENDER_OUT].fd); |
sess, &pfd[PFD_SENDER_OUT].fd); |
if (c < 0) { |
if (c < 0) { |
ERRX1(sess, "rsync_uploader"); |
ERRX1(sess, "rsync_uploader"); |
|
|
} |
} |
} |
} |
|
|
/* |
/* |
* We need to run the downloader when we either have |
* We need to run the downloader when we either have |
* read events from the sender or an asynchronous local |
* read events from the sender or an asynchronous local |
* open is ready. |
* open is ready. |
|
|
* messages, which will otherwise clog up the pipes. |
* messages, which will otherwise clog up the pipes. |
*/ |
*/ |
|
|
if ((POLLIN & pfd[PFD_SENDER_IN].revents) || |
if ((POLLIN & pfd[PFD_SENDER_IN].revents) || |
(POLLIN & pfd[PFD_DOWNLOADER_IN].revents)) { |
(POLLIN & pfd[PFD_DOWNLOADER_IN].revents)) { |
c = rsync_downloader(dl, sess, |
c = rsync_downloader(dl, sess, |
&pfd[PFD_DOWNLOADER_IN].fd); |
&pfd[PFD_DOWNLOADER_IN].fd); |
if (c < 0) { |
if (c < 0) { |
ERRX1(sess, "rsync_downloader"); |
ERRX1(sess, "rsync_downloader"); |
|
|
* here we should bump our checksum length and |
* here we should bump our checksum length and |
* go into the second phase. |
* go into the second phase. |
*/ |
*/ |
} |
} |
} |
} |
|
|
/* Properly close us out by progressing through the phases. */ |
/* Properly close us out by progressing through the phases. */ |