package

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

commit 6b3183b31c81b6628e28ec0cf1c586f6c1a71e09
parent 60a6d13073272d562efe456001827885fbfb8768
Author: Josuah Demangeon <mail@josuah.net>
Date:   Tue, 15 Jan 2019 01:16:48 +0100

can build packages

Diffstat:
Mforkexec.c | 4++--
Mhier.c | 9+++++----
Mpack-build.c | 31+++++++++++++++++--------------
3 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/forkexec.c b/forkexec.c @@ -33,8 +33,8 @@ forkexec_wait_redir(char const *argv[], int fd) case -1: return -1; case 0: - close(1); if (dup(fd) != 1) exit(126); - close(2); if (dup(fd) != 2) exit(126); + close(1); if (dup(fd) == -1) exit(126); + close(2); if (dup(fd) == -1) exit(126); execvp(*argv, (char *const *) argv); exit(127); } diff --git a/hier.c b/hier.c @@ -127,6 +127,7 @@ hier_copy_recurse(stralloc *from, stralloc *to, int action) from->n = from_n; if (!stralloc_cats(from, de->d_name)) break; if (!stralloc_cat0(from)) break; + if (lstat(from->x, &st) == -1) break; if (S_ISDIR(st.st_mode)) { @@ -161,8 +162,8 @@ hier_copy(char const *from, char const *to) if (!stralloc_cats(&sa_from, from)) goto err; if (!stralloc_cats(&sa_to, to)) goto err; ret = hier_copy_recurse(&sa_from, &sa_to, 0); - -err: stralloc_free(&sa_from); +err: + stralloc_free(&sa_from); stralloc_free(&sa_to); return ret; } @@ -177,8 +178,8 @@ hier_symlink(char const *from, char const *to) if (!stralloc_cats(&sa_from, from)) goto err; if (!stralloc_cats(&sa_to, to)) goto err; ret = hier_copy_recurse(&sa_from, &sa_to, 1); - -err: stralloc_free(&sa_from); +err: + stralloc_free(&sa_from); stralloc_free(&sa_to); return ret; } diff --git a/pack-build.c b/pack-build.c @@ -105,19 +105,18 @@ data(pack const *p, char const *def) if (!stralloc_cats(&sa, "/")) goto err; if (!stralloc_cats(&sa, p->name)) goto err; if (!stralloc_cats(&sa, "/")) goto err; + + if (close(open_trunc("../log/3-data")) == -1) goto err; + n = sa.n; if (!stralloc_cats(&sa, "default/data")) goto err; if (!stralloc_cat0(&sa)) goto err; - - if (!close(open_trunc("../log/3-data"))) goto err; - if (stat_isdir(sa.x)) if (!hier_copy(sa.x, ".")) goto err; sa.n = n; if (!stralloc_cats(&sa, p->ver)) goto err; if (!stralloc_cats(&sa, "/data")) goto err; if (!stralloc_cat0(&sa)) goto err; - if (stat_isdir(sa.x)) if (!hier_copy(sa.x, ".")) goto err; ret = 1; @@ -133,33 +132,33 @@ build(pack const *p, char const *def) char const *argv[] = { NULL, NULL }; size_t n; int fd = - 1; + int ret = -1; stralloc_init(&sa); if (!stralloc_cats(&sa, def)) goto err; if (!stralloc_cats(&sa, "/")) goto err; if (!stralloc_cats(&sa, p->name)) goto err; if (!stralloc_cats(&sa, "/")) goto err; - n = sa.n; if ((fd = open_trunc("../log/4-build")) == -1) goto err; + n = sa.n; if (!stralloc_cats(&sa, p->ver)) goto err; if (!stralloc_cats(&sa, "/build")) goto err; if (!stralloc_cat0(&sa)) goto err; argv[0] = sa.x; - forkexec_wait_redir(argv, fd); - if (!(errno == ENOTDIR || errno == ENOENT)) goto err; + if (stat_isfile(sa.x)) { ret = forkexec_wait_redir(argv, fd); goto err; } sa.n = n; if (!stralloc_cats(&sa, "default/build")) goto err; if (!stralloc_cat0(&sa)) goto err; argv[0] = sa.x; - forkexec_wait_redir(argv, fd); - if (!(errno == ENOTDIR || errno == ENOENT)) goto err; + if (stat_isfile(sa.x)) { ret = forkexec_wait_redir(argv, fd); goto err; } -err: stralloc_free(&sa); +err: + stralloc_free(&sa); if (fd >= 0) close(fd); - return 0; + return ret; } static int @@ -247,6 +246,7 @@ main(int argc, char **argv) char *pkg; char **av = argv; char id[50 + PACK_FMT]; + int x; (void)argc; @@ -305,11 +305,14 @@ main(int argc, char **argv) log_diesys6(100, "copying ", p.name, "'s data from ", def, " to ", pkg); if (!env(&p, def, pkg, id)) log_diesys2(100, "could not set environment variables for ", *argv); - if (!build(&p, def)) - log_diesys2(100, "could not execute build script of ", p.name); + if ((x = build(&p, def)) != 0) { + char fmt[50]; + fmt_long(fmt, x); + log_die4(100, "build script of ", p.name, " returned ", fmt); + } if (symlink(id, "../current") == -1 && errno != EEXIST) log_diesys9(101, "symlink ", pkg, "/", p.name, "/", p.ver, "/", id, "/current"); - if (rename("../../current", "current") == -1 && errno != EEXIST) + if (rename("../current", "../../current") == -1 && errno != EEXIST) log_diesys7(101, "rename ", pkg, "/", p.name, "/", p.ver, "/current"); return 0;