* initialise the integers PPID, OPTIND, RANDOM, SECONDS, and TMOUT to base-10
* bring back PGRP as base-10 integer to the process group via getpgrp(2)
* initialise USER_ID as base-10 integer to the effective user id as retrieved
  from geteuid(2) = $(id -u)
* use $USER_ID in dot.mkshrc instead of spawning an id(1) process
  -> dot.mkshrc,v 1.34 now requires mksh R34
* convert more int to bool where appropriate
* remove dead code - getpgrp(2) cannot fail
* sync manual page to reality
* bump to mksh R34(beta) - feature freeze

XXX check if our_pgrp in jobs.c is still really needed, the setpgid call
XXX probably just makes us our own pgrp leader, and we might have to use
XXX and update kshpgrp accordingly - need feedback/help here but I think
XXX this simplification should be possible if I grok the code correctly.

etc/profile:
* adjust to $USER_ID changes in mksh (speed-up here, too)

mksh.hts:
* sync changelog
This commit is contained in:
tg 2008-05-15 15:24:11 +00:00
parent 67b4dc8731
commit 6be5205b36
6 changed files with 32 additions and 31 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.194 2008/05/10 03:16:07 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.195 2008/05/15 15:24:09 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas 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: 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 $ # $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 # http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R33 2008/05/04 @(#)MIRBSD KSH R34 2008/05/15
description: description:
Check version of shell. Check version of shell.
category: pdksh category: pdksh

View File

@ -1,10 +1,10 @@
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.33 2008/04/22 13:48:15 tg Rel $ # $MirOS: src/bin/mksh/dot.mkshrc,v 1.34 2008/05/15 15:24:09 tg Exp $
#- #-
# ~/.mkshrc: mksh initialisation file for interactive shells # ~/.mkshrc: mksh initialisation file for interactive shells
: ${EDITOR:=/bin/ed} ${TERM:=vt100} ${HOSTNAME:=$(ulimit -c 0;hostname -s 2>&-)} : ${EDITOR:=/bin/ed} ${TERM:=vt100} ${HOSTNAME:=$(ulimit -c 0;hostname -s 2>&-)}
[[ $HOSTNAME = @(localhost|*([ ])) ]] && HOSTNAME=$(ulimit -c 0;hostname 2>&-) [[ $HOSTNAME = @(localhost|*([ ])) ]] && HOSTNAME=$(ulimit -c 0;hostname 2>&-)
: ${HOSTNAME:=nil}; PS1='#'; [[ "$(ulimit -c 0; id -u 2>&-)" -eq 0 ]] || PS1='$' : ${HOSTNAME:=nil}; if (( USER_ID )); then PS1='$'; else PS1='#'; fi
function precmd { function precmd {
typeset -i e=$? typeset -i e=$?

28
jobs.c
View File

@ -2,7 +2,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.33 2008/04/01 21:50:58 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.34 2008/05/15 15:24:09 tg Exp $");
/* Order important! */ /* Order important! */
#define PRUNNING 0 #define PRUNNING 0
@ -99,7 +99,7 @@ static int32_t njobs; /* # of jobs started */
static volatile sig_atomic_t held_sigchld; static volatile sig_atomic_t held_sigchld;
static struct shf *shl_j; static struct shf *shl_j;
static int ttypgrp_ok; /* set if can use tty pgrps */ static bool ttypgrp_ok; /* set if can use tty pgrps */
static pid_t restore_ttypgrp = -1; static pid_t restore_ttypgrp = -1;
static pid_t our_pgrp; static pid_t our_pgrp;
static int const tt_sigs[] = { SIGTSTP, SIGTTIN, SIGTTOU }; static int const tt_sigs[] = { SIGTSTP, SIGTTIN, SIGTTOU };
@ -221,14 +221,8 @@ j_change(void)
tty_init(false); tty_init(false);
/* no controlling tty, no SIGT* */ /* no controlling tty, no SIGT* */
ttypgrp_ok = use_tty && tty_fd >= 0 && tty_devtty; if ((ttypgrp_ok = use_tty && tty_fd >= 0 && tty_devtty)) {
our_pgrp = kshpgrp;
if (ttypgrp_ok && (our_pgrp = getpgrp()) < 0) {
warningf(false, "j_init: getpgrp() failed: %s",
strerror(errno));
ttypgrp_ok = 0;
}
if (ttypgrp_ok) {
setsig(&sigtraps[SIGTTIN], SIG_DFL, setsig(&sigtraps[SIGTTIN], SIG_DFL,
SS_RESTORE_ORIG|SS_FORCE); SS_RESTORE_ORIG|SS_FORCE);
/* wait to be given tty (POSIX.1, B.2, job control) */ /* wait to be given tty (POSIX.1, B.2, job control) */
@ -239,7 +233,7 @@ j_change(void)
warningf(false, warningf(false,
"j_init: tcgetpgrp() failed: %s", "j_init: tcgetpgrp() failed: %s",
strerror(errno)); strerror(errno));
ttypgrp_ok = 0; ttypgrp_ok = false;
break; break;
} }
if (ttypgrp == our_pgrp) if (ttypgrp == our_pgrp)
@ -255,13 +249,13 @@ j_change(void)
warningf(false, warningf(false,
"j_init: setpgid() failed: %s", "j_init: setpgid() failed: %s",
strerror(errno)); strerror(errno));
ttypgrp_ok = 0; ttypgrp_ok = false;
} else { } else {
if (tcsetpgrp(tty_fd, kshpid) < 0) { if (tcsetpgrp(tty_fd, kshpid) < 0) {
warningf(false, warningf(false,
"j_init: tcsetpgrp() failed: %s", "j_init: tcsetpgrp() failed: %s",
strerror(errno)); strerror(errno));
ttypgrp_ok = 0; ttypgrp_ok = false;
} else } else
restore_ttypgrp = our_pgrp; restore_ttypgrp = our_pgrp;
our_pgrp = kshpid; our_pgrp = kshpid;
@ -272,7 +266,7 @@ j_change(void)
if (tty_fd >= 0) if (tty_fd >= 0)
tcgetattr(tty_fd, &tty_state); tcgetattr(tty_fd, &tty_state);
} else { } else {
ttypgrp_ok = 0; ttypgrp_ok = false;
if (Flag(FTALKING)) if (Flag(FTALKING))
for (i = NELEM(tt_sigs); --i >= 0; ) for (i = NELEM(tt_sigs); --i >= 0; )
setsig(&sigtraps[tt_sigs[i]], SIG_IGN, setsig(&sigtraps[tt_sigs[i]], SIG_IGN,
@ -426,7 +420,7 @@ exchild(struct op *t, int flags, /* used if XPCLOSE or XCCLOSE */ int close_fd)
} }
remove_job(j, "child"); /* in case of $(jobs) command */ remove_job(j, "child"); /* in case of $(jobs) command */
nzombie = 0; nzombie = 0;
ttypgrp_ok = 0; ttypgrp_ok = false;
Flag(FMONITOR) = 0; Flag(FMONITOR) = 0;
Flag(FTALKING) = 0; Flag(FTALKING) = 0;
tty_close(); tty_close();
@ -685,7 +679,7 @@ j_resume(const char *cp, int bg)
if (ttypgrp_ok && tcsetpgrp(tty_fd, our_pgrp) < 0) { if (ttypgrp_ok && tcsetpgrp(tty_fd, our_pgrp) < 0) {
warningf(true, warningf(true,
"fg: 2nd tcsetpgrp(%d, %d) failed: %s", "fg: 2nd tcsetpgrp(%d, %d) failed: %s",
tty_fd, (int) our_pgrp, tty_fd, (int)our_pgrp,
strerror(errno)); strerror(errno));
} }
} }
@ -951,7 +945,7 @@ j_waitj(Job *j,
if (tcsetpgrp(tty_fd, our_pgrp) < 0) { if (tcsetpgrp(tty_fd, our_pgrp) < 0) {
warningf(true, warningf(true,
"j_waitj: tcsetpgrp(%d, %d) failed: %s", "j_waitj: tcsetpgrp(%d, %d) failed: %s",
tty_fd, (int) our_pgrp, tty_fd, (int)our_pgrp,
strerror(errno)); strerror(errno));
} }
if (j->state == PSTOPPED) { if (j->state == PSTOPPED) {

12
main.c
View File

@ -13,7 +13,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.96 2008/05/04 01:58:14 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.97 2008/05/15 15:24:10 tg Exp $");
extern char **environ; extern char **environ;
@ -32,8 +32,8 @@ static const char initsubs[] = "${PS2=> } ${PS3=#? } ${PS4=+ }";
static const char *initcoms[] = { static const char *initcoms[] = {
"typeset", "-r", initvsn, NULL, "typeset", "-r", initvsn, NULL,
"typeset", "-x", "SHELL", "PATH", "HOME", NULL, "typeset", "-x", "SHELL", "PATH", "HOME", NULL,
"typeset", "-i", "PPID", "OPTIND=1", NULL, "typeset", "-i10", "OPTIND=1", "PGRP", "PPID", "USER_ID", NULL,
"eval", "typeset -i RANDOM SECONDS=\"${SECONDS-0}\" TMOUT=\"${TMOUT-0}\"", NULL, "eval", "typeset -i10 RANDOM SECONDS=\"${SECONDS-0}\" TMOUT=\"${TMOUT-0}\"", NULL,
"alias", "integer=typeset -i", "local=typeset", NULL, "alias", "integer=typeset -i", "local=typeset", NULL,
"alias", "alias",
"hash=alias -t", /* not "alias -t --": hash -r needs to work */ "hash=alias -t", /* not "alias -t --": hash -r needs to work */
@ -213,7 +213,6 @@ main(int argc, const char *argv[])
#if HAVE_ARC4RANDOM #if HAVE_ARC4RANDOM
Flag(FARC4RANDOM) = 2; /* use arc4random(3) until $RANDOM is written */ Flag(FARC4RANDOM) = 2; /* use arc4random(3) until $RANDOM is written */
#endif #endif
setint(global("PPID"), (long)ppid);
for (wp = initcoms; *wp != NULL; wp++) { for (wp = initcoms; *wp != NULL; wp++) {
shcomexec(wp); shcomexec(wp);
@ -228,6 +227,9 @@ main(int argc, const char *argv[])
(!ksheuid && !strchr(str_val(vp), '#'))) (!ksheuid && !strchr(str_val(vp), '#')))
/* setstr can't fail here */ /* setstr can't fail here */
setstr(vp, safe_prompt, KSH_RETURN_ERROR); setstr(vp, safe_prompt, KSH_RETURN_ERROR);
setint(global("PGRP"), (long)(kshpgrp = getpgrp()));
setint(global("PPID"), (long)ppid);
setint(global("USER_ID"), (long)ksheuid);
/* Set this before parsing arguments */ /* Set this before parsing arguments */
#if HAVE_SETRESUGID #if HAVE_SETRESUGID
@ -636,7 +638,7 @@ quitenv(struct shf *shf)
* dump a core.. * dump a core..
*/ */
if ((sig == SIGINT || sig == SIGTERM) && if ((sig == SIGINT || sig == SIGTERM) &&
getpgrp() == kshpid) { (kshpgrp == kshpid)) {
setsig(&sigtraps[sig], SIG_DFL, setsig(&sigtraps[sig], SIG_DFL,
SS_RESTORE_CURR | SS_FORCE); SS_RESTORE_CURR | SS_FORCE);
kill(0, sig); kill(0, sig);

10
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.126 2008/05/10 18:10:02 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.127 2008/05/15 15:24:10 tg Exp $
.\" $OpenBSD: ksh.1,v 1.121 2008/03/21 12:51:19 millert Exp $ .\" $OpenBSD: ksh.1,v 1.121 2008/03/21 12:51:19 millert Exp $
.\"- .\"-
.\" Try to make GNU groff and AT&T nroff more compatible .\" 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 .el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
.. ..
.\"- .\"-
.Dd $Mdocdate: May 10 2008 $ .Dd $Mdocdate: May 15 2008 $
.Dt MKSH 1 .Dt MKSH 1
.Os MirBSD .Os MirBSD
.Sh NAME .Sh NAME
@ -1551,8 +1551,10 @@ An empty string resulting from a leading or trailing
colon, or two adjacent colons, is treated as a colon, or two adjacent colons, is treated as a
.Sq \&. .Sq \&.
(the current directory). (the current directory).
.It Ev PGRP
The process ID of the shell's process group leader.
.It Ev PPID .It Ev PPID
The process ID of the shell's parent (read-only). The process ID of the shell's parent.
.It Ev PS1 .It Ev PS1
The primary prompt for interactive shells. The primary prompt for interactive shells.
Parameter, command, and arithmetic Parameter, command, and arithmetic
@ -1683,6 +1685,8 @@ If this parameter is not
set, or does not contain the absolute path of a writable directory, temporary set, or does not contain the absolute path of a writable directory, temporary
files are created in files are created in
.Pa /tmp . .Pa /tmp .
.It Ev USER_ID
The effective user id of the shell.
.El .El
.Ss Tilde expansion .Ss Tilde expansion
Tilde expansion which is done in parallel with parameter substitution, is done Tilde expansion which is done in parallel with parameter substitution, is done

5
sh.h
View File

@ -96,9 +96,9 @@
#define __SCCSID(x) __IDSTRING(sccsid,x) #define __SCCSID(x) __IDSTRING(sccsid,x)
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.214 2008/05/04 01:51:31 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.215 2008/05/15 15:24:11 tg Exp $");
#endif #endif
#define MKSH_VERSION "R33 2008/05/04" #define MKSH_VERSION "R34 2008/05/15"
#ifndef MKSH_INCLUDES_ONLY #ifndef MKSH_INCLUDES_ONLY
@ -280,6 +280,7 @@ typedef int32_t Tflag;
EXTERN const char *kshname; /* $0 */ EXTERN const char *kshname; /* $0 */
EXTERN pid_t kshpid; /* $$, shell pid */ EXTERN pid_t kshpid; /* $$, shell pid */
EXTERN pid_t procpid; /* pid of executing process */ EXTERN pid_t procpid; /* pid of executing process */
EXTERN pid_t kshpgrp; /* process group of shell */
EXTERN uid_t ksheuid; /* effective uid of shell */ EXTERN uid_t ksheuid; /* effective uid of shell */
EXTERN int exstat; /* exit status */ EXTERN int exstat; /* exit status */
EXTERN int subst_exstat; /* exit status of last $(..)/`..` */ EXTERN int subst_exstat; /* exit status of last $(..)/`..` */