diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2018-12-08 15:02:01 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2018-12-08 15:02:01 +0000 |
commit | f9afa26f44b7787adb01e2fb400e20a606e09380 (patch) | |
tree | cc6b1890c962701a2da974cf6b0f8a49847479a1 | |
parent | 2c3f58f0959604af0eca3b4d9d623a738a0e70e6 (diff) | |
download | s6-portable-utils-f9afa26f44b7787adb01e2fb400e20a606e09380.tar.gz s6-portable-utils-f9afa26f44b7787adb01e2fb400e20a606e09380.tar.xz s6-portable-utils-f9afa26f44b7787adb01e2fb400e20a606e09380.zip |
Use new mklinktemp() in s6-ln
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | INSTALL | 2 | ||||
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | doc/index.html | 4 | ||||
-rw-r--r-- | doc/upgrade.html | 6 | ||||
-rw-r--r-- | package/info | 2 | ||||
-rw-r--r-- | src/skaembutils/s6-ln.c | 59 |
7 files changed, 43 insertions, 39 deletions
diff --git a/.gitignore b/.gitignore index 5c6415e..180d04c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ *.lo *.so *.so.* +/config.mak +/src/include/s6-portable-utils/config.h diff --git a/INSTALL b/INSTALL index 2b887c3..74aaa72 100644 --- a/INSTALL +++ b/INSTALL @@ -6,7 +6,7 @@ Build Instructions - A POSIX-compliant C development environment - GNU make version 3.81 or later - - skalibs version 2.7.0.0 or later: http://skarnet.org/software/skalibs/ + - skalibs version 2.8.0.0 or later: http://skarnet.org/software/skalibs/ This software will run on any operating system that implements POSIX.1-2008, available at: diff --git a/NEWS b/NEWS index a8be3ec..90217ff 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,12 @@ Changelog for s6-portable-utils. +In 2.2.1.3 +---------- + + - s6-ln doesn't use potentially blocking random anymore, so it's +usable in early boot. This needs skalibs-2.8.0.0, however. + + In 2.2.1.2 ---------- diff --git a/doc/index.html b/doc/index.html index 444ac7b..b03f518 100644 --- a/doc/index.html +++ b/doc/index.html @@ -61,7 +61,7 @@ the package is now used to host specific utilities such as <li> A POSIX-compliant system with a standard C development environment </li> <li> GNU make, version 3.81 or later </li> <li> <a href="//skarnet.org/software/skalibs/">skalibs</a> version -2.7.0.0 or later. It's a build-time requirement. It's also a run-time +2.8.0.0 or later. It's a build-time requirement. It's also a run-time requirement if you link against the shared version of the skalibs library. </li> </ul> @@ -77,7 +77,7 @@ library. </li> <ul> <li> The current released version of s6-portable-utils is -<a href="s6-portable-utils-2.2.1.2.tar.gz">2.2.1.2</a>. </li> +<a href="s6-portable-utils-2.2.1.3.tar.gz">2.2.1.3</a>. </li> <li> Alternatively, you can checkout a copy of the <a href="//git.skarnet.org/cgi-bin/cgit.cgi/s6-portable-utils/">s6-portable-utils git repository</a>: diff --git a/doc/upgrade.html b/doc/upgrade.html index b4149ad..b2427fb 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -18,6 +18,12 @@ <h1> What has changed in s6-portable-utils </h1> +<h2> in 2.2.1.3 </h2> + +<ul> + <li> skalibs dependency bumped to 2.8.0.0. </li> +</ul> + <h2> in 2.2.1.2 </h2> <ul> diff --git a/package/info b/package/info index 53ad634..11de70b 100644 --- a/package/info +++ b/package/info @@ -1,4 +1,4 @@ package=s6-portable-utils -version=2.2.1.2 +version=2.2.1.3 category=admin package_macro_name=S6_PORTABLE_UTILS diff --git a/src/skaembutils/s6-ln.c b/src/skaembutils/s6-ln.c index d600aab..e7af8c3 100644 --- a/src/skaembutils/s6-ln.c +++ b/src/skaembutils/s6-ln.c @@ -12,21 +12,16 @@ #include <unistd.h> #include <errno.h> #include <stdio.h> + #include <skalibs/posixplz.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> -#include <skalibs/random.h> #include <skalibs/skamisc.h> #define USAGE "s6-ln [ -n ] [ -s ] [ -f ] [ -L ] [ -P ] src... dest" - -typedef int linkfunc_t (char const *, char const *) ; -typedef linkfunc_t *linkfunc_t_ref ; - -typedef void ln_t (char const *, char const *, linkfunc_t_ref) ; -typedef ln_t *ln_t_ref ; +#define SUFFIX ":s6-ln:XXXXXX" #ifdef SKALIBS_HASLINKAT @@ -47,38 +42,34 @@ static int linkderef (char const *old, char const *new) #endif -static void force (char const *old, char const *new, linkfunc_t_ref doit) +static void doit (char const *old, char const *new, linkfunc_t_ref mylink, int force) { - if ((*doit)(old, new) == -1) + if ((*mylink)(old, new) == -1) { - size_t base = satmp.len ; - if (errno != EEXIST) + if (!force || errno != EEXIST) strerr_diefu5sys(111, "make a link", " from ", new, " to ", old) ; - if (!stralloc_cats(&satmp, new) - || !random_sauniquename(&satmp, 8) - || !stralloc_0(&satmp)) - strerr_diefu2sys(111, "make a unique name for ", old) ; - if ((*doit)(old, satmp.s + base) == -1) - strerr_diefu3sys(111, "make a link", " to ", old) ; - if (rename(satmp.s + base, new) == -1) { - unlink_void(satmp.s + base) ; - strerr_diefu2sys(111, "atomically replace ", new) ; + 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) ; + if (rename(fn, new) == -1) + { + unlink_void(fn) ; + strerr_diefu2sys(111, "atomically replace ", new) ; + } + /* if old == new, rename() didn't remove fn */ + unlink_void(fn) ; } - satmp.len = base ; } } -static void noforce (char const *old, char const *new, linkfunc_t_ref doit) -{ - if ((*doit)(old, new) == -1) - strerr_diefu5sys(111, "make a link", " from ", new, " to ", old) ; -} - int main (int argc, char const *const *argv) { linkfunc_t_ref mylink = &link ; /* default to system behaviour */ - ln_t_ref f = &noforce ; + int force = 0 ; int nodir = 0 ; PROG = "s6-ln" ; { @@ -91,7 +82,7 @@ int main (int argc, char const *const *argv) { case 'n' : nodir = 1 ; break ; case 's': mylink = &symlink ; break ; - case 'f': f = &force ; break ; + case 'f': force = 1 ; break ; case 'L': if (mylink != &symlink) mylink = &linkderef ; break ; case 'P': if (mylink != &symlink) mylink = &linknoderef ; break ; default : strerr_dieusage(100, USAGE) ; @@ -100,8 +91,6 @@ int main (int argc, char const *const *argv) argc -= l.ind ; argv += l.ind ; } if (argc < 2) strerr_dieusage(100, USAGE) ; - if (!random_init()) - strerr_diefu1sys(111, "init random generator") ; if (argc > 2) { stralloc sa = STRALLOC_ZERO ; @@ -116,7 +105,7 @@ int main (int argc, char const *const *argv) if (!sabasename(&sa, argv[i], strlen(argv[i]))) strerr_diefu1sys(111, "sabasename") ; if (!stralloc_0(&sa)) strerr_diefu1sys(111, "stralloc_0") ; - (*f)(argv[i], sa.s, mylink) ; + doit(argv[i], sa.s, mylink, force) ; } return 0 ; } @@ -126,12 +115,12 @@ 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]) ; - (*f)(argv[0], argv[1], mylink) ; + doit(argv[0], argv[1], mylink, force) ; return 0 ; } if (!S_ISDIR(st.st_mode)) { - (*f)(argv[0], argv[1], mylink) ; + doit(argv[0], argv[1], mylink, force) ; return 0 ; } } @@ -143,7 +132,7 @@ int main (int argc, char const *const *argv) || !sabasename(&sa, argv[0], strlen(argv[0])) || !stralloc_0(&sa)) strerr_diefu1sys(111, "stralloc_catb") ; - (*f)(argv[0], sa.s, mylink) ; + doit(argv[0], sa.s, mylink, force) ; } return 0 ; } |