version 1.27, 2025/06/30 01:44:28 |
version 1.29, 2025/06/30 12:23:42 |
|
|
#include <sys/socket.h> |
#include <sys/socket.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
|
|
|
#include <assert.h> |
#if HAVE_ERR |
#if HAVE_ERR |
#include <err.h> |
#include <err.h> |
#endif |
#endif |
Line 169 process_manpage(int srv_fd, int dstdir_fd, const char |
|
Line 170 process_manpage(int srv_fd, int dstdir_fd, const char |
|
int |
int |
process_tree(int srv_fd, int dstdir_fd) |
process_tree(int srv_fd, int dstdir_fd) |
{ |
{ |
|
const struct timespec timeout = { 0, 10000000 }; /* 0.01 s */ |
|
const int max_inflight = 16; |
|
|
FTS *ftsp; |
FTS *ftsp; |
FTSENT *entry; |
FTSENT *entry; |
const char *argv[2]; |
const char *argv[2]; |
const char *path; |
const char *path; |
int fatal; |
int inflight, irc, decr, fatal; |
int gooddirs, baddirs, goodfiles, badfiles; |
int gooddirs, baddirs, goodfiles, badfiles; |
|
char dummy[1]; |
|
|
argv[0] = "."; |
argv[0] = "."; |
argv[1] = (char *)NULL; |
argv[1] = (char *)NULL; |
Line 185 process_tree(int srv_fd, int dstdir_fd) |
|
Line 190 process_tree(int srv_fd, int dstdir_fd) |
|
return -1; |
return -1; |
} |
} |
|
|
fatal = 0; |
if (verbose_flag >= 2) { |
gooddirs = baddirs = goodfiles = badfiles = 0; |
warnx("allowing up to %d files in flight", max_inflight); |
|
fflush(stderr); |
|
} |
|
inflight = fatal = gooddirs = baddirs = goodfiles = badfiles = 0; |
while (fatal == 0 && got_signal == 0 && |
while (fatal == 0 && got_signal == 0 && |
(entry = fts_read(ftsp)) != NULL) { |
(entry = fts_read(ftsp)) != NULL) { |
|
if (inflight >= max_inflight) { |
|
while (recv(srv_fd, dummy, sizeof(dummy), 0) == -1) { |
|
if (errno != EAGAIN) { |
|
warn("FATAL: recv"); |
|
fatal = errno; |
|
break; |
|
} |
|
nanosleep(&timeout, NULL); |
|
} |
|
if (fatal != 0) |
|
break; |
|
decr = 1; |
|
while ((irc = recv(srv_fd, dummy, sizeof(dummy), |
|
MSG_DONTWAIT)) > 0) |
|
decr++; |
|
assert(inflight >= decr); |
|
if (verbose_flag >= 2 && decr > 1) { |
|
warnx("files in flight: %d - %d = %d", |
|
inflight, decr, inflight - decr); |
|
fflush(stderr); |
|
} |
|
inflight -= decr; |
|
if (irc == 0) { |
|
errno = ECONNRESET; |
|
inflight = -1; |
|
} |
|
if (errno != EAGAIN) { |
|
warn("FATAL: recv"); |
|
fatal = errno; |
|
break; |
|
} |
|
} |
path = entry->fts_path + 2; |
path = entry->fts_path + 2; |
switch (entry->fts_info) { |
switch (entry->fts_info) { |
case FTS_F: |
case FTS_F: |
Line 201 process_tree(int srv_fd, int dstdir_fd) |
|
Line 241 process_tree(int srv_fd, int dstdir_fd) |
|
break; |
break; |
default: |
default: |
goodfiles++; |
goodfiles++; |
|
inflight++; |
break; |
break; |
} |
} |
break; |
break; |
Line 255 process_tree(int srv_fd, int dstdir_fd) |
|
Line 296 process_tree(int srv_fd, int dstdir_fd) |
|
warnx("FATAL: signal SIG%s", sys_signame[got_signal]); |
warnx("FATAL: signal SIG%s", sys_signame[got_signal]); |
break; |
break; |
} |
} |
|
inflight = -1; |
fatal = 1; |
fatal = 1; |
} else if (fatal == 0 && (fatal = errno) != 0) |
} else if (fatal == 0 && (fatal = errno) != 0) |
warn("FATAL: fts_read"); |
warn("FATAL: fts_read"); |
|
|
fts_close(ftsp); |
fts_close(ftsp); |
|
if (verbose_flag >= 2 && inflight > 0) { |
|
warnx("waiting for %d files in flight", inflight); |
|
fflush(stderr); |
|
} |
|
while (inflight > 0) { |
|
irc = recv(srv_fd, dummy, sizeof(dummy), 0); |
|
if (irc > 0) |
|
inflight--; |
|
else if (irc == -1 && errno == EAGAIN) |
|
nanosleep(&timeout, NULL); |
|
else { |
|
if (irc == 0) |
|
errno = ECONNRESET; |
|
warn("recv"); |
|
inflight = -1; |
|
} |
|
} |
if (verbose_flag) |
if (verbose_flag) |
warnx("processed %d files in %d directories", |
warnx("processed %d files in %d directories", |
goodfiles, gooddirs); |
goodfiles, gooddirs); |
Line 272 process_tree(int srv_fd, int dstdir_fd) |
|
Line 331 process_tree(int srv_fd, int dstdir_fd) |
|
if (fatal != 0) { |
if (fatal != 0) { |
warnx("processing aborted due to fatal error, " |
warnx("processing aborted due to fatal error, " |
"results are probably incomplete"); |
"results are probably incomplete"); |
|
inflight = -1; |
} |
} |
return 0; |
return inflight; |
} |
} |
|
|
int |
int |
Line 297 main(int argc, char **argv) |
|
Line 357 main(int argc, char **argv) |
|
outtype = optarg; |
outtype = optarg; |
break; |
break; |
case 'v': |
case 'v': |
verbose_flag = 1; |
verbose_flag += 1; |
break; |
break; |
default: |
default: |
usage(); |
usage(); |