Slightly modified patch from James Beal: add --no-eof (or --noeof) as
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Fri, 17 Dec 2010 16:24:33 +0000 (16:24 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Fri, 17 Dec 2010 16:24:33 +0000 (16:24 +0000)
an option to the web server mode, to inhibit it from trying to read
stdin and treating EOF there as a cue to shut down.

git-svn-id: svn://svn.tartarus.org/sgt/agedu@9036 cda61777-01e9-0310-a592-d414129be87e

agedu.but
agedu.c
httpd.c
httpd.h

index e98e556..4e90a14 100644 (file)
--- a/agedu.but
+++ b/agedu.but
@@ -166,10 +166,11 @@ default it invents its own URL and prints it out.
 
 \lcont{
 
 
 \lcont{
 
-The web server runs until \cw{agedu} receives an end-of-file event
-on its standard input. (The expected usage is that you run it from
-the command line, immediately browse web pages until you're
-satisfied, and then press Ctrl-D.)
+The web server runs until \cw{agedu} receives an end-of-file event on
+its standard input. (The expected usage is that you run it from the
+command line, immediately browse web pages until you're satisfied, and
+then press Ctrl-D.) To disable the EOF behaviour, use the
+\cw{--no-eof} option.
 
 In case the index file contains any confidential information about
 your file system, the web server protects the pages it serves from
 
 In case the index file contains any confidential information about
 your file system, the web server protects the pages it serves from
@@ -638,6 +639,11 @@ consist of the username, followed by a colon, followed by the
 password, followed \e{immediately} by end of file (no trailing
 newline, or else it will be considered part of the password).
 
 password, followed \e{immediately} by end of file (no trailing
 newline, or else it will be considered part of the password).
 
+\dt \cw{--no-eof}
+
+\dd Stop \cw{agedu} in web server mode from looking for end-of-file on
+standard input and treating it as a signal to terminate.
+
 \U LIMITATIONS
 
 The data file is pretty large. The core of \cw{agedu} is the
 \U LIMITATIONS
 
 The data file is pretty large. The core of \cw{agedu} is the
diff --git a/agedu.c b/agedu.c
index 08286a5..afaa556 100644 (file)
--- a/agedu.c
+++ b/agedu.c
@@ -341,6 +341,8 @@ static void text_query(const void *mappedfile, const char *querydir,
         HELPOPT("[--scan,--load] keep real atimes on directories") \
     NOVAL(NODIRATIME) LONG(no_dir_atime) LONG(no_dir_atimes) \
         HELPOPT("[--scan,--load] fake atimes on directories") \
         HELPOPT("[--scan,--load] keep real atimes on directories") \
     NOVAL(NODIRATIME) LONG(no_dir_atime) LONG(no_dir_atimes) \
         HELPOPT("[--scan,--load] fake atimes on directories") \
+    NOVAL(NOEOF) LONG(no_eof) LONG(noeof) \
+        HELPOPT("[--web] do not close web server on EOF") \
     NOVAL(MTIME) LONG(mtime) \
         HELPOPT("[--scan] use mtime instead of atime") \
     NOVAL(SHOWFILES) LONG(files) \
     NOVAL(MTIME) LONG(mtime) \
         HELPOPT("[--scan] use mtime instead of atime") \
     NOVAL(SHOWFILES) LONG(files) \
@@ -510,6 +512,7 @@ int main(int argc, char **argv)
     int depth = -1, gotdepth = 0;
     int fakediratimes = 1;
     int mtime = 0;
     int depth = -1, gotdepth = 0;
     int fakediratimes = 1;
     int mtime = 0;
+    int closeoneof = 1;
     int showfiles = 0;
 
 #ifdef DEBUG_MAD_OPTION_PARSING_MACROS
     int showfiles = 0;
 
 #ifdef DEBUG_MAD_OPTION_PARSING_MACROS
@@ -767,6 +770,9 @@ int main(int argc, char **argv)
                  case OPT_MTIME:
                    mtime = 1;
                    break;
                  case OPT_MTIME:
                    mtime = 1;
                    break;
+                  case OPT_NOEOF:
+                    closeoneof = 0;
+                    break;
                  case OPT_DATAFILE:
                    filename = optval;
                    break;
                  case OPT_DATAFILE:
                    filename = optval;
                    break;
@@ -1589,6 +1595,7 @@ int main(int argc, char **argv)
 
            dcfg.address = httpserveraddr;
            dcfg.port = httpserverport;
 
            dcfg.address = httpserveraddr;
            dcfg.port = httpserverport;
+           dcfg.closeoneof = closeoneof;
            dcfg.basicauthdata = httpauthdata;
            pcfg.format = NULL;
            pcfg.rootpage = NULL;
            dcfg.basicauthdata = httpauthdata;
            pcfg.format = NULL;
            pcfg.rootpage = NULL;
diff --git a/httpd.c b/httpd.c
index aa40084..dd7aa23 100644 (file)
--- a/httpd.c
+++ b/httpd.c
@@ -569,17 +569,20 @@ void run_httpd(const void *t, int authmask, const struct httpd_config *dcfg,
        printf("URL: http://%s:%d/\n",
               inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
     }
        printf("URL: http://%s:%d/\n",
               inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
     }
+    fflush(stdout);
 
     /*
      * Now construct an fd structure to hold it.
      */
     new_fdstruct(fd, FD_LISTENER);
 
 
     /*
      * Now construct an fd structure to hold it.
      */
     new_fdstruct(fd, FD_LISTENER);
 
-    /*
-     * Read from standard input, and treat EOF as a notification
-     * to exit.
-     */
-    new_fdstruct(0, FD_CLIENT);
+    if (dcfg->closeoneof) {
+        /*
+         * Read from standard input, and treat EOF as a notification
+         * to exit.
+         */
+       new_fdstruct(0, FD_CLIENT);
+    }
 
     /*
      * Now we're ready to run our main loop. Keep looping round on
 
     /*
      * Now we're ready to run our main loop. Keep looping round on
diff --git a/httpd.h b/httpd.h
index 1683ebb..a964e2f 100644 (file)
--- a/httpd.h
+++ b/httpd.h
@@ -10,6 +10,7 @@
 struct httpd_config {
     const char *address;
     int port;
 struct httpd_config {
     const char *address;
     int port;
+    int closeoneof;
     const char *basicauthdata;
 };
 
     const char *basicauthdata;
 };