get rid of $PGRP

get rid of special bourne-shell emulating mode
This commit is contained in:
tg 2005-07-04 12:34:24 +00:00
parent e392a30930
commit 76c700b3a6
8 changed files with 33 additions and 110 deletions

16
exec.c
View File

@ -1,11 +1,11 @@
/** $MirOS: src/bin/mksh/exec.c,v 1.6 2005/07/04 12:27:25 tg Exp $ */ /** $MirOS: src/bin/mksh/exec.c,v 1.7 2005/07/04 12:34:22 tg Exp $ */
/* $OpenBSD: exec.c,v 1.41 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: exec.c,v 1.41 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h" #include "sh.h"
#include <sys/stat.h> #include <sys/stat.h>
#include <ctype.h> #include <ctype.h>
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.6 2005/07/04 12:27:25 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/exec.c,v 1.7 2005/07/04 12:34:22 tg Exp $");
static int comexec(struct op *, struct tbl *volatile, char **, static int comexec(struct op *, struct tbl *volatile, char **,
int volatile); int volatile);
@ -398,7 +398,7 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags)
* functions/dot scripts, but in interactive and script) - * functions/dot scripts, but in interactive and script) -
* perhaps save last arg here and set it in shell()?. * perhaps save last arg here and set it in shell()?.
*/ */
if (!Flag(FSH) && Flag(FTALKING) && *(lastp = ap)) { if (Flag(FTALKING) && *(lastp = ap)) {
while (*++lastp) while (*++lastp)
; ;
/* setstr() can't fail here */ /* setstr() can't fail here */
@ -647,12 +647,10 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags)
break; break;
} }
if (!Flag(FSH)) { /* set $_ to programme's full path */
/* set $_ to programme's full path */ /* setstr() can't fail here */
/* setstr() can't fail here */ setstr(typeset("_", LOCAL|EXPORT, 0, INTEGER, 0),
setstr(typeset("_", LOCAL|EXPORT, 0, INTEGER, 0), tp->val.s, KSH_RETURN_ERROR);
tp->val.s, KSH_RETURN_ERROR);
}
if (flags&XEXEC) { if (flags&XEXEC) {
j_exit(); j_exit();

13
funcs.c
View File

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/funcs.c,v 1.13 2005/07/04 12:27:26 tg Exp $ */ /** $MirOS: src/bin/mksh/funcs.c,v 1.14 2005/07/04 12:34:22 tg Exp $ */
/* $OpenBSD: c_ksh.c,v 1.27 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: c_ksh.c,v 1.27 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: c_sh.c,v 1.29 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: c_sh.c,v 1.29 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: c_test.c,v 1.17 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: c_test.c,v 1.17 2005/03/30 17:16:37 deraadt Exp $ */
@ -13,7 +13,7 @@
#include <ulimit.h> #include <ulimit.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.13 2005/07/04 12:27:26 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.14 2005/07/04 12:34:22 tg Exp $");
int int
c_cd(char **wp) c_cd(char **wp)
@ -2183,13 +2183,8 @@ c_exec(char **wp __attribute__((unused)))
for (i = 0; i < NUFILE; i++) { for (i = 0; i < NUFILE; i++) {
if (e->savefd[i] > 0) if (e->savefd[i] > 0)
close(e->savefd[i]); close(e->savefd[i]);
/* /* For ksh keep anything > 2 private */
* For ksh keep anything > 2 private, if (i > 2 && e->savefd[i])
* for sh, let them be (POSIX says what
* happens is unspecified and the bourne shell
* keeps them open).
*/
if (!Flag(FSH) && i > 2 && e->savefd[i])
fcntl(i, F_SETFD, FD_CLOEXEC); fcntl(i, F_SETFD, FD_CLOEXEC);
} }
e->savefd = NULL; e->savefd = NULL;

16
lex.c
View File

@ -1,11 +1,11 @@
/** $MirOS: src/bin/mksh/lex.c,v 1.5 2005/07/04 12:27:26 tg Exp $ */ /** $MirOS: src/bin/mksh/lex.c,v 1.6 2005/07/04 12:34:23 tg Exp $ */
/* $OpenBSD: lex.c,v 1.36 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: lex.c,v 1.36 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h" #include "sh.h"
#include <ctype.h> #include <ctype.h>
#include <libgen.h> #include <libgen.h>
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.5 2005/07/04 12:27:26 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/lex.c,v 1.6 2005/07/04 12:34:23 tg Exp $");
/* Structure to keep track of the lexing state and the various pieces of info /* Structure to keep track of the lexing state and the various pieces of info
* needed for each particular state. */ * needed for each particular state. */
@ -677,13 +677,11 @@ Done:
return c; return c;
case '(': /*)*/ case '(': /*)*/
if (!Flag(FSH)) { if ((c2 = getsc()) == '(') /*)*/
if ((c2 = getsc()) == '(') /*)*/ /* XXX need to handle ((...); (...)) */
/* XXX need to handle ((...); (...)) */ c = MDPAREN;
c = MDPAREN; else
else ungetsc(c2);
ungetsc(c2);
}
return c; return c;
/*(*/ /*(*/
case ')': case ')':

15
main.c
View File

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/main.c,v 1.18 2005/07/04 12:27:26 tg Exp $ */ /** $MirOS: src/bin/mksh/main.c,v 1.19 2005/07/04 12:34:23 tg Exp $ */
/* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */
@ -13,7 +13,7 @@
#include <time.h> #include <time.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.18 2005/07/04 12:27:26 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.19 2005/07/04 12:34:23 tg Exp $");
const char ksh_version[] = "@(#)MIRBSD KSH R23 2005/07/04"; const char ksh_version[] = "@(#)MIRBSD KSH R23 2005/07/04";
@ -29,8 +29,7 @@ static const char initsubs[] = "${PS2=> } ${PS3=#? } ${PS4=+ }";
static const char *initcoms[] = { static const char *initcoms[] = {
"typeset", "-r", "KSH_VERSION", NULL, "typeset", "-r", "KSH_VERSION", NULL,
"typeset", "-x", "SHELL", "PATH", "HOME", NULL, "typeset", "-x", "SHELL", "PATH", "HOME", NULL,
"typeset", "-i", "PGRP=0", "PPID", NULL, "typeset", "-i", "PPID", "OPTIND=1", NULL,
"typeset", "-i", "OPTIND=1", NULL,
"eval", "typeset -i RANDOM SECONDS=\"${SECONDS-0}\" TMOUT=\"${TMOUT-0}\"", NULL, "eval", "typeset -i RANDOM SECONDS=\"${SECONDS-0}\" TMOUT=\"${TMOUT-0}\"", NULL,
"alias", "alias",
/* Standard ksh aliases */ /* Standard ksh aliases */
@ -156,11 +155,6 @@ main(int argc, char *argv[])
*/ */
Flag(FBRACEEXPAND) = 1; Flag(FBRACEEXPAND) = 1;
/* Check to see if we're /bin/sh. */
if (!strcmp(&kshname[strlen(kshname) - 3], "/sh") ||
!strcmp(kshname, "sh") || !strcmp(kshname, "-sh"))
Flag(FSH) = 1;
/* Set edit mode to emacs by default, may be overridden /* Set edit mode to emacs by default, may be overridden
* by the environment or the user. Also, we want tab completion * by the environment or the user. Also, we want tab completion
* on in vi by default. */ * on in vi by default. */
@ -207,8 +201,7 @@ main(int argc, char *argv[])
#endif #endif
setint(global("PPID"), (long)ppid); setint(global("PPID"), (long)ppid);
/* setstr can't fail here */ /* setstr can't fail here */
if (!Flag(FSH)) setstr(global("KSH_VERSION"), ksh_version, KSH_RETURN_ERROR);
setstr(global("KSH_VERSION"), ksh_version, KSH_RETURN_ERROR);
/* execute initialisation statements */ /* execute initialisation statements */
for (wp = (char **)initcoms; *wp != NULL; wp++) { for (wp = (char **)initcoms; *wp != NULL; wp++) {

6
misc.c
View File

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/misc.c,v 1.5 2005/07/04 12:27:27 tg Exp $ */ /** $MirOS: src/bin/mksh/misc.c,v 1.6 2005/07/04 12:34:23 tg Exp $ */
/* $OpenBSD: misc.c,v 1.28 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: misc.c,v 1.28 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: path.c,v 1.12 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: path.c,v 1.12 2005/03/30 17:16:37 deraadt Exp $ */
@ -7,7 +7,7 @@
#include <sys/param.h> /* for MAXPATHLEN */ #include <sys/param.h> /* for MAXPATHLEN */
#include <sys/stat.h> #include <sys/stat.h>
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.5 2005/07/04 12:27:27 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.6 2005/07/04 12:34:23 tg Exp $");
short chtypes[UCHAR_MAX+1]; /* type bits for unsigned char */ short chtypes[UCHAR_MAX+1]; /* type bits for unsigned char */
@ -252,7 +252,7 @@ change_flag(enum sh_flag f,
int oldval; int oldval;
/* disabled functionality */ /* disabled functionality */
if (f == FPOSIX) if ((f == FPOSIX) || (f == FSH))
return; return;
oldval = Flag(f); oldval = Flag(f);

56
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.12 2005/07/04 12:27:27 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.13 2005/07/04 12:34:23 tg Exp $
.\" $OpenBSD: ksh.1,v 1.99 2005/05/25 16:52:06 jaredy Exp $ .\" $OpenBSD: ksh.1,v 1.99 2005/05/25 16:52:06 jaredy Exp $
.\" $OpenBSD: sh.1tbl,v 1.53 2004/12/10 01:56:56 jaredy Exp $ .\" $OpenBSD: sh.1tbl,v 1.53 2004/12/10 01:56:56 jaredy Exp $
.\" .\"
@ -22,7 +22,7 @@
.. ..
.Sh NAME .Sh NAME
.Nm mksh .Nm mksh
.Nd MirBSD Korn/Bourne shell .Nd MirBSD Korn shell
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Bk -words .Bk -words
@ -1454,8 +1454,6 @@ 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 current process group (read-only).
.It Ev PPID .It Ev PPID
The process ID of the shell's parent (read-only). The process ID of the shell's parent (read-only).
.It Ev PS1 .It Ev PS1
@ -2263,51 +2261,6 @@ trapped) will have their default effect in a function.
The EXIT trap, if set in a function, will be executed after the function The EXIT trap, if set in a function, will be executed after the function
returns. returns.
.El .El
.Ss Strict Bourne shell mode
When the
.Ic sh
option is enabled (see the
.Ic set
command),
.Nm
will behave like
.Xr sh 1
in the following ways:
.Bl -bullet
.It
The parameter
.Ic $_
is not set to:
.Pp
.Bl -dash -compact
.It
the expanded alias' full programme path after entering commands
that are tracked aliases
.It
the last argument on the command line after entering external
commands
.El
.It
File descriptors are left untouched when executing
.Ic exec
with no arguments.
.It
Backslash-escaped special characters are not substituted in
.Ev PS1 .
.It
Sequences of
.Sq ((...))
are not interpreted as arithmetic expressions.
.El
.Pp
This does not make
.Nm
a real bourne shell emulation, though.
Access to many enhanced features is still available, and
.Ql ^
as synonym for
.Ql |
has probably not been in use since the 1980s anyway.
.Ss Command execution .Ss Command execution
After evaluation of command-line arguments, redirections, and parameter After evaluation of command-line arguments, redirections, and parameter
assignments, the type of command is determined: a special built-in, a assignments, the type of command is determined: a special built-in, a
@ -3316,10 +3269,6 @@ commands above for more details.
The shell is a restricted shell. The shell is a restricted shell.
This option can only be used when the shell is invoked. This option can only be used when the shell is invoked.
See above for a description of what this means. See above for a description of what this means.
.It Ic sh
Enable strict Bourne shell mode (see
.Sx Strict Bourne shell mode
above).
.It Ic vi .It Ic vi
Enable Enable
.Xr vi 1 Ns -like .Xr vi 1 Ns -like
@ -5156,7 +5105,6 @@ Shell database.
.Xr dup 2 , .Xr dup 2 ,
.Xr execve 2 , .Xr execve 2 ,
.Xr getgid 2 , .Xr getgid 2 ,
.Xr getpgrp 2 ,
.Xr getuid 2 , .Xr getuid 2 ,
.Xr open 2 , .Xr open 2 ,
.Xr pipe 2 , .Xr pipe 2 ,

11
sh.h
View File

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/sh.h,v 1.13 2005/07/04 12:07:41 tg Exp $ */ /** $MirOS: src/bin/mksh/sh.h,v 1.14 2005/07/04 12:34:24 tg Exp $ */
/* $OpenBSD: sh.h,v 1.27 2005/03/28 21:33:04 deraadt Exp $ */ /* $OpenBSD: sh.h,v 1.27 2005/03/28 21:33:04 deraadt Exp $ */
/* $OpenBSD: shf.h,v 1.5 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: shf.h,v 1.5 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: table.h,v 1.6 2004/12/18 20:55:52 millert Exp $ */ /* $OpenBSD: table.h,v 1.6 2004/12/18 20:55:52 millert Exp $ */
@ -190,10 +190,10 @@ enum sh_flag {
FNOTIFY, /* -b: asynchronous job completion notification */ FNOTIFY, /* -b: asynchronous job completion notification */
FNOUNSET, /* -u: using an unset var is an error */ FNOUNSET, /* -u: using an unset var is an error */
FPHYSICAL, /* -o physical: don't do logical cds/pwds */ FPHYSICAL, /* -o physical: don't do logical cds/pwds */
FPOSIX, /* -o posix: be posixly correct */ FPOSIX, /* -o posix (disabled) */
FPRIVILEGED, /* -p: use suid_profile */ FPRIVILEGED, /* -p: use suid_profile */
FRESTRICTED, /* -r: restricted shell */ FRESTRICTED, /* -r: restricted shell */
FSH, /* -o sh: favor sh behaviour */ FSH, /* -o sh (disabled) */
FSTDIN, /* -s: (invocation) parse stdin */ FSTDIN, /* -s: (invocation) parse stdin */
FTRACKALL, /* -h: create tracked aliases for all commands */ FTRACKALL, /* -h: create tracked aliases for all commands */
FVERBOSE, /* -v: echo input */ FVERBOSE, /* -v: echo input */
@ -204,7 +204,7 @@ enum sh_flag {
FVIESCCOMPLETE, /* enable ESC as file name completion in command mode */ FVIESCCOMPLETE, /* enable ESC as file name completion in command mode */
FXTRACE, /* -x: execution trace */ FXTRACE, /* -x: execution trace */
FTALKING_I, /* (internal): initial shell was interactive */ FTALKING_I, /* (internal): initial shell was interactive */
FNFLAGS /* (place holder: how many flags are there) */ FNFLAGS /* (place holder: how many flags are there) */
}; };
#define Flag(f) (shell_flags[(int) (f)]) #define Flag(f) (shell_flags[(int) (f)])
@ -626,13 +626,10 @@ extern const struct builtin shbuiltins [], kshbuiltins [];
#define V_RANDOM 8 #define V_RANDOM 8
#define V_HISTSIZE 9 #define V_HISTSIZE 9
#define V_HISTFILE 10 #define V_HISTFILE 10
#define V_VISUAL 11
#define V_EDITOR 12
#define V_COLUMNS 13 #define V_COLUMNS 13
#define V_TMOUT 15 #define V_TMOUT 15
#define V_TMPDIR 16 #define V_TMPDIR 16
#define V_LINENO 17 #define V_LINENO 17
#define V_PGRP 18
/* values for set_prompt() */ /* values for set_prompt() */
#define PS1 0 /* command */ #define PS1 0 /* command */

10
var.c
View File

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/var.c,v 1.7 2005/07/04 12:07:41 tg Exp $ */ /** $MirOS: src/bin/mksh/var.c,v 1.8 2005/07/04 12:34:24 tg Exp $ */
/* $OpenBSD: var.c,v 1.26 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: var.c,v 1.26 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h" #include "sh.h"
@ -6,7 +6,7 @@
#include <ctype.h> #include <ctype.h>
#include <time.h> #include <time.h>
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.7 2005/07/04 12:07:41 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/var.c,v 1.8 2005/07/04 12:34:24 tg Exp $");
/* /*
* Variables * Variables
@ -98,7 +98,6 @@ initvar(void)
{ "SECONDS", V_SECONDS }, { "SECONDS", V_SECONDS },
{ "TMOUT", V_TMOUT }, { "TMOUT", V_TMOUT },
{ "LINENO", V_LINENO }, { "LINENO", V_LINENO },
{ "PGRP", V_PGRP },
{ NULL, 0 } { NULL, 0 }
}; };
int i; int i;
@ -934,11 +933,6 @@ getspec(struct tbl *vp)
setint(vp, (long) current_lineno + user_lineno); setint(vp, (long) current_lineno + user_lineno);
vp->flag |= SPECIAL; vp->flag |= SPECIAL;
break; break;
case V_PGRP:
vp->flag &= ~SPECIAL;
setint(vp, getpgrp());
vp->flag |= SPECIAL;
break;
} }
} }