summaryrefslogtreecommitdiff
path: root/src/libs6rc
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-10-09 10:38:37 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-10-09 10:38:37 +0000
commit7a6766da53fa06a02d818208c51801dd79e88a54 (patch)
tree1378bbe390e9cd8077f75efdd6ac1ee79be0bf80 /src/libs6rc
parentf9940bb7d1a6ce7d7772e8cbdbbd55a321cc5c18 (diff)
downloads6-rc-7a6766da53fa06a02d818208c51801dd79e88a54.tar.xz
Replace suffix with prefix
Diffstat (limited to 'src/libs6rc')
-rw-r--r--src/libs6rc/deps-lib/s6rc4
-rw-r--r--src/libs6rc/s6rc_livedir_prefix.c (renamed from src/libs6rc/s6rc_livedir_suffix.c)7
-rw-r--r--src/libs6rc/s6rc_livedir_prefixsize.c (renamed from src/libs6rc/s6rc_livedir_suffixsize.c)4
-rw-r--r--src/libs6rc/s6rc_servicedir_manage.c18
-rw-r--r--src/libs6rc/s6rc_servicedir_unsupervise.c10
5 files changed, 22 insertions, 21 deletions
diff --git a/src/libs6rc/deps-lib/s6rc b/src/libs6rc/deps-lib/s6rc
index 3768378..f42783b 100644
--- a/src/libs6rc/deps-lib/s6rc
+++ b/src/libs6rc/deps-lib/s6rc
@@ -5,8 +5,8 @@ s6rc_db_read.o
s6rc_db_read_sizes.o
s6rc_db_read_uint32.o
s6rc_graph_closure.o
-s6rc_livedir_suffix.o
-s6rc_livedir_suffixsize.o
+s6rc_livedir_prefix.o
+s6rc_livedir_prefixsize.o
s6rc_lock.o
s6rc_read_uint.o
s6rc_sanitize_dir.o
diff --git a/src/libs6rc/s6rc_livedir_suffix.c b/src/libs6rc/s6rc_livedir_prefix.c
index 98236cd..18a95fe 100644
--- a/src/libs6rc/s6rc_livedir_suffix.c
+++ b/src/libs6rc/s6rc_livedir_prefix.c
@@ -5,15 +5,16 @@
#include <skalibs/djbunix.h>
#include <s6-rc/s6rc-utils.h>
-ssize_t s6rc_livedir_suffix (char const *live, char *s, size_t n)
+ssize_t s6rc_livedir_prefix (char const *live, char *s, size_t n)
{
size_t llen = strlen(live) ;
size_t r ;
char sfn[llen + 8] ;
memcpy(sfn, live, llen) ;
- memcpy(sfn + llen, "/suffix", 8) ;
+ memcpy(sfn + llen, "/prefix", 8) ;
r = openreadnclose(sfn, s, n) ;
if (r < 0) return r ;
- if (memchr(s, '/', r)) return (errno = EINVAL, 0) ;
+ if (memchr(s, '/', r) || memchr(s, '\n', r))
+ return (errno = EINVAL, -1) ;
return r ;
}
diff --git a/src/libs6rc/s6rc_livedir_suffixsize.c b/src/libs6rc/s6rc_livedir_prefixsize.c
index b571dad..daa8481 100644
--- a/src/libs6rc/s6rc_livedir_suffixsize.c
+++ b/src/libs6rc/s6rc_livedir_prefixsize.c
@@ -5,13 +5,13 @@
#include <errno.h>
#include <s6-rc/s6rc-utils.h>
-int s6rc_livedir_suffixsize (char const *live, size_t *n)
+int s6rc_livedir_prefixsize (char const *live, size_t *n)
{
struct stat st ;
size_t llen = strlen(live) ;
char sfn[llen + 8] ;
memcpy(sfn, live, llen) ;
- memcpy(sfn + llen, "/suffix", 8) ;
+ memcpy(sfn + llen, "/prefix", 8) ;
if (stat(sfn, &st) < 0)
{
if (errno != ENOENT) return 0 ;
diff --git a/src/libs6rc/s6rc_servicedir_manage.c b/src/libs6rc/s6rc_servicedir_manage.c
index d39d045..940582c 100644
--- a/src/libs6rc/s6rc_servicedir_manage.c
+++ b/src/libs6rc/s6rc_servicedir_manage.c
@@ -13,24 +13,24 @@
#include <s6/ftrigw.h>
#include <s6-rc/s6rc-servicedir.h>
-static inline void rollback (char const *live, char const *suffix, char const *s, size_t len)
+static inline void rollback (char const *live, char const *prefix, char const *s, size_t len)
{
while (len)
{
size_t n = strlen(s) + 1 ;
- s6rc_servicedir_unsupervise(live, suffix, s, 0) ;
+ s6rc_servicedir_unsupervise(live, prefix, s, 0) ;
s += n ; len -= n ;
}
}
-int s6rc_servicedir_manage (char const *live, char const *suffix, tain_t const *deadline, tain_t *stamp)
+int s6rc_servicedir_manage (char const *live, char const *prefix, tain_t const *deadline, tain_t *stamp)
{
ftrigr_t a = FTRIGR_ZERO ;
stralloc newnames = STRALLOC_ZERO ;
genalloc ids = GENALLOC_ZERO ; /* uint16_t */
gid_t gid = getgid() ;
size_t livelen = strlen(live) ;
- size_t suffixlen = strlen(suffix) ;
+ size_t prefixlen = strlen(prefix) ;
int ok = 1 ;
int e = 0 ;
DIR *dir ;
@@ -53,7 +53,7 @@ int s6rc_servicedir_manage (char const *live, char const *suffix, tain_t const *
int r ;
uint16_t id ;
char srcfn[livelen + 20 + len] ;
- char dstfn[livelen + 10 + len + suffixlen] ;
+ char dstfn[livelen + 10 + prefixlen + len] ;
memcpy(srcfn, dirfn, livelen + 12) ;
srcfn[livelen + 12] = '/' ;
memcpy(srcfn + livelen + 13, d->d_name, len + 1) ;
@@ -76,8 +76,8 @@ int s6rc_servicedir_manage (char const *live, char const *suffix, tain_t const *
else s6_svc_lock_release(fdlock) ;
memcpy(dstfn, live, livelen) ;
memcpy(dstfn + livelen, "/scandir/", 9) ;
- memcpy(dstfn + livelen + 9, d->d_name, len) ;
- memcpy(dstfn + livelen + 9 + len, suffix, suffixlen + 1) ;
+ memcpy(dstfn + livelen + 9, prefix, prefixlen) ;
+ memcpy(dstfn + livelen + 9 + prefixlen, d->d_name, len + 1) ;
if (symlink(srcfn, dstfn) < 0)
{
if (!r || errno != EEXIST) goto err ;
@@ -87,7 +87,7 @@ int s6rc_servicedir_manage (char const *live, char const *suffix, tain_t const *
if (!stralloc_catb(&newnames, d->d_name, len + 1))
{
e = errno ;
- s6rc_servicedir_unsupervise(live, suffix, d->d_name, 0) ;
+ s6rc_servicedir_unsupervise(live, prefix, d->d_name, 0) ;
goto errn ;
}
}
@@ -127,7 +127,7 @@ int s6rc_servicedir_manage (char const *live, char const *suffix, tain_t const *
closederrn:
ftrigr_end(&a) ;
genalloc_free(uint16_t, &ids) ;
- rollback(live, suffix, newnames.s, newnames.len) ;
+ rollback(live, prefix, newnames.s, newnames.len) ;
stralloc_free(&newnames) ;
errno = e ;
return 0 ;
diff --git a/src/libs6rc/s6rc_servicedir_unsupervise.c b/src/libs6rc/s6rc_servicedir_unsupervise.c
index ed95152..5db127b 100644
--- a/src/libs6rc/s6rc_servicedir_unsupervise.c
+++ b/src/libs6rc/s6rc_servicedir_unsupervise.c
@@ -5,16 +5,16 @@
#include <s6/s6-supervise.h>
#include <s6-rc/s6rc-servicedir.h>
-void s6rc_servicedir_unsupervise (char const *live, char const *suffix, char const *name, int keepsupervisor)
+void s6rc_servicedir_unsupervise (char const *live, char const *prefix, char const *name, int keepsupervisor)
{
size_t livelen = strlen(live) ;
- size_t suffixlen = strlen(suffix) ;
+ size_t prefixlen = strlen(prefix) ;
size_t namelen = strlen(name) ;
- char fn[livelen + 14 + namelen + suffixlen] ;
+ char fn[livelen + 14 + prefixlen + namelen] ;
memcpy(fn, live, livelen) ;
memcpy(fn + livelen, "/scandir/", 9) ;
- memcpy(fn + livelen + 9, name, namelen) ;
- memcpy(fn + livelen + 9 + namelen, suffix, suffixlen + 1) ;
+ memcpy(fn + livelen + 9, prefix, prefixlen) ;
+ memcpy(fn + livelen + 9 + prefixlen, name, namelen + 1) ;
unlink(fn) ;
if (!keepsupervisor)
{