Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 27409 - rc-script of mini_httpd fails to start daemon when cgi-file patterns are enabled because of shell pattern expansion
Summary: rc-script of mini_httpd fails to start daemon when cgi-file patterns are enab...
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Server (show other bugs)
Hardware: x86 Linux
: High minor (vote)
Assignee: Gentoo Web Application Packages Maintainers
Depends on:
Reported: 2003-08-27 02:12 UTC by Karsten Schulz
Modified: 2004-02-27 03:58 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Note You need to log in before you can comment on or make changes to this bug.
Description Karsten Schulz 2003-08-27 02:12:45 UTC
The mini_httpd-1.17_beta1.ebuild installs a config file in /etc/conf.d/mini_httpd. in this 
config file one can activate the cgi functionality by activating the following line: 
unfortunately the rc-script /etc/init.d/mini_httpd will expand the given file pattern 'cgi/*' 
if it matches existing files in the htdocs-directory and so the start-daemon call will fail 
with a syntax error (wrong options) 

Reproducible: Always
Steps to Reproduce:
1. copy some files into $MINI_HTTPD_DOCROOT/cgi/ 
2. remove '#' from the line MINI_HTTPD_OPTS="$MINI_HTTPD_OPTS -c cgi/*" in 
3. try to start daemon: /etc/init.d/mini_httpd start 
Actual Results:  
the mini_httpd daemon will not start and print the following error message: 
 * Starting mini_httpd... 
usage:  /usr/sbin/mini_httpd [-C configfile] [-D] [-S] [-E certfile] [-Y cipher] [-p port] [-d 
dir] [-c cgipat] [-u user] [-h hostname] [-r] [-v] [-l logfile] [-i pidfile] [-T charset] [-P P3P] 
[-M maxage]                 [ !! ] 
This is, because the pattern cgi/* expands to the existing filenames in the directory  
$MINI_HTTPD_DOCROOT/cgi/ and so the option -c of the command line will have too 
much arguments (all filenames in ../cgi/*) 

Expected Results:  
start the daemon 

As far as I can see, the easiest way to solve this bug is to use a config file for 
mini_httpd instead of command line options. So the content of /etc/conf.d/mini_httpd 
should be changed to: 
MINI_HTTPD_OPTS="-C /etc/mini_httpd.conf" 
and one should use (and the ebuild should install) a /etc/mini_httpd.conf file. 
(an example config file is provided in 
After that, the daemon will read its configuration from /etc/mini_httpd.conf.
Comment 1 Thomas Eckert 2003-08-30 00:29:39 UTC
It seems to work for me.
1. the default conf.d/mini_httpd suggests
  resulting in _all_ files ending with .cgi _anywhere_ in your docroot to be
  handled as cgis.
  => that works without pattern-expansion of "*" by the shell
2. I changed MINI_HTTPD_OPTS to your line and tested ... that works too:
  relevant start-line from init-script:
     start-stop-daemon --quiet --start --startas /usr/sbin/mini_httpd \
                --pidfile /var/run/ -- ${MINI_HTTPD_OPTS}
  => startup results in the following:
# ps aux | grep mini
nobody   21123  0.0  0.1  2608  928 ?        S    09:22   0:00 /usr/sbin/mini_httpd -p 80 -u nobody -i /var/run/ -l /var/log/mini_httpd.log -c cgi/*

Are you 100% sure that there is no quoting-/syntax-error in your conf.d-script?

Comment 2 Karsten Schulz 2003-08-30 04:33:21 UTC
Hi Thomas, 
thanks for testing! 
If my line works for you, you probably forgot to populate the cgi-directory with some 
files, which name match the given wildcard? 
this is my /etc/conf.d/mini_httpd (copy and paste, comment lines deleted): 
MINI_HTTPD_OPTS=" -S -p 8080 -u nobody -i /var/run/ -l 
this is the content of the htdoc dir (ls /home/httpd/htdocs): 
root@t800:root > ls /home/httpd/htdocs/ 
cgi  htdig  index.html 
and this is the content of the cgi dir (ls /home/httpd/htdocs/cgi): 
root@t800:root > ls /home/httpd/htdocs/cgi/ 
bla.cgi  fasel.cgi  x.cgi 
root@t800:root > 
in this configuration,  the startscript fails: 
* Starting mini_httpd... 
usage:  /usr/sbin/mini_httpd [-C configfile] [-D] [-S] [-E certfile] [-Y cipher] [-p port] [-d 
dir] [-c cgipat] [-u user] [-h hostname] [-r] [-v] [-l logfile] [-i pidfile] [-T charset] [-P 
P3P] [-M maxage]                 [ !! ] 
this is, because the command line ist expanded to: 
+ start-stop-daemon --quiet --start --startas /usr/sbin/mini_httpd --pidfile 
/var/run/ -- -S -p 8080 -u nobody -i /var/run/ -l 
/var/log/mini_httpd.log -c cgi/bla.cgi cgi/fasel.cgi cgi/x.cgi 
(you can see this line, if you add set -x to the script) 
That should not happen, because the option '-c cgi-bin/*' is taken from the manpage 
of mini_httpd. 
I agree, that the pattern '**.cgi' does not raise this error situation, but the start  script 
should be more robust in the case, that someone uses other patterns. 
Comment 3 Thomas Eckert 2003-08-30 05:13:21 UTC
as you suspected -- I did not populate the cgi-directory, if I do so I get the
error you described.

trying to preserve the cmd-line-option in conf.d/mini_httpd would lead to a quoting-desert (if it works at all) that isn't less error-prone than the
current solution.

the only clean solution that comes to my mind is to remove the cmd-line-stuff
completely from conf.d/mini_httpd and point the user to the sample-configfile.

what do you think?
Comment 4 Karsten Schulz 2003-08-30 08:59:33 UTC
I would suggest, that the ebuild unpacks 
/usr/doc/mini_httpd-VERSION/mini_httpd.conf.sample.gz and copy it into 
/etc/mini_httpd.conf and change the /etc/conf.d/mini_httpd file into: 
MINI_HTTPD_OPTS="-C /etc/mini_httpd.conf" 
the provided conf example does exact the same setting, the command line options 
do now. 
Comment 5 Thomas Eckert 2003-09-06 08:18:42 UTC
OK, here are 2 suggestions for the gentoo-devs:

1. eliminate the options in conf.d and use a /etc/mini_httpd.conf:
--- mini_httpd.init     2003-03-04 07:51:41.000000000 +0100
+++ mini_httpd.init-r1  2003-09-06 17:11:23.000000000 +0200
@@ -18,7 +18,7 @@
                eend $? "ERROR: cannot change to docroot \"$MINI_HTTPD_DOCROOT\""
        start-stop-daemon --quiet --start --startas /usr/sbin/mini_httpd \
-               --pidfile /var/run/ -- ${MINI_HTTPD_OPTS}
+               --pidfile /var/run/ -- -C /etc/mini_httpd.conf
        eend $?
--- mini_httpd-1.17_beta1.ebuild        2003-09-06 04:13:23.000000000 +0200
+++ mini_httpd-1.17_beta1-r1.ebuild     2003-09-06 17:13:03.000000000 +0200
@@ -54,12 +54,14 @@
        mv ${D}/usr/share/man/man1/{,mini_}htpasswd.1
        exeinto /etc/init.d
-       newexe ${FILESDIR}/mini_httpd.init mini_httpd
-       insinto /etc/conf.d
-       newins ${FILESDIR}/mini_httpd.confd mini_httpd
-       dodoc README ${FILESDIR}/mini_httpd.conf.sample
+       newexe ${FILESDIR}/mini_httpd.init-r1 mini_httpd
+       insinto /etc
+       newins ${FILESDIR}/mini_httpd.conf.sample mini_httpd.conf
+       dodoc README
 pkg_postinst() {
-       ewarn "Adjust MINI_HTTPD_DOCROOT in /etc/conf.d/mini_httpd !"
+       ewarn "Adjust /etc/mini_httpd.conf!"

2. add a note to /etc/conf.d/mini_httpd like the following:
--- mini_httpd.confd    2003-03-04 07:51:41.000000000 +0100
+++ mini_httpd.confd-r1 2003-09-06 17:16:52.000000000 +0200
@@ -18,5 +18,9 @@
 MINI_HTTPD_OPTS="-p 8080 -u nobody -r -i /var/run/ -l /var/log/mini_httpd.log"
-## to add cgi-support:
+## to add cgi-support you should switch over to a config-file, a sample can
+## be found in your DOCDESTTREE (/usr/share/doc/mini_httpd-xxxx) named
+##     mini_httpd.conf.sample.gz
+## copy the sample to /etc/mini_httpd.conf and replace the MINI_HTTPD_OPTS-line
+## above by:
+##MINI_HTTPD_OPTS="-C /etc/mini_httpd.conf"

Personally I would prefer 2. as it's following KISS.

Comment 6 Karsten Schulz 2003-09-07 00:39:33 UTC
Thank you Thomas. I would support the KISS principle, too. So suggestion #2 seems 
to be fine. 
Comment 7 Stuart Herbert (RETIRED) gentoo-dev 2003-10-04 06:17:34 UTC

I've committed the suggested comment changes to the conf.d file.  It should
appear on your local rsync mirror within the hour.  Could you please take
a look, and confirm that the changes made are what you need?

Comment 8 Thomas Eckert 2003-10-04 08:57:17 UTC
Perfect -- I think it should be clear enough what to do to get CGIs working.

Thanks for adding,
Comment 9 Stuart Herbert (RETIRED) gentoo-dev 2003-10-04 09:27:10 UTC
Excellent - bug closed.
Comment 10 Stuart Herbert (RETIRED) gentoo-dev 2004-02-27 03:58:36 UTC
Closing bug - user verified that the fix worked.