use PublicInbox::Git qw(read_all);
use Socket qw(SOL_SOCKET SO_TYPE SOCK_SEQPACKET AF_UNIX);
use PublicInbox::DS qw(awaitpid);
+use autodie qw(open);
use POSIX qw(:signal_h);
use Fcntl qw(LOCK_UN LOCK_EX);
my $X = \%PublicInbox::Search::X;
$qry_str // return
warn('usage: dump_roots [OPTIONS] ROOT2ID_FILE QRY_STR');
$req->{A} or return warn('dump_roots requires -A PREFIX');
- open my $fh, '<', $root2id_file or die "open($root2id_file): $!";
+ open my $fh, '<', $root2id_file;
my $root2id; # record format: $OIDHEX "\0" uint32_t
my @x = split(/\0/, read_all($fh));
while (@x) {
PublicInbox::DS::block_signals();
my $req = bless {}, __PACKAGE__;
my $i = 0;
- for my $fd (@fds) {
- open($req->{$i++}, '+<&=', $fd) and next;
- warn("open(+<&=$fd) (FD=$i): $!");
- undef $req;
- last;
- }
- $req or next;
+ open($req->{$i++}, '+<&=', $_) for @fds;
local $stderr = $req->{1} // \*STDERR;
if (chop($rbuf) ne "\0") {
warn "not NUL-terminated";
size_t len = cmsg.hdr.cmsg_len;
int *fdp = (int *)CMSG_DATA(&cmsg.hdr);
size_t i;
- bool fd_ok = true;
for (i = 0; CMSG_LEN((i + 1) * sizeof(int)) <= len; i++) {
int fd = *fdp++;
const char *mode = NULL;
- int fl = fd_ok ? fcntl(fd, F_GETFL) : 0;
- if (fl == 0) {
- continue; // hit previous error
- } else if (fl == -1) {
- warnx("invalid fd=%d", fd);
- fd_ok = false;
+ int fl = fcntl(fd, F_GETFL);
+ if (fl == -1) {
+ errx(EXIT_FAILURE, "invalid fd=%d", fd);
} else if (fl & O_WRONLY) {
mode = "w";
} else if (fl & O_RDWR) {
mode = "r+";
if (i == 0) req->has_input = true;
} else {
- warnx("invalid mode from F_GETFL: 0x%x", fl);
- fd_ok = false;
- }
- if (!fd_ok) {
- xclose(fd);
- } else {
- req->fp[i] = fdopen(fd, mode);
- if (!req->fp[i]) {
- warn("fdopen(fd=%d)", fd);
- fd_ok = false;
- }
+ errx(EXIT_FAILURE,
+ "invalid mode from F_GETFL: 0x%x", fl);
}
+ req->fp[i] = fdopen(fd, mode);
+ if (!req->fp[i])
+ err(EXIT_FAILURE, "fdopen(fd=%d)", fd);
}
- for (i = 0; !fd_ok && i < MY_ARRAY_SIZE(req->fp); i++)
- if (req->fp[i]) fclose(req->fp[i]);
- return fd_ok;
+ return true;
}
- warnx("no FD received in %zd-byte request", r);
+ errx(EXIT_FAILURE, "no FD received in %zd-byte request", r);
return false;
}