summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.macos (renamed from README.macosx)2
-rw-r--r--src/s6-rc/s6-rc-compile.c50
2 files changed, 35 insertions, 17 deletions
diff --git a/README.macosx b/README.macos
index d71a096..4c497de 100644
--- a/README.macosx
+++ b/README.macos
@@ -1,4 +1,4 @@
- This package will compile and run on Darwin (MacOS X), but the building of
+ This package will compile and run on Darwin (MacOS), but the building of
shared libraries is not supported.
Make sure you use the --disable-shared option to configure.
diff --git a/src/s6-rc/s6-rc-compile.c b/src/s6-rc/s6-rc-compile.c
index cca081d..a07a6f2 100644
--- a/src/s6-rc/s6-rc-compile.c
+++ b/src/s6-rc/s6-rc-compile.c
@@ -6,6 +6,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
+#include <stdlib.h> /* qsort */
#include <skalibs/types.h>
#include <skalibs/bitarray.h>
#include <skalibs/strerr2.h>
@@ -486,18 +487,16 @@ static inline void add_source (before_t *be, int dirfd, char const *srcdir, char
else strerr_dief6x(1, "invalid ", srcdir, "/", name, "/type", ": must be oneshot, longrun, or bundle") ;
}
-static inline void add_sources (before_t *be, char const *srcdir)
+static inline void add_sources (before_t *be, char const *srcdir, stralloc *sa)
{
- size_t start = satmp.len ;
- size_t cur ;
+ unsigned int n = 0 ;
+ int fdsrc ;
DIR *dir = opendir(srcdir) ;
if (!dir) strerr_diefu2sys(111, "opendir ", srcdir) ;
- if (!stralloc_cats(&satmp, srcdir) || !stralloc_catb(&satmp, "/", 1)) dienomem() ;
- cur = satmp.len ;
+ fdsrc = dirfd(dir) ;
for (;;)
{
struct stat st ;
- int fd ;
direntry *d ;
errno = 0 ;
d = readdir(dir) ;
@@ -506,19 +505,34 @@ static inline void add_sources (before_t *be, char const *srcdir)
if (strchr(d->d_name, '\n'))
strerr_dief3x(1, "subdirectory of ", srcdir, " contains a newline character") ;
check_identifier(srcdir, d->d_name) ;
- satmp.len = cur ;
- if (!stralloc_catb(&satmp, d->d_name, strlen(d->d_name) + 1)) dienomem() ;
- if (stat(satmp.s + start, &st) < 0)
- strerr_diefu2sys(111, "stat ", satmp.s + start) ;
+ if (stat_at(fdsrc, d->d_name, &st) < 0)
+ strerr_diefu4sys(111, "stat ", srcdir, "/", d->d_name) ;
if (!S_ISDIR(st.st_mode)) continue ;
- fd = open_readb(satmp.s + start) ;
- if (fd < 0) strerr_diefu2sys(111, "open ", satmp.s + start) ;
- add_source(be, fd, srcdir, d->d_name) ;
- close(fd) ;
+ n++ ;
+ if (!stralloc_catb(sa, d->d_name, strlen(d->d_name)+1)) dienomem() ;
}
if (errno) strerr_diefu2sys(111, "readdir ", srcdir) ;
+ if (n)
+ {
+ size_t pos = 0 ;
+ char const *names[n] ;
+ for (unsigned int i = 0 ; i < n ; i++)
+ {
+ names[i] = sa->s + pos ;
+ pos += strlen(sa->s + pos) + 1 ;
+ }
+ qsort(names, n, sizeof(char const *), (int (*)(const void *, const void *))&strcmp) ;
+ for (unsigned int i = 0 ; i < n ; i++)
+ {
+ int fd = open_readatb(fdsrc, names[i]) ;
+ if (fd < 0) strerr_diefu4sys(111, "open ", srcdir, "/", names[i]) ;
+ add_source(be, fd, srcdir, names[i]) ;
+ close(fd) ;
+ }
+ sa->len = 0 ;
+ }
+ else if (verbosity) strerr_warnw3x("source ", srcdir, " is empty") ;
dir_close(dir) ;
- satmp.len = start ;
}
struct pipeline_recinfo_s
@@ -1463,7 +1477,11 @@ int main (int argc, char const *const *argv)
compiled = *argv++ ;
before.specialdeps[0] = add_internal_longrun(&before, S6RC_ONESHOT_RUNNER) ;
before.specialdeps[1] = add_internal_longrun(&before, S6RC_FDHOLDER) ;
- for (; *argv ; argv++) add_sources(&before, *argv) ;
+ {
+ stralloc sa = STRALLOC_ZERO ;
+ for (; *argv ; argv++) add_sources(&before, *argv, &sa) ;
+ stralloc_free(&sa) ;
+ }
add_pipeline_bundles(&before) ;
{