From acd73ed156e6f10b96fc277738845f833c514b77 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Thu, 22 Mar 2012 14:32:52 -0700 Subject: fail edify script if set_perm() or symlink() fails It's surprising if these fail, so abort the whole edify script to catch any problems early. Bug: 2284848 Change-Id: Ia2a0b60e7f086fc590b242616028905a229c9e05 --- updater/install.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'updater') diff --git a/updater/install.c b/updater/install.c index c087d4ebe..7b7bfc903 100644 --- a/updater/install.c +++ b/updater/install.c @@ -450,21 +450,27 @@ Value* SymlinkFn(const char* name, State* state, int argc, Expr* argv[]) { return NULL; } + int bad = 0; int i; for (i = 0; i < argc-1; ++i) { if (unlink(srcs[i]) < 0) { if (errno != ENOENT) { fprintf(stderr, "%s: failed to remove %s: %s\n", name, srcs[i], strerror(errno)); + ++bad; } } if (symlink(target, srcs[i]) < 0) { fprintf(stderr, "%s: failed to symlink %s to %s: %s\n", name, srcs[i], target, strerror(errno)); + ++bad; } free(srcs[i]); } free(srcs); + if (bad) { + return ErrorAbort(state, "%s: some symlinks failed", name); + } return StringValue(strdup("")); } @@ -483,6 +489,7 @@ Value* SetPermFn(const char* name, State* state, int argc, Expr* argv[]) { char* end; int i; + int bad = 0; int uid = strtoul(args[0], &end, 0); if (*end != '\0' || args[0][0] == 0) { @@ -524,10 +531,12 @@ Value* SetPermFn(const char* name, State* state, int argc, Expr* argv[]) { if (chown(args[i], uid, gid) < 0) { fprintf(stderr, "%s: chown of %s to %d %d failed: %s\n", name, args[i], uid, gid, strerror(errno)); + ++bad; } if (chmod(args[i], mode) < 0) { fprintf(stderr, "%s: chmod of %s to %o failed: %s\n", name, args[i], mode, strerror(errno)); + ++bad; } } } @@ -539,6 +548,10 @@ done: } free(args); + if (bad) { + free(result); + return ErrorAbort(state, "%s: some changes failed", name); + } return StringValue(result); } -- cgit v1.2.3