commit - 83985e6a8ae699605976783dc7e854050f1bd79f
commit + 3d97effaa4fe16c79f725bf260f06220e62e5c6a
blob - 5b26d6d8645a84a229ccc5481c0b41026ec9b0e2
blob + b8cf3ed84c2bcdb68a3853783af0e070f30dd66a
--- gotd/auth.c
+++ gotd/auth.c
char *username = NULL;
size_t len;
const size_t maxlen = MAX_IMSGSIZE - IMSG_HEADER_SIZE;
+ int fd = -1;
log_debug("authentication request received");
memcpy(&iauth, imsg->data, datalen);
- if (imsg->fd == -1)
+ fd = imsg_get_fd(imsg);
+ if (fd == -1)
return got_error(GOT_ERR_PRIVSEP_NO_FD);
- if (getpeereid(imsg->fd, &euid, &egid) == -1)
+ if (getpeereid(fd, &euid, &egid) == -1)
return got_error_from_errno("getpeerid");
if (iauth.euid != euid)
blob - 3007bcfd7e144bb4bed06fa4aca8ebb8f5606abf
blob + 06930323b2023b42abe628c2dfe3bc4a12762e70
--- gotd/gotd.c
+++ gotd/gotd.c
return got_error(GOT_ERR_PRIVSEP_LEN);
memcpy(&iconnect, imsg->data, sizeof(iconnect));
- s = imsg->fd;
+ s = imsg_get_fd(imsg);
if (s == -1) {
err = got_error(GOT_ERR_PRIVSEP_NO_FD);
goto done;
blob - d061355ea0a84bb5d92a825b752fa8c2914a9a57
blob + 5860623235693f75c4c5c3dae27ad355ee084be1
--- gotd/repo_read.c
+++ gotd/repo_read.c
size_t datalen;
struct gotd_imsg_reflist irefs;
struct imsgbuf ibuf;
- int client_fd = imsg->fd;
+ int client_fd;
struct got_object_id *head_target_id = NULL;
TAILQ_INIT(&refs);
+ client_fd = imsg_get_fd(imsg);
if (client_fd == -1)
return got_error(GOT_ERR_PRIVSEP_NO_FD);
size_t datalen;
log_debug("receiving delta cache file");
-
- if (imsg->fd == -1)
- return got_error(GOT_ERR_PRIVSEP_NO_FD);
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
if (datalen != sizeof(ireq))
if (client->delta_cache_fd != -1)
return got_error(GOT_ERR_PRIVSEP_MSG);
- client->delta_cache_fd = imsg->fd;
+ client->delta_cache_fd = imsg_get_fd(imsg);
+ if (client->delta_cache_fd == -1)
+ return got_error(GOT_ERR_PRIVSEP_NO_FD);
+
client->report_progress = ireq.report_progress;
return NULL;
}
log_debug("receiving pack pipe descriptor");
- if (imsg->fd == -1)
- return got_error(GOT_ERR_PRIVSEP_NO_FD);
-
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
if (datalen != sizeof(ireq))
return got_error(GOT_ERR_PRIVSEP_LEN);
if (client->pack_pipe != -1)
return got_error(GOT_ERR_PRIVSEP_MSG);
- client->pack_pipe = imsg->fd;
+ client->pack_pipe = imsg_get_fd(imsg);
+ if (client->pack_pipe == -1)
+ return got_error(GOT_ERR_PRIVSEP_NO_FD);
+
return NULL;
}
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
if (datalen != 0)
return got_error(GOT_ERR_PRIVSEP_LEN);
- if (imsg->fd == -1)
- return got_error(GOT_ERR_PRIVSEP_NO_FD);
if (repo_read.session_fd != -1)
return got_error(GOT_ERR_PRIVSEP_MSG);
- repo_read.session_fd = imsg->fd;
+ repo_read.session_fd = imsg_get_fd(imsg);
+ if (repo_read.session_fd == -1)
+ return got_error(GOT_ERR_PRIVSEP_NO_FD);
imsg_init(&iev->ibuf, repo_read.session_fd);
iev->handler = repo_read_dispatch_session;
blob - fae40607e756382fd72276604fff6f4a1040c452
blob + 75d16b4a52946182333abe8cc658752b4842b7d3
--- gotd/repo_write.c
+++ gotd/repo_write.c
size_t datalen;
struct gotd_imsg_reflist irefs;
struct imsgbuf ibuf;
- int client_fd = imsg->fd;
+ int client_fd;
TAILQ_INIT(&refs);
+ client_fd = imsg_get_fd(imsg);
if (client_fd == -1)
return got_error(GOT_ERR_PRIVSEP_NO_FD);
return got_error(GOT_ERR_PRIVSEP_NO_FD);
imsg_init(&ibuf, client->fd);
-
- if (imsg->fd == -1)
- return got_error(GOT_ERR_PRIVSEP_NO_FD);
pack = &client->pack;
memset(pack, 0, sizeof(*pack));
- pack->fd = imsg->fd;
+ pack->fd = imsg_get_fd(imsg);
+ if (pack->fd == -1)
+ return got_error(GOT_ERR_PRIVSEP_NO_FD);
+
err = got_delta_cache_alloc(&pack->delta_cache);
if (err)
return err;
log_debug("receiving pack pipe descriptor");
- if (imsg->fd == -1)
- return got_error(GOT_ERR_PRIVSEP_NO_FD);
-
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
if (datalen != sizeof(ireq))
return got_error(GOT_ERR_PRIVSEP_LEN);
if (client->pack_pipe != -1)
return got_error(GOT_ERR_PRIVSEP_MSG);
- client->pack_pipe = imsg->fd;
+ client->pack_pipe = imsg_get_fd(imsg);
+ if (client->pack_pipe == -1)
+ return got_error(GOT_ERR_PRIVSEP_NO_FD);
+
return NULL;
}
log_debug("receiving pack index output file");
- if (imsg->fd == -1)
- return got_error(GOT_ERR_PRIVSEP_NO_FD);
-
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
if (datalen != sizeof(ireq))
return got_error(GOT_ERR_PRIVSEP_LEN);
if (client->packidx_fd != -1)
return got_error(GOT_ERR_PRIVSEP_MSG);
- client->packidx_fd = imsg->fd;
+ client->packidx_fd = imsg_get_fd(imsg);
+ if (client->packidx_fd == -1)
+ return got_error(GOT_ERR_PRIVSEP_NO_FD);
+
return NULL;
}
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
if (datalen != 0)
return got_error(GOT_ERR_PRIVSEP_LEN);
- if (imsg->fd == -1)
- return got_error(GOT_ERR_PRIVSEP_NO_FD);
if (repo_write.session_fd != -1)
return got_error(GOT_ERR_PRIVSEP_MSG);
- repo_write.session_fd = imsg->fd;
+ repo_write.session_fd = imsg_get_fd(imsg);
+ if (repo_write.session_fd == -1)
+ return got_error(GOT_ERR_PRIVSEP_NO_FD);
imsg_init(&iev->ibuf, repo_write.session_fd);
iev->handler = repo_write_dispatch_session;
blob - b9059883b276557469eb6e0eee0207d19e630185
blob + b4c8a49f654b65665982670d9b56b7314a10efd5
--- gotd/session.c
+++ gotd/session.c
if (datalen != sizeof(iconnect))
return got_error(GOT_ERR_PRIVSEP_LEN);
memcpy(&iconnect, imsg->data, sizeof(iconnect));
-
- if (imsg->fd == -1)
- return got_error(GOT_ERR_PRIVSEP_NO_FD);
- client->fd = imsg->fd;
client->euid = iconnect.euid;
client->egid = iconnect.egid;
+ client->fd = imsg_get_fd(imsg);
+ if (client->fd == -1)
+ return got_error(GOT_ERR_PRIVSEP_NO_FD);
imsg_init(&client->iev.ibuf, client->fd);
client->iev.handler = session_dispatch_client;
struct gotd_imsg_connect_repo_child ichild;
struct gotd_session_client *client = &gotd_session_client;
size_t datalen;
+ int fd;
if (client->state != GOTD_STATE_EXPECT_LIST_REFS)
return got_error(GOT_ERR_PRIVSEP_MSG);
return got_error_msg(GOT_ERR_PRIVSEP_MSG,
"bad child process type");
- if (imsg->fd == -1)
+ fd = imsg_get_fd(imsg);
+ if (fd == -1)
return got_error(GOT_ERR_PRIVSEP_NO_FD);
- imsg_init(&client->repo_child_iev.ibuf, imsg->fd);
+ imsg_init(&client->repo_child_iev.ibuf, fd);
client->repo_child_iev.handler = session_dispatch_repo_child;
client->repo_child_iev.events = EV_READ;
client->repo_child_iev.handler_arg = NULL;
blob - 9b76c142f7896c6574ee51aef180f428c3e8480c
blob + eb61f54564d20341ee600522a273544e76a332d5
--- gotwebd/config.c
+++ gotwebd/config.c
/* create a new socket */
if ((sock = calloc(1, sizeof(*sock))) == NULL) {
- if (imsg->fd != -1)
- close(imsg->fd);
return 1;
}
memcpy(&sock->conf, &sock_conf, sizeof(sock->conf));
- sock->fd = imsg->fd;
+ sock->fd = imsg_get_fd(imsg);
TAILQ_INSERT_TAIL(&env->sockets, sock, entry);
{
struct socket *sock;
uint8_t *p = imsg->data;
- int sock_id, match = 0, i;
+ int sock_id, match = 0, i, j;
if (IMSG_DATA_SIZE(imsg) != sizeof(sock_id))
fatalx("%s: wrong size", __func__);
const int nfds = (GOTWEB_PACK_NUM_TEMPFILES + PRIV_FDS__MAX);
for (i = 0; i < nfds; i++) {
if (i < PRIV_FDS__MAX && sock->priv_fd[i] == -1) {
+ sock->priv_fd[i] = imsg_get_fd(imsg);
log_debug("%s: assigning socket %d priv_fd %d",
- __func__, sock_id, imsg->fd);
- sock->priv_fd[i] = imsg->fd;
+ __func__, sock_id, sock->priv_fd[i]);
match = 1;
break;
}
- if (sock->pack_fds[i - PRIV_FDS__MAX] == -1) {
+
+ j = i - PRIV_FDS__MAX;
+ if (sock->pack_fds[j] == -1) {
+ sock->pack_fds[j] = imsg_get_fd(imsg);
log_debug("%s: assigning socket %d pack_fd %d",
- __func__, sock_id, imsg->fd);
- sock->pack_fds[i - PRIV_FDS__MAX] = imsg->fd;
+ __func__, sock_id, sock->pack_fds[j]);
match = 1;
break;
}
blob - ee38a8cc66e5006ea0943dbbdd1e278ab7549fd3
blob + efc694b36944f601e4a9ce7d58e37865850e5689
--- lib/serve.c
+++ lib/serve.c
{
const struct got_error *err;
struct imsg imsg;
+ int fd;
*packfd = -1;
err = gotd_imsg_recv_error(NULL, &imsg);
break;
case GOTD_IMSG_PACKFILE_PIPE:
- if (imsg.fd != -1)
- *packfd = imsg.fd;
+ fd = imsg_get_fd(&imsg);
+ if (fd != -1)
+ *packfd = fd;
else
err = got_error(GOT_ERR_PRIVSEP_NO_FD);
break;
if (datalen != 0)
return got_error(GOT_ERR_PRIVSEP_MSG);
- if (imsg->fd == -1)
+ packfd = imsg_get_fd(imsg);
+ if (packfd == -1)
return got_error(GOT_ERR_PRIVSEP_NO_FD);
- packfd = imsg->fd;
while (!pack_done) {
ssize_t r = 0;
blob - 33229996cb6bb8c8db24c52a6631b833be22b3a5
blob + c85fb402c902f5fda8a01743ae051712444ced6e
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
goto done;
}
memcpy(&fetch_req, imsg.data, sizeof(fetch_req));
- fetchfd = imsg.fd;
+ fetchfd = imsg_get_fd(&imsg);
if (datalen != sizeof(fetch_req) +
fetch_req.worktree_branch_len + fetch_req.remote_head_len) {
err = got_error(GOT_ERR_PRIVSEP_LEN);
goto done;
}
- packfd = imsg.fd;
+ packfd = imsg_get_fd(&imsg);
err = fetch_pack(fetchfd, packfd, pack_sha1, &have_refs,
fetch_req.fetch_all_branches, &wanted_branches,
blob - 85c7a6b22b87d00ea63811681448ccb592e87830
blob + 87bf91f479ea673c698af41e4f037937415b1567
--- libexec/got-index-pack/got-index-pack.c
+++ libexec/got-index-pack/got-index-pack.c
goto done;
}
memcpy(pack_hash, imsg.data, sizeof(pack_hash));
- pack.fd = imsg.fd;
+ pack.fd = imsg_get_fd(&imsg);
err = got_privsep_recv_imsg(&imsg, &ibuf, 0);
if (err)
err = got_error(GOT_ERR_PRIVSEP_LEN);
goto done;
}
- idxfd = imsg.fd;
+ idxfd = imsg_get_fd(&imsg);
for (i = 0; i < nitems(tmpfiles); i++) {
err = got_privsep_recv_imsg(&imsg, &ibuf, 0);
err = got_error(GOT_ERR_PRIVSEP_LEN);
goto done;
}
- tmpfd = imsg.fd;
+ tmpfd = imsg_get_fd(&imsg);
tmpfiles[i] = fdopen(tmpfd, "w+");
if (tmpfiles[i] == NULL) {
err = got_error_from_errno("fdopen");
blob - 1b8716f656c76d4d70c14bbcc33c627b7d30b3ce
blob + e9efb90c2107143711b3b4283142f00087f5eba9
--- libexec/got-read-blob/got-read-blob.c
+++ libexec/got-read-blob/got-read-blob.c
for (;;) {
struct imsg imsg, imsg_outfd;
FILE *f = NULL;
+ int fd = -1, outfd = -1;
size_t size;
struct got_object *obj = NULL;
uint8_t *buf = NULL;
csum.output_ctx = &ctx;
memset(&imsg, 0, sizeof(imsg));
- imsg.fd = -1;
memset(&imsg_outfd, 0, sizeof(imsg_outfd));
- imsg_outfd.fd = -1;
if (sigint_received) {
err = got_error(GOT_ERR_CANCELLED);
}
memcpy(&expected_id, imsg.data, sizeof(expected_id));
- if (imsg.fd == -1) {
+ fd = imsg_get_fd(&imsg);
+ if (fd == -1) {
err = got_error(GOT_ERR_PRIVSEP_NO_FD);
goto done;
}
err = got_error(GOT_ERR_PRIVSEP_LEN);
goto done;
}
- if (imsg_outfd.fd == -1) {
+ outfd = imsg_get_fd(&imsg_outfd);
+ if (outfd == -1) {
err = got_error(GOT_ERR_PRIVSEP_NO_FD);
goto done;
}
- err = got_object_read_header(&obj, imsg.fd);
+ err = got_object_read_header(&obj, fd);
if (err)
goto done;
- if (lseek(imsg.fd, SEEK_SET, 0) == -1) {
+ if (lseek(fd, SEEK_SET, 0) == -1) {
err = got_error_from_errno("lseek");
goto done;
}
- f = fdopen(imsg.fd, "rb");
+ f = fdopen(fd, "rb");
if (f == NULL) {
err = got_error_from_errno("fdopen");
goto done;
if (err)
goto done;
} else {
- err = got_inflate_to_fd(&size, f, &csum, imsg_outfd.fd);
+ err = got_inflate_to_fd(&size, f, &csum, outfd);
if (err)
goto done;
}
if (f) {
if (fclose(f) == EOF && err == NULL)
err = got_error_from_errno("fclose");
- } else if (imsg.fd != -1) {
- if (close(imsg.fd) == -1 && err == NULL)
+ } else if (fd != -1) {
+ if (close(fd) == -1 && err == NULL)
err = got_error_from_errno("close");
}
- if (imsg_outfd.fd != -1) {
- if (close(imsg_outfd.fd) == -1 && err == NULL)
+ if (outfd != -1) {
+ if (close(outfd) == -1 && err == NULL)
err = got_error_from_errno("close");
}
blob - cdd1a966e34a11d85d27e9e65b280de9e8c735b7
blob + 3626bf63eb05a8178334d20bc4d1e4649d1b9c17
--- libexec/got-read-commit/got-read-commit.c
+++ libexec/got-read-commit/got-read-commit.c
struct imsg imsg;
struct got_commit_object *commit = NULL;
struct got_object_id expected_id;
+ int fd = -1;
if (sigint_received) {
err = got_error(GOT_ERR_CANCELLED);
}
memcpy(&expected_id, imsg.data, sizeof(expected_id));
- if (imsg.fd == -1) {
+ fd = imsg_get_fd(&imsg);
+ if (fd == -1) {
err = got_error(GOT_ERR_PRIVSEP_NO_FD);
goto done;
}
- err = got_object_read_commit(&commit, imsg.fd, &expected_id, 0);
+ err = got_object_read_commit(&commit, fd, &expected_id, 0);
if (err)
goto done;
err = got_privsep_send_commit(&ibuf, commit);
got_object_commit_close(commit);
done:
- if (imsg.fd != -1 && close(imsg.fd) == -1 && err == NULL)
+ if (fd != -1 && close(fd) == -1 && err == NULL)
err = got_error_from_errno("close");
imsg_free(&imsg);
if (err)
blob - bb635b215634101143c5a58e5accde6ed94389f5
blob + 6c8b57b3facca5b9dcc832edc6f66a039c44c654
--- libexec/got-read-gitconfig/got-read-gitconfig.c
+++ libexec/got-read-gitconfig/got-read-gitconfig.c
for (;;) {
struct imsg imsg;
+ int fd = -1;
memset(&imsg, 0, sizeof(imsg));
- imsg.fd = -1;
if (sigint_received) {
err = got_error(GOT_ERR_CANCELLED);
err = got_error(GOT_ERR_PRIVSEP_LEN);
break;
}
- if (imsg.fd == -1){
+ fd = imsg_get_fd(&imsg);
+ if (fd == -1) {
err = got_error(GOT_ERR_PRIVSEP_NO_FD);
break;
}
if (gitconfig)
got_gitconfig_close(gitconfig);
- err = got_gitconfig_open(&gitconfig, imsg.fd);
+ err = got_gitconfig_open(&gitconfig, fd);
break;
case GOT_IMSG_GITCONFIG_REPOSITORY_FORMAT_VERSION_REQUEST:
err = gitconfig_num_request(&ibuf, gitconfig, "core",
break;
}
- if (imsg.fd != -1) {
- if (close(imsg.fd) == -1 && err == NULL)
+ if (fd != -1) {
+ if (close(fd) == -1 && err == NULL)
err = got_error_from_errno("close");
}
blob - 3059b04c7096a2c0e70448da106d41c4d9ea6530
blob + 56d436f414c7ef9f23bd78db1d42297ca021c18a
--- libexec/got-read-gotconfig/got-read-gotconfig.c
+++ libexec/got-read-gotconfig/got-read-gotconfig.c
for (;;) {
struct imsg imsg;
+ int fd = -1;
memset(&imsg, 0, sizeof(imsg));
- imsg.fd = -1;
if (sigint_received) {
err = got_error(GOT_ERR_CANCELLED);
err = got_error(GOT_ERR_PRIVSEP_LEN);
break;
}
- if (imsg.fd == -1){
+ fd = imsg_get_fd(&imsg);
+ if (fd == -1){
err = got_error(GOT_ERR_PRIVSEP_NO_FD);
break;
}
if (gotconfig)
gotconfig_free(gotconfig);
- err = gotconfig_parse(&gotconfig, filename, &imsg.fd);
+ err = gotconfig_parse(&gotconfig, filename, &fd);
if (err)
break;
err = validate_config(gotconfig);
break;
}
- if (imsg.fd != -1) {
- if (close(imsg.fd) == -1 && err == NULL)
+ if (fd != -1) {
+ if (close(fd) == -1 && err == NULL)
err = got_error_from_errno("close");
}
blob - f32cb7bfb6961e17dda8f36484ee88cedf52059f
blob + 617c9f4bf78b4fb4843546569061e3c6fc6c7c0b
--- libexec/got-read-object/got-read-object.c
+++ libexec/got-read-object/got-read-object.c
#endif
for (;;) {
+ int fd = -1, outfd = -1;
+
if (sigint_received) {
err = got_error(GOT_ERR_CANCELLED);
break;
}
memcpy(&expected_id, imsg.data, sizeof(expected_id));
- if (imsg.fd == -1) {
+ fd = imsg_get_fd(&imsg);
+ if (fd == -1) {
err = got_error(GOT_ERR_PRIVSEP_NO_FD);
goto done;
}
- err = got_object_read_header(&obj, imsg.fd);
+ err = got_object_read_header(&obj, fd);
if (err)
goto done;
imsg_free(&imsg_outfd);
goto done;
}
- if (imsg_outfd.fd == -1) {
+ outfd = imsg_get_fd(&imsg_outfd);
+ if (outfd == -1) {
err = got_error(GOT_ERR_PRIVSEP_NO_FD);
imsg_free(&imsg_outfd);
goto done;
}
err = send_raw_obj(&ibuf, obj, &expected_id,
- imsg.fd, imsg_outfd.fd);
- imsg.fd = -1; /* imsg.fd is owned by send_raw_obj() */
- if (close(imsg_outfd.fd) == -1 && err == NULL)
+ fd, outfd);
+ fd = -1; /* fd is owned by send_raw_obj() */
+ if (close(outfd) == -1 && err == NULL)
err = got_error_from_errno("close");
imsg_free(&imsg_outfd);
if (err)
} else
err = got_privsep_send_obj(&ibuf, obj);
done:
- if (imsg.fd != -1 && close(imsg.fd) == -1 && err == NULL)
+ if (fd != -1 && close(fd) == -1 && err == NULL)
err = got_error_from_errno("close");
imsg_free(&imsg);
if (obj)
blob - 896cda68aacfa5e72656423d26a4cd8b962d04f1
blob + 00bb589bc2faa0903e3a4664d5d35bf948fa0aec
--- libexec/got-read-pack/got-read-pack.c
+++ libexec/got-read-pack/got-read-pack.c
const struct got_error *err;
struct imsg imsg;
size_t datalen;
+ int fd;
err = got_privsep_recv_imsg(&imsg, ibuf, 0);
if (err)
err = got_error(GOT_ERR_PRIVSEP_LEN);
goto done;
}
- if (imsg.fd == -1) {
+ fd = imsg_get_fd(&imsg);
+ if (fd == -1) {
err = got_error(GOT_ERR_PRIVSEP_NO_FD);
goto done;
}
- *f = fdopen(imsg.fd, "w+");
+ *f = fdopen(fd, "w+");
if (*f == NULL) {
err = got_error_from_errno("fdopen");
- close(imsg.fd);
+ close(fd);
goto done;
}
done:
receive_tempfile(FILE **f, const char *mode, struct imsg *imsg,
struct imsgbuf *ibuf)
{
+ const struct got_error *err;
size_t datalen;
+ int fd;
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
if (datalen != 0)
return got_error(GOT_ERR_PRIVSEP_LEN);
- if (imsg->fd == -1)
+ fd = imsg_get_fd(imsg);
+ if (fd == -1)
return got_error(GOT_ERR_PRIVSEP_NO_FD);
- *f = fdopen(imsg->fd, mode);
- if (*f == NULL)
- return got_error_from_errno("fdopen");
- imsg->fd = -1;
+ *f = fdopen(fd, mode);
+ if (*f == NULL) {
+ err = got_error_from_errno("fdopen");
+ close(fd);
+ return err;
+ }
return NULL;
}
memcpy(&req, imsg->data, sizeof(req));
memcpy(&id, &req.id, sizeof(id));
- imsg->fd = -1;
-
err = got_packfile_extract_raw_delta(&delta_buf, &delta_size,
&delta_compressed_size, &delta_offset, &delta_data_offset,
&base_offset, &base_id, &base_size, &result_size,
goto done;
}
- if (imsg.fd == -1) {
- err = got_error(GOT_ERR_PRIVSEP_NO_FD);
- goto done;
- }
-
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
if (datalen != sizeof(ipackidx)) {
err = got_error(GOT_ERR_PRIVSEP_LEN);
}
memcpy(&ipackidx, imsg.data, sizeof(ipackidx));
+ p->fd = imsg_get_fd(&imsg);
p->len = ipackidx.len;
- p->fd = dup(imsg.fd);
if (p->fd == -1) {
- err = got_error_from_errno("dup");
+ err = got_error(GOT_ERR_PRIVSEP_NO_FD);
goto done;
}
if (lseek(p->fd, 0, SEEK_SET) == -1) {
err = got_packidx_init_hdr(p, 1, ipackidx.packfile_size);
done:
if (err) {
- if (imsg.fd != -1)
- close(imsg.fd);
- got_packidx_close(p);
+ if (p != NULL)
+ got_packidx_close(p);
} else
*packidx = p;
imsg_free(&imsg);
goto done;
}
- if (imsg.fd == -1) {
- err = got_error(GOT_ERR_PRIVSEP_NO_FD);
- goto done;
- }
-
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
if (datalen != sizeof(ipack)) {
err = got_error(GOT_ERR_PRIVSEP_LEN);
memcpy(&ipack, imsg.data, sizeof(ipack));
pack->filesize = ipack.filesize;
- pack->fd = dup(imsg.fd);
+ pack->fd = imsg_get_fd(&imsg);
if (pack->fd == -1) {
- err = got_error_from_errno("dup");
+ err = got_error(GOT_ERR_PRIVSEP_NO_FD);
goto done;
}
if (lseek(pack->fd, 0, SEEK_SET) == -1) {
#endif
done:
if (err) {
- if (imsg.fd != -1)
- close(imsg.fd);
- free(pack);
+ if (pack != NULL)
+ got_pack_close(pack);
} else
*packp = pack;
imsg_free(&imsg);
}
for (;;) {
- imsg.fd = -1;
-
if (sigint_received) {
err = got_error(GOT_ERR_CANCELLED);
break;
break;
}
- if (imsg.hdr.type == GOT_IMSG_STOP)
+ if (imsg.hdr.type == GOT_IMSG_STOP) {
+ imsg_free(&imsg);
break;
+ }
switch (imsg.hdr.type) {
case GOT_IMSG_TMPFD:
break;
}
- if (imsg.fd != -1 && close(imsg.fd) == -1 && err == NULL)
- err = got_error_from_errno("close");
imsg_free(&imsg);
if (err)
break;
blob - dec83c1a875916235977245236b2aa9d6bcf2b03
blob + e05cc1e029ded2a60dc787775eeb1c4e9f05d7e8
--- libexec/got-read-tag/got-read-tag.c
+++ libexec/got-read-tag/got-read-tag.c
struct imsg imsg;
struct got_tag_object *tag = NULL;
struct got_object_id expected_id;
+ int fd = -1;
if (sigint_received) {
err = got_error(GOT_ERR_CANCELLED);
}
memcpy(&expected_id, imsg.data, sizeof(expected_id));
- if (imsg.fd == -1) {
+ fd = imsg_get_fd(&imsg);
+ if (fd == -1) {
err = got_error(GOT_ERR_PRIVSEP_NO_FD);
goto done;
}
/* Always assume file offset zero. */
- err = got_object_read_tag(&tag, imsg.fd, &expected_id, 0);
+ err = got_object_read_tag(&tag, fd, &expected_id, 0);
if (err)
goto done;
err = got_privsep_send_tag(&ibuf, tag);
done:
- if (imsg.fd != -1 && close(imsg.fd) == -1 && err == NULL)
+ if (fd != -1 && close(fd) == -1 && err == NULL)
err = got_error_from_errno("close");
imsg_free(&imsg);
if (err)
blob - a578eadbbddbc594dac437cf55427bbc85eadb71
blob + 50b57c79841c9add0976612b0ff40ef71cb31419
--- libexec/got-read-tree/got-read-tree.c
+++ libexec/got-read-tree/got-read-tree.c
struct imsg imsg;
uint8_t *buf = NULL;
struct got_object_id expected_id;
+ int fd = -1;
if (sigint_received) {
err = got_error(GOT_ERR_CANCELLED);
}
memcpy(&expected_id, imsg.data, sizeof(expected_id));
- if (imsg.fd == -1) {
+ fd = imsg_get_fd(&imsg);
+ if (fd == -1) {
err = got_error(GOT_ERR_PRIVSEP_NO_FD);
goto done;
}
/* Always assume file offset zero. */
err = got_object_read_tree(&entries, &nentries, &nentries_alloc,
- &buf, imsg.fd, &expected_id);
+ &buf, fd, &expected_id);
if (err)
goto done;
err = got_privsep_send_tree(&ibuf, entries, nentries);
done:
free(buf);
- if (imsg.fd != -1 && close(imsg.fd) == -1 && err == NULL)
+ if (fd != -1 && close(fd) == -1 && err == NULL)
err = got_error_from_errno("close");
imsg_free(&imsg);
if (err)
blob - 48bdedda02f983189b3ee1273078927953fa18e8
blob + 76552a0cd46c0a952c443ddca495e8d107d49fde
--- libexec/got-send-pack/got-send-pack.c
+++ libexec/got-send-pack/got-send-pack.c
goto done;
}
- *packfd = imsg.fd;
+ *packfd = imsg_get_fd(&imsg);
done:
imsg_free(&imsg);
return err;
goto done;
}
memcpy(&send_req, imsg.data, sizeof(send_req));
- sendfd = imsg.fd;
+ sendfd = imsg_get_fd(&imsg);
imsg_free(&imsg);
if (send_req.verbosity > 0)