You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by pg...@sweng.stortek.com on 1999/11/24 03:41:24 UTC

[PATCH] OS/390 vs. CGI

POSIX, the whole POSIX, and nothing but POSIX.  Httpd makes a couple
assumptions that are unsupported by POSIX and ANSI respectively,
and which cause cgi-bin to malfunction on OS/390.  Descriptions are
in comments in the attached patch, which I submit more for review than
as a serious candidate for integration.  I need, for example, to ponder
whether it's appropriate to use malloc(), or to learn and use ap_palloc().

-- gil
-- 
StorageTek
INFORMATION made POWERFUL
========================================================================
diff -bru orig/apache_1.3.9/src/main/util_script.c apache_1.3.9/src/main/util_script.c
--- orig/apache_1.3.9/src/main/util_script.c	Thu Aug 12 12:34:15 1999
+++ apache_1.3.9/src/main/util_script.c	Tue Nov 23 19:16:25 1999
@@ -155,18 +155,37 @@
     return res;
 }
 
+#ifdef   OS390
+/* ANSI C 4.10.4.4 states "The string pointed to ... may be modified
+ * by a subsequent call to getenv.  OS/390 does this.  Sigh.
+ */
+char *ap_getenv(char **u, const char *s)
+{
+    char *t;
+
+    if (t = getenv(s)) {
+        if (*u) free(*u);
+        *u = malloc(strlen(t)+1);
+        return strcpy(*u, t);
+    }
+    return NULL;
+}
+#else  /*OS390*/
+#define ap_getenv(u, s) getenv((s))
+#endif /*OS390*/
+
 API_EXPORT(char **) ap_create_environment(pool *p, table *t)
 {
     array_header *env_arr = ap_table_elts(t);
     table_entry *elts = (table_entry *) env_arr->elts;
     char **env = (char **) ap_palloc(p, (env_arr->nelts + 2) * sizeof(char *));
     int i, j;
-    char *tz;
+    static char *tz = NULL;
     char *whack;
 
     j = 0;
     if (!ap_table_get(t, "TZ")) {
-	tz = getenv("TZ");
+	tz = ap_getenv(&tz, "TZ");
 	if (tz != NULL) {
 	    env[j++] = ap_pstrcat(p, "TZ=", tz, NULL);
 	}
@@ -200,6 +219,7 @@
     conn_rec *c = r->connection;
     const char *rem_logname;
     char *env_path;
+    static char *path = NULL;
 #ifdef WIN32
     char *env_temp;
 #endif
@@ -250,7 +270,7 @@
 	}
     }
 
-    if (!(env_path = getenv("PATH"))) {
+    if (!(env_path = ap_getenv(&path, "PATH"))) {
 	env_path = DEFAULT_PATH;
     }
 
@@ -1125,6 +1145,15 @@
 
 	else if ((!r->args) || (!r->args[0]) || strchr(r->args, '=')) {
 	    execle(r->filename, argv0, NULL, env);
+#ifdef   OS390
+/* POSIX requires only the exec*p() forms to autoexec shell scripts.
+ * OS/390 does not extend beyond the POSIX requirement.
+ */
+            if (errno == ENOEXEC) {
+	    execle(SHELL_PATH, argv0, r->filename, NULL, env);
+                execlp(r->filename, argv0, NULL);
+            }
+#endif /*OS390*/
 	}
 
 	else {

Re: [PATCH] OS/390 vs. CGI revisited.

Posted by Martin Kraemer <Ma...@mch.sni.de>.
On Wed, Nov 24, 1999 at 07:32:31PM -0700, pg@sweng.stortek.com wrote:
> > Look for the #define NEED_HASHBANG_EMUL in ap_config.h! It improves (what

> I persisted.  Yow!  to compile hashbang emulation on OS/390, I had to
> do all the casting below.  Am I even on the right track?

Uh oh! Yes, I saw all the warnings, but I never took the time to "persist"
and fix it all. Thanks a lot, I think your patch does it correctly (where
it had been broken for a long time). I'd suggest we commit your patches
(after I had the time to recompile and test it on my platform), because
it looks very good.

> But it does work.

Fine. That's what it was supposed to do in the first place ;-)

    Martin
-- 
<Ma...@MchP.Siemens.De>             |    Fujitsu Siemens
Fon: +49-89-636-46021, FAX: +49-89-636-41143 | 81730  Munich,  Germany

Re: [PATCH] OS/390 vs. CGI

Posted by Martin Kraemer <Ma...@mch.sni.de>.
On Tue, Nov 23, 1999 at 07:41:24PM -0700, pg@sweng.stortek.com wrote:
> +#ifdef   OS390
> +/* POSIX requires only the exec*p() forms to autoexec shell scripts.
> + * OS/390 does not extend beyond the POSIX requirement.
> + */
> +            if (errno == ENOEXEC) {
> +	    execle(SHELL_PATH, argv0, r->filename, NULL, env);
> +                execlp(r->filename, argv0, NULL);
> +            }
> +#endif /*OS390*/

Look for the #define NEED_HASHBANG_EMUL in ap_config.h! It improves (what
you have realized by this patch) by interpreting a 1st script line
   #!/some/interpreter -with -args etc.
   remainder of script
by calling /some/interpreter with argv[1]="-with" argv[2]="-args"
argv[3]="etc." and argv[4...]="$@" (whatever you passed in argv[]
to the script).

This is what modern unix kernels do internally, realized in apache
(taken from tcsh, by the way). Definitely a must if your OS doesn't
handle it.

    Martin

+1 for the rest, BTW.
-- 
<Ma...@MchP.Siemens.De>             |    Fujitsu Siemens
Fon: +49-89-636-46021, FAX: +49-89-636-41143 | 81730  Munich,  Germany