* reduce amount of empty lines

* replace some spaces by tabs
* shuffle code around (shrink)
This commit is contained in:
tg
2004-12-13 18:53:25 +00:00
parent f4b8bc819c
commit 978a1d53a1
13 changed files with 309 additions and 407 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
# $MirBSD: src/bin/ksh/Build.sh,v 2.2 2004/12/13 17:33:35 tg Exp $ # $MirBSD: src/bin/ksh/Build.sh,v 2.3 2004/12/13 18:53:25 tg Exp $
#- #-
# Copyright (c) 2004 # Copyright (c) 2004
# Thorsten "mirabile" Glaser <tg@66h.42h.de> # Thorsten "mirabile" Glaser <tg@66h.42h.de>
@ -36,7 +36,7 @@
SHELL="${SHELL:-/bin/sh}"; export SHELL SHELL="${SHELL:-/bin/sh}"; export SHELL
CONFIG_SHELL="${SHELL}"; export CONFIG_SHELL CONFIG_SHELL="${SHELL}"; export CONFIG_SHELL
CC="${CC:-gcc}" CC="${CC:-gcc}"
CPPFLAGS="$CPPFLAGS -DHAVE_CONFIG_H -I. -DKSH -DMKSH" CPPFLAGS="$CPPFLAGS -DHAVE_CONFIG_H -I. -DKSH"
COPTS="-O2 -fomit-frame-pointer -fno-strict-aliasing -fno-strength-reduce" COPTS="-O2 -fomit-frame-pointer -fno-strict-aliasing -fno-strength-reduce"
[ -z "$WEIRD_OS" ] && LDFLAGS="${LDFLAGS:--static}" [ -z "$WEIRD_OS" ] && LDFLAGS="${LDFLAGS:--static}"

View File

@ -1,9 +1,9 @@
$MirBSD: src/bin/ksh/CONTRIBUTORS,v 2.1 2004/12/10 18:09:40 tg Exp $ $MirBSD: src/bin/ksh/CONTRIBUTORS,v 2.2 2004/12/13 18:53:25 tg Exp $
$OpenBSD: CONTRIBUTORS,v 1.9 1999/07/14 13:37:23 millert Exp $ $OpenBSD: CONTRIBUTORS,v 1.9 1999/07/14 13:37:23 millert Exp $
This is a partial history of this shell gleened from old change logs and This is a partial history of this shell gleened from old change logs and
readmes (most of which are still in the misc directory) and the source readmes and source code.
code. Hopefully it is correct and no contributors have been left out Hopefully it is correct and no contributors have been left out
(file a bug report if you spot a problem :-)). (file a bug report if you spot a problem :-)).
Release history: Release history:
@ -26,7 +26,7 @@ Release history:
* Michael Rendell (michael@cs.mun.ca) takes over as maintainer * Michael Rendell (michael@cs.mun.ca) takes over as maintainer
July, 1994 July, 1994
Released versions: 5.0 .. 5.2 Released versions: 5.0 .. 5.2
* Thorsten Glaser (tg@66h.42h.de) releases mirbsdksh and is the guy * Thorsten Glaser (tg@66h.42h.de) releases mksh and is the guy
to blame for all mirbsdksh-specific or MirOS-specific bugs. to blame for all mirbsdksh-specific or MirOS-specific bugs.
Released versions: 5.2.14 MirOS 1.1-1.x Released versions: 5.2.14 MirOS 1.1-1.x

View File

@ -1,11 +1,10 @@
# $MirBSD: src/bin/ksh/Makefile,v 2.2 2004/12/13 16:50:50 tg Exp $ # $MirBSD: src/bin/ksh/Makefile,v 2.3 2004/12/13 18:53:25 tg Exp $
# $OpenBSD: Makefile,v 1.18 2004/02/16 19:07:19 deraadt Exp $ # $OpenBSD: Makefile,v 1.18 2004/02/16 19:07:19 deraadt Exp $
PROG= ksh PROG= ksh
SRCS= alloc.c c_ksh.c c_sh.c c_test.c c_ulimit.c chvt.c edit.c \ SRCS= alloc.c c_ksh.c c_sh.c c_test.c c_ulimit.c edit.c emacs.c eval.c \
emacs.c eval.c exec.c expr.c history.c io.c jobs.c lex.c \ exec.c expr.c history.c io.c jobs.c lex.c main.c misc.c missing.c \
main.c misc.c missing.c path.c rnd.c shf.c syn.c table.c \ path.c shf.c syn.c table.c trap.c tree.c tty.c var.c vi.c
trap.c tree.c tty.c var.c version.c vi.c
MAN= ksh.1tbl sh.1tbl MAN= ksh.1tbl sh.1tbl
CPPFLAGS+= -DHAVE_CONFIG_H -I. -DKSH -DMIRBSD_NATIVE CPPFLAGS+= -DHAVE_CONFIG_H -I. -DKSH -DMIRBSD_NATIVE

2
NOTES
View File

@ -1,4 +1,4 @@
$MirBSD: src/bin/ksh/NOTES,v 2.2 2004/12/13 17:33:35 tg Exp $ $MirBSD: src/bin/ksh/NOTES,v 2.3 2004/12/13 18:53:25 tg Exp $
$OpenBSD: NOTES,v 1.9 2003/10/26 15:07:25 jmc Exp $ $OpenBSD: NOTES,v 1.9 2003/10/26 15:07:25 jmc Exp $
General features of at&t ksh88 that are not (yet) in pdksh: General features of at&t ksh88 that are not (yet) in pdksh:

24
README
View File

@ -1,13 +1,13 @@
$MirBSD: src/bin/ksh/README,v 2.2 2004/12/13 17:33:35 tg Exp $ $MirBSD: src/bin/ksh/README,v 2.3 2004/12/13 18:53:25 tg Exp $
This is the README for mirbsdksh, developed as part of the MirBSD This is the README for mirbsdksh, developed as part of the MirBSD
operating system at The MirOS Project, and produced portably. operating system at The MirOS Project, and produced portably.
Legal information is provided about a screenpage farther down. Legal information is provided about a screenpage farther down.
To build on MirOS only, issue 'make obj && make depend && make'. To build mksh on MirOS, issue 'make obj && make depend && make'.
To build on other systems, consult http://wiki.mirbsd.de/MirbsdKsh To build mksh on other operating systems, read Builsd.sh first
or read Build.sh first. or consult http://wiki.mirbsd.de/MirbsdKsh for further infos.
Set the CC, CFLAGS, CPPFLAGS and LDFLAGS environment variables Set the CC, CFLAGS, CPPFLAGS and LDFLAGS environment variables
to your likes. Don't complain if anything doesn't work. to your likes. Don't complain if anything doesn't work.
@ -16,8 +16,8 @@ to your likes. Don't complain if anything doesn't work.
LEGAL INFORMATION LEGAL INFORMATION
This package as a whole is placed under the MirOS licence template This package as a whole is placed under the MirOS licence template
as contained in the "version.c" source code file in this distribu- as contained in the "Build.sh" source file in this distribution,
tion, by having the project leader asserting a collective copyright. by having the project leader asserting a collective copyright.
The files alloc.c (Marc Espie), ksh.1tbl and sh.1tbl (University of The files alloc.c (Marc Espie), ksh.1tbl and sh.1tbl (University of
California, Berkeley) are provided under a 2-clause or 3-clause BSD California, Berkeley) are provided under a 2-clause or 3-clause BSD
@ -48,11 +48,6 @@ machines. For example, in the CS dept. of MUN, pdksh is installed on a
variety of machines including Suns, HPs, DecStations, pcs running Linux, variety of machines including Suns, HPs, DecStations, pcs running Linux,
etc., and is the login shell of ~5200 users. etc., and is the login shell of ~5200 users.
Note that pdksh is provided AS IS, with NO WARRANTY, either expressed or
implied. Also note that although the bulk of the code in pdksh is in the
public domain, some files are copyrighted (but freely distributable) and
subject to certain conditions.
If you would like to be notified via email of new releases as they become If you would like to be notified via email of new releases as they become
available, send mail to pdksh-request@cs.mun.ca with subject available, send mail to pdksh-request@cs.mun.ca with subject
"send release notifications" (or "don't send release notifications" to stop "send release notifications" (or "don't send release notifications" to stop
@ -60,12 +55,7 @@ them).
Newer versions of pdksh may be available from Newer versions of pdksh may be available from
ftp://ftp.cs.mun.ca:/pub/pdksh/ ftp://ftp.cs.mun.ca:/pub/pdksh/
you may want to check for one if you run into any problems, as the problem may [...]
already be fixed (you can get new release notifications automatically - see
above). The file pdksh-unstable-XXX.tar.gz has the very latest version which
may not compile (it is generated automatically when changes are detected
in the main source repository) - it is for those who want to follow
changes as they are made.
You can send bug reports, fixes, and enhancements to pdksh@cs.mun.ca (please You can send bug reports, fixes, and enhancements to pdksh@cs.mun.ca (please
don't assume I will see bug reports that are posted to some newsgroup or don't assume I will see bug reports that are posted to some newsgroup or

25
aclocal.m4 vendored
View File

@ -1,4 +1,4 @@
dnl $MirBSD: src/bin/ksh/aclocal.m4,v 2.1 2004/12/10 18:09:40 tg Exp $ dnl $MirBSD: src/bin/ksh/aclocal.m4,v 2.2 2004/12/13 18:53:25 tg Exp $
dnl- dnl-
dnl Copyright (c) 2004 dnl Copyright (c) 2004
dnl Thorsten "mirabile" Glaser <tg@66h.42h.de> dnl Thorsten "mirabile" Glaser <tg@66h.42h.de>
@ -20,7 +20,7 @@ dnl of this work, even if advised of the possibility of such damage.
dnl- dnl-
dnl Based upon code by: dnl Based upon code by:
dnl Copyright (C) 1996, Memorial University of Newfoundland. dnl Copyright (C) 1996, Memorial University of Newfoundland.
dnl ------------------------------------------------------------ dnl-
dnl dnl
dnl dnl
dnl Like AC_CHECK_TYPE(), only dnl Like AC_CHECK_TYPE(), only
@ -48,7 +48,6 @@ $3
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Check for memmove and if not found, check for bcopy. AC_CHECK_FUNCS() dnl Check for memmove and if not found, check for bcopy. AC_CHECK_FUNCS()
dnl not used 'cause it confuses some compilers that have memmove/bcopy builtin; dnl not used 'cause it confuses some compilers that have memmove/bcopy builtin;
dnl Also want to check if the function deals with overlapping src/dst properly. dnl Also want to check if the function deals with overlapping src/dst properly.
@ -114,7 +113,6 @@ AC_DEFUN(KSH_MEMMOVE,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Check for sigsetjmp()/siglongjmp() and _setjmp()/_longjmp() pairs. dnl Check for sigsetjmp()/siglongjmp() and _setjmp()/_longjmp() pairs.
dnl Can't use simple library check as QNX 422 has _setjmp() but not _longjmp() dnl Can't use simple library check as QNX 422 has _setjmp() but not _longjmp()
dnl (go figure). dnl (go figure).
@ -135,7 +133,6 @@ AC_DEFUN(KSH_SETJMP,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Check for memset function. AC_CHECK_FUNCS() not used 'cause it confuses dnl Check for memset function. AC_CHECK_FUNCS() not used 'cause it confuses
dnl some compilers that have memset builtin. dnl some compilers that have memset builtin.
AC_DEFUN(KSH_MEMSET, AC_DEFUN(KSH_MEMSET,
@ -158,7 +155,6 @@ AC_DEFUN(KSH_MEMSET,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Check for rlim_t in a few places, and if not found, figure out the dnl Check for rlim_t in a few places, and if not found, figure out the
dnl size rlim_t should be by looking at struct rlimit.rlim_cur. dnl size rlim_t should be by looking at struct rlimit.rlim_cur.
AC_DEFUN(KSH_RLIM_CHECK, AC_DEFUN(KSH_RLIM_CHECK,
@ -193,7 +189,6 @@ AC_DEFUN(KSH_RLIM_CHECK,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
AC_DEFUN(KSH_DEV_FD, AC_DEFUN(KSH_DEV_FD,
[AC_CACHE_CHECK(if you have /dev/fd/n, ksh_cv_dev_fd, [AC_CACHE_CHECK(if you have /dev/fd/n, ksh_cv_dev_fd,
[AC_TRY_RUN([ [AC_TRY_RUN([
@ -229,7 +224,6 @@ AC_DEFUN(KSH_DEV_FD,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Check for sys_siglist[] declaration and existence. dnl Check for sys_siglist[] declaration and existence.
AC_DEFUN(KSH_SYS_SIGLIST, AC_DEFUN(KSH_SYS_SIGLIST,
[AC_DECL_SYS_SIGLIST [AC_DECL_SYS_SIGLIST
@ -250,7 +244,6 @@ AC_DEFUN(KSH_SYS_SIGLIST,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Check for sys_errlist[] declaration and existence. dnl Check for sys_errlist[] declaration and existence.
AC_DEFUN(KSH_SYS_ERRLIST, AC_DEFUN(KSH_SYS_ERRLIST,
[AC_CACHE_CHECK(for sys_errlist declaration in errno.h, ksh_cv_decl_sys_errlist, [AC_CACHE_CHECK(for sys_errlist declaration in errno.h, ksh_cv_decl_sys_errlist,
@ -276,7 +269,6 @@ AC_DEFUN(KSH_SYS_ERRLIST,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Check if time() declared in time.h dnl Check if time() declared in time.h
AC_DEFUN(KSH_TIME_DECLARED, AC_DEFUN(KSH_TIME_DECLARED,
[AC_CACHE_CHECK(time() declaration in time.h, ksh_cv_time_delcared, [AC_CACHE_CHECK(time() declaration in time.h, ksh_cv_time_delcared,
@ -289,7 +281,6 @@ AC_DEFUN(KSH_TIME_DECLARED,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Check for working times (ie, it exists and doesn't always return 0). dnl Check for working times (ie, it exists and doesn't always return 0).
dnl Defines TIMES_BROKEN if it doesn't exist or if it always returns 0 dnl Defines TIMES_BROKEN if it doesn't exist or if it always returns 0
dnl (also checks for existance of getrusage if times doesn't work). dnl (also checks for existance of getrusage if times doesn't work).
@ -329,7 +320,6 @@ AC_DEFUN(KSH_TIMES_CHECK,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
AC_DEFUN(KSH_C_VOID, AC_DEFUN(KSH_C_VOID,
[AC_CACHE_CHECK(if compiler understands void, ksh_cv_c_void, [AC_CACHE_CHECK(if compiler understands void, ksh_cv_c_void,
[AC_TRY_COMPILE( [AC_TRY_COMPILE(
@ -346,7 +336,6 @@ AC_DEFUN(KSH_C_VOID,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Early MIPS compilers (used in Ultrix 4.2) don't like dnl Early MIPS compilers (used in Ultrix 4.2) don't like
dnl "int x; int *volatile a = &x; *a = 0;" dnl "int x; int *volatile a = &x; *a = 0;"
AC_DEFUN(KSH_C_VOLATILE, AC_DEFUN(KSH_C_VOLATILE,
@ -363,7 +352,6 @@ AC_DEFUN(KSH_C_VOLATILE,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Check if C compiler understands gcc's __attribute((...)). dnl Check if C compiler understands gcc's __attribute((...)).
dnl checks for noreturn, const, and format(type,fmt,param), also checks dnl checks for noreturn, const, and format(type,fmt,param), also checks
dnl that the compiler doesn't die when it sees an unknown attribute (this dnl that the compiler doesn't die when it sees an unknown attribute (this
@ -388,7 +376,6 @@ void test_uk() { return; }
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Check if dup2() does not clear the close on exec flag dnl Check if dup2() does not clear the close on exec flag
AC_DEFUN(KSH_DUP2_CLEXEC_CHECK, AC_DEFUN(KSH_DUP2_CLEXEC_CHECK,
[AC_CACHE_CHECK([if dup2() works (ie, resets the close-on-exec flag)], ksh_cv_dup2_clexec_ok, [AC_CACHE_CHECK([if dup2() works (ie, resets the close-on-exec flag)], ksh_cv_dup2_clexec_ok,
@ -428,7 +415,6 @@ main()
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Check type of signal routines (posix, 4.2bsd, 4.1bsd or v7) dnl Check type of signal routines (posix, 4.2bsd, 4.1bsd or v7)
AC_DEFUN(KSH_SIGNAL_CHECK, AC_DEFUN(KSH_SIGNAL_CHECK,
[AC_CACHE_CHECK(flavour of signal routines, ksh_cv_signal_check, [AC_CACHE_CHECK(flavour of signal routines, ksh_cv_signal_check,
@ -565,7 +551,6 @@ AC_DEFUN(KSH_SIGNAL_CHECK,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl What kind of process groups: POSIX, BSD, SYSV or none dnl What kind of process groups: POSIX, BSD, SYSV or none
dnl BSD uses setpgrp(pid, pgrp), getpgrp(pid) dnl BSD uses setpgrp(pid, pgrp), getpgrp(pid)
dnl POSIX uses setpid(pid, pgrp), getpgrp(void) dnl POSIX uses setpid(pid, pgrp), getpgrp(void)
@ -668,7 +653,6 @@ AC_DEFUN(KSH_PGRP_CHECK,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Check if the pgrp of setpgrp() can't be the pid of a zombie process. dnl Check if the pgrp of setpgrp() can't be the pid of a zombie process.
dnl On some systems, the kernel doesn't count zombie processes when checking dnl On some systems, the kernel doesn't count zombie processes when checking
dnl if a process group is valid, which can cause problems in creating the dnl if a process group is valid, which can cause problems in creating the
@ -730,7 +714,6 @@ AC_DEFUN(KSH_PGRP_SYNC,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Check to see if opendir will open non-directories (not a nice thing) dnl Check to see if opendir will open non-directories (not a nice thing)
AC_DEFUN(KSH_OPENDIR_CHECK, AC_DEFUN(KSH_OPENDIR_CHECK,
[AC_CACHE_CHECK(if opendir() fails to open non-directories, ksh_cv_opendir_ok, [AC_CACHE_CHECK(if opendir() fails to open non-directories, ksh_cv_opendir_ok,
@ -779,7 +762,6 @@ AC_DEFUN(KSH_OPENDIR_CHECK,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Like AC_HAVE_HEADER(unistd.h) but only defines HAVE_UNISTD_H if dnl Like AC_HAVE_HEADER(unistd.h) but only defines HAVE_UNISTD_H if
dnl the header file is sane (MIPS RISC/os 5.0 (and later?) has a unistd.h dnl the header file is sane (MIPS RISC/os 5.0 (and later?) has a unistd.h
dnl in the bsd43 environ that is incorrect - it defines POSIX_VERSION even dnl in the bsd43 environ that is incorrect - it defines POSIX_VERSION even
@ -799,7 +781,6 @@ AC_DEFUN(KSH_UNISTD_H,
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Several OSes need to be detected and symbols defined so the shell can dnl Several OSes need to be detected and symbols defined so the shell can
dnl deal with them. This is a bit kludgy, but... dnl deal with them. This is a bit kludgy, but...
dnl Currently tests for: dnl Currently tests for:
@ -1024,7 +1005,6 @@ README file for work arounds.]))dnl
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Some systems (eg, SunOS 4.0.3) have <termios.h> and <termio.h> but don't dnl Some systems (eg, SunOS 4.0.3) have <termios.h> and <termio.h> but don't
dnl have the related functions/defines (eg, tcsetattr(), TCSADRAIN, etc.) dnl have the related functions/defines (eg, tcsetattr(), TCSADRAIN, etc.)
dnl or the functions don't work well with tty process groups. Sun's bad dnl or the functions don't work well with tty process groups. Sun's bad
@ -1081,7 +1061,6 @@ dnl fi
])dnl ])dnl
dnl dnl
dnl dnl
dnl
dnl Check if lstat() is available - special test needed 'cause lstat only dnl Check if lstat() is available - special test needed 'cause lstat only
dnl becomes visable if <sys/stat.h> is included (linux 1.3.x)... dnl becomes visable if <sys/stat.h> is included (linux 1.3.x)...
AC_DEFUN(KSH_FUNC_LSTAT, AC_DEFUN(KSH_FUNC_LSTAT,

75
chvt.c
View File

@ -1,75 +0,0 @@
/** $MirBSD: src/bin/ksh/chvt.c,v 2.1 2004/12/10 18:09:41 tg Exp $ */
/*-
* Copyright (c) 2004
* Thorsten "mirabile" Glaser <tg@66h.42h.de>
*
* Licensee is hereby permitted to deal in this work without restric-
* tion, including unlimited rights to use, publicly perform, modify,
* merge, distribute, sell, give away or sublicence, provided all co-
* pyright notices above, these terms and the disclaimer are retained
* in all redistributions or reproduced in accompanying documentation
* or other materials provided with binary redistributions.
*
* Licensor hereby provides this work "AS IS" and WITHOUT WARRANTY of
* any kind, expressed or implied, to the maximum extent permitted by
* applicable law, but with the warranty of being written without ma-
* licious intent or gross negligence; in no event shall licensor, an
* author or contributor be held liable for any damage, direct, indi-
* rect or other, however caused, arising in any way out of the usage
* of this work, even if advised of the possibility of such damage.
*/
#include "sh.h"
#include <sys/ioctl.h>
#include "ksh_stat.h"
__RCSID("$MirBSD: src/bin/ksh/chvt.c,v 2.1 2004/12/10 18:09:41 tg Exp $");
char *
chvt(char *f)
{
#ifdef HAVE_SETSID
#ifdef TIOCSCTTY
int fd;
if (chown(f, 0, 0))
return "chown";
if (chmod(f, 0600))
return "chmod";
#if defined(HAVE_REVOKE) && !defined(linux)
if (revoke(f))
return "revoke";
#endif
if ((fd = open(f, O_RDWR)) == -1) {
sleep(1);
if ((fd = open(f, O_RDWR)) == -1)
return "open";
}
switch (fork()) {
case -1:
return "fork";
case 0:
break;
default:
_exit(0);
}
if (setsid() == -1)
return "setsid";
if (ioctl(fd, TIOCSCTTY, NULL) == -1)
return "ioctl";
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
if (fd > 2)
close(fd);
return NULL;
#else
return "ioctl - TIOCSCTTY not implemented";
#endif
#else
return "setsid not implemented";
#endif
}

42
main.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: src/bin/ksh/main.c,v 2.2 2004/12/13 16:48:54 tg Exp $ */ /** $MirBSD: src/bin/ksh/main.c,v 2.3 2004/12/13 18:53:25 tg Exp $ */
/* $OpenBSD: main.c,v 1.28 2004/08/23 14:56:32 millert Exp $ */ /* $OpenBSD: main.c,v 1.28 2004/08/23 14:56:32 millert Exp $ */
/* /*
@ -11,14 +11,42 @@
#include "ksh_stat.h" #include "ksh_stat.h"
#include "ksh_time.h" #include "ksh_time.h"
__RCSID("$MirBSD: src/bin/ksh/main.c,v 2.2 2004/12/13 16:48:54 tg Exp $"); /*
* shell version
*/
extern char **environ; __RCSID("$MirBSD: src/bin/ksh/main.c,v 2.3 2004/12/13 18:53:25 tg Exp $");
static const char version_param[] =
#ifdef KSH
"KSH_VERSION"
#else /* KSH */
"SH_VERSION"
#endif /* KSH */
;
const char ksh_version[] =
"@(#)PD KSH v5.2.14 MirOS R19 in "
#ifdef MIRBSD_NATIVE
"native "
#endif
#ifdef KSH
"KSH"
#else
"POSIX"
#endif
" mode"
#ifndef MIRBSD_NATIVE
" as mksh"
#endif
;
/* /*
* global data * global data
*/ */
extern char **environ;
static void reclaim(void); static void reclaim(void);
static void remove_temps(struct temp *tp); static void remove_temps(struct temp *tp);
static int is_restricted(char *name); static int is_restricted(char *name);
@ -31,14 +59,6 @@ static const char initifs[] = "IFS= \t\n";
static const char initsubs[] = "${PS2=> } ${PS3=#? } ${PS4=+ }"; static const char initsubs[] = "${PS2=> } ${PS3=#? } ${PS4=+ }";
static const char version_param[] =
#ifdef KSH
"KSH_VERSION"
#else /* KSH */
"SH_VERSION"
#endif /* KSH */
;
static const char *const initcoms [] = { static const char *const initcoms [] = {
"typeset", "-x", "SHELL", "PATH", "HOME", NULL, "typeset", "-x", "SHELL", "PATH", "HOME", NULL,
"typeset", "-r", version_param, NULL, "typeset", "-r", version_param, NULL,

59
misc.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: src/bin/ksh/misc.c,v 2.1 2004/12/10 18:09:41 tg Exp $ */ /** $MirBSD: src/bin/ksh/misc.c,v 2.2 2004/12/13 18:53:25 tg Exp $ */
/* $OpenBSD: misc.c,v 1.20 2003/10/22 07:40:38 jmc Exp $ */ /* $OpenBSD: misc.c,v 1.20 2003/10/22 07:40:38 jmc Exp $ */
/* /*
@ -10,8 +10,10 @@
#ifdef HAVE_LIMITS_H #ifdef HAVE_LIMITS_H
# include <limits.h> # include <limits.h>
#endif #endif
#include <sys/ioctl.h>
#include "ksh_stat.h"
__RCSID("$MirBSD: src/bin/ksh/misc.c,v 2.1 2004/12/10 18:09:41 tg Exp $"); __RCSID("$MirBSD: src/bin/ksh/misc.c,v 2.2 2004/12/13 18:53:25 tg Exp $");
#ifndef UCHAR_MAX #ifndef UCHAR_MAX
# define UCHAR_MAX 0xFF # define UCHAR_MAX 0xFF
@ -1334,10 +1336,60 @@ ksh_get_wd(char *buf, int bsize)
} }
#ifdef KSH #ifdef KSH
#include "ksh_stat.h"
#if !defined(HAVE_SETSID)
#define NO_CHVT "setsid not implemented"
#elif !defined(TIOCSCTTY)
#define NO_CHVT "no TIOCSCTTY ioctl"
#else
static char *
chvt(char *f)
{
int fd;
if (chown(f, 0, 0))
return "chown";
if (chmod(f, 0600))
return "chmod";
#if defined(HAVE_REVOKE) && !defined(linux)
if (revoke(f))
return "revoke";
#endif
if ((fd = open(f, O_RDWR)) == -1) {
sleep(1);
if ((fd = open(f, O_RDWR)) == -1)
return "open";
}
switch (fork()) {
case -1:
return "fork";
case 0:
break;
default:
_exit(0);
}
if (setsid() == -1)
return "setsid";
if (ioctl(fd, TIOCSCTTY, NULL) == -1)
return "ioctl";
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
if (fd > 2)
close(fd);
return NULL;
}
#endif
static int static int
parse_T(char *fn) parse_T(char *fn)
{ {
#ifdef NO_CHVT
warningf(0, "chvt: %s", NO_CHVT);
return -1;
#else
char *rv, dv[20]; char *rv, dv[20];
struct stat sb; struct stat sb;
@ -1361,5 +1413,6 @@ parse_T(char *fn)
return -1; return -1;
} }
return 0; return 0;
#endif
} }
#endif #endif

View File

@ -1,4 +1,4 @@
/** $MirBSD: src/bin/ksh/missing.c,v 2.1 2004/12/10 18:09:41 tg Exp $ */ /** $MirBSD: src/bin/ksh/missing.c,v 2.2 2004/12/13 18:53:25 tg Exp $ */
/* $OpenBSD: missing.c,v 1.5 2003/05/16 18:49:46 jsyn Exp $ */ /* $OpenBSD: missing.c,v 1.5 2003/05/16 18:49:46 jsyn Exp $ */
/* /*
@ -9,6 +9,8 @@
#include "ksh_stat.h" #include "ksh_stat.h"
#include "ksh_dir.h" #include "ksh_dir.h"
__RCSID("$MirBSD: src/bin/ksh/missing.c,v 2.2 2004/12/13 18:53:25 tg Exp $");
#ifndef HAVE_MEMSET #ifndef HAVE_MEMSET
void * void *
memset(d, c, n) memset(d, c, n)
@ -289,3 +291,67 @@ dup2(oldd, newd)
return fcntl(oldd, F_DUPFD, newd); return fcntl(oldd, F_DUPFD, newd);
} }
#endif /* !HAVE_DUP2 */ #endif /* !HAVE_DUP2 */
/*
* Random functions
*/
#ifndef HAVE_SRANDOM
#undef HAVE_RANDOM
#endif
#ifdef KSH
int rnd_state;
void
rnd_seed(long newval)
{
rnd_put(newval);
rnd_state = 0;
}
long
rnd_get(void)
{
#ifdef HAVE_ARC4RANDOM
if (!rnd_state)
return arc4random() & 0x7FFF;
#endif
#ifdef HAVE_RANDOM
return random() & 0x7FFF;
#else
return rand();
#endif
}
void
rnd_put(long newval)
{
long sv;
rnd_state = 1 | rnd_get();
sv = (rnd_get() << (newval & 7)) ^ newval;
#if defined(HAVE_ARC4RANDOM_PUSH)
arc4random_push(sv);
#elif defined(HAVE_ARC4RANDOM_ADDRANDOM)
arc4random_addrandom((char *)&sv, sizeof(sv));
#endif
#ifdef HAVE_ARC4RANDOM
sv ^= arc4random();
#endif
#ifdef HAVE_RANDOM
srandom(sv);
#else
srand(sv);
#endif
while (rnd_state) {
rnd_get();
rnd_state >>= 1;
}
rnd_state = 1;
}
#endif /* def KSH */

12
proto.h
View File

@ -1,4 +1,4 @@
/** $MirBSD: src/bin/ksh/proto.h,v 2.2 2004/12/13 16:48:54 tg Exp $ */ /** $MirBSD: src/bin/ksh/proto.h,v 2.3 2004/12/13 18:53:25 tg Exp $ */
/* $OpenBSD: proto.h,v 1.11 2003/05/16 19:58:57 jsyn Exp $ */ /* $OpenBSD: proto.h,v 1.11 2003/05/16 19:58:57 jsyn Exp $ */
/* $From: proto.h,v 1.3 1994/05/19 18:32:40 michael Exp michael $ */ /* $From: proto.h,v 1.3 1994/05/19 18:32:40 michael Exp michael $ */
@ -54,8 +54,6 @@ int c_exec(char **wp);
int c_builtin(char **wp); int c_builtin(char **wp);
/* c_test.c */ /* c_test.c */
int c_test(char **wp); int c_test(char **wp);
/* chvt.c */
char * chvt(char *);
/* edit.c: most prototypes in edit.h */ /* edit.c: most prototypes in edit.h */
void x_init(void); void x_init(void);
int x_read(char *buf, size_t len); int x_read(char *buf, size_t len);
@ -205,16 +203,16 @@ char *str_zcpy(char *dst, const char *src, int dsize);
int blocking_read(int fd, char *buf, int nbytes); int blocking_read(int fd, char *buf, int nbytes);
int reset_nonblock(int fd); int reset_nonblock(int fd);
char *ksh_get_wd(char *buf, int bsize); char *ksh_get_wd(char *buf, int bsize);
/* missing.c */
long rnd_get(void);
void rnd_put(long);
void rnd_seed(long);
/* path.c */ /* path.c */
int make_path(const char *cwd, const char *file, int make_path(const char *cwd, const char *file,
char **pathlist, XString *xsp, int *phys_pathp); char **pathlist, XString *xsp, int *phys_pathp);
void simplify_path(char *path); void simplify_path(char *path);
char *get_phys_path(const char *path); char *get_phys_path(const char *path);
void set_current_wd(char *path); void set_current_wd(char *path);
/* rnd.c */
long rnd_get(void);
void rnd_put(long);
void rnd_seed(long);
/* syn.c */ /* syn.c */
void initkeywords(void); void initkeywords(void);
struct op * compile(Source *s); struct op * compile(Source *s);

86
rnd.c
View File

@ -1,86 +0,0 @@
/** $MirBSD: src/bin/ksh/rnd.c,v 2.1 2004/12/10 18:09:42 tg Exp $ */
/*-
* Copyright (c) 2004
* Thorsten "mirabile" Glaser <tg@66h.42h.de>
*
* Licensee is hereby permitted to deal in this work without restric-
* tion, including unlimited rights to use, publicly perform, modify,
* merge, distribute, sell, give away or sublicence, provided all co-
* pyright notices above, these terms and the disclaimer are retained
* in all redistributions or reproduced in accompanying documentation
* or other materials provided with binary redistributions.
*
* Licensor hereby provides this work "AS IS" and WITHOUT WARRANTY of
* any kind, expressed or implied, to the maximum extent permitted by
* applicable law, but with the warranty of being written without ma-
* licious intent or gross negligence; in no event shall licensor, an
* author or contributor be held liable for any damage, direct, indi-
* rect or other, however caused, arising in any way out of the usage
* of this work, even if advised of the possibility of such damage.
*/
#include "sh.h"
#include "proto.h"
__RCSID("$MirBSD: src/bin/ksh/rnd.c,v 2.1 2004/12/10 18:09:42 tg Exp $");
#ifndef HAVE_SRANDOM
#undef HAVE_RANDOM
#endif
#ifdef KSH
int rnd_state;
void
rnd_seed(long newval)
{
rnd_put(newval);
rnd_state = 0;
}
long
rnd_get(void)
{
#ifdef HAVE_ARC4RANDOM
if (!rnd_state)
return arc4random() & 0x7FFF;
#endif
#ifdef HAVE_RANDOM
return random() & 0x7FFF;
#else
return rand();
#endif
}
void
rnd_put(long newval)
{
long sv;
rnd_state = 1 | rnd_get();
sv = (rnd_get() << (newval & 7)) ^ newval;
#if defined(HAVE_ARC4RANDOM_PUSH)
arc4random_push(sv);
#elif defined(HAVE_ARC4RANDOM_ADDRANDOM)
arc4random_addrandom((char *)&sv, sizeof(sv));
#endif
#ifdef HAVE_ARC4RANDOM
sv ^= arc4random();
#endif
#ifdef HAVE_RANDOM
srandom(sv);
#else
srand(sv);
#endif
while (rnd_state) {
rnd_get();
rnd_state >>= 1;
}
rnd_state = 1;
}
#endif /* def KSH */

View File

@ -1,42 +0,0 @@
/** $MirBSD: src/bin/ksh/version.c,v 2.1 2004/12/10 18:09:42 tg Exp $ */
/* $OpenBSD: version.c,v 1.12 1999/07/14 13:37:24 millert Exp $ */
/*-
* Copyright (c) 2004
* Thorsten "mirabile" Glaser <tg@66h.42h.de>
*
* Licensee is hereby permitted to deal in this work without restric-
* tion, including unlimited rights to use, publicly perform, modify,
* merge, distribute, sell, give away or sublicence, provided all co-
* pyright notices above, these terms and the disclaimer are retained
* in all redistributions or reproduced in accompanying documentation
* or other materials provided with binary redistributions.
*
* Licensor hereby provides this work "AS IS" and WITHOUT WARRANTY of
* any kind, expressed or implied, to the maximum extent permitted by
* applicable law, but with the warranty of being written without ma-
* licious intent or gross negligence; in no event shall licensor, an
* author or contributor be held liable for any damage, direct, indi-
* rect or other, however caused, arising in any way out of the usage
* of this work, even if advised of the possibility of such damage.
*-
* value of $KSH_VERSION (or $SH_VERSION)
*/
#include "sh.h"
const char ksh_version[] =
"@(#)PD KSH v5.2.14 MirOS R19 in "
#ifdef MIRBSD_NATIVE
"native "
#endif
#ifdef KSH
"KSH"
#else
"POSIX"
#endif
" mode"
#ifdef MKSH
" as mksh"
#endif
;