summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-06-11 10:20:57 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-06-11 10:20:57 +0000
commit04025bdc6c15c307ffa4fbcf39eec39024b9b935 (patch)
tree7b8ef3976b28882a9071279f27f203d9e5b42925 /src
parentc1000a7cfdd12a686e3846f15dce81a5c5d79955 (diff)
downloads6-rc-04025bdc6c15c307ffa4fbcf39eec39024b9b935.tar.xz
Fix totally buggy db->argvs management
Diffstat (limited to 'src')
-rw-r--r--src/include/s6-rc/s6rc-db.h2
-rw-r--r--src/libs6rc/s6rc_db_read.c18
-rw-r--r--src/s6-rc/s6-rc-compile.c30
-rw-r--r--src/s6-rc/s6-rc-db.c4
-rw-r--r--src/s6-rc/s6-rc.c4
5 files changed, 29 insertions, 29 deletions
diff --git a/src/include/s6-rc/s6rc-db.h b/src/include/s6-rc/s6rc-db.h
index bc475c7..cc2bb9f 100644
--- a/src/include/s6-rc/s6rc-db.h
+++ b/src/include/s6-rc/s6rc-db.h
@@ -54,7 +54,7 @@ struct s6rc_db_s
unsigned int nargvs ;
unsigned int ndeps ;
char *string ;
- char **argvs ;
+ char const **argvs ;
uint32 *deps ;
} ;
diff --git a/src/libs6rc/s6rc_db_read.c b/src/libs6rc/s6rc_db_read.c
index f0c7909..f10462c 100644
--- a/src/libs6rc/s6rc_db_read.c
+++ b/src/libs6rc/s6rc_db_read.c
@@ -52,7 +52,7 @@ static inline int s6rc_db_read_services (buffer *b, s6rc_db_t *db)
unsigned int n = db->nshort + db->nlong ;
s6rc_service_t *sv = db->services ;
unsigned int nargvs = db->nargvs ;
- char **argvs = db->argvs ;
+ unsigned int argvpos = 0 ;
char type ;
#ifdef DEBUG
register unsigned int i = 0 ;
@@ -106,19 +106,19 @@ static inline int s6rc_db_read_services (buffer *b, s6rc_db_t *db)
sv->type = 0 ;
for (; i < 2 ; i++)
{
- uint32 argvpos, argc ;
+ uint32 pos, argc ;
if (!s6rc_db_read_uint32(b, &argc)) return -1 ;
DBG(" argc[%u] is %u, nargvs is %u", i, argc, nargvs) ;
if (argc > nargvs) return 0 ;
- if (!s6rc_db_read_uint32(b, &argvpos)) return -1 ;
- DBG(" argvpos[%u] is %u", i, argvpos) ;
- if (!s6rc_db_check_valid_strings(db->string, db->stringlen, argvpos, argc)) return 0 ;
- if (!env_make((char const **)argvs, argc, db->string + argvpos, db->stringlen - argvpos)) return -1 ;
- DBG(" first arg is %s", argvs[0]) ;
+ if (!s6rc_db_read_uint32(b, &pos)) return -1 ;
+ DBG(" pos[%u] is %u", i, pos) ;
+ if (!s6rc_db_check_valid_strings(db->string, db->stringlen, pos, argc)) return 0 ;
+ if (!env_make((char const **)db->argvs + argvpos, argc, db->string + pos, db->stringlen - pos)) return -1 ;
+ DBG(" first arg is %s", db->argvs[argvpos]) ;
sv->x.oneshot.argv[i] = argvpos ;
sv->x.oneshot.argc[i] = argc ;
- argvs += argc ; nargvs -= argc ;
- if (!nargvs--) return 0 ; *argvs++ = 0 ;
+ argvpos += argc ; nargvs -= argc ;
+ if (!nargvs--) return 0 ; db->argvs[argvpos++] = 0 ;
}
}
if (buffer_get(b, &type, 1) < 1) return -1 ;
diff --git a/src/s6-rc/s6-rc-compile.c b/src/s6-rc/s6-rc-compile.c
index 87808ef..3e41ac1 100644
--- a/src/s6-rc/s6-rc-compile.c
+++ b/src/s6-rc/s6-rc-compile.c
@@ -25,12 +25,12 @@
#include <s6/config.h>
#include <s6-rc/s6rc.h>
-#ifdef DEBUG
-# include <skalibs/lolstdio.h>
-# define DBG(...) do { buffer_puts(buffer_2, PROG) ; buffer_puts(buffer_2, ": debug: ") ; bprintf(buffer_2, __VA_ARGS__) ; buffer_putflush(buffer_2, "\n", 1) ; } while (0)
-#else
-# define DBG(...)
-#endif
+// #ifdef DEBUG
+// # include <skalibs/lolstdio.h>
+// # define DBG(...) do { buffer_puts(buffer_2, PROG) ; buffer_puts(buffer_2, ": debug: ") ; bprintf(buffer_2, __VA_ARGS__) ; buffer_putflush(buffer_2, "\n", 1) ; } while (0)
+// #else
+// # define DBG(...)
+// #endif
#define USAGE "s6-rc-compile [ -v verbosity ] destdir sources..."
#define dieusage() strerr_dieusage(100, USAGE)
@@ -547,20 +547,20 @@ static void resolve_bundle_rec (bundle_recinfo_t *recinfo, unsigned int i)
register nameinfo_t const *p ;
avltree_search(&names_map, data.s + listindex[j], &id) ;
p = genalloc_s(nameinfo_t, &nameinfo) + id ;
- DBG("resolve_bundle_rec: %s depends on %s", data.s + me->name, data.s + p->pos) ;
+// DBG("resolve_bundle_rec: %s depends on %s", data.s + me->name, data.s + p->pos) ;
switch (p->type)
{
case SVTYPE_ONESHOT :
bitarray_set(recinfo->barray + i * recinfo->nbits, recinfo->nlong + p->i) ;
- DBG("resolve_bundle_rec: %s is a oneshot, setting bit %u in barray[%u]", data.s + p->pos, recinfo->nlong + p->i, i) ;
+// DBG("resolve_bundle_rec: %s is a oneshot, setting bit %u in barray[%u]", data.s + p->pos, recinfo->nlong + p->i, i) ;
break ;
case SVTYPE_LONGRUN :
bitarray_set(recinfo->barray + i * recinfo->nbits, p->i) ;
- DBG("resolve_bundle_rec: %s is a longrun, setting bit %u in barray[%u]", data.s + p->pos, p->i, i) ;
+// DBG("resolve_bundle_rec: %s is a longrun, setting bit %u in barray[%u]", data.s + p->pos, p->i, i) ;
break ;
case SVTYPE_BUNDLE :
resolve_bundle_rec(recinfo, p->i) ;
- DBG("resolve_bundle_rec: %s is a bundle, adding barray[%u] to barray[%u]", data.s + p->pos, p->i, i) ;
+// DBG("resolve_bundle_rec: %s is a bundle, adding barray[%u] to barray[%u]", data.s + p->pos, p->i, i) ;
bitarray_or(recinfo->barray + i * recinfo->nbits, recinfo->barray + i * recinfo->nbits, recinfo->barray + p->i * recinfo->nbits, recinfo->n) ;
break ;
default :
@@ -607,7 +607,7 @@ static inline void flatlist_bundles (bundle_t *bundles, unsigned int nbundles, u
if (bitarray_peek(mybits, j))
{
mydeps[k++] = j ;
- DBG("flatlist_bundles: bundle %u contains service %u", i, j) ;
+// DBG("flatlist_bundles: bundle %u contains service %u", i, j) ;
}
}
}
@@ -621,12 +621,12 @@ static void resolve_deps (common_t const *me, unsigned int nlong, unsigned int n
register nameinfo_t const *p ;
avltree_search(&names_map, data.s + indices[me->depindex + j], &id) ;
p = genalloc_s(nameinfo_t, &nameinfo) + id ;
- DBG("resolve_deps: %s depends on %s", data.s + me->name, data.s + p->pos) ;
+// DBG("resolve_deps: %s depends on %s", data.s + me->name, data.s + p->pos) ;
switch (p->type)
{
case SVTYPE_ONESHOT :
bitarray_set(sarray, nlong + p->i) ;
- DBG("resolve_deps: %s is a oneshot, setting bit %u in sarray for %s", data.s + p->pos, nlong + p->i, data.s + me->name) ;
+// DBG("resolve_deps: %s is a oneshot, setting bit %u in sarray for %s", data.s + p->pos, nlong + p->i, data.s + me->name) ;
if (verbosity >= 4)
{
char fmt[UINT_FMT] ;
@@ -636,7 +636,7 @@ static void resolve_deps (common_t const *me, unsigned int nlong, unsigned int n
break ;
case SVTYPE_LONGRUN :
bitarray_set(sarray, p->i) ;
- DBG("resolve_deps: %s is a longrun, setting bit %u in sarray for %s", data.s + p->pos, p->i, data.s + me->name) ;
+// DBG("resolve_deps: %s is a longrun, setting bit %u in sarray for %s", data.s + p->pos, p->i, data.s + me->name) ;
if (verbosity >= 4)
{
char fmt[UINT_FMT] ;
@@ -646,7 +646,7 @@ static void resolve_deps (common_t const *me, unsigned int nlong, unsigned int n
break ;
case SVTYPE_BUNDLE :
bitarray_or(sarray, sarray, barray + p->i * nbits, n) ;
- DBG("resolve_deps: %s is a bundle, ORing barray[%u] into sarray for %s", data.s + p->pos, p->i, data.s + me->name) ;
+// DBG("resolve_deps: %s is a bundle, ORing barray[%u] into sarray for %s", data.s + p->pos, p->i, data.s + me->name) ;
if (verbosity >= 4)
{
char fmt[UINT_FMT] ;
diff --git a/src/s6-rc/s6-rc-db.c b/src/s6-rc/s6-rc-db.c
index d0bd845..e6b5e8c 100644
--- a/src/s6-rc/s6-rc-db.c
+++ b/src/s6-rc/s6-rc-db.c
@@ -211,7 +211,7 @@ static void print_deps (char const *name, int h)
static void print_script (char const *name, int h)
{
unsigned int argc ;
- char *const *argv ;
+ char const *const *argv ;
unsigned int n = resolve_service(name) ;
if (n >= db->nshort + db->nlong)
strerr_dief5x(1, "in database ", compiled, ": identifier ", name, " represents a bundle") ;
@@ -409,7 +409,7 @@ int main (int argc, char const *const *argv)
{
unsigned int n = dbblob.nshort + dbblob.nlong ;
s6rc_service_t serviceblob[n] ;
- char *argvblob[dbblob.nargvs] ;
+ char const *argvblob[dbblob.nargvs] ;
uint32 depsblob[dbblob.ndeps << 1] ;
char stringblob[dbblob.stringlen] ;
register int r ;
diff --git a/src/s6-rc/s6-rc.c b/src/s6-rc/s6-rc.c
index a60439e..ad69d5d 100644
--- a/src/s6-rc/s6-rc.c
+++ b/src/s6-rc/s6-rc.c
@@ -84,7 +84,7 @@ static void print_services (void)
static pid_t start_oneshot (unsigned int i, int h)
{
unsigned int argc = db->services[i].x.oneshot.argc[h] ;
- char const *const *argv = (char const *const *)db->argvs + h * db->ndeps + db->services[i].x.oneshot.argv[h] ;
+ char const *const *argv = db->argvs + db->services[i].x.oneshot.argv[h] ;
unsigned int m = 0 ;
char const *newargv[9 + argc + (!!dryrun[0] << 2)] ;
char fmt[UINT32_FMT] ;
@@ -390,7 +390,7 @@ int main (int argc, char const *const *argv)
{
s6rc_service_t serviceblob[n] ;
- char *argvblob[dbblob.nargvs] ;
+ char const *argvblob[dbblob.nargvs] ;
uint32 depsblob[dbblob.ndeps << 1] ;
char stringblob[dbblob.stringlen] ;
unsigned char stateblob[n] ;