aboutsummaryrefslogtreecommitdiff
path: root/lib/libkse/thread/thr_init.c
diff options
context:
space:
mode:
authorJohn Birrell <jb@FreeBSD.org>1998-08-10 01:24:22 +0000
committerJohn Birrell <jb@FreeBSD.org>1998-08-10 01:24:22 +0000
commitbbf157fac435c87e5f8a2e2da5d75e93f9a1f643 (patch)
treee15d392751c43c58896ff93a6709cf656d8963df /lib/libkse/thread/thr_init.c
parent7955cdca14053d1361f88f62bbebd3b396fe76f6 (diff)
downloadsrc-bbf157fac435c87e5f8a2e2da5d75e93f9a1f643.tar.gz
src-bbf157fac435c87e5f8a2e2da5d75e93f9a1f643.zip
Add extra initialisation code that is required for processes that
are started instead of init (pid = 1). This allows an embedded implementation quite like VxWorks, with (possibly) a single threaded program running instead of init. The neat thing is that the same threaded process can run in a multi-user workstation environment too.
Notes
Notes: svn path=/head/; revision=38208
Diffstat (limited to 'lib/libkse/thread/thr_init.c')
-rw-r--r--lib/libkse/thread/thr_init.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/libkse/thread/thr_init.c b/lib/libkse/thread/thr_init.c
index c267a2c8b313..69b0fef563ae 100644
--- a/lib/libkse/thread/thr_init.c
+++ b/lib/libkse/thread/thr_init.c
@@ -38,8 +38,10 @@
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
+#include <paths.h>
#include <unistd.h>
#include <sys/time.h>
+#include <sys/ttycom.h>
#ifdef _THREAD_SAFE
#include <machine/reg.h>
#include <pthread.h>
@@ -76,6 +78,7 @@ static void ***dynamic_allocator_handler_fn()
void
_thread_init(void)
{
+ int fd;
int flags;
int i;
struct sigaction act;
@@ -85,6 +88,31 @@ _thread_init(void)
/* Only initialise the threaded application once. */
return;
+ /*
+ * Check for the special case of this process running as
+ * or in place of init as pid = 1:
+ */
+ if (getpid() == 1) {
+ /*
+ * Setup a new session for this process which is
+ * assumed to be running as root.
+ */
+ if (setsid() == -1)
+ PANIC("Can't set session ID");
+ if (revoke(_PATH_CONSOLE) != 0)
+ PANIC("Can't revoke console");
+ if ((fd = _thread_sys_open(_PATH_CONSOLE, O_RDWR)) < 0)
+ PANIC("Can't open console");
+ if (setlogin("root") == -1)
+ PANIC("Can't set login to root");
+ if (_thread_sys_ioctl(fd,TIOCSCTTY, (char *) NULL) == -1)
+ PANIC("Can't set controlling terminal");
+ if (_thread_sys_dup2(fd,0) == -1 ||
+ _thread_sys_dup2(fd,1) == -1 ||
+ _thread_sys_dup2(fd,2) == -1)
+ PANIC("Can't dup2");
+ }
+
/* Get the standard I/O flags before messing with them : */
for (i = 0; i < 3; i++)
if ((_pthread_stdio_flags[i] =
@@ -154,7 +182,7 @@ _thread_init(void)
/* Initialise the global signal action structure: */
sigfillset(&act.sa_mask);
act.sa_handler = (void (*) ()) _thread_sig_handler;
- act.sa_flags = SA_RESTART;
+ act.sa_flags = 0;
/* Enter a loop to get the existing signal status: */
for (i = 1; i < NSIG; i++) {