Documentation Source Text

Check-in [a970d449c6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improvements to standalone mode in althttpd.c.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a970d449c6c82ea34e5f2ea906ee018f1057954b
User & Date: drh 2013-07-16 22:15:57
Context
2013-07-17
00:17
Tweaks to the text describing the hazards of upgrading to the NGQP. check-in: 232b584bda user: drh tags: trunk
2013-07-16
22:15
Improvements to standalone mode in althttpd.c. check-in: a970d449c6 user: drh tags: trunk
2013-07-15
17:11
The log file for althttpd is now RFC-4180 CSV. Cherry-pick merge from check-in [52bfa21f48e14a29]. check-in: 93ba1a8d9d user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to misc/althttpd.c.

   140    140   static time_t beginTime;         /* Time when this process starts */
   141    141   static int closeConnection = 0;  /* True to send Connection: close in reply */
   142    142   static int nRequest = 0;         /* Number of requests processed */
   143    143   static int omitLog = 0;          /* Do not make logfile entries if true */
   144    144   static int useHttps = 0;         /* True to use HTTPS: instead of HTTP: */
   145    145   static char *zHttp = "http";     /* http or https */
   146    146   static int useTimeout = 1;       /* True to use times */
          147  +static int standalone = 0;       /* Run as a standalone server (no inetd) */
   147    148   static int ipv6Only = 0;         /* Use IPv6 only */
   148    149   static int ipv4Only = 0;         /* Use IPv4 only */
   149    150   
   150    151   /*
   151    152   ** Double any double-quote characters in a string.
   152    153   */
   153    154   static char *Escape(char *z){
................................................................................
  1147   1148         }
  1148   1149       }
  1149   1150       strcpy(&zLine[i], ".website");
  1150   1151     }
  1151   1152     if( stat(zLine,&statbuf) || !S_ISDIR(statbuf.st_mode) ){
  1152   1153       sprintf(zLine, "%s/default.website", zRoot);
  1153   1154       if( stat(zLine,&statbuf) || !S_ISDIR(statbuf.st_mode) ){
  1154         -      NotFound(__LINE__);
         1155  +      if( standalone ){
         1156  +        sprintf(zLine, "%s\n", zRoot);
         1157  +      }else{
         1158  +        NotFound(__LINE__);
         1159  +      }
  1155   1160       }
  1156   1161     }
  1157         -  
  1158   1162     zHome = StrDup(zLine);
  1159   1163   
  1160   1164     /* Change directories to the root of the HTTP filesystem
  1161   1165     */
  1162   1166     if( chdir(zHome)!=0 ){
  1163   1167       char zBuf[1000];
  1164   1168       Malfunction(__LINE__, "cannot chdir to [%s] from [%s]",
................................................................................
  1604   1608               int nErr = 0, fd;
  1605   1609               close(0);
  1606   1610               fd = dup(connection);
  1607   1611               if( fd!=0 ) nErr++;
  1608   1612               close(1);
  1609   1613               fd = dup(connection);
  1610   1614               if( fd!=1 ) nErr++;
  1611         -            close(2);
  1612         -            fd = dup(connection);
  1613         -            if( fd!=2 ) nErr++;
  1614   1615               close(connection);
  1615   1616               return nErr;
  1616   1617             }
  1617   1618           }
  1618   1619         }
  1619   1620         /* Bury dead children */
  1620   1621         while( (child = waitpid(0, 0, WNOHANG))>0 ){
................................................................................
  1652   1653       }else if( strcmp(z,"-logfile")==0 ){
  1653   1654         zLogFile = zArg;
  1654   1655       }else if( strcmp(z,"-https")==0 ){
  1655   1656         useHttps = atoi(zArg);
  1656   1657         zHttp = useHttps ? "http" : "https";
  1657   1658       }else if( strcmp(z, "-port")==0 ){
  1658   1659         zPort = zArg;
         1660  +      standalone = 1;
  1659   1661       }else if( strcmp(z, "-family")==0 ){
  1660   1662         if( strcmp(zArg, "ipv4")==0 ){
  1661   1663           ipv4Only = 1;
  1662   1664         }else if( strcmp(zArg, "ipv6")==0 ){
  1663   1665           ipv6Only = 1;
  1664   1666         }else{
  1665   1667           Malfunction(__LINE__, "unknown IP protocol: [%s]", zArg);
................................................................................
  1675   1677       }else{
  1676   1678         Malfunction(__LINE__, "unknown argument: [%s]", z);
  1677   1679       }
  1678   1680       argv += 2;
  1679   1681       argc -= 2;
  1680   1682     }
  1681   1683     if( zRoot==0 ){
  1682         -    Malfunction(__LINE__, "no --root specified");
         1684  +    if( standalone ){
         1685  +      zRoot = ".";
         1686  +    }else{
         1687  +      Malfunction(__LINE__, "no --root specified");
         1688  +    }
  1683   1689     }
  1684   1690     
  1685   1691     /* Change directories to the root of the HTTP filesystem.  Then
  1686   1692     ** create a chroot jail there.
  1687   1693     */
  1688   1694     if( chdir(zRoot)!=0 ){
  1689   1695       Malfunction(__LINE__, "cannot change to directory [%s]", zRoot);