Commits

Mechiel Lukkien committed 28f9cb7 Draft

second release. from tarball.

"Fixes running on Linux, the previous version would not free the
thread's memory stacks when done. This has been fixed, and the
stacksize is now set explicitly to 32KB (instead of the 8MB on my
system)."

Comments (0)

Files changed (2)

 .Pp
 Calc.py should be explained better.  Some important things:  start-end ranges can be specified as numbers with a prefix such as k, m, g, etc.  Multiple ranges can be specified, each separated by a comma.
 .Pp
-Memventi first binds to addresses, then initializes (involving a fork) and only then starts accepting connections.  On OpenBSD, this does not work:  new connections are not "seen" by the accept.  The soluation is to first initialize and then bind and accept.
+Memventi first binds to addresses, then initializes (involving a fork) and only then starts accepting connections.  On OpenBSD, this does not work:  new connections are not "seen" by the accept.  The solution is to first initialize and then bind and accept.
 enum {
 	Listenmax	= 32,
 	Addressesmax	= 16,
+	Stacksize	= 32*1024,
 };
 
 enum {
 	Args *args;
 	int fd;
 	int listenfd, allowwrite;
+	pthread_attr_t attrs;
 
 	args = (Args *)p;
 	listenfd = args->fd;
 		thread = malloc(sizeof thread[0]);
 		if(thread == nil)
 			goto error;
-		if(pthread_create(thread, nil, connproc, args) != 0)
+		if(pthread_attr_init(&attrs) != 0
+			|| pthread_attr_setstacksize(&attrs, Stacksize) != 0
+			|| pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) != 0)
 			goto error;
+		if(pthread_create(thread, &attrs, connproc, args) != 0)
+			goto error;
+		pthread_attr_destroy(&attrs);
 		free(thread);
 		continue;
 
 startlisten(pthread_t *thread, int listenfd,  int allowwrite)
 {
 	Args *args;
+	pthread_attr_t attrs;
 
 	args = emalloc(sizeof args[0]);
 	args->fd = listenfd;
 	args->allowwrite = allowwrite;
-	if(pthread_create(thread, nil, listenproc, args) != 0)
+	if(pthread_attr_init(&attrs) != 0
+		|| pthread_attr_setstacksize(&attrs, Stacksize) != 0)
+		errsyslog(1, "error setting stacksize for listenproc");
+	if(pthread_create(thread, &attrs, listenproc, args) != 0)
 		errsyslog(1, "error creating listenproc");
+	pthread_attr_destroy(&attrs);
 }
 
 
 	int readfds[Listenmax];
 	int writefds[Listenmax];
 	int i;
+	pthread_attr_t attrs;
 
 	fflag = 0;
 	vflag = 0;
 		startlisten(&readlistenthread[i], readfds[i], 0);
 	for(i = 0; i < nwritelistens; i++)
 		startlisten(&writelistenthread[i], writefds[i], 1);
-	if(pthread_create(&syncprocthread, nil, syncproc, nil) != 0)
+
+	if(pthread_attr_init(&attrs) != 0
+		|| pthread_attr_setstacksize(&attrs, Stacksize) != 0)
+		errsyslog(1, "error setting stacksize for listenproc");
+	if(pthread_create(&syncprocthread, &attrs, syncproc, nil) != 0)
 		errsyslog(1, "error creating syncproc");
+	pthread_attr_destroy(&attrs);
 
 	sigaddset(&mask, SIGINT);
 	sigaddset(&mask, SIGTERM);