commit - 50b6e2b853641f2523a175298f865fc44f44d8a7
commit + 2c52c623be04b56400a5c94cc8d86b6fda214d16
blob - 9b609e44eeac3d33dce8caa01cf42c14e12968fd
blob + 7c46d073738bc4c8180ca50eeb70353430e7a9ca
--- 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 - ed4f349309e803afa86a9c0fa10c1b204d43250a
blob + b46b5573bc4b7b42b5b311fec8206262a1111da3
--- 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 - 4dcacace4ec9959df611dda2a6fa9adf1eb3fb90
blob + d68ef57610af2d102688f0961076da441add53d7
--- 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 - 77d19b7ba1f7170166ad70f68c5f8c7e0fe92f3c
blob + 780677ae9232bbcf5aee0de51f94c9105efe7a72
--- 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 - 1c4f5ef4003d20c175c7cccfb4dd5cf5a9f79c80
blob + 6e0018108f6f7c5dabd6f13ff0adde909c3e9e8f
--- 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 - bde889cb381f5d8e90f44b27a11986e29f2f27d2
blob + ebe0bac12e5e093bd83e0efed0048485805ea07d
--- 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 - 4b4b5a6eb83db18b356def90dad243397510f7d5
blob + 843fa5982aee9be13ae1370c9db781d173b43021
--- 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 - cb8defa207bb0da2d9fc2ed1c5efbf17d671c6c1
blob + 00fd3248748839d85a7ffa90d9f8b8113b49b4f9
--- 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 - 9d814fc7b44d62a6a31880c030beba561c834ba0
blob + 6891969704cec149dec63e3d8e89a50d6da5d5b9
--- 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 - e4c92bbc9d32142b0790c085ca4e39a36991795e
blob + bef01d3c3adfe6a70c48ee294f475d29377f5400
--- 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 - 349ab039f60b6ca3745866df6ab52257ed03fd1b
blob + 7f75afa1f1f24fe910ee48fc4058be6cef03a8ee
--- 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 - 4c5615e9a61fc968bb76b520dd500a60adaceb08
blob + 83c6c390aa8e24bc88e8e20d346d2ec34dc5a0c2
--- 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 - 0c3010abcae4d96473ce98b378f9dd456bbfe4c0
blob + cc9c5eceb4d4b6f891f43c7228043d26893782bf
--- 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 - 4396edfaac8ae4bf97e83da86f49717f922fdee0
blob + 0270712db89ff118f330ae2524053b281b8d46e2
--- 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 - 47432bc05913abd4ec23ec1b1aed9d66279e7d3c
blob + 2105026a81511417fce4297207c3af3298d8f1de
--- 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 - 9a510beab9f689e0356e77e698d30b666c6f4521
blob + 39ff4fdaae7bf2fd23444ef6aae255310a4f2ad1
--- 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 - b8c40928c6dbf801b5730c92cd5ada9803a890d1
blob + 500f786f501a74944230154788890612bf220f7c
--- 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 - 654cb49d9d96580f6af08455db5b1407f1483dbd
blob + 64baada11e1ccee7903385f01a1dd207eb53ddd4
--- 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)