X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=www%2Fwcgi.c;h=b97bbd43c2fe610d7fe9eea59cb6f6d08007d1d4;hb=7f332a840baf336e34d612cdee0ef27901f0dd11;hp=f6ae6432a063bcd5896b72034516a9163824618c;hpb=d1fc0ff84894bba24f827a81597717e9f69b6c06;p=egate.git diff --git a/www/wcgi.c b/www/wcgi.c index f6ae643..b97bbd4 100644 --- a/www/wcgi.c +++ b/www/wcgi.c @@ -41,7 +41,24 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wcgi.c,v $ - * Revision 1.15 1996/01/26 09:02:20 adam + * Revision 1.20 2001/02/26 14:32:36 adam + * Updated for YAZ 1.7. HTML output tidy up. Added LOC target. + * + * Revision 1.19 1997/01/24 13:13:10 adam + * Implemnted egw_source and added a "raw" option to the URL. + * Fixed a bug in the buffering system of wproto; the macro wo_putc could + * override memory if it was the first HTML generating function called. + * + * Revision 1.18 1996/03/14 11:48:37 adam + * New function egw_prog that returns name of shell. + * + * Revision 1.17 1996/02/26 10:36:15 adam + * Better error handling when (re)spawn of the shell fails. + * + * Revision 1.16 1996/02/12 10:10:29 adam + * Resource/config system used by the gateway. + * + * Revision 1.15 1996/01/26 09:02:20 adam * Open of client FIFO called with O_NDELAY when reconnecting to shell * in order to prevent serious lock if previous shell died without * unlinking client FIFO. @@ -103,6 +120,7 @@ #include #include +#include #include #include #include @@ -112,10 +130,8 @@ #include #endif -#define DEADSTRING "Your database server has terminated. To reactivate \ -the server, please reload the server's 'front page'." - #include +#include #include "wproto.h" static char *prog = "cgi"; @@ -139,18 +155,18 @@ static void fatal(char *p) static int spawn (char *sprog, int id) { - int r; + int r, fd; char path[256]; char envstr[80]; sprintf (envstr, "GWID=%d", id); putenv (envstr); - sprintf(path, "%s/%s", CGIDIR, sprog); + sprintf(path, "%s/%s", EGWDIR, sprog); switch(r = fork()) { case -1: gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, prog, "fork"); - exit(1); + fatal ("Internal error in server"); case 0: close (0); close (1); @@ -158,7 +174,13 @@ static int spawn (char *sprog, int id) gw_log (GW_LOG_DEBUG, prog, "execl %s", path); execl (path, sprog, 0); gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, prog, "execl %s", path); - exit(0); + fd = open (serverp, O_WRONLY); + if (fd >= 0) + { + write (fd, "FA", 2); + close (fd); + } + exit(1); default: return r; } @@ -183,27 +205,40 @@ static void print_environ (void) */ int main() { - char clientp[256], tmp[256], *path_info, *p, *operation, *t; + char clientp[256], *path_info, *p, *operation, *t; char combuf[COMBUF]; + const char *fifoDir; + GwRes cgiRes; int serverf_fd = -1; int linein = -1, lineout, data, gw_id; - chdir ("/usr/local/etc/httpd/cgi-bin"); + if (chdir (EGWDIR)) + fatal ("egwcgi: Couldn't change directory to " EGWDIR); gw_log_init ("egw"); - gw_log_file (GW_LOG_ALL, LOGDIR "/egwcgi_log"); + gw_log_file (GW_LOG_ALL, "egwcgi_log"); +#if 0 gw_log_level (GW_LOG_ALL); +#endif gw_log_session (getpid()); gw_log (GW_LOG_STAT, prog, "Europagate www cgi server"); + cgiRes = gw_res_init (); + gw_res_merge (cgiRes, "egw.res"); +#if 1 + gw_log_level (gw_log_mask_str ( + gw_res_get (cgiRes, "log.level", "default"))); +#endif + fifoDir = gw_res_get (cgiRes, "fifo.dir", "/tmp/egw"); + /* Create fifo directory if it doesn't exist already */ - sprintf(tmp, "%s/%s", FIFOROOT, FIFODIR); - if (access(tmp, R_OK|W_OK) < 0 && mkdir(tmp, 0777) < 0) + if (access(fifoDir, R_OK|W_OK) < 0 && mkdir(fifoDir, 0777) < 0) { - gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, prog, "Failed to create %s", tmp); + gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, prog, "Failed to create %s", + fifoDir); fatal("Internal error in server."); } /* Delete server FIFO if it does exist */ - sprintf(serverp, "%s/srv%d", tmp, getpid()); + sprintf(serverp, "%s/srv%d", fifoDir, getpid()); if (access(serverp, R_OK|W_OK) == 0) { if (unlink(serverp) < 0) @@ -229,7 +264,7 @@ int main() } /* Create lock file that ensures the server (shell) doesn't */ /* terminate before we have read the whole response */ - sprintf (serverf, "%s/srf%d", tmp, getpid ()); + sprintf (serverf, "%s/srf%d", fifoDir, getpid ()); gw_log (GW_LOG_DEBUG, prog, "open w %s", serverf); serverf_fd = open (serverf, O_WRONLY|O_CREAT|O_TRUNC, 0666); if (serverf_fd == -1) @@ -292,13 +327,13 @@ int main() fatal("Internal error in server"); } gw_log (GW_LOG_DEBUG, prog, "Synchronized"); - sprintf(clientp, "%s/clt%d", tmp, gw_id); + sprintf(clientp, "%s/clt%d", fifoDir, gw_id); gw_log (GW_LOG_DEBUG, prog, "open w %s", clientp); lineout = open (clientp, O_WRONLY); } else /* A session is continued */ { - sprintf(clientp, "%s/clt%d", tmp, gw_id); + sprintf(clientp, "%s/clt%d", fifoDir, gw_id); gw_log (GW_LOG_DEBUG, prog, "open w|n %s", clientp); /* Open the FIFO in O_NDELAY-mode: This prevents blocking */ /* even though the shell died without unlinking the FIFO */ @@ -351,7 +386,7 @@ int main() strcpy (p, serverf); p += strlen (p) + 1; strcpy (p, path_info); - gw_log (GW_LOG_DEBUG, prog, "P:%s", p); + gw_log (GW_LOG_STAT, prog, "P:%s", p); p += strlen(p) + 1; *(p++) = '\0'; /* no envvars tranferred at present */ if ((t = getenv("CONTENT_LENGTH")) && (data = atoi(t)) > 0)