alt-httpd/boa patch

Don Mahurin <[email protected]> Mon, 9 Dec 2002 15:46:56 -0800
Newsgroups gmane.comp.file-systems.intermezzo.devel
Message-ID <[email protected]>
Attached is a patch that lets you use boa or another http daemon with 
intermezzo.

I works against boa 0.94.14rc7.

This patch is useful when using intermezzo in an embedded system, where apache 
is less suitable.

to use it, specify --alt-http=boa or --alt-http=/somelocation/boa

You can actually specify web servers other than boa. If the httpd name is not 
boa or apache, it will use a generic httpd conf file.

Can others try this out and report success or failures.

-don
alt-httpd.patch (text/x-diff, 7.5 KB)
diff -ru intersync-0.9.5/intersync/intersync.c intersync-0.9.5-new/intersync/intersync.c
--- intersync-0.9.5/intersync/intersync.c	Thu Sep 26 12:23:26 2002
+++ intersync-0.9.5-new/intersync/intersync.c	Thu Dec  5 13:44:15 2002
@@ -103,21 +103,28 @@
                 kill_pidfile(pidfile, sig);
 
         if (sig == SIGHUP)
-                CERROR("Reloading apache");
+                CERROR("Reloading httpd");
         else {
                 pidfile = NULL;
                 g_error("Shutting down on signal %d\n", sig);
         }
 }
 
+/* return last filename in path */
+static char * pathfilename(char *path)
+{
+	char *match = NULL;
+	if(path != NULL) match = strrchr(path, '/');
+	return (match == NULL) ? path : match + 1;
+}
 
-static void start_server(char *docroot, char * ip, int port)
+static void start_server(char *docroot, char * ip, int port, char *httpd)
 {
         struct passwd *pw; 
         struct group *gr;
         struct stat stbuf;
         struct sigaction sigact;
-        char *cmd, *httpd, *configfile;
+        char *cmd, *configfile, *httpdname;
         int rc;
         struct sockaddr_in sa;
         __u64 localip;
@@ -142,8 +149,6 @@
         }
 
         pidfile = g_strdup_printf("%s/httpd.pid", docroot);
-        configfile = g_strdup_printf("%s/intersync-httpd.conf", docroot);
-        config_apache_conf(configfile, ip, port, docroot, IS_CGIDIR);
 
         sigact.sa_handler = signal_server;
         sigfillset(&sigact.sa_mask);
@@ -152,15 +157,27 @@
         sigaction(SIGINT, &sigact, NULL);
         sigaction(SIGTERM, &sigact, NULL);
 
-        httpd = "/usr/sbin/httpd";
-        if (stat(httpd, &stbuf) && errno == ENOENT)
-                httpd = "/usr/sbin/apache";
-        cmd = g_strdup_printf("%s -f %s", httpd, configfile);
-
+	httpdname = pathfilename(httpd);
+	if(httpdname == NULL) httpdname = "apache";
+        if(!strcmp(httpdname, "apache"))
+        {
+                httpd = "/usr/sbin/httpd";
+                if (stat(httpd, &stbuf) && errno == ENOENT)
+                        httpd = "/usr/sbin/apache";
+
+        }
+	configfile = g_strdup_printf("%s/intersync-%s-httpd.conf", docroot, httpdname);
+	config_httpd_conf(httpdname, configfile, ip, port, docroot, IS_CGIDIR);
+	if(!strcmp(httpdname, "boa")) /* this -c may not be needed in future */
+                /* cmd = g_strdup_printf("%s -c %s", httpd, docroot); */
+       		cmd = g_strdup_printf("%s -c %s -f %s", httpd, docroot, configfile);
+	else
+        	cmd = g_strdup_printf("%s -f %s", httpd, configfile);
+        
         rc = system(cmd);
         g_free(cmd);
         if (rc)
-                g_error("Cannot start apache with config file %s: error code "
+                g_error("Cannot start httpd with config file %s: error code "
                         "0x%x\n", configfile, rc);
         g_free(configfile);
 
@@ -198,6 +215,7 @@
 \n\
     --server=HOSTNAME     The server to contact for the initial profile\n\
     --server-port=PORT    Server connect port (default %d)\n\
+    --alt-httpd=ALTHTTPD   Alternate httpd server\n\
 \n\
     --clientid=CLIENTID   Configure system using CLIENTID\n\
     --fset=FSETNAME       Use fsetname, can include branch\n\
@@ -246,6 +264,8 @@
                 {"fsetname", required_argument, NULL, OPT_FSET},
 #define OPT_DAEMON -11
                 {"daemon", no_argument, NULL, OPT_DAEMON},
+#define OPT_ALTHTTPD -13
+                {"alt-httpd", required_argument, NULL, OPT_ALTHTTPD},
                 {0}
         };
 
@@ -256,6 +276,7 @@
         cfg->cfg_local_port = -1;
         cfg->cfg_hoard_conf = NULL;
         cfg->cfg_reint_only = 0;
+        cfg->cfg_alt_httpd = NULL;
         cfg->cfg_daemon = 0;
         cfg->cfg_clientid = NULL;
         cfg->cfg_fsetname = NULL;
@@ -280,6 +301,9 @@
                 case OPT_DOCROOT:
                         cfg->cfg_docroot = g_strdup(optarg);
                         break;
+                case OPT_ALTHTTPD:
+                        cfg->cfg_alt_httpd = g_strdup(optarg);
+                        break;
                 case OPT_LOCAL_IP:
                         cfg->cfg_local_ip = g_strdup(optarg);
                         break;
@@ -561,7 +585,7 @@
 
         if (cfg.cfg_local_port > 0) {
                 create_docroot(cache->cache_docroot, cache->cache_mtpt);
-                start_server(cache->cache_docroot, cfg.cfg_local_ip, cfg.cfg_local_port);
+                start_server(cache->cache_docroot, cfg.cfg_local_ip, cfg.cfg_local_port, cfg.cfg_alt_httpd);
         }
 
 	if (cfg.cfg_daemon == 1) {
diff -ru intersync-0.9.5/lib/config.c intersync-0.9.5-new/lib/config.c
--- intersync-0.9.5/lib/config.c	Thu Sep 26 12:23:26 2002
+++ intersync-0.9.5-new/lib/config.c	Thu Dec  5 13:44:15 2002
@@ -251,8 +251,50 @@
 </VirtualHost>\n\
 ";
 
-void config_apache_conf(char *configfile, char * ip, int port, char *docroot,
-                        char *cgi_dir)
+static char const default_httpd_boa_config []= 
+"\n\
+Port %d\n\
+\n\
+User intermezzo\n\
+Group intermezzo\n\
+\n\
+\n\
+ErrorLog %s/httpd_error_log\n\
+AccessLog %s/httpd_access_log\n\
+CgiLog %s/httpd_cgi_log\n\
+\n\
+PidFile %s/httpd.pid\n\
+\n\
+ScriptAlias /cgi-bin/ %s/\n\
+\n\
+DocumentRoot %s\n\
+ServerRoot %s\n\
+\n\
+DefaultType text/plain\n\
+";
+
+static char const default_httpd_portable_config []= 
+"\n\
+Port %d\n\
+\n\
+User intermezzo\n\
+Group intermezzo\n\
+\n\
+\n\
+ErrorLog %s/httpd_error_log\n\
+\n\
+PidFile %s/httpd.pid\n\
+\n\
+ScriptAlias /cgi-bin/ %s/\n\
+\n\
+DocumentRoot %s\n\
+ServerRoot %s\n\
+\n\
+DefaultType text/plain\n\
+";
+
+void config_httpd_conf(char *httpdname, char *configfile,
+                char * ip, int port, char *docroot, char *cgi_dir)
 {
         gchar *config;
         int fd;
@@ -262,8 +304,18 @@
                 g_error("cannot write %s: %s\n", configfile, strerror(errno));
         }
 
-        config = g_strdup_printf(default_apache_config, ip, port, port, docroot, docroot,
-                                 docroot, cgi_dir, cgi_dir, docroot);
+        if(!strcmp(httpdname, "apache"))
+                config = g_strdup_printf(default_apache_config,
+                        ip, port, port, docroot, docroot,
+                        docroot, cgi_dir, cgi_dir, docroot);
+        else if(!strcmp(httpdname, "boa"))
+                config = g_strdup_printf(default_httpd_boa_config,
+                        port, docroot, docroot, docroot,
+                        docroot, cgi_dir, docroot, docroot);
+        else
+                config = g_strdup_printf(default_httpd_portable_config,
+                        port, docroot,
+                        docroot, cgi_dir, docroot, docroot);
         write(fd, config, strlen(config));
         g_free(config);
         close(fd); 
diff -ru intersync-0.9.5/lib/izolib.h intersync-0.9.5-new/lib/izolib.h
--- intersync-0.9.5/lib/izolib.h	Thu Sep 26 12:23:26 2002
+++ intersync-0.9.5-new/lib/izolib.h	Thu Dec  5 13:44:15 2002
@@ -96,6 +96,7 @@
         char *cfg_hoard_conf;
         int   cfg_reint_only;
         int   cfg_daemon;
+        char *cfg_alt_httpd;
         char *cfg_clientid;
         char *cfg_fsetname;
 };
@@ -103,8 +104,8 @@
 struct is_config *is_parse_response(char * rsp);
 struct is_config *read_local_config(char *cache);
 int write_local_config(struct is_config *cfg);
-void config_apache_conf(char *configfile, char *ip, int port, char *docroot,
-                        char *cgi_dir);
+void config_httpd_conf(char *httpdname, char *configfile,
+                char *ip, int port, char *docroot, char *cgi_dir);
 int parse_configuration(struct is_config *is_cfg, char *file);
 
 /* ioctl.c */