summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/s6-rc/s6rc-utils.h3
-rw-r--r--src/libs6rc/deps-lib/s6rc1
-rw-r--r--src/libs6rc/s6rc_livedir_canon.c25
-rw-r--r--src/s6-rc/s6-rc-init.c2
-rw-r--r--src/s6-rc/s6-rc-update.c3
5 files changed, 34 insertions, 0 deletions
diff --git a/src/include/s6-rc/s6rc-utils.h b/src/include/s6-rc/s6rc-utils.h
index 8f67920..841e026 100644
--- a/src/include/s6-rc/s6rc-utils.h
+++ b/src/include/s6-rc/s6rc-utils.h
@@ -4,7 +4,9 @@
#define S6RC_UTILS_H
#include <sys/types.h>
+
#include <skalibs/stralloc.h>
+
#include <s6-rc/s6rc-db.h>
extern void s6rc_graph_closure (s6rc_db_t const *, unsigned char *, unsigned int, int) ;
@@ -15,5 +17,6 @@ extern int s6rc_sanitize_dir (stralloc *, char const *, size_t *) ;
extern int s6rc_livedir_prefixsize (char const *, size_t *) ;
extern ssize_t s6rc_livedir_prefix (char const *, char *, size_t) ;
extern int s6rc_livedir_create (stralloc *, char const *, char const *, char const *, char const *, char const *, unsigned char const *, unsigned int, size_t *) ;
+extern int s6rc_livedir_canon (char const **) ;
#endif
diff --git a/src/libs6rc/deps-lib/s6rc b/src/libs6rc/deps-lib/s6rc
index 52c220f..5dbb4de 100644
--- a/src/libs6rc/deps-lib/s6rc
+++ b/src/libs6rc/deps-lib/s6rc
@@ -5,6 +5,7 @@ s6rc_db_read.o
s6rc_db_read_sizes.o
s6rc_db_read_uint32.o
s6rc_graph_closure.o
+s6rc_livedir_canon.o
s6rc_livedir_create.o
s6rc_livedir_prefix.o
s6rc_livedir_prefixsize.o
diff --git a/src/libs6rc/s6rc_livedir_canon.c b/src/libs6rc/s6rc_livedir_canon.c
new file mode 100644
index 0000000..db5d3a1
--- /dev/null
+++ b/src/libs6rc/s6rc_livedir_canon.c
@@ -0,0 +1,25 @@
+/* ISC license. */
+
+#include <string.h>
+#include <errno.h>
+
+#include <skalibs/alloc.h>
+
+#include <s6-rc/s6rc-utils.h>
+
+int s6rc_livedir_canon (char const **live)
+{
+ size_t llen = strlen(*live) ;
+ size_t n = llen ;
+ while (n && (*live)[n - 1] == '/') --n ;
+ if (!n) return (errno = EINVAL, 0) ;
+ if (n < llen)
+ {
+ char *x = alloc(n + 1) ;
+ if (!x) return 0 ;
+ memcpy(x, *live, n) ;
+ x[n] = 0 ;
+ *live = x ;
+ }
+ return 1 ;
+}
diff --git a/src/s6-rc/s6-rc-init.c b/src/s6-rc/s6-rc-init.c
index e90211f..ea52255 100644
--- a/src/s6-rc/s6-rc-init.c
+++ b/src/s6-rc/s6-rc-init.c
@@ -73,6 +73,8 @@ int main (int argc, char const *const *argv)
tain_now_set_stopwatch_g() ;
tain_add_g(&deadline, &deadline) ;
+ if (!s6rc_livedir_canon(&live))
+ strerr_diefu1sys(111, "canonicalize livedir") ;
if (deref)
{
char *x = realpath(compiled, 0) ;
diff --git a/src/s6-rc/s6-rc-update.c b/src/s6-rc/s6-rc-update.c
index 830214d..fd13f8a 100644
--- a/src/s6-rc/s6-rc-update.c
+++ b/src/s6-rc/s6-rc-update.c
@@ -594,6 +594,9 @@ int main (int argc, char const *const *argv, char const *const *envp)
strerr_dief2x(100, live, " is not an absolute path") ;
if (argv[0][0] != '/')
strerr_dief2x(100, argv[0], " is not an absolute path") ;
+
+ if (!s6rc_livedir_canon(&live))
+ strerr_diefu1sys(111, "canonicalize livedir") ;
livelen = strlen(live) ;
{