support dæmonisation in mksh, for example

|	csh -cf '/command/svscanboot &'
and
|	/usr/mpkg/bin/pgrphack /usr/mpkg/bin/svscanboot &
can now be replaced with
|	/bin/mksh -T- /usr/mpkg/bin/svscanboot
This commit is contained in:
tg 2008-03-23 22:09:59 +00:00
parent 38a53603d3
commit 83b8798da3
4 changed files with 36 additions and 29 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.160 2008/03/23 20:54:29 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.161 2008/03/23 22:09:57 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -7,7 +7,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R33 2008/03/05
@(#)MIRBSD KSH R33 2008/03/23
description:
Check version of shell.
category: pdksh

46
misc.c
View File

@ -6,7 +6,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.68 2008/02/27 01:00:09 tg Exp $\t"
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.69 2008/03/23 22:09:58 tg Exp $\t"
MKSH_SH_H_ID);
#undef USE_CHVT
@ -1337,28 +1337,32 @@ chvt(const char *fn)
struct stat sb;
int fd;
if (stat(fn, &sb)) {
memcpy(dv, "/dev/ttyC", 9);
strlcpy(dv + 9, fn, 20 - 9);
if (stat(dv, &sb)) {
strlcpy(dv + 8, fn, 20 - 8);
if (stat(dv, &sb))
errorf("chvt: can't find tty %s", fn);
if (*fn == '-') {
memcpy(dv, "-/dev/null", sizeof ("-/dev/null"));
fn = dv + 1;
} else {
if (stat(fn, &sb)) {
memcpy(dv, "/dev/ttyC", 9);
strlcpy(dv + 9, fn, 20 - 9);
if (stat(dv, &sb)) {
strlcpy(dv + 8, fn, 20 - 8);
if (stat(dv, &sb))
errorf("chvt: can't find tty %s", fn);
}
fn = dv;
}
fn = dv;
}
if (!(sb.st_mode & S_IFCHR))
errorf("chvt: not a char device: %s", fn);
if ((sb.st_uid != 0) && chown(fn, 0, 0))
warningf(false, "chvt: cannot chown root %s", fn);
if (((sb.st_mode & 07777) != 0600) && chmod(fn, 0600))
warningf(false, "chvt: cannot chmod 0600 %s", fn);
if (!(sb.st_mode & S_IFCHR))
errorf("chvt: not a char device: %s", fn);
if ((sb.st_uid != 0) && chown(fn, 0, 0))
warningf(false, "chvt: cannot chown root %s", fn);
if (((sb.st_mode & 07777) != 0600) && chmod(fn, 0600))
warningf(false, "chvt: cannot chmod 0600 %s", fn);
#if HAVE_REVOKE
if (revoke(fn))
if (revoke(fn))
#endif
warningf(false, "chvt: cannot revoke %s, new shell is"
" potentially insecure", fn);
warningf(false, "chvt: cannot revoke %s, new shell is"
" potentially insecure", fn);
}
if ((fd = open(fn, O_RDWR)) == -1) {
sleep(1);
if ((fd = open(fn, O_RDWR)) == -1)
@ -1374,7 +1378,7 @@ chvt(const char *fn)
}
if (setsid() == -1)
errorf("chvt: setsid failed");
if (ioctl(fd, TIOCSCTTY, NULL) == -1)
if ((fn != dv + 1) && ioctl(fd, TIOCSCTTY, NULL) == -1)
errorf("chvt: TIOCSCTTY failed");
dup2(fd, 0);
dup2(fd, 1);

11
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.113 2008/03/04 00:09:34 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.114 2008/03/23 22:09:58 tg Exp $
.\" $OpenBSD: ksh.1,v 1.120 2007/05/31 20:47:44 otto Exp $
.\"-
.\" Try to make GNU groff and AT&T nroff more compatible
@ -30,7 +30,7 @@
.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
..
.\"-
.Dd $Mdocdate: March 4 2008 $
.Dd $Mdocdate: March 23 2008 $
.Dt MKSH 1
.Os MirBSD
.Sh NAME
@ -41,7 +41,7 @@
.Nm
.Bk -words
.Op Fl +abCefhiklmnprUuvXx
.Op Fl T Ar /dev/ttyCn
.Op Fl T Ar /dev/ttyCn | \-
.Op Fl +o Ar option
.Oo Fl c Ar string \*(Ba Fl s \*(Ba
.Ar \ file\ \&
@ -171,6 +171,9 @@ on the
.Xr tty 4
device given.
Superuser only.
If
.Ar tty
is a dash, detach from controlling terminal (daemonise) instead.
.El
.Pp
In addition to the above, the options described in the
@ -5452,7 +5455,7 @@ and many other persons, and is currently maintained by
.An Thorsten Glaser Aq tg@mirbsd.de .
.Sh BUGS
This document attempts to describe
.Nm mksh\ R33
.Nm mksh\ R33b
and up,
compiled without any options impacting functionality, such as
.Dv MKSH_SMALL ,

4
sh.h
View File

@ -8,8 +8,8 @@
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.196 2008/03/23 20:55:18 tg Exp $"
#define MKSH_VERSION "R33 2008/03/05"
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.197 2008/03/23 22:09:59 tg Exp $"
#define MKSH_VERSION "R33 2008/03/23"
#if HAVE_SYS_PARAM_H
#include <sys/param.h>