shithub: riscv

Download patch

ref: 83fe7aaa5ce4776c394cb9edd89189b62efb89a9
parent: e3d8fe9d4a1085cbf7237411bcd1996613334994
author: cinap_lenrek <[email protected]>
date: Mon Oct 23 02:08:18 EDT 2017

upas/smtpd: don't call syslog() from the note handler, this can deadlock

when the alarm hits while the process is currently in syslog(), holding
the sl lock, then calling syslog again will deadlock:

/proc/1729193/text:386 plan 9 executable
/sys/lib/acid/port
/sys/lib/acid/386
acid: lstk()
sleep()+0x7 /sys/src/libc/9syscall/sleep.s:5
lock(lk=0x394d8)+0xb7 /sys/src/libc/port/lock.c:25
	i=0x3e8
syslog(logname=0x41c64,cons=0x0,fmt=0x41c6a)+0x2d /sys/src/libc/9sys/syslog.c:60
	err=0x79732f27
	d=0x0
	ctim=0x0
	buf=0x0
	p=0x0
	arg=0x0
	n=0x0
catchalarm(msg=0xdfffc854)+0x7a /sys/src/cmd/upas/smtp/smtpd.c:71
notifier+0x30 /sys/src/libc/port/atnotify.c:15

--- a/sys/src/cmd/upas/smtp/smtpd.c
+++ b/sys/src/cmd/upas/smtp/smtpd.c
@@ -55,23 +55,12 @@
 catchalarm(void*, char *msg)
 {
 	int ign;
-	static int chattycathy;
 
 	ign = strstr(msg, "closed pipe") != nil;
 	if(ign)
 		return 0;
-	if(chattycathy++ < 5){
-		if(senders.first && rcvers.first)
-			syslog(0, "smtpd", "note: %s->%s: %s",
-				s_to_c(senders.first->p),
-				s_to_c(rcvers.first->p), msg);
-		else
-			syslog(0, "smtpd", "note: %s", msg);
-	}
-	if(pp){
+	if(pp)
 		syskill(pp->pid);
-	//	pp = 0;
-	}
 	return strstr(msg, "alarm") != nil;
 }