Re: [uClinux-dev] Problem execute CGI with boa on uClinux (fwd)

Ilguiz Latypov <[email protected]>
Newsgroups gmane.network.mathopd
Message-ID <[email protected]>
I attempted to make the earlier version of mathopd run on uClinux.  The
HTTP POST requests are yet to be fixed.

Would these 2 new files and the patch be of any interest to mathopd
developers?

Ilguiz


new file: Makefile
====================================================================
.EXPORT_ALL_VARIABLES:

all:  src/mathopd

src/mathopd:
	$(MAKE) -C src

clean:
	-$(MAKE) -C src clean

distclean: clean
	-rm -rf autom4te*.cache 
	-rm -f configure config.h config.h.in \
		config.status config.cache config.log


new file: configure.in
====================================================================
AC_INIT(mathopd, 1.1)

AC_CONFIG_HEADER(config.h)

dnl uClinux has only a stub fork() which calls vfork().  This fact
dnl is not reflected in autoconf-2.53.
AC_DEFUN([AC_FORK_IS_A_STUB_IN_UCLINUX],
[AC_BEFORE([$0], [AC_FUNC_FORK])dnl
case $host in
    (*-uClinux | *-uclinux)
        ac_cv_func_fork=no
	AC_MSG_NOTICE([uClinux has only a stub fork() that calls vfork()])
	AC_DEFINE(HAVE_VFORK, 1, 
		[indicates that the vfork() call is available])dnl
	AC_DEFINE(HAVE_WORKING_VFORK, 1, 
		[indicates that the vfork() call works as expected])dnl
        ;;
    (*)
	# Check for presence of fork() and vfork() in the C library
	# and define HAVE_FORK and HAVE_VFORK accordingly.
	# Also, run tests if compiling native code or make assumptions
	# to determine if fork() and vfork() work when they exist.
	# Set or unset HAVE_WORKING_FORK and HAVE_WORKING_VFORK.
	AC_FUNC_FORK[]dnl
	;;
esac
])# AC_FORK_IS_A_STUB_IN_UCLINUX
AC_FORK_IS_A_STUB_IN_UCLINUX

AH_BOTTOM([
#ifdef HAVE_WORKING_FORK

/* fork() exists and works */
#  define FINISHVOID(code)    _exit(code)
#  define FINISH(code)        _exit(code)

#elif defined(HAVE_WORKING_VFORK)

#  define fork                vfork
#  define FINISHVOID(code)    return
#  define FINISH(code)        return (!code)

#else

#  error fork() or vfork() are not found in the standard C library \
         or are not working or are assumed to not work on the target \
         platform.
#endif])

AC_OUTPUT

====================================================================


---------- Forwarded message ----------
Date: Thu, 11 Jul 2002 10:49:18 -0400 (EDT)
From: Ilguiz Latypov <[email protected]>
To: uClinux <[email protected]>
Subject: Re: [uClinux-dev] Problem execute CGI with boa on uClinux


This can be related to no-mmu specifics:

   a) memory not belonging to the process can be corrupted by the process
   b) vfork usage assumes that the data segment is shared by the parent 
      and the child
   c) only _exit() or exec..() are allowed in the end of the child process
   d) the parent will be activated only after the child _exit()s or passes 
      control to another program through exec..()

I believe the user/boa module in Greg Ungerer's uClinux distribution
contains all the necessary fixes.

I myself only tried a different embedded web server from
http://www.mathopd.org/.  I adjusted it to no-mmu case, but succeeded only
in making it serve the HTTP GET requests.  No HTTP POST requests would
work for me with mathopd on m68k-nommu platform.  I attached my
adjustments.

Ilguiz

On Thu, 11 Jul 2002, Van Duc Uy wrote:

> now the boa can run seem well with HTML file. but with CGI it encounter 
> problem. when i browse a cgi file I can see the result on the browser. but 
> After  executed a CGI program the kernel halt on (dead).


Index: src/Makefile
===================================================================
RCS file: /usr/local/cvsroot/user/mathopd/src/Makefile,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- src/Makefile	21 Apr 2002 22:54:48 -0000	1.1.1.1
+++ src/Makefile	22 Apr 2002 22:30:05 -0000	1.2
@@ -1,10 +1,10 @@
 BIN = mathopd
-CC = gcc
-CFLAGS = -O -Wall
-CPPFLAGS = 
-LDFLAGS = 
-LIBS = -lcrypt
-PREFIX = /usr/local
+# CC = gcc
+CFLAGS += -O -Wall
+CPPFLAGS += -I.. -DIGNORE_SECURITY=1 -DIGNORE_SIGHUP
+# LDFLAGS = 
+LIBS += -lcrypt
+PREFIX = /usr
 SBINDIR = $(PREFIX)/sbin
 
 # On Solaris, uncomment the following
@@ -12,7 +12,7 @@
 # LIBS = -lsocket -lnsl
 
 # On Linux, uncomment the following
-# CPPFLAGS = -DHAVE_CRYPT_H
+CPPFLAGS += -DHAVE_CRYPT_H
 
 OBJS = base64.o cgi.o config.o core.o dump.o imap.o log.o main.o \
 	request.o util.o
@@ -26,13 +26,20 @@
 # CPPFLAGS += -DNEED_SOCKLEN_T
 
 all: $(BIN)
+
 install: $(BIN)
 	install -c $(BIN) $(SBINDIR)
+
 $(BIN): $(OBJS)
 	$(CC) $(LDFLAGS) -o $(BIN) $(OBJS) $(LIBS)
+
 $(OBJS): $(DEPENDS)
+
 .c.o:
 	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
+
 clean:
-	rm -f $(BIN) $(OBJS)
+	rm -f $(BIN) $(OBJS) *.gdb
+
 .PHONY: install clean
+
Index: src/cgi.c
===================================================================
RCS file: /usr/local/cvsroot/user/mathopd/src/cgi.c,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- src/cgi.c	21 Apr 2002 22:54:48 -0000	1.1.1.1
+++ src/cgi.c	24 Apr 2002 00:52:32 -0000	1.3
@@ -35,7 +35,7 @@
 
 /* Peg */
 
-static const char rcsid[] = "$Id: cgi.c,v 1.1.1.1 2002/04/21 22:54:48 ilatypov Exp $";
+static const char rcsid[] = "$Id: cgi.c,v 1.3 2002/04/24 00:52:32 ilatypov Exp $";
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -72,7 +72,7 @@
 	if (name == 0) {
 		if (value == 0)
 			cp->cgi_envp[cp->cgi_envc] = 0;
-		else if ((cp->cgi_envp[cp->cgi_envc] = strdup(value)) == 0)
+		else if ((cp->cgi_envp[cp->cgi_envc] = xstrdup(value)) == 0)
 			return -1;
 	} else {
 		namelen = strlen(name);
@@ -83,7 +83,7 @@
 			else
 				valuelen = 0;
 		}
-		tmp = malloc(namelen + valuelen + 2);
+		tmp = xmalloc(namelen + valuelen + 2);
 		if (tmp == 0) {
 			cp->cgi_envp[cp->cgi_envc] = 0;
 			return -1;
@@ -112,14 +112,14 @@
 		cp->cgi_argv[cp->cgi_argc] = 0;
 	else {
 		s = b ? b - a : strlen(a);
-		tmp = malloc(s + 1);
+		tmp = xmalloc(s + 1);
 		if (tmp == 0) {
 			cp->cgi_argv[cp->cgi_argc] = 0;
 			return -1;
 		}
 		if (decode) {
 			if (unescape_url_n(a, tmp, s)) {
-				free(tmp);
+				xfree(tmp);
 				cp->cgi_argv[cp->cgi_argc] = 0;
 				return -1;
 			}
@@ -143,7 +143,7 @@
 	h = gethostbyaddr((char *) &ia, sizeof ia, AF_INET);
 	if (h == 0 || h->h_name == 0)
 		return 0;
-	tmp = strdup(h->h_name);
+	tmp = xstrdup(h->h_name);
 	if (tmp == 0) {
 		log_d("dnslookup: strdup failed");
 		return 0;
@@ -168,7 +168,7 @@
 			}
 	if (message) {
 		log_d("dnslookup: %s, address=%s, name=%s", message, inet_ntoa(ia), tmp);
-		free(tmp);
+		xfree(tmp);
 		return 0;
 	}
 	return tmp;
@@ -214,15 +214,15 @@
 	if (add("QUERY_STRING", r->args, 0, cp) == -1)
 		return -1;
 	if (r->args) {
-		tmp = malloc(strlen(r->url) + strlen(r->args) + 2);
+		tmp = xmalloc(strlen(r->url) + strlen(r->args) + 2);
 		if (tmp == 0)
 			return -1;
 		sprintf(tmp, "%s?%s", r->url, r->args);
 		if (add("REQUEST_URI", tmp, 0, cp) == -1) {
-			free(tmp);
+			xfree(tmp);
 			return -1;
 		}
-		free(tmp);
+		xfree(tmp);
 	} else if (add("REQUEST_URI", r->url, 0, cp) == -1)
 		return -1;
 	sprintf(t, "%s", inet_ntoa(r->cn->peer.sin_addr));
@@ -235,10 +235,10 @@
 		tmp = dnslookup(r->cn->peer.sin_addr);
 		if (tmp) {
 			if (add("REMOTE_HOST", tmp, 0, cp) == -1) {
-				free(tmp);
+				xfree(tmp);
 				return -1;
 			}
-			free(tmp);
+			xfree(tmp);
 		}
 	}
 	if (add("REQUEST_METHOD", r->method_s, 0, cp) == -1)
@@ -340,6 +340,7 @@
 	return 0;
 }
 
+#ifndef IGNORE_SECURITY
 static int become_user(const char *name)
 {
 	struct passwd *pw;
@@ -394,6 +395,7 @@
 	}
 	return 0;
 }
+#endif
 
 static void destroy_parameters(struct cgi_parameters *cp)
 {
@@ -402,22 +404,23 @@
 	if (cp->cgi_envp) {
 		for (i = 0; i < cp->cgi_envc; i++)
 			if (cp->cgi_envp[i])
-				free(cp->cgi_envp[i]);
-		free(cp->cgi_envp);
+				xfree(cp->cgi_envp[i]);
+		xfree(cp->cgi_envp);
 	}
 	if (cp->cgi_argv) {
 		for (i = 0; i < cp->cgi_argc; i++)
 			if (cp->cgi_argv[i])
-				free(cp->cgi_argv[i]);
-		free(cp->cgi_argv);
+				xfree(cp->cgi_argv[i]);
+		xfree(cp->cgi_argv);
 	}
-	free(cp);
+	xfree(cp);
 }
 
 static int exec_cgi(struct request *r)
 {
 	struct cgi_parameters *cp;
 
+#ifndef IGNORE_SECURITY
 	if (setuid(0) != -1) {
 		if (r->c->script_user) {
 			if (become_user(r->c->script_user) == -1)
@@ -434,7 +437,8 @@
 		log_d("cannot run scripts as the super-user");
 		return cgi_error(r, 500);
 	}
-	cp = malloc(sizeof *cp);
+#endif
+	cp = xmalloc(sizeof *cp);
 	if (cp == 0)
 		return cgi_error(r, 500);
 	cp->cgi_envc = 0;
Index: src/config.c
===================================================================
RCS file: /usr/local/cvsroot/user/mathopd/src/config.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- src/config.c	21 Apr 2002 22:54:48 -0000	1.1.1.1
+++ src/config.c	24 Apr 2002 00:52:32 -0000	1.2
@@ -35,7 +35,7 @@
 
 /* House of Games */
 
-static const char rcsid[] = "$Id: config.c,v 1.1.1.1 2002/04/21 22:54:48 ilatypov Exp $";
+static const char rcsid[] = "$Id: config.c,v 1.2 2002/04/24 00:52:32 ilatypov Exp $";
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -313,7 +313,7 @@
 
 	if ((t = gettoken(p)) != t_string)
 		return t;
-	if ((*a = strdup(p->tokbuf)) == 0)
+	if ((*a = xstrdup(p->tokbuf)) == 0)
 		return e_memory;
 	return 0;
 }
@@ -371,9 +371,9 @@
 	while ((t = gettoken(p)) != t_close) {
 		if (t != t_string)
 			return t;
-		if ((l = malloc(sizeof *l)) == 0)
+		if ((l = xmalloc(sizeof *l)) == 0)
 			return e_memory;
-		if ((l->name = strdup(p->tokbuf)) == 0)
+		if ((l->name = xstrdup(p->tokbuf)) == 0)
 			return e_memory;
 		l->next = *ls;
 		*ls = l;
@@ -450,20 +450,20 @@
 	while ((t = gettoken(p)) != t_close) {
 		if (t != t_string)
 			return t;
-		if ((name = strdup(p->tokbuf)) == 0)
+		if ((name = xstrdup(p->tokbuf)) == 0)
 			return e_memory;
 		if ((t = gettoken(p)) != t_open)
 			return t;
 		while ((t = gettoken(p)) != t_close) {
 			if (t != t_string)
 				return t;
-			if ((m = malloc(sizeof *m)) == 0)
+			if ((m = xmalloc(sizeof *m)) == 0)
 				return e_memory;
 			m->class = class;
 			m->name = name;
 			if (!strcasecmp(p->tokbuf, c_all))
 				m->ext = 0;
-			else if ((m->ext = strdup(p->tokbuf)) == 0)
+			else if ((m->ext = xstrdup(p->tokbuf)) == 0)
 				return e_memory;
 			m->next = *ms;
 			*ms = m;
@@ -524,7 +524,7 @@
 	while ((t = gettoken(p)) != t_close) {
 		if (t != t_string)
 			return t;
-		if ((l = malloc(sizeof *l)) == 0)
+		if ((l = xmalloc(sizeof *l)) == 0)
 			return e_memory;
 		l->next = *ls;
 		*ls = l;
@@ -590,7 +590,7 @@
 	b = *as;
 	while (b && b->locations)
 		b = b->next;
-	if ((a = malloc(sizeof *a)) == 0)
+	if ((a = xmalloc(sizeof *a)) == 0)
 		return e_memory;
 	a->locations = 0;
 	a->alias = 0;
@@ -644,12 +644,12 @@
 		if (t != t_string)
 			return t;
 		if (!strcasecmp(p->tokbuf, c_location)) {
-			if ((l = malloc(sizeof *l)) == 0)
+			if ((l = xmalloc(sizeof *l)) == 0)
 				return e_memory;
 			if ((t = gettoken(p)) != t_string)
 				return t;
 			chopslash(p->tokbuf);
-			if ((l->name = strdup(p->tokbuf)) == 0)
+			if ((l->name = xstrdup(p->tokbuf)) == 0)
 				return e_memory;
 			if (a->locations) {
 				l->next = a->locations->next;
@@ -663,7 +663,7 @@
 			if ((t = gettoken(p)) != t_string)
 				return t;
 			chopslash(p->tokbuf);
-			if ((a->alias = strdup(p->tokbuf)) == 0)
+			if ((a->alias = xstrdup(p->tokbuf)) == 0)
 				return e_memory;
 			continue;
 		} else if (!strcasecmp(p->tokbuf, c_path_args))
@@ -726,12 +726,12 @@
 {
 	struct virtual *v;
 
-	if ((v = malloc(sizeof *v)) == 0)
+	if ((v = xmalloc(sizeof *v)) == 0)
 		return e_memory;
 	if (host == 0)
 		v->host = 0;
 	else {
-		if ((v->host = strdup(host)) == 0)
+		if ((v->host = xstrdup(host)) == 0)
 			return e_memory;
 		sanitize_host(v->host);
 	}
@@ -750,7 +750,7 @@
 	struct vserver *v;
 	const char *t;
 
-	if ((v = malloc(sizeof *v)) == 0)
+	if ((v = xmalloc(sizeof *v)) == 0)
 		return e_memory;
 	v->server = parent;
 	v->controls = parent->controls;
@@ -785,7 +785,7 @@
 	struct server *s;
 	const char *t;
 
-	if ((s = malloc(sizeof *s)) == 0)
+	if ((s = xmalloc(sizeof *s)) == 0)
 		return e_memory;
 	s->port = 80;
 	s->addr.s_addr = 0;
@@ -840,7 +840,7 @@
 				if (s->port == 80)
 					v->fullname = name;
 				else {
-					v->fullname = malloc(strlen(name) + sprintf(buf, ":%lu", s->port) + 1);
+					v->fullname = xmalloc(strlen(name) + sprintf(buf, ":%lu", s->port) + 1);
 					if (v->fullname == 0)
 						return e_memory;
 					strcpy(v->fullname, name);
@@ -927,12 +927,12 @@
 	char *t;
 	struct pool *p;
 
-	p = malloc(sizeof *p);
+	p = xmalloc(sizeof *p);
 	if (p == 0)
 		return 0;
-	t = malloc(s);
+	t = xmalloc(s);
 	if (t == 0) {
-		free(p);
+		xfree(p);
 		return 0;
 	}
 	p->floor = t;
@@ -947,21 +947,21 @@
 	struct connection *cn;
 	struct configuration *p;
 
-	p = malloc(sizeof *p);
+	p = xmalloc(sizeof *p);
 	if (p == 0)
 		return e_memory;
 	p->size = TOKEN_LENGTH_INCREMENT;
-	p->tokbuf = malloc(p->size);
+	p->tokbuf = xmalloc(p->size);
 	if (p->tokbuf == 0) {
-		free(p);
+		xfree(p);
 		return e_memory;
 	}
 	if (config_filename) {
 		p->config_file = fopen(config_filename, "r");
 		if (p->config_file == 0) {
 			fprintf(stderr, "Cannot open configuration file %s\n", config_filename);
-			free(p->tokbuf);
-			free(p);
+			xfree(p->tokbuf);
+			xfree(p);
 			return e_noinput;
 		}
 	} else
@@ -984,12 +984,12 @@
 		if (config_filename)
 			fprintf(stderr, "In configuration file: %s\n", config_filename);
 		fprintf(stderr, "Error at token '%s' around line %d\n", p->tokbuf, p->line);
-		free(p->tokbuf);
-		free(p);
+		xfree(p->tokbuf);
+		xfree(p);
 		return s;
 	}
-	free(p->tokbuf);
-	free(p);
+	xfree(p->tokbuf);
+	xfree(p);
 	if (log_column == 0) {
 		log_column = default_log_column;
 		log_columns = sizeof default_log_column / sizeof default_log_column[0];
@@ -1000,9 +1000,9 @@
 	if (init_pollfds(tuning.num_connections + num_servers) == -1)
 		return e_memory;
 	for (n = 0; n < tuning.num_connections; n++) {
-		if ((cn = malloc(sizeof *cn)) == 0)
+		if ((cn = xmalloc(sizeof *cn)) == 0)
 			return e_memory;
-		if ((cn->r = malloc(sizeof *cn->r)) == 0)
+		if ((cn->r = xmalloc(sizeof *cn->r)) == 0)
 			return e_memory;
 		if ((cn->input = new_pool(tuning.input_buf_size)) == 0)
 			return e_memory;
Index: src/log.c
===================================================================
RCS file: /usr/local/cvsroot/user/mathopd/src/log.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- src/log.c	21 Apr 2002 22:54:48 -0000	1.1.1.1
+++ src/log.c	22 Apr 2002 22:32:34 -0000	1.2
@@ -35,7 +35,7 @@
 
 /* Piece Of My Luck */
 
-static const char rcsid[] = "$Id: log.c,v 1.1.1.1 2002/04/21 22:54:48 ilatypov Exp $";
+static const char rcsid[] = "$Id: log.c,v 1.2 2002/04/22 22:32:34 ilatypov Exp $";
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -179,7 +179,9 @@
 	}
 	b[-1] = '\n';
 	if (write(log_file, log_buffer, b - log_buffer) == -1) {
+#ifndef EMBED
 		gotsigterm = 1;
+#endif
 		log_d("log_request: cannot write to log file");
 		lerror("write");
 	}
@@ -249,8 +251,11 @@
 	n = vsnprintf(log_line + l, m, fmt, ap);
 	l += n < m ? n : m - 1;
 	log_line[l++] = '\n';
-	if (error_file != -1 && write(error_file, log_line, l) == -1)
+	if (error_file != -1 && write(error_file, log_line, l) == -1) {
+#ifndef EMBED
 		gotsigterm = 1;
+#endif
+	}
 	if (am_daemon == 0 && forked == 0)
 		write(2, log_line, l);
 	errno = saved_errno;
Index: src/main.c
===================================================================
RCS file: /usr/local/cvsroot/user/mathopd/src/main.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- src/main.c	21 Apr 2002 22:54:48 -0000	1.1.1.1
+++ src/main.c	22 Apr 2002 22:38:24 -0000	1.2
@@ -35,7 +35,7 @@
 
 /* Once Around */
 
-static const char rcsid[] = "$Id: main.c,v 1.1.1.1 2002/04/21 22:54:48 ilatypov Exp $";
+static const char rcsid[] = "$Id: main.c,v 1.2 2002/04/22 22:38:24 ilatypov Exp $";
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -220,8 +220,10 @@
 		pwd = getpwnam(user_name);
 		if (pwd == 0)
 			die(0, "%s: Unknown user.", user_name);
+#ifndef IGNORE_SECURITY
 		if (pwd->pw_uid == 0)
 			die(0, "%s: Invalid user.", user_name);
+#endif
 		if (initgroups(user_name, pwd->pw_gid) == -1)
 			die("initgroups", 0);
 		if (setgid(pwd->pw_gid) == -1)
@@ -261,14 +263,22 @@
 	}
 	close(null_fd);
 	if (am_daemon) {
+#if HAVE_WORKING_FORK - 0
 		if (fork())
 			_exit(0);
+#endif
 		setsid();
+#if HAVE_WORKING_FORK - 0
 		if (fork())
 			_exit(0);
+#endif
 	}
 	mysignal(SIGCHLD, sighandler);
+#ifndef IGNORE_SIGHUP
 	mysignal(SIGHUP, sighandler);
+#else
+	mysignal(SIGHUP, SIG_IGN);
+#endif
 	mysignal(SIGTERM, sighandler);
 	mysignal(SIGINT, sighandler);
 	mysignal(SIGQUIT, sighandler);
@@ -286,6 +296,24 @@
 	return 0;
 }
 
+static int store_query(const char *query)
+{
+	int fd;
+	char tmpbuf[32];
+
+	strcpy(tmpbuf, "/tmp/mathop-query.XXXXXXXX");
+	fd = mkstemp(tmpbuf);
+	if (fd == -1) {
+		lerror("mkstemp");
+		return -1;
+	}
+	write(fd, query, strlen(query));
+	write(fd, "\n", 1);
+	lseek(fd, 0, SEEK_SET);
+	unlink(tmpbuf);
+	return fd;
+}
+
 int fork_request(struct request *r, int (*f)(struct request *))
 {
 	int fd, efd;
@@ -298,7 +326,14 @@
 	switch (pid) {
 	case 0:
 		my_pid = getpid();
+/*
+   The data segment is shared by the parent and the child in 
+   fork()-deprived uClinux.  This means that forked would be 1
+   in both child and parent processes.
+ */
+#if HAVE_WORKING_FORK - 0
 		forked = 1;
+#endif
 		mysignal(SIGPIPE, SIG_DFL);
 		fd = r->cn->fd;
 		child_filename = r->c->child_filename;
@@ -313,7 +348,15 @@
 			}
 		}
 		fcntl(fd, F_SETFL, 0);
-		dup2(fd, 0);
+		if (r->args) {
+			int fdq = store_query(r->args);
+			if (fdq > 0) {
+				dup2(fdq, 0);
+				close(fdq);
+			}
+		} else {
+			dup2(fd, 0);
+		}
 		dup2(fd, 1);
 		dup2(efd, 2);
 		close(fd);
Index: src/mathopd.h
===================================================================
RCS file: /usr/local/cvsroot/user/mathopd/src/mathopd.h,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- src/mathopd.h	21 Apr 2002 22:54:48 -0000	1.1.1.1
+++ src/mathopd.h	24 Apr 2002 00:52:32 -0000	1.3
@@ -43,6 +43,63 @@
 #include <netinet/in.h>
 #include <signal.h>
 
+#include "config.h"
+
+/*
+#define DEBUG_EXEC 1
+#define DEBUG_MALLOC 1
+*/
+
+#if DEBUG_EXEC - 0
+#  include <syslog.h>
+#  define DEBUG_LOG(fmt, args...)    do { \
+	syslog(LOG_INFO, "%s (%d): " fmt "\n", \
+		__FUNCTION__, __LINE__ , ##args); \
+	} while (0)
+#  define D(x) x
+
+#else
+
+#  define DEBUG_LOG(fmt, args...)  do { } while (0)
+#  define D(x)
+#endif
+
+#define DEBUG_MARK()  DEBUG_LOG("debug mark")
+
+#if DEBUG_MALLOC - 0
+#  include <syslog.h>
+#  define xmalloc(n)	( { \
+	void *ptr; \
+	ptr = malloc(n); \
+	syslog(LOG_INFO, "%s (%d): malloc(%ld) %p\n", \
+		__FUNCTION__, __LINE__ , (long)n, ptr); \
+	ptr ; \
+	} )
+#  define xstrdup(s)	( { \
+	char *ptr; \
+	ptr = strdup(s); \
+	syslog(LOG_INFO, "%s (%d): strdup(%s) %p\n", \
+		__FUNCTION__, __LINE__ , s, ptr); \
+	ptr ; \
+	} )
+#  define xfree(p)	( \
+	syslog(LOG_INFO, "%s (%d): free %p\n", \
+		__FUNCTION__, __LINE__ , p), \
+	free(p), \
+	p = NULL \
+	)
+#  define DEBUG_MALLOC_LOG(fmt, args...)    do { \
+	syslog(LOG_INFO, "%s (%d): " fmt "\n", \
+		__FUNCTION__, __LINE__ , ##args); \
+	} while (0)
+#else
+#  define xmalloc(n)	malloc(n)
+#  define xstrdup(s)	strdup(s)
+#  define xfree(p)	free(p)
+#  define DEBUG_MALLOC_LOG(fmt, args...)  do { } while (0)
+#endif
+
+
 #define CGI_MAGIC_TYPE "CGI"
 #define IMAP_MAGIC_TYPE "Imagemap"
 #define DUMMY_MAGIC_TYPE "Dummy"
Index: src/request.c
===================================================================
RCS file: /usr/local/cvsroot/user/mathopd/src/request.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- src/request.c	21 Apr 2002 22:54:48 -0000	1.1.1.1
+++ src/request.c	22 Apr 2002 22:40:22 -0000	1.2
@@ -35,7 +35,7 @@
 
 /* Mysterons */
 
-static const char rcsid[] = "$Id: request.c,v 1.1.1.1 2002/04/21 22:54:48 ilatypov Exp $";
+static const char rcsid[] = "$Id: request.c,v 1.2 2002/04/22 22:40:22 ilatypov Exp $";
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -545,7 +545,7 @@
 	}
 	r->content_length = r->finfo.st_size;
 	r->last_modified = r->finfo.st_mtime;
-	if (r->last_modified <= r->ims) {
+	if (r->last_modified < r->ims) {
 		close(fd);
 		r->num_content = -1;
 		return 304;
===================================================================
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.