summaryrefslogtreecommitdiffstats
path: root/lib/libc_r
diff options
context:
space:
mode:
authorjb <jb@FreeBSD.org>1998-08-10 01:24:22 +0000
committerjb <jb@FreeBSD.org>1998-08-10 01:24:22 +0000
commitb3abc25f214cbfcd1eba42942573dcf492412810 (patch)
tree2001e71b2867e1aea26fbb912778b335e7187231 /lib/libc_r
parent40e3575af7863782e4b0996520553cdeab80a99b (diff)
downloadFreeBSD-src-b3abc25f214cbfcd1eba42942573dcf492412810.zip
FreeBSD-src-b3abc25f214cbfcd1eba42942573dcf492412810.tar.gz
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.
Diffstat (limited to 'lib/libc_r')
-rw-r--r--lib/libc_r/uthread/uthread_init.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/libc_r/uthread/uthread_init.c b/lib/libc_r/uthread/uthread_init.c
index c267a2c..69b0fef 100644
--- a/lib/libc_r/uthread/uthread_init.c
+++ b/lib/libc_r/uthread/uthread_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++) {
OpenPOWER on IntegriCloud