runtime: fix running under nohup

There are two ways nohup(1) might be implemented:
it might mask away the signal, or it might set the handler
to SIG_IGN, both of which are inherited across fork+exec.
So two fixes:

* Make sure to preserve the inherited signal mask at
minit instead of clearing it.

* If the SIGHUP handler is SIG_IGN, leave it that way.

Fixes #4491.

R=golang-dev, mikioh.mikioh, iant
CC=golang-dev
https://golang.org/cl/7308102
diff --git a/src/pkg/runtime/thread_darwin.c b/src/pkg/runtime/thread_darwin.c
index 0758d68..d55ec8d 100644
--- a/src/pkg/runtime/thread_darwin.c
+++ b/src/pkg/runtime/thread_darwin.c
@@ -10,7 +10,6 @@
 extern SigTab runtime·sigtab[];
 
 static Sigset sigset_all = ~(Sigset)0;
-static Sigset sigset_none;
 static Sigset sigset_prof = 1<<(SIGPROF-1);
 
 static void
@@ -99,6 +98,8 @@
 	}
 
 	runtime·sigprocmask(SIG_SETMASK, &sigset_all, &oset);
+	mp->sigset = runtime·mal(sizeof(Sigset));
+	*(Sigset*)mp->sigset = oset;
 	errno = runtime·bsdthread_create(stk, mp, gp, fn);
 	runtime·sigprocmask(SIG_SETMASK, &oset, nil);
 
@@ -116,10 +117,9 @@
 	m->gsignal = runtime·malg(32*1024);	// OS X wants >=8K, Linux >=2K
 	runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024);
 
-	if(m->profilehz > 0)
-		runtime·sigprocmask(SIG_SETMASK, &sigset_none, nil);
-	else
-		runtime·sigprocmask(SIG_SETMASK, &sigset_prof, nil);
+	if(m->sigset != nil)
+		runtime·sigprocmask(SIG_SETMASK, m->sigset, nil);
+	runtime·setprof(m->profilehz > 0);
 }
 
 // Mach IPC, to get at semaphores