commit - 9b4458b41088db703d890881c32dfd242efce4df
commit + 68036464ea72a92fd21d72135814faed6abad71a
blob - 0aed8754f53747ab02a5563d0a6435959c59c3d4
blob + bfee6f4277cb3046739bccf25fc842f391a9b670
--- lib/got_lib_pack.h
+++ lib/got_lib_pack.h
struct got_packidx;
+const struct got_error *got_pack_start_privsep_child(struct got_pack *,
+ struct got_packidx *);
const struct got_error *got_pack_close(struct got_pack *);
const struct got_error *got_pack_parse_offset_delta(off_t *, size_t *,
blob - b4a0b763969633b6075afe7960a4a01da96d421e
blob + dda75c34856cd363ca246441656445d61b9d1b0b
--- lib/object.c
+++ lib/object.c
#include <sys/uio.h>
#include <sys/socket.h>
#include <sys/wait.h>
-#include <sys/resource.h>
#include <sys/mman.h>
#include <errno.h>
return err;
return NULL;
-}
-
-static void
-set_max_datasize(void)
-{
- struct rlimit rl;
-
- if (getrlimit(RLIMIT_DATA, &rl) != 0)
- return;
-
- rl.rlim_cur = rl.rlim_max;
- setrlimit(RLIMIT_DATA, &rl);
-}
-
-static const struct got_error *
-start_pack_privsep_child(struct got_pack *pack, struct got_packidx *packidx)
-{
- const struct got_error *err = NULL;
- int imsg_fds[2];
- pid_t pid;
- struct imsgbuf *ibuf;
-
- ibuf = calloc(1, sizeof(*ibuf));
- if (ibuf == NULL)
- return got_error_from_errno("calloc");
-
- pack->privsep_child = calloc(1, sizeof(*pack->privsep_child));
- if (pack->privsep_child == NULL) {
- err = got_error_from_errno("calloc");
- free(ibuf);
- return err;
- }
- pack->child_has_tempfiles = 0;
- pack->child_has_delta_outfd = 0;
-
- if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
- err = got_error_from_errno("socketpair");
- goto done;
- }
-
- pid = fork();
- if (pid == -1) {
- err = got_error_from_errno("fork");
- goto done;
- } else if (pid == 0) {
- set_max_datasize();
- got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_PACK,
- pack->path_packfile);
- /* not reached */
- }
-
- if (close(imsg_fds[1]) == -1)
- return got_error_from_errno("close");
- pack->privsep_child->imsg_fd = imsg_fds[0];
- pack->privsep_child->pid = pid;
- imsg_init(ibuf, imsg_fds[0]);
- pack->privsep_child->ibuf = ibuf;
-
- err = got_privsep_init_pack_child(ibuf, pack, packidx);
- if (err) {
- const struct got_error *child_err;
- err = got_privsep_send_stop(pack->privsep_child->imsg_fd);
- child_err = got_privsep_wait_for_child(
- pack->privsep_child->pid);
- if (child_err && err == NULL)
- err = child_err;
- }
-done:
- if (err) {
- free(ibuf);
- free(pack->privsep_child);
- pack->privsep_child = NULL;
- }
- return err;
}
static const struct got_error *
const struct got_error *err = NULL;
if (pack->privsep_child == NULL) {
- err = start_pack_privsep_child(pack, packidx);
+ err = got_pack_start_privsep_child(pack, packidx);
if (err)
return err;
}
const struct got_error *err = NULL;
if (pack->privsep_child == NULL) {
- err = start_pack_privsep_child(pack, packidx);
+ err = got_pack_start_privsep_child(pack, packidx);
if (err)
return err;
}
}
if (pack->privsep_child == NULL) {
- err = start_pack_privsep_child(pack, packidx);
+ err = got_pack_start_privsep_child(pack, packidx);
if (err)
return err;
}
return got_privsep_recv_raw_delta(base_size, result_size, delta_size,
delta_compressed_size, delta_offset, delta_out_offset, base_id,
pack->privsep_child->ibuf);
-}
-
-/*
- * XXX This function does not really belong in object.c. It is only here
- * because it needs start_pack_privsep_child(); relevant code should
- * probably be moved to pack.c/pack_create.c.
- */
-const struct got_error *
-got_object_prepare_delta_reuse(struct got_pack **pack,
- struct got_packidx *packidx, int delta_outfd, struct got_repository *repo)
-{
- const struct got_error *err = NULL;
- char *path_packfile = NULL;
-
- err = got_packidx_get_packfile_path(&path_packfile,
- packidx->path_packidx);
- if (err)
- return err;
-
- *pack = got_repo_get_cached_pack(repo, path_packfile);
- if (*pack == NULL) {
- err = got_repo_cache_pack(pack, repo, path_packfile, packidx);
- if (err)
- goto done;
- }
- if ((*pack)->privsep_child == NULL) {
- err = start_pack_privsep_child(*pack, packidx);
- if (err)
- goto done;
- }
-
- if (!(*pack)->child_has_delta_outfd) {
- int outfd_child;
- outfd_child = dup(delta_outfd);
- if (outfd_child == -1) {
- err = got_error_from_errno("dup");
- goto done;
- }
- err = got_privsep_send_raw_delta_outfd(
- (*pack)->privsep_child->ibuf, outfd_child);
- if (err)
- goto done;
- (*pack)->child_has_delta_outfd = 1;
- }
-
- err = got_privsep_send_delta_reuse_req((*pack)->privsep_child->ibuf);
-done:
- free(path_packfile);
- return err;
}
static const struct got_error *
if (pack->privsep_child)
return request_packed_commit(commit, pack, idx, id);
- err = start_pack_privsep_child(pack, packidx);
+ err = got_pack_start_privsep_child(pack, packidx);
if (err)
return err;
if (pack->privsep_child)
return request_packed_tree(tree, pack, idx, id);
- err = start_pack_privsep_child(pack, packidx);
+ err = got_pack_start_privsep_child(pack, packidx);
if (err)
return err;
const struct got_error *err = NULL;
if (pack->privsep_child == NULL) {
- err = start_pack_privsep_child(pack, packidx);
+ err = got_pack_start_privsep_child(pack, packidx);
if (err)
return err;
}
if (pack->privsep_child)
return request_packed_tag(tag, pack, idx, id);
- err = start_pack_privsep_child(pack, packidx);
+ err = got_pack_start_privsep_child(pack, packidx);
if (err)
return err;
}
if (pack->privsep_child == NULL) {
- err = start_pack_privsep_child(pack, packidx);
+ err = got_pack_start_privsep_child(pack, packidx);
if (err)
goto done;
}
}
if (pack->privsep_child == NULL) {
- err = start_pack_privsep_child(pack, packidx);
+ err = got_pack_start_privsep_child(pack, packidx);
if (err)
goto done;
}
blob - fb0db87c32da83d311bda6a69b946e48e3167f8f
blob + 054ae905f1c60527376ced496a88d48170382727
--- lib/pack.c
+++ lib/pack.c
#include <sys/stat.h>
#include <sys/uio.h>
#include <sys/mman.h>
+#include <sys/resource.h>
+#include <sys/socket.h>
#include <fcntl.h>
#include <errno.h>
if (err)
got_object_id_queue_free(matched_ids);
+ return err;
+}
+
+static void
+set_max_datasize(void)
+{
+ struct rlimit rl;
+
+ if (getrlimit(RLIMIT_DATA, &rl) != 0)
+ return;
+
+ rl.rlim_cur = rl.rlim_max;
+ setrlimit(RLIMIT_DATA, &rl);
+}
+
+const struct got_error *
+got_pack_start_privsep_child(struct got_pack *pack, struct got_packidx *packidx)
+{
+ const struct got_error *err = NULL;
+ int imsg_fds[2];
+ pid_t pid;
+ struct imsgbuf *ibuf;
+
+ ibuf = calloc(1, sizeof(*ibuf));
+ if (ibuf == NULL)
+ return got_error_from_errno("calloc");
+
+ pack->privsep_child = calloc(1, sizeof(*pack->privsep_child));
+ if (pack->privsep_child == NULL) {
+ err = got_error_from_errno("calloc");
+ free(ibuf);
+ return err;
+ }
+ pack->child_has_tempfiles = 0;
+ pack->child_has_delta_outfd = 0;
+
+ if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
+ err = got_error_from_errno("socketpair");
+ goto done;
+ }
+
+ pid = fork();
+ if (pid == -1) {
+ err = got_error_from_errno("fork");
+ goto done;
+ } else if (pid == 0) {
+ set_max_datasize();
+ got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_PACK,
+ pack->path_packfile);
+ /* not reached */
+ }
+
+ if (close(imsg_fds[1]) == -1)
+ return got_error_from_errno("close");
+ pack->privsep_child->imsg_fd = imsg_fds[0];
+ pack->privsep_child->pid = pid;
+ imsg_init(ibuf, imsg_fds[0]);
+ pack->privsep_child->ibuf = ibuf;
+
+ err = got_privsep_init_pack_child(ibuf, pack, packidx);
+ if (err) {
+ const struct got_error *child_err;
+ err = got_privsep_send_stop(pack->privsep_child->imsg_fd);
+ child_err = got_privsep_wait_for_child(
+ pack->privsep_child->pid);
+ if (child_err && err == NULL)
+ err = child_err;
+ }
+done:
+ if (err) {
+ free(ibuf);
+ free(pack->privsep_child);
+ pack->privsep_child = NULL;
+ }
return err;
}
blob - 8ebcec37cc5884e4fd3f5f0986dee830277e39c8
blob + 207a6edd8617d1afeb8e3b428a73d56ebf40f146
--- lib/pack_create.c
+++ lib/pack_create.c
return got_error_from_errno("got_object_id_dup");
return add_meta(m, v);
+}
+
+static const struct got_error *
+prepare_delta_reuse(struct got_pack **pack, struct got_packidx *packidx,
+ int delta_outfd, struct got_repository *repo)
+{
+ const struct got_error *err = NULL;
+ char *path_packfile = NULL;
+
+ err = got_packidx_get_packfile_path(&path_packfile,
+ packidx->path_packidx);
+ if (err)
+ return err;
+
+ *pack = got_repo_get_cached_pack(repo, path_packfile);
+ if (*pack == NULL) {
+ err = got_repo_cache_pack(pack, repo, path_packfile, packidx);
+ if (err)
+ goto done;
+ }
+ if ((*pack)->privsep_child == NULL) {
+ err = got_pack_start_privsep_child(*pack, packidx);
+ if (err)
+ goto done;
+ }
+
+ if (!(*pack)->child_has_delta_outfd) {
+ int outfd_child;
+ outfd_child = dup(delta_outfd);
+ if (outfd_child == -1) {
+ err = got_error_from_errno("dup");
+ goto done;
+ }
+ err = got_privsep_send_raw_delta_outfd(
+ (*pack)->privsep_child->ibuf, outfd_child);
+ if (err)
+ goto done;
+ (*pack)->child_has_delta_outfd = 1;
+ }
+
+ err = got_privsep_send_delta_reuse_req((*pack)->privsep_child->ibuf);
+done:
+ free(path_packfile);
+ return err;
}
+
static const struct got_error *
search_deltas(struct got_pack_metavec *v, struct got_object_idset *idset,
int delta_cache_fd, int ncolored, int nfound, int ntrees, int ncommits,
if (packidx == NULL)
return NULL;
- err = got_object_prepare_delta_reuse(&pack, packidx,
- delta_cache_fd, repo);
+ err = prepare_delta_reuse(&pack, packidx, delta_cache_fd, repo);
if (err)
return err;