diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2022-07-19 10:44:59 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2022-07-19 10:44:59 +0000 |
commit | 6b040be882ab684eda9b1a03ed7c4807c8a37947 (patch) | |
tree | 3b78d79d0fbc36bafb2fd5e8a548fb4639192add /src | |
parent | 43dde3b628331bf43cacc93e85c676ffa9a76e2f (diff) | |
download | s6-portable-utils-6b040be882ab684eda9b1a03ed7c4807c8a37947.tar.xz |
s6-ln: make posix-compliant in the case of several operands
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/skaembutils/s6-ln.c | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/src/skaembutils/s6-ln.c b/src/skaembutils/s6-ln.c index dff9bc2..6fab547 100644 --- a/src/skaembutils/s6-ln.c +++ b/src/skaembutils/s6-ln.c @@ -42,28 +42,36 @@ static int linkderef (char const *old, char const *new) #endif -static void doit (char const *old, char const *new, link_func_ref mylink, int force) +static int doit (char const *old, char const *new, link_func_ref mylink, int force) { if ((*mylink)(old, new) == -1) { if (!force || errno != EEXIST) - strerr_diefu5sys(111, "make a link", " from ", new, " to ", old) ; + { + strerr_warnwu5sys("make a link", " from ", new, " to ", old) ; + return 1 ; + } { size_t newlen = strlen(new) ; char fn[newlen + sizeof(SUFFIX)] ; memcpy(fn, new, newlen) ; memcpy(fn + newlen, SUFFIX, sizeof(SUFFIX)) ; if (mklinktemp(old, fn, mylink) == -1) - strerr_diefu3sys(111, "make a link", " to ", old) ; + { + strerr_warnwu3sys("make a link", " to ", old) ; + return 1 ; + } if (rename(fn, new) == -1) { unlink_void(fn) ; - strerr_diefu2sys(111, "atomically replace ", new) ; + strerr_warnwu2sys("atomically replace ", new) ; + return 1 ; } /* if old == new, rename() didn't remove fn */ unlink_void(fn) ; } } + return 0 ; } int main (int argc, char const *const *argv) @@ -95,6 +103,7 @@ int main (int argc, char const *const *argv) { stralloc sa = STRALLOC_ZERO ; unsigned int i = 0 ; + int e = 0 ; size_t base ; if (!stralloc_cats(&sa, argv[argc-1]) || !stralloc_catb(&sa, "/", 1)) strerr_diefu1sys(111, "stralloc_cats") ; @@ -103,11 +112,20 @@ int main (int argc, char const *const *argv) { sa.len = base ; if (!sabasename(&sa, argv[i], strlen(argv[i]))) - strerr_diefu1sys(111, "sabasename") ; - if (!stralloc_0(&sa)) strerr_diefu1sys(111, "stralloc_0") ; - doit(argv[i], sa.s, mylink, force) ; + { + strerr_warnwu1sys("sabasename") ; + e++ ; + continue ; + } + if (!stralloc_0(&sa)) + { + strerr_warnwu1sys("stralloc_0") ; + e++ ; + continue ; + } + e += doit(argv[i], sa.s, mylink, force) ; } - return 0 ; + return e ; } { @@ -115,14 +133,10 @@ int main (int argc, char const *const *argv) if (nodir ? lstat(argv[1], &st) : stat(argv[1], &st) < 0) { if (errno != ENOENT) strerr_diefu2sys(111, "stat ", argv[1]) ; - doit(argv[0], argv[1], mylink, force) ; - return 0 ; + return doit(argv[0], argv[1], mylink, force) ; } if (!S_ISDIR(st.st_mode)) - { - doit(argv[0], argv[1], mylink, force) ; - return 0 ; - } + return doit(argv[0], argv[1], mylink, force) ; } { @@ -132,7 +146,6 @@ int main (int argc, char const *const *argv) || !sabasename(&sa, argv[0], strlen(argv[0])) || !stralloc_0(&sa)) strerr_diefu1sys(111, "stralloc_catb") ; - doit(argv[0], sa.s, mylink, force) ; + return doit(argv[0], sa.s, mylink, force) ; } - return 0 ; } |