* 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: 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/05/04
@(#)MIRBSD KSH R34 2008/05/15
description:
Check version of shell.
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
: ${EDITOR:=/bin/ed} ${TERM:=vt100} ${HOSTNAME:=$(ulimit -c 0;hostname -s 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 {
typeset -i e=$?

28
jobs.c
View File

@ -2,7 +2,7 @@
#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! */
#define PRUNNING 0
@ -99,7 +99,7 @@ static int32_t njobs; /* # of jobs started */
static volatile sig_atomic_t held_sigchld;
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 our_pgrp;
static int const tt_sigs[] = { SIGTSTP, SIGTTIN, SIGTTOU };
@ -221,14 +221,8 @@ j_change(void)
tty_init(false);
/* no controlling tty, no SIGT* */
ttypgrp_ok = use_tty && tty_fd >= 0 && tty_devtty;
if (ttypgrp_ok && (our_pgrp = getpgrp()) < 0) {
warningf(false, "j_init: getpgrp() failed: %s",
strerror(errno));
ttypgrp_ok = 0;
}
if (ttypgrp_ok) {
if ((ttypgrp_ok = use_tty && tty_fd >= 0 && tty_devtty)) {
our_pgrp = kshpgrp;
setsig(&sigtraps[SIGTTIN], SIG_DFL,
SS_RESTORE_ORIG|SS_FORCE);
/* wait to be given tty (POSIX.1, B.2, job control) */
@ -239,7 +233,7 @@ j_change(void)
warningf(false,
"j_init: tcgetpgrp() failed: %s",
strerror(errno));
ttypgrp_ok = 0;
ttypgrp_ok = false;
break;
}
if (ttypgrp == our_pgrp)
@ -255,13 +249,13 @@ j_change(void)
warningf(false,
"j_init: setpgid() failed: %s",
strerror(errno));
ttypgrp_ok = 0;
ttypgrp_ok = false;
} else {
if (tcsetpgrp(tty_fd, kshpid) < 0) {
warningf(false,
"j_init: tcsetpgrp() failed: %s",
strerror(errno));
ttypgrp_ok = 0;
ttypgrp_ok = false;
} else
restore_ttypgrp = our_pgrp;
our_pgrp = kshpid;
@ -272,7 +266,7 @@ j_change(void)
if (tty_fd >= 0)
tcgetattr(tty_fd, &tty_state);
} else {
ttypgrp_ok = 0;
ttypgrp_ok = false;
if (Flag(FTALKING))
for (i = NELEM(tt_sigs); --i >= 0; )
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 */
nzombie = 0;
ttypgrp_ok = 0;
ttypgrp_ok = false;
Flag(FMONITOR) = 0;
Flag(FTALKING) = 0;
tty_close();
@ -685,7 +679,7 @@ j_resume(const char *cp, int bg)
if (ttypgrp_ok && tcsetpgrp(tty_fd, our_pgrp) < 0) {
warningf(true,
"fg: 2nd tcsetpgrp(%d, %d) failed: %s",
tty_fd, (int) our_pgrp,
tty_fd, (int)our_pgrp,
strerror(errno));
}
}
@ -951,7 +945,7 @@ j_waitj(Job *j,
if (tcsetpgrp(tty_fd, our_pgrp) < 0) {
warningf(true,
"j_waitj: tcsetpgrp(%d, %d) failed: %s",
tty_fd, (int) our_pgrp,
tty_fd, (int)our_pgrp,
strerror(errno));
}
if (j->state == PSTOPPED) {

12
main.c
View File

@ -13,7 +13,7 @@
#include <locale.h>
#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;
@ -32,8 +32,8 @@ static const char initsubs[] = "${PS2=> } ${PS3=#? } ${PS4=+ }";
static const char *initcoms[] = {
"typeset", "-r", initvsn, NULL,
"typeset", "-x", "SHELL", "PATH", "HOME", NULL,
"typeset", "-i", "PPID", "OPTIND=1", NULL,
"eval", "typeset -i RANDOM SECONDS=\"${SECONDS-0}\" TMOUT=\"${TMOUT-0}\"", NULL,
"typeset", "-i10", "OPTIND=1", "PGRP", "PPID", "USER_ID", NULL,
"eval", "typeset -i10 RANDOM SECONDS=\"${SECONDS-0}\" TMOUT=\"${TMOUT-0}\"", NULL,
"alias", "integer=typeset -i", "local=typeset", NULL,
"alias",
"hash=alias -t", /* not "alias -t --": hash -r needs to work */
@ -213,7 +213,6 @@ main(int argc, const char *argv[])
#if HAVE_ARC4RANDOM
Flag(FARC4RANDOM) = 2; /* use arc4random(3) until $RANDOM is written */
#endif
setint(global("PPID"), (long)ppid);
for (wp = initcoms; *wp != NULL; wp++) {
shcomexec(wp);
@ -228,6 +227,9 @@ main(int argc, const char *argv[])
(!ksheuid && !strchr(str_val(vp), '#')))
/* setstr can't fail here */
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 */
#if HAVE_SETRESUGID
@ -636,7 +638,7 @@ quitenv(struct shf *shf)
* dump a core..
*/
if ((sig == SIGINT || sig == SIGTERM) &&
getpgrp() == kshpid) {
(kshpgrp == kshpid)) {
setsig(&sigtraps[sig], SIG_DFL,
SS_RESTORE_CURR | SS_FORCE);
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 $
.\"-
.\" 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: May 10 2008 $
.Dd $Mdocdate: May 15 2008 $
.Dt MKSH 1
.Os MirBSD
.Sh NAME
@ -1551,8 +1551,10 @@ An empty string resulting from a leading or trailing
colon, or two adjacent colons, is treated as a
.Sq \&.
(the current directory).
.It Ev PGRP
The process ID of the shell's process group leader.
.It Ev PPID
The process ID of the shell's parent (read-only).
The process ID of the shell's parent.
.It Ev PS1
The primary prompt for interactive shells.
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
files are created in
.Pa /tmp .
.It Ev USER_ID
The effective user id of the shell.
.El
.Ss Tilde expansion
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)
#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
#define MKSH_VERSION "R33 2008/05/04"
#define MKSH_VERSION "R34 2008/05/15"
#ifndef MKSH_INCLUDES_ONLY
@ -280,6 +280,7 @@ typedef int32_t Tflag;
EXTERN const char *kshname; /* $0 */
EXTERN pid_t kshpid; /* $$, shell pid */
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 int exstat; /* exit status */
EXTERN int subst_exstat; /* exit status of last $(..)/`..` */