From 8d7cba497938020ee5e8f408e6a52cd37274722b Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 22 Sep 2023 08:14:38 +0000 Subject: Make /etc configurable; fix some bugs Signed-off-by: Laurent Bercot --- configure | 8 +++++++- doc/tipidee-config.html | 4 +++- doc/tipideed.html | 4 +++- src/config/tipidee-config.c | 4 ++-- src/tipideed/send_file.c | 35 ++++++++++++++++++----------------- src/tipideed/tipideed.c | 2 +- 6 files changed, 34 insertions(+), 23 deletions(-) diff --git a/configure b/configure index 60c9c45..bbc68e7 100755 --- a/configure +++ b/configure @@ -23,6 +23,7 @@ Fine tuning of the installation directories: --libexecdir=DIR package-scoped executables [EPREFIX/libexec] --libdir=DIR static library files [PREFIX/lib/$package] --includedir=DIR C header files [PREFIX/include] + --sysconfdir=DIR global configuration files [PREFIX/etc] If no --prefix option is given, by default libdir (but not dynlibdir) will be /usr/lib/$package, and includedir will be /usr/include. @@ -140,6 +141,7 @@ libexecdir='$exec_prefix/libexec' bindir='$exec_prefix/bin' libdir='$prefix/lib/$package' includedir='$prefix/include' +sysconfdir='$prefix/etc' sysdeps='$prefix/lib/skalibs/sysdeps' manualsysdeps=false shared=false @@ -169,6 +171,7 @@ for arg ; do --bindir=*) bindir=${arg#*=} ;; --libdir=*) libdir=${arg#*=} ;; --includedir=*) includedir=${arg#*=} ;; + --sysconfdir=*) sysconfdir=${arg#*=} ;; --with-sysdeps=*) sysdeps=${arg#*=} manualsysdeps=true ;; --with-include=*) var=${arg#*=} ; stripdir var ; addincpath="$addincpath -I$var" ;; --with-lib=*) var=${arg#*=} ; stripdir var ; addlibspath="$addlibspath -L$var" ; vpaths="$vpaths $var" ;; @@ -215,7 +218,7 @@ fi # Expand installation directories stripdir prefix -for i in exec_prefix dynlibdir libexecdir bindir libdir includedir sysdeps sproot ; do +for i in exec_prefix dynlibdir libexecdir bindir libdir includedir sysconfdir sysdeps sproot ; do eval tmp=\${$i} eval $i=$tmp stripdir $i @@ -393,6 +396,7 @@ libexecdir := $libexecdir bindir := $bindir libdir := $libdir includedir := $includedir +sysconfdir := $sysconfdir sysdeps := $sysdeps slashpackage := $slashpackage sproot := $sproot @@ -468,6 +472,8 @@ else echo "#define ${package_macro_name}_EXTBINPREFIX \"\"" fi echo "#define ${package_macro_name}_LIBEXECPREFIX \"$libexecdir/\"" +echo "#define ${package_macro_name}_SYSCONFPREFIX \"$sysconfdir/\"" + echo echo "#endif" exec 1>&3 3>&- diff --git a/doc/tipidee-config.html b/doc/tipidee-config.html index 39ca514..2ade779 100644 --- a/doc/tipidee-config.html +++ b/doc/tipidee-config.html @@ -32,7 +32,9 @@ web server. diff --git a/doc/tipideed.html b/doc/tipideed.html index 1b1b17c..955948f 100644 --- a/doc/tipideed.html +++ b/doc/tipideed.html @@ -202,7 +202,9 @@ command line option overrides any setting present in the configuration file. -f file
Use file as the compiled configuration database, typically obtained by running tipidee-config -o file. -The default is /etc/tipidee.conf.cdb.
+The default is /etc/tipidee.conf.cdb; /etc may be something +else if the --sysconfdir option has been given to configure at +build time.
-d docroot
Change the working directory to docroot before serving. Default diff --git a/src/config/tipidee-config.c b/src/config/tipidee-config.c index 235725d..3a8d999 100644 --- a/src/config/tipidee-config.c +++ b/src/config/tipidee-config.c @@ -87,8 +87,8 @@ static inline void conf_output (char const *ofile, unsigned int omode) int main (int argc, char const *const *argv, char const *const *envp) { - char const *ifile = "/etc/tipidee.conf" ; - char const *ofile = "/etc/tipidee.conf.cdb" ; + char const *ifile = TIPIDEE_SYSCONFPREFIX "tipidee.conf" ; + char const *ofile = TIPIDEE_SYSCONFPREFIX "tipidee.conf.cdb" ; unsigned int omode = 0644 ; PROG = "tipidee-config" ; diff --git a/src/tipideed/send_file.c b/src/tipideed/send_file.c index 23a0373..2aeec65 100644 --- a/src/tipideed/send_file.c +++ b/src/tipideed/send_file.c @@ -99,25 +99,26 @@ void send_file (int fd, uint64_t n, char const *fn) { tain deadline ; struct iovec v[2] ; - while (n) + ssize_t r ; + if (!n) goto flushit ; /* I know, I know, but do-while SUCKS */ + fillit: + buffer_wpeek(buffer_1, v) ; + r = allreadv(fd, v, 2) ; + if (r == -1) strerr_diefu2sys(111, "read from ", fn) ; + if (!r) strerr_diefu3x(111, "serve ", fn, ": file was truncated") ; + if (r > n) { - ssize_t r ; - buffer_rpeek(buffer_1, v) ; - r = allreadv(fd, v, 2) ; - if (r == -1) strerr_diefu2sys(111, "read from ", fn) ; - if (!r) strerr_diefu3x(111, "serve ", fn, ": file was truncated") ; - if (r > n) - { - r = n ; - if (g.verbosity >= 2) - strerr_warnw2x("serving elongated file: ", fn) ; - } - buffer_rseek(buffer_1, r) ; - tain_add_g(&deadline, &g.writetto) ; - if (!buffer_timed_flush_g(buffer_1, &deadline)) - strerr_diefu1sys(111, "write to stdout") ; - n -= r ; + r = n ; + if (g.verbosity >= 2) + strerr_warnw2x("serving elongated file: ", fn) ; } + buffer_wseek(buffer_1, r) ; + n -= r ; + flushit: + tain_add_g(&deadline, &g.writetto) ; + if (!buffer_timed_flush_g(buffer_1, &deadline)) + strerr_diefu1sys(111, "write to stdout") ; + if (n) goto fillit ; } #endif diff --git a/src/tipideed/tipideed.c b/src/tipideed/tipideed.c index 13e5d7b..c41553e 100644 --- a/src/tipideed/tipideed.c +++ b/src/tipideed/tipideed.c @@ -335,7 +335,7 @@ int main (int argc, char const *const *argv, char const *const *envp) PROG = progstr ; { - char const *conffile = "/etc/tipidee.conf.cdb" ; + char const *conffile = TIPIDEE_SYSCONFPREFIX "tipidee.conf.cdb" ; char const *newroot = 0 ; unsigned int h = 0 ; int gotv = 0 ; -- cgit v1.2.3