package

simple and robust package manager
Log | Files | Refs | README

commit 7779e9efbd569c5fd6340cc463e44549924dbcea
parent c2117457b370fdddffc97e6249934ddf9de264d1
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sat, 19 Jan 2019 16:11:43 +0100

make logs more consistents

Diffstat:
Mpackage-build.c | 14++++++++------
Mpackage-get.c | 29++++++++++++++++++++---------
2 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/package-build.c b/package-build.c @@ -36,7 +36,7 @@ patch(package const *p, char *def) size_t n; DIR *dp = NULL; int fd = -1; - int ret = -1; + int ret = 0; stralloc_init(&sa); if (!stralloc_cats(&sa, def)) goto err; @@ -253,10 +253,12 @@ main(int argc, char **argv) log_fatal_sys_4(101, "version ", def, "/", p.name); if (mkdir(p.ver, 075) == -1 && errno != EEXIST) log_fatal_sys_6(101, "mkdir ", pkg, "/", p.name, "/", p.ver); - if (!lock_exclusive(open_read("source.tar"))) - log_fatal_7(101, "flock ", pkg, "/", p.name, "/", p.ver, "/source.tar"); if (chdir(p.ver) == -1) log_fatal_sys_6(101, "chdir ", pkg, "/", p.name, "/", p.ver); + if ((x = open_read("source.tar")) == -1) + log_fatal_sys_7(101, "open ", pkg, "/", p.name, "/", p.ver, "/source.tar"); + if (lock_exclusive(x) == -1) + log_fatal_sys_7(101, "flock ", pkg, "/", p.name, "/", p.ver, "/source.tar"); if (mkdir(id, 075) == -1 && errno != EEXIST) log_fatal_sys_8(101, "mkdir ", pkg, "/", p.name, "/", p.ver, "/", id); if (chdir(id) == -1) @@ -277,7 +279,7 @@ main(int argc, char **argv) write(1, "=== untar ===\n", 14); if ((x = untar()) != 0) { char fmt[50]; - fmt_long(fmt, x); + fmt[fmt_long(fmt, x)] = '\0'; log_fatal_8(100, "tar -x -f ", pkg, "/", p.name, "/", p.ver, "/source.tar -> exit ", fmt); } write(1, "=== end ===\n", 12); @@ -285,7 +287,7 @@ main(int argc, char **argv) write(1, "\n=== patch ===\n", 15); if ((x = patch(&p, def)) != 0) { char fmt[50]; - fmt_long(fmt, x); + fmt[fmt_long(fmt, x)] = '\0'; log_fatal_8(100, "patch -N ", def, "/", p.name, "/", p.ver, "/patch/* -> exit ", fmt); } write(1, "=== end ===\n", 12); @@ -303,7 +305,7 @@ main(int argc, char **argv) write(1, "\n=== build ===\n", 15); if ((x = build(&p, def)) != 0) { char fmt[50]; - fmt_long(fmt, x); + fmt[fmt_long(fmt, x)] = '\0'; log_fatal_7(100, def, "/", p.name, "/", p.ver, "/build -> exit ", fmt); } write(1, "=== end ===\n", 12); diff --git a/package-get.c b/package-get.c @@ -23,13 +23,16 @@ main(int argc, char **argv) { stralloc sa; package p; - buffer b; - char buf[1024]; + buffer b_uri; + buffer b_log; + char buf_uri[1024]; + char buf_log[1024]; char *def = PACKAGE_DEF; char *pkg = PACKAGE_DIR; char *cmd = NULL; char **av = argv; - int fd = -1; + int fd_uri = -1; + int fd_log = -1; size_t n; ssize_t r; @@ -58,7 +61,8 @@ main(int argc, char **argv) if (!stralloc_cats(&sa, p.ver)) die_nomem(); if (!stralloc_cats(&sa, "/uri")) die_nomem(); if (!stralloc_cat0(&sa)) die_nomem(); - fd = open_read(sa.x); if (fd == -1) die_nomem(); + if ((fd_uri = open_read(sa.x)) == -1) + log_fatal_sys_2(101, "open ", sa.x); stralloc_zero(&sa); if (!stralloc_cats(&sa, pkg)) die_nomem(); @@ -75,11 +79,15 @@ main(int argc, char **argv) sa.n--; if (close(1) == -1 || (open_trunc("source.tmp")) == -1) log_fatal_sys_3(100, "open ", sa.x, "/source.tmp"); - if (!lock_exclusive(1)) + if (lock_exclusive(1) == -1) log_fatal_sys_3(100, "flock ", sa.x, "/source.tmp"); - buffer_init(&b, &read, fd, buf, sizeof buf); - while (stralloc_zero(&sa), (r = buffer_getline(&b, &sa)) > 0) { + if ((fd_log = open_trunc("source.log")) == -1) + log_fatal_sys_3(100, "open ", sa.x, "/source.log"); + + buffer_init(&b_uri, &read, fd_uri, buf_uri, sizeof buf_uri); + buffer_init(&b_log, &write, fd_log, buf_log, sizeof buf_log); + while (stralloc_zero(&sa), (r = buffer_getline(&b_uri, &sa)) > 0) { char const *argv[] = { NULL, NULL, NULL, NULL }; char fmt[PACKAGE_FMT]; @@ -95,14 +103,17 @@ main(int argc, char **argv) if (str_start(sa.x, "cvs://")) cmd = "package-cvs"; if (!cmd) log_warn_2("no handler found for downloading ", sa.x); - log_info_2("trying mirror ", sa.x); + buffer_puts(&b_log, "=== "); + buffer_puts(&b_log, sa.x); + buffer_puts(&b_log, " ===\n"); + buffer_flush(&b_log); package_fmt(&p, fmt); argv[0] = cmd; argv[1] = fmt; argv[2] = sa.x; argv[3] = NULL; - if ((forkexec_redir(argv, 2, open_trunc("source.log"))) != 0) + if ((forkexec_redir(argv, 2, fd_log)) != 0) log_error_4("downloading packageage ", p.name, "/", p.ver); else if (rename("source.tmp", "source.tar") == -1) log_fatal_sys_1(100, "rename source.tmp source.tar");