summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/s6-rc/s6-rc-bundle.c102
-rw-r--r--src/s6-rc/s6-rc-compile.c18
-rw-r--r--src/s6-rc/s6-rc-db.c104
-rw-r--r--src/s6-rc/s6-rc-update.c85
-rw-r--r--src/s6-rc/s6-rc.c39
5 files changed, 127 insertions, 221 deletions
diff --git a/src/s6-rc/s6-rc-bundle.c b/src/s6-rc/s6-rc-bundle.c
index 3825e25..9ba5084 100644
--- a/src/s6-rc/s6-rc-bundle.c
+++ b/src/s6-rc/s6-rc-bundle.c
@@ -14,7 +14,7 @@
#include <skalibs/bitarray.h>
#include <skalibs/djbunix.h>
#include <skalibs/cdb.h>
-#include <skalibs/cdb_make.h>
+#include <skalibs/cdbmake.h>
#include <skalibs/unix-transactional.h>
#include <execline/execline.h>
@@ -53,10 +53,11 @@ static inline int renameit (char const *compiled, char const *src, char const *d
return rename(srcfn, dstfn) ;
}
-static void check (cdb_t *cr, s6rc_db_t *db, char const *name, int h, int force, char const *compiled)
+static void check (cdb const *cr, s6rc_db_t *db, char const *name, int h, int force, char const *compiled)
{
size_t namelen = strlen(name) ;
- int r = cdb_find(cr, name, namelen) ;
+ cdb_data data ;
+ int r = cdb_find(cr, &data, name, namelen) ;
if (r < 0) strerr_diefu3sys(111, "cdb_find in ", compiled, "/resolve.cdb") ;
if (!r)
{
@@ -66,13 +67,10 @@ static void check (cdb_t *cr, s6rc_db_t *db, char const *name, int h, int force,
}
if (h && !force)
strerr_dief4x(1, "identifier ", name, " already exists in database ", compiled) ;
- if (cdb_datalen(cr) == 4)
+ if (data.len == 4)
{
uint32_t x ;
- char pack[4] ;
- if (cdb_read(cr, pack, 4, cdb_datapos(cr)) < 0)
- strerr_diefu3sys(111, "cdb_read ", compiled, "/resolve.cdb") ;
- uint32_unpack_big(pack, &x) ;
+ uint32_unpack_big(data.s, &x) ;
if (x >= db->nshort + db->nlong)
strerr_dief2x(4, "invalid database in ", compiled) ;
if (!strcmp(name, db->string + db->services[x].name))
@@ -82,63 +80,43 @@ static void check (cdb_t *cr, s6rc_db_t *db, char const *name, int h, int force,
static void modify_resolve (int fdcompiled, s6rc_db_t *db, char const *const *todel, unsigned int todeln, char const *const *toadd, char const *const *const *toadd_contents, unsigned int toaddn, int force, char const *compiled)
{
- cdb_t cr = CDB_ZERO ;
- struct cdb_make cw = CDB_MAKE_ZERO ;
- uint32_t kpos ;
+ cdb cr = CDB_ZERO ;
+ cdbmaker cw = CDBMAKER_ZERO ;
+ uint32_t pos = CDB_TRAVERSE_INIT() ;
unsigned int i = toaddn ;
int fdw ;
- int fdr = open_readatb(fdcompiled, "resolve.cdb") ;
unsigned int n = db->nlong + db->nshort ;
unsigned char bits[bitarray_div8(n)] ;
- if (fdr < 0) strerr_diefu3sys(111, "open ", compiled, "/resolve.cdb") ;
- if (!cdb_init_map(&cr, fdr, 1))
+ if (!cdb_init_at(&cr, fdcompiled, "resolve.cdb"))
strerr_diefu3sys(111, "cdb_init ", compiled, "/resolve.cdb") ;
while (i--) check(&cr, db, toadd[i], 1, force, compiled) ;
i = todeln ;
while (i--) check(&cr, db, todel[i], 0, force, compiled) ;
fdw = open_truncatb(fdcompiled, "resolve.cdb.new") ;
if (fdw < 0) strerr_diefu3sys(111, "open ", compiled, "/resolve.cdb.new") ;
- if (cdb_make_start(&cw, fdw) < 0)
+ if (!cdbmake_start(&cw, fdw))
{
cleanup(compiled) ;
- strerr_diefu1sys(111, "cdb_make_start") ;
+ strerr_diefu1sys(111, "cdbmake_start") ;
}
- cdb_traverse_init(&cr, &kpos) ;
for (;;)
{
- int r = cdb_nextkey(&cr, &kpos) ;
+ cdb_data key, data ;
+ int r = cdb_traverse_next(&cr, &key, &data, &pos) ;
if (r < 0)
{
cleanup(compiled) ;
- strerr_diefu3sys(111, "cdb_nextkey in ", compiled, "/resolve.cdb") ;
+ strerr_dief3x(4, "invalid cdb in ", compiled, "/resolve.cdb") ;
}
if (!r) break ;
+ for (i = 0 ; i < todeln ; i++) if (key.len == strlen(todel[i]) && !strncmp(todel[i], key.s, key.len)) break ;
+ if (i < todeln) continue ;
+ for (i = 0 ; i < toaddn ; i++) if (key.len == strlen(toadd[i]) && !strncmp(toadd[i], key.s, key.len)) break ;
+ if (i < toaddn) continue ;
+ if (!cdbmake_add(&cw, key.s, key.len, data.s, data.len))
{
- uint32_t klen = cdb_keylen(&cr) ;
- char ktmp[klen + 1] ;
- if (cdb_read(&cr, ktmp, klen, cdb_keypos(&cr)) < 0)
- {
- cleanup(compiled) ;
- strerr_diefu3sys(111, "cdb_read ", compiled, "/resolve.cdb") ;
- }
- for (i = 0 ; i < todeln ; i++) if (klen == strlen(todel[i]) && !strncmp(todel[i], ktmp, klen)) break ;
- if (i < todeln) continue ;
- for (i = 0 ; i < toaddn ; i++) if (klen == strlen(toadd[i]) && !strncmp(toadd[i], ktmp, klen)) break ;
- if (i < toaddn) continue ;
- {
- uint32_t dlen = cdb_datalen(&cr) ;
- char dtmp[dlen + 1] ;
- if (cdb_read(&cr, dtmp, dlen, cdb_datapos(&cr)) < 0)
- {
- cleanup(compiled) ;
- strerr_diefu3sys(111, "cdb_read ", compiled, "/resolve.cdb") ;
- }
- if (cdb_make_add(&cw, ktmp, klen, dtmp, dlen) < 0)
- {
- cleanup(compiled) ;
- strerr_diefu1sys(111, "cdb_make_add") ;
- }
- }
+ cleanup(compiled) ;
+ strerr_diefu1sys(111, "cdb_make_add") ;
}
}
i = toaddn ;
@@ -149,30 +127,21 @@ static void modify_resolve (int fdcompiled, s6rc_db_t *db, char const *const *to
memset(bits, 0, bitarray_div8(n)) ;
for (; *p ; p++)
{
- int r = cdb_find(&cr, *p, strlen(*p)) ;
- if (r < 0) strerr_diefu3sys(111, "cdb_find in ", compiled, "/resolve.cdb") ;
+ cdb_data data ;
+ int r = cdb_find(&cr, &data, *p, strlen(*p)) ;
+ if (r < 0) strerr_diefu3x(4, "invalid cdb in ", compiled, "/resolve.cdb") ;
if (!r) strerr_dief4x(3, "identifier ", *p, " does not exist in database ", compiled) ;
+ for (uint32_t j = 0 ; j < data.len ; j += 4)
{
- uint32_t j = cdb_datalen(&cr) ;
- char pack[j + 1] ;
- if (cdb_read(&cr, pack, j, cdb_datapos(&cr)) < 0)
- {
- cleanup(compiled) ;
- strerr_diefu3sys(111, "cdb_read ", compiled, "/resolve.cdb") ;
- }
- j >>= 2 ;
- while (j--)
- {
- uint32_t x ;
- uint32_unpack_big(pack + (j << 2), &x) ;
- if (x >= db->nshort + db->nlong)
- strerr_dief2x(4, "invalid database in ", compiled) ;
- if (!bitarray_testandset(bits, x)) total++ ;
- }
+ uint32_t x ;
+ uint32_unpack_big(data.s + j, &x) ;
+ if (x >= db->nshort + db->nlong)
+ strerr_dief2x(4, "invalid database in ", compiled) ;
+ if (!bitarray_testandset(bits, x)) total++ ;
}
}
{
- char pack[(total << 2) + 1] ;
+ char pack[total << 2 ? total << 2 : 1] ;
char *s = pack ;
uint32_t j = n ;
while (j--) if (bitarray_peek(bits, j))
@@ -180,16 +149,15 @@ static void modify_resolve (int fdcompiled, s6rc_db_t *db, char const *const *to
uint32_pack_big(s, j) ;
s += 4 ;
}
- if (cdb_make_add(&cw, toadd[i], strlen(toadd[i]), pack, total << 2) < 0)
+ if (!cdbmake_add(&cw, toadd[i], strlen(toadd[i]), pack, total << 2))
{
cleanup(compiled) ;
- strerr_diefu1sys(111, "cdb_make_add") ;
+ strerr_diefu1sys(111, "cdbmake_add") ;
}
}
}
cdb_free(&cr) ;
- close(fdr) ;
- if (cdb_make_finish(&cw) < 0 || fsync(fdw) < 0)
+ if (!cdbmake_finish(&cw) || fsync(fdw) < 0)
{
cleanup(compiled) ;
strerr_diefu3sys(111, "write to ", compiled, "/resolve.cdb.new") ;
diff --git a/src/s6-rc/s6-rc-compile.c b/src/s6-rc/s6-rc-compile.c
index c233f1a..4e9f270 100644
--- a/src/s6-rc/s6-rc-compile.c
+++ b/src/s6-rc/s6-rc-compile.c
@@ -14,7 +14,7 @@
#include <skalibs/sgetopt.h>
#include <skalibs/allreadwrite.h>
#include <skalibs/buffer.h>
-#include <skalibs/cdb_make.h>
+#include <skalibs/cdbmake.h>
#include <skalibs/direntry.h>
#include <skalibs/djbunix.h>
#include <skalibs/stralloc.h>
@@ -1114,7 +1114,7 @@ static inline void write_resolve (char const *compiled, s6rc_db_t const *db, bun
{
size_t clen = strlen(compiled) ;
int fd ;
- struct cdb_make c = CDB_MAKE_ZERO ;
+ cdbmaker c = CDBMAKER_ZERO ;
unsigned int i = db->nshort + db->nlong ;
char fn[clen + 13] ;
if (verbosity >= 3) strerr_warni3x("writing ", compiled, "/resolve.cdb") ;
@@ -1126,10 +1126,10 @@ static inline void write_resolve (char const *compiled, s6rc_db_t const *db, bun
cleanup(compiled) ;
strerr_diefu2sys(111, "open_trunc ", fn) ;
}
- if (cdb_make_start(&c, fd) < 0)
+ if (!cdbmake_start(&c, fd))
{
cleanup(compiled) ;
- strerr_diefu2sys(111, "cdb_make_start on ", fn) ;
+ strerr_diefu2sys(111, "cdbmake_start on ", fn) ;
}
/* atomic services */
@@ -1137,10 +1137,10 @@ static inline void write_resolve (char const *compiled, s6rc_db_t const *db, bun
{
char pack[4] ;
uint32_pack_big(pack, i) ;
- if (cdb_make_add(&c, db->string + db->services[i].name, strlen(db->string + db->services[i].name), pack, 4) < 0)
+ if (!cdbmake_add(&c, db->string + db->services[i].name, strlen(db->string + db->services[i].name), pack, 4))
{
cleanup(compiled) ;
- strerr_diefu1sys(111, "cdb_make_add") ;
+ strerr_diefu1sys(111, "cdbmake_add") ;
}
}
@@ -1152,14 +1152,14 @@ static inline void write_resolve (char const *compiled, s6rc_db_t const *db, bun
char pack[(bundles[i].n << 2) + 1] ; /* +1 because braindead C standard */
for (; j < bundles[i].n ; j++)
uint32_pack_big(pack + (j << 2), bdeps[bundles[i].listindex + j]) ;
- if (cdb_make_add(&c, data.s + bundles[i].name, strlen(data.s + bundles[i].name), pack, bundles[i].n << 2) < 0)
+ if (!cdbmake_add(&c, data.s + bundles[i].name, strlen(data.s + bundles[i].name), pack, bundles[i].n << 2))
{
cleanup(compiled) ;
- strerr_diefu1sys(111, "cdb_make_add") ;
+ strerr_diefu1sys(111, "cdbmake_add") ;
}
}
- if (cdb_make_finish(&c) < 0 || fsync(fd) < 0)
+ if (!cdbmake_finish(&c) || fsync(fd) < 0)
{
cleanup(compiled) ;
strerr_diefu2sys(111, "write to ", fn) ;
diff --git a/src/s6-rc/s6-rc-db.c b/src/s6-rc/s6-rc-db.c
index d29b148..5650124 100644
--- a/src/s6-rc/s6-rc-db.c
+++ b/src/s6-rc/s6-rc-db.c
@@ -24,22 +24,18 @@ static s6rc_db_t *db ;
static void print_bundle_contents (char const *name)
{
- cdb_t c = CDB_ZERO ;
- int fd = open_readatb(fdcompiled, "resolve.cdb") ;
+ cdb c = CDB_ZERO ;
+ cdb_data data ;
int r ;
- if (fd < 0) strerr_diefu3sys(111, "open ", compiled, "/resolve.cdb") ;
- if (!cdb_init_map(&c, fd, 1))
+ if (!cdb_init_at(&c, fdcompiled, "resolve.cdb"))
strerr_diefu3sys(111, "cdb_init ", compiled, "/resolve.cdb") ;
- r = cdb_find(&c, name, strlen(name)) ;
- if (r < 0) strerr_diefu3sys(111, "read ", compiled, "/resolve.cdb") ;
+ r = cdb_find(&c, &data, name, strlen(name)) ;
+ if (r < 0) strerr_dief3x(4, "invalid cdb in ", compiled, "/resolve.cdb") ;
if (!r) strerr_dief3x(3, name, " is not a valid identifier in ", compiled) ;
- if (cdb_datalen(&c) == 4)
+ if (data.len == 4)
{
uint32_t x ;
- char pack[4] ;
- if (cdb_read(&c, pack, 4, cdb_datapos(&c)) < 0)
- strerr_diefu3sys(111, "cdb_read ", compiled, "/resolve.cdb") ;
- uint32_unpack_big(pack, &x) ;
+ uint32_unpack_big(data.s, &x) ;
if (x >= db->nshort + db->nlong)
strerr_dief2x(4, "invalid database in ", compiled) ;
if (!strcmp(name, db->string + db->services[x].name))
@@ -50,17 +46,12 @@ static void print_bundle_contents (char const *name)
}
else
{
- uint32_t len = cdb_datalen(&c) >> 2 ;
- char pack[cdb_datalen(&c) + 1] ;
- char const *p = pack ;
- if (cdb_datalen(&c) & 3)
+ if (data.len & 3)
strerr_dief2x(4, "invalid database in ", compiled) ;
- if (cdb_read(&c, pack, cdb_datalen(&c), cdb_datapos(&c)) < 0)
- strerr_diefu3sys(111, "cdb_read ", compiled, "/resolve.cdb") ;
- while (len--)
+ while (data.len)
{
uint32_t x ;
- uint32_unpack_big(p, &x) ; p += 4 ;
+ uint32_unpack_big(data.s, &x) ; data.s += 4 ; data.len -= 4 ;
if (x >= db->nshort + db->nlong)
strerr_dief2x(4, "invalid database in ", compiled) ;
if (buffer_puts(buffer_1, db->string + db->services[x].name) < 0
@@ -69,7 +60,6 @@ static void print_bundle_contents (char const *name)
}
}
cdb_free(&c) ;
- close(fd) ;
if (!buffer_flush(buffer_1))
strerr_diefu1sys(111, "write to stdout") ;
}
@@ -88,63 +78,49 @@ static void print_services (unsigned int from, unsigned int to)
static void print_all (int bundlesonly)
{
- cdb_t c = CDB_ZERO ;
- uint32_t kpos ;
- int fd = open_readatb(fdcompiled, "resolve.cdb") ;
- if (fd < 0) strerr_diefu3sys(111, "open ", compiled, "/resolve.cdb") ;
- if (!cdb_init_map(&c, fd, 1))
+ cdb c = CDB_ZERO ;
+ uint32_t pos = CDB_TRAVERSE_INIT() ;
+ if (!cdb_init_at(&c, fdcompiled, "resolve.cdb"))
strerr_diefu3sys(111, "cdb_init ", compiled, "/resolve.cdb") ;
- cdb_traverse_init(&c, &kpos) ;
for (;;)
{
- int r = cdb_nextkey(&c, &kpos) ;
- char name[cdb_keylen(&c) + 1] ;
- if (r < 0) strerr_diefu3sys(111, "read ", compiled, "/resolve.cdb") ;
+ cdb_data key, data ;
+ int r = cdb_traverse_next(&c, &key, &data, &pos) ;
+ if (r < 0) strerr_dief3x(4, "invalid cdb in ", compiled, "/resolve.cdb") ;
if (!r) break ;
- if (cdb_read(&c, name, cdb_keylen(&c), cdb_keypos(&c)) < 0)
- strerr_diefu3sys(111, "cdb_read ", compiled, "/resolve.cdb") ;
- if (bundlesonly && cdb_datalen(&c) == 4)
+ if (bundlesonly && data.len == 4)
{
uint32_t x ;
- char pack[4] ;
- if (cdb_read(&c, pack, 4, cdb_datapos(&c)) < 0)
- strerr_diefu3sys(111, "cdb_read ", compiled, "/resolve.cdb") ;
- uint32_unpack_big(pack, &x) ;
+ uint32_unpack_big(data.s, &x) ;
if (x >= db->nshort + db->nlong)
strerr_dief2x(4, "invalid database in ", compiled) ;
- if (!memcmp(name, db->string + db->services[x].name, cdb_keylen(&c))
- && !db->string[db->services[x].name + cdb_keylen(&c)])
+ if (!strncmp(key.s, db->string + db->services[x].name, key.len)
+ && !db->string[db->services[x].name + key.len])
continue ;
}
- name[cdb_keylen(&c)] = '\n' ;
- if (buffer_put(buffer_1, name, cdb_keylen(&c) + 1) < 0)
+ if (buffer_put(buffer_1, key.s, key.len) < 0
+ || buffer_put(buffer_1, "\n", 1) < 0)
strerr_diefu1sys(111, "write to stdout") ;
}
cdb_free(&c) ;
- close(fd) ;
if (!buffer_flush(buffer_1))
strerr_diefu1sys(111, "write to stdout") ;
}
static unsigned int resolve_service (char const *name)
{
- cdb_t c = CDB_ZERO ;
- int fd = open_readatb(fdcompiled, "resolve.cdb") ;
+ cdb c = CDB_ZERO ;
+ cdb_data data ;
uint32_t x ;
- char pack[4] ;
int r ;
- if (fd < 0) strerr_diefu3sys(111, "open ", compiled, "/resolve.cdb") ;
- if (!cdb_init_map(&c, fd, 1))
+ if (!cdb_init_at(&c, fdcompiled, "resolve.cdb"))
strerr_diefu3sys(111, "cdb_init ", compiled, "/resolve.cdb") ;
- r = cdb_find(&c, name, strlen(name)) ;
- if (r < 0) strerr_diefu3sys(111, "read ", compiled, "/resolve.cdb") ;
+ r = cdb_find(&c, &data, name, strlen(name)) ;
+ if (r < 0) strerr_dief3x(4, "invalid cdb in ", compiled, "/resolve.cdb") ;
if (!r) strerr_dief3x(3, name, " is not a valid identifier in ", compiled) ;
- if (cdb_datalen(&c) != 4) return db->nshort + db->nlong ;
- if (cdb_read(&c, pack, 4, cdb_datapos(&c)) < 0)
- strerr_diefu3sys(111, "cdb_read ", compiled, "/resolve.cdb") ;
- uint32_unpack_big(pack, &x) ;
+ if (data.len != 4) return db->nshort + db->nlong ;
+ uint32_unpack_big(data.s, &x) ;
cdb_free(&c) ;
- close(fd) ;
if (x >= db->nshort + db->nlong)
strerr_dief2x(4, "invalid database in ", compiled) ;
if (strcmp(name, db->string + db->services[x].name))
@@ -238,28 +214,23 @@ static inline void print_flags (char const *name)
static void print_union (char const *const *argv, int h, int isdeps, int doclosure)
{
unsigned int n = db->nshort + db->nlong ;
- cdb_t c = CDB_ZERO ;
- int fd = open_readatb(fdcompiled, "resolve.cdb") ;
+ cdb c = CDB_ZERO ;
unsigned char state[n] ;
- if (fd < 0) strerr_diefu3sys(111, "open ", compiled, "/resolve.cdb") ;
- if (!cdb_init_map(&c, fd, 1))
+ if (!cdb_init_at(&c, fdcompiled, "resolve.cdb"))
strerr_diefu3sys(111, "cdb_init ", compiled, "/resolve.cdb") ;
memset(state, 0, n) ;
for (; *argv ; argv++)
{
- int r = cdb_find(&c, *argv, strlen(*argv)) ;
- if (r < 0) strerr_diefu3sys(111, "read ", compiled, "/resolve.cdb") ;
+ cdb_data data ;
+ int r = cdb_find(&c, &data, *argv, strlen(*argv)) ;
+ if (r < 0) strerr_dief3x(4, "invalid cdb in ", compiled, "/resolve.cdb") ;
if (!r) strerr_dief3x(3, *argv, " is not a valid identifier in ", compiled) ;
{
- uint32_t len = cdb_datalen(&c) >> 2 ;
- char pack[cdb_datalen(&c) + 1] ;
- char const *p = pack ;
- if (cdb_read(&c, pack, cdb_datalen(&c), cdb_datapos(&c)) < 0)
- strerr_diefu3sys(111, "cdb_read ", compiled, "/resolve.cdb") ;
- while (len--)
+ if (data.len & 3) strerr_dief2x(4, "invalid database in ", compiled) ;
+ while (data.len)
{
uint32_t x ;
- uint32_unpack_big(p, &x) ; p += 4 ;
+ uint32_unpack_big(data.s, &x) ; data.s += 4 ; data.len -= 4 ;
if (x >= db->nshort + db->nlong)
strerr_dief2x(4, "invalid database in ", compiled) ;
if (isdeps)
@@ -273,7 +244,6 @@ static void print_union (char const *const *argv, int h, int isdeps, int doclosu
}
}
cdb_free(&c) ;
- close(fd) ;
if (doclosure) s6rc_graph_closure(db, state, 0, h) ;
while (n--) if (state[n])
if (buffer_puts(buffer_1, db->string + db->services[n].name) < 0
diff --git a/src/s6-rc/s6-rc-update.c b/src/s6-rc/s6-rc-update.c
index eb6104a..2a308a9 100644
--- a/src/s6-rc/s6-rc-update.c
+++ b/src/s6-rc/s6-rc-update.c
@@ -66,7 +66,7 @@ static unsigned int verbosity = 1 ;
128 -> depends on a new service, has to be restarted
*/
-static inline void parse_line (stralloc *sa, char const *s, size_t slen, unsigned int *newnames, unsigned char *oldstate, cdb_t *oldc, s6rc_db_t const *olddb)
+static inline void parse_line (stralloc *sa, char const *s, size_t slen, unsigned int *newnames, unsigned char *oldstate, cdb const *oldc, s6rc_db_t const *olddb)
{
size_t base = sa->len ;
unsigned int oldn = olddb->nshort + olddb->nlong ;
@@ -84,16 +84,14 @@ static inline void parse_line (stralloc *sa, char const *s, size_t slen, unsigne
sa->len = base ;
if (n--)
{
- char pack[4] ;
+ cdb_data data ;
uint32_t x ;
unsigned int cur ;
- int r = cdb_find(oldc, sa->s + base + slen, strlen(sa->s + base + slen)) ;
- if (r < 0) strerr_diefu3sys(111, "read ", live, "/compiled/resolve.cdb") ;
+ int r = cdb_find(oldc, &data, sa->s + base + slen, strlen(sa->s + base + slen)) ;
+ if (r < 0) strerr_dief3x(4, "invalid cdb in ", live, "/compiled/resolve.cdb") ;
if (!r) strerr_dief5x(3, "unknown identifier in ", live, "/compiled/resolve.cdb", ": ", sa->s + base + slen) ;
- if (cdb_datalen(oldc) != 4) strerr_dief5x(5, "identifier ", sa->s + base + slen, " does not represent an atomic service in ", live, "/compiled") ;
- if (cdb_read(oldc, pack, 4, cdb_datapos(oldc)) < 0)
- strerr_diefu3sys(111, "read ", live, "/compiled/resolve.cdb") ;
- uint32_unpack_big(pack, &x) ;
+ if (data.len != 4) strerr_dief5x(5, "identifier ", sa->s + base + slen, " does not represent an atomic service in ", live, "/compiled") ;
+ uint32_unpack_big(data.s, &x) ;
if (x >= oldn) strerr_dief3x(4, "invalid database in ", live, "/compiled") ;
if (oldstate[x] & 64)
strerr_dief3x(6, "service ", olddb->string + olddb->services[x].name, " appears more than once in conversion file") ;
@@ -118,7 +116,7 @@ static inline void parse_line (stralloc *sa, char const *s, size_t slen, unsigne
}
}
-static inline void parse_conversion_file (char const *convfile, stralloc *sa, unsigned int *newnames, unsigned char *oldstate, cdb_t *oldc, s6rc_db_t const *olddb)
+static inline void parse_conversion_file (char const *convfile, stralloc *sa, unsigned int *newnames, unsigned char *oldstate, cdb const *oldc, s6rc_db_t const *olddb)
{
int fd = openb_read(convfile) ;
char buf[4096] ;
@@ -146,19 +144,14 @@ static inline void parse_conversion_file (char const *convfile, stralloc *sa, un
static inline void stuff_with_oldc (unsigned char *oldstate, int fdoldc, s6rc_db_t const *olddb, char const *convfile, unsigned int *oldindex, stralloc *namedata)
{
- cdb_t oldc = CDB_ZERO ;
- int oldfdres = open_readatb(fdoldc, "resolve.cdb") ;
- if (oldfdres < 0) strerr_diefu3sys(111, "open ", live, "/compiled/resolve.cdb") ;
- if (!cdb_init_map(&oldc, oldfdres, 1))
+ cdb oldc = CDB_ZERO ;
+ if (!cdb_init_at(&oldc, fdoldc, "resolve.cdb"))
strerr_diefu3sys(111, "cdb_init ", live, "/compiled/resolve.cdb") ;
-
parse_conversion_file(convfile, namedata, oldindex, oldstate, &oldc, olddb) ;
-
cdb_free(&oldc) ;
- close(oldfdres) ;
}
-static inline void fill_convtable_and_flags (unsigned char *conversion_table, unsigned char *oldstate, unsigned char *newstate, char const *namedata, unsigned int const *oldindex, unsigned int *invimage, cdb_t *newc, char const *newfn, s6rc_db_t const *olddb, s6rc_db_t const *newdb)
+static inline void fill_convtable_and_flags (unsigned char *conversion_table, unsigned char *oldstate, unsigned char *newstate, char const *namedata, unsigned int const *oldindex, unsigned int *invimage, cdb const *newc, char const *newfn, s6rc_db_t const *olddb, s6rc_db_t const *newdb)
{
unsigned int newn = newdb->nshort + newdb->nlong ;
unsigned int i = olddb->nshort + olddb->nlong ;
@@ -166,9 +159,9 @@ static inline void fill_convtable_and_flags (unsigned char *conversion_table, un
while (i--)
{
char const *newname = oldstate[i] & 16 ? namedata + oldindex[i] : olddb->string + olddb->services[i].name ;
- uint32_t len ;
- int r = cdb_find(newc, newname, strlen(newname)) ;
- if (r < 0) strerr_diefu3sys(111, "read ", newfn, "/resolve.cdb") ;
+ cdb_data data ;
+ int r = cdb_find(newc, &data, newname, strlen(newname)) ;
+ if (r < 0) strerr_dief3x(111, "invalid cdb in ", newfn, "/resolve.cdb") ;
if (!r)
{
if (oldstate[i] & 16)
@@ -176,35 +169,26 @@ static inline void fill_convtable_and_flags (unsigned char *conversion_table, un
oldstate[i] |= 34 ; /* disappeared */
continue ;
}
- if (cdb_datalen(newc) & 3)
- strerr_dief3x(4, "invalid resolve database in ", newfn, "/resolve.cdb") ;
- len = cdb_datalen(newc) >> 2 ;
- if (len > newn)
+ if (data.len & 3) strerr_dief3x(4, "invalid resolve database in ", newfn, "/resolve.cdb") ;
+ if (data.len >> 2 > newn)
strerr_dief3x(4, "invalid resolve database in ", newfn, "/resolve.cdb") ;
+ if (data.len == 4) oldstate[i] |= 8 ;
+ while (data.len)
{
- char pack[cdb_datalen(newc) + 1] ;
- char const *p = pack ;
- if (cdb_read(newc, pack, cdb_datalen(newc), cdb_datapos(newc)) < 0)
- strerr_diefu3sys(111, "read ", newfn, "/resolve.cdb") ;
- if (len == 1) oldstate[i] |= 8 ;
- while (len--)
+ uint32_t x ;
+ uint32_unpack_big(data.s, &x) ; data.s += 4 ; data.len -= 4 ;
+ if (x >= newn)
+ strerr_dief3x(4, "invalid resolve database in ", newfn, "/resolve.cdb") ;
+ if (newstate[x] & 8)
+ strerr_diefu4x(6, "convert database: new service ", newdb->string + newdb->services[x].name, " is a target for more than one conversion, including old service ", olddb->string + olddb->services[i].name) ;
+ newstate[x] |= 8 ;
+ invimage[x] = i ;
+ if (oldstate[i] & 16) newstate[x] |= 16 ;
+ bitarray_set(conversion_table + i * bitarray_div8(newn), x) ;
+ if (oldstate[i] & 8)
{
- uint32_t x ;
- uint32_unpack_big(p, &x) ; p += 4 ;
- if (x >= newn)
- strerr_dief3x(4, "invalid resolve database in ", newfn, "/resolve.cdb") ;
- if (newstate[x] & 8)
- strerr_diefu4x(6, "convert database: new service ", newdb->string + newdb->services[x].name, " is a target for more than one conversion, including old service ", olddb->string + olddb->services[i].name) ;
- newstate[x] |= 8 ;
- invimage[x] = i ;
- if (oldstate[i] & 16) newstate[x] |= 16 ;
- bitarray_set(conversion_table + i * bitarray_div8(newn), x) ;
- if (oldstate[i] & 8)
- {
- newstate[x] |= 4 ;
- if ((i < olddb->nlong) != (x < newdb->nlong))
- oldstate[i] |= 4 ;
- }
+ newstate[x] |= 4 ;
+ if ((i < olddb->nlong) != (x < newdb->nlong)) oldstate[i] |= 4 ;
}
}
}
@@ -212,16 +196,11 @@ static inline void fill_convtable_and_flags (unsigned char *conversion_table, un
static inline void stuff_with_newc (int fdnewc, char const *newfn, unsigned char *conversion_table, unsigned char *oldstate, unsigned char *newstate, char const *namedata, unsigned int const *oldindex, unsigned int *invimage, s6rc_db_t const *olddb, s6rc_db_t const *newdb)
{
- cdb_t newc = CDB_ZERO ;
- int newfdres = open_readatb(fdnewc, "resolve.cdb") ;
- if (newfdres < 0) strerr_diefu3sys(111, "open ", newfn, "/compiled/resolve.cdb") ;
- if (!cdb_init_map(&newc, newfdres, 1))
+ cdb newc = CDB_ZERO ;
+ if (!cdb_init_at(&newc, fdnewc, "resolve.cdb"))
strerr_diefu3sys(111, "cdb_init ", newfn, "/compiled/resolve.cdb") ;
-
fill_convtable_and_flags(conversion_table, oldstate, newstate, namedata, oldindex, invimage, &newc, newfn, olddb, newdb) ;
-
cdb_free(&newc) ;
- close(newfdres) ;
}
static void compute_transitions (char const *convfile, unsigned char *oldstate, int fdoldc, s6rc_db_t const *olddb, unsigned char *newstate, unsigned int *invimage, int fdnewc, char const *newfn, s6rc_db_t const *newdb, stralloc *sa)
diff --git a/src/s6-rc/s6-rc.c b/src/s6-rc/s6-rc.c
index b63fd14..0c67722 100644
--- a/src/s6-rc/s6-rc.c
+++ b/src/s6-rc/s6-rc.c
@@ -589,40 +589,29 @@ int main (int argc, char const *const *argv)
/* Resolve the args and add them to the selection */
{
- cdb_t c = CDB_ZERO ;
- int fd = open_readatb(fdcompiled, "resolve.cdb") ;
- if (fd < 0) strerr_diefu3sys(111, "open ", dbfn, "/resolve.cdb") ;
- if (!cdb_init_map(&c, fd, 1))
+ cdb c = CDB_ZERO ;
+ if (!cdb_init_at(&c, fdcompiled, "resolve.cdb"))
strerr_diefu3sys(111, "cdb_init ", dbfn, "/resolve.cdb") ;
for (; *argv ; argv++)
{
- uint32_t len ;
- int r = cdb_find(&c, *argv, strlen(*argv)) ;
- if (r < 0) strerr_diefu3sys(111, "read ", dbfn, "/resolve.cdb") ;
- if (!r)
- strerr_dief4x(3, *argv, " is not a recognized identifier in ", dbfn, "/resolve.cdb") ;
- if (cdb_datalen(&c) & 3)
+ cdb_data data ;
+ int r = cdb_find(&c, &data, *argv, strlen(*argv)) ;
+ if (r < 0) strerr_dief3x(4, "invalid cdb in ", dbfn, "/resolve.cdb") ;
+ if (!r) strerr_dief4x(3, *argv, " is not a recognized identifier in ", dbfn, "/resolve.cdb") ;
+ if (data.len & 3)
strerr_dief3x(4, "invalid resolve database in ", dbfn, "/resolve.cdb") ;
- len = cdb_datalen(&c) >> 2 ;
- if (len > n)
+ if (data.len >> 2 > n)
strerr_dief3x(4, "invalid resolve database in ", dbfn, "/resolve.cdb") ;
+ while (data.len)
{
- char pack[cdb_datalen(&c) + 1] ;
- char const *p = pack ;
- if (cdb_read(&c, pack, cdb_datalen(&c), cdb_datapos(&c)) < 0)
- strerr_diefu3sys(111, "read ", dbfn, "/resolve.cdb") ;
- while (len--)
- {
- uint32_t x ;
- uint32_unpack_big(p, &x) ; p += 4 ;
- if (x >= n)
- strerr_dief3x(4, "invalid resolve database in ", dbfn, "/resolve.cdb") ;
- state[x] |= 2 ;
- }
+ uint32_t x ;
+ uint32_unpack_big(data.s, &x) ; data.s += 4 ; data.len -= 4 ;
+ if (x >= n)
+ strerr_dief3x(4, "invalid resolve database in ", dbfn, "/resolve.cdb") ;
+ state[x] |= 2 ;
}
}
cdb_free(&c) ;
- close(fd) ;
}
close(fdcompiled) ;