diff options
| author | Casper H.S. Dik <Casper.Dik@Sun.COM> | 2009-02-13 18:28:51 +0100 |
|---|---|---|
| committer | Casper H.S. Dik <Casper.Dik@Sun.COM> | 2009-02-13 18:28:51 +0100 |
| commit | 81af778e872fc2ec5f0ac36e7b25bdb24ebd2d6a (patch) | |
| tree | 676e6d985d7467919454b04cff593561bc316419 /usr/src/cmd/ksh | |
| parent | 7c2ac4814b2e73c72798fe6d7b84ac8540fdd35b (diff) | |
| download | illumos-joyent-81af778e872fc2ec5f0ac36e7b25bdb24ebd2d6a.tar.gz | |
6793120 pkill fails on native and sn1 branded zones
6800929 snv_106 ksh93 update breaks Install(1M)
Contributed by Roland Mainz <roland.mainz@nrubsig.org>
Diffstat (limited to 'usr/src/cmd/ksh')
| -rw-r--r-- | usr/src/cmd/ksh/builtins/Makefile | 43 | ||||
| -rw-r--r-- | usr/src/cmd/ksh/builtins/alias.c | 101 | ||||
| -rw-r--r-- | usr/src/cmd/ksh/builtins/alias.sh | 51 |
3 files changed, 136 insertions, 59 deletions
diff --git a/usr/src/cmd/ksh/builtins/Makefile b/usr/src/cmd/ksh/builtins/Makefile index 57584c04cc..d697d90fd1 100644 --- a/usr/src/cmd/ksh/builtins/Makefile +++ b/usr/src/cmd/ksh/builtins/Makefile @@ -20,7 +20,7 @@ # # -# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # @@ -63,14 +63,41 @@ all: $(PROG) $(ROOTBIN)/%: $(ROOTBIN)/alias $(INS.link) -# In the future we should replace the "cat" with a call to -# "shcomp" to compile the script (for better performance). -$(PROG): alias.sh - cat "alias.sh" >"$@" +include ../../Makefile.cmd + +.KEEP_STATE: + +# Set common AST build flags (e.g., needed to support the math stuff). +include ../../../Makefile.ast + +OBJECTS= \ + alias.o + +SRCS= $(OBJECTS:%.o=%.c) + +GROUP= bin +LDLIBS += -lshell -last + +CPPFLAGS = \ + $(DTEXTDOM) $(DTS_ERRNO) \ + -I$(ROOT)/usr/include/ast + +CFLAGS += \ + $(ASTCFLAGS) +CFLAGS64 += \ + $(ASTCFLAGS64) + +ROOTCMDDIR=$(ROOT)/usr/bin + +# .WAIT is needed to get the hardlinks properly done +install: all $(ROOTCMD) .WAIT $(ROOTALIASPROG) -install: all $(ROOTALIASPROG) +$(PROG): $(OBJECTS) + $(RM) alias + $(LINK.c) $(OBJECTS) -o $@ $(LDLIBS) + $(POST_PROCESS) clean clobber: - rm -f $(PROG) + rm -f $(PROG) $(OBJECTS) -lint: +lint _msg: diff --git a/usr/src/cmd/ksh/builtins/alias.c b/usr/src/cmd/ksh/builtins/alias.c new file mode 100644 index 0000000000..0e2a5623fe --- /dev/null +++ b/usr/src/cmd/ksh/builtins/alias.c @@ -0,0 +1,101 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * alias.c is a C version of the alias.sh wrapper (which links ksh + * builtins to commands in /usr/bin/, e.g. calling this wrapper as + * /usr/bin/alias will call the ksh "alias" builtin, running it as + * /usr/bin/cut will call the ksh "cut" builtin etc. + */ + +#include <shell.h> +#include <nval.h> +#include <stdio.h> + +/* Builtin script, original derived from alias.sh */ +static const char *script = "\n" +/* Get name of builtin */ +"builtin basename\n" +"typeset cmd=\"$(basename \"$0\")\"\n" +/* + * If the requested command is not an alias load it explicitly + * to make sure it is not bound to a path (those built-ins which + * are mapped via shell aliases point to commands which are + * "special shell built-ins" which cannot be bound to a specific + * PATH element) - otherwise we may execute the wrong command + * if an executable with the same name sits in a PATH element + * before /usr/bin (e.g. /usr/xpg4/bin/ls would be executed + * before /usr/bin/ls if the path was something like + * PATH=/usr/xpg4/bin:/usr/bin). + */ +"if [[ \"${cmd}\" != ~(Elr)(alias|unalias|command) ]] && " + "! alias \"${cmd}\" >/dev/null 2>&1 ; then\n" +" builtin \"${cmd}\"\n" +"fi\n" +/* command is a keyword and needs to be handled separately */ +"if [[ \"${cmd}\" == \"command\" ]] ; then\n" +" command \"$@\"\n" +"else\n" +" \"${cmd}\" \"$@\"\n" +"fi\n" +"exitval=$?"; + +int +main(int argc, char *argv[]) +{ + int i; + Shell_t *shp; + Namval_t *np; + int exitval; + + /* + * Create copy of |argv| array shifted by one position to + * emulate $ /usr/bin/sh <scriptname> <args1> <arg2> ... #. + * First position is set to "/usr/bin/sh" since other + * values may trigger special shell modes (e.g. *rsh* will + * trigger "restricted" shell mode etc.). + */ + char *xargv[argc+2]; + xargv[0] = "/usr/bin/sh"; + xargv[1] = "scriptname"; + for (i = 0; i < argc; i++) { + xargv[i+1] = argv[i]; + } + xargv[i+1] = NULL; + + shp = sh_init(argc+1, xargv, 0); + if (!shp) + error(ERROR_exit(1), "shell initialisation failed."); + (void) sh_trap(script, 0); + + np = nv_open("exitval", shp->var_tree, 0); + if (!np) + error(ERROR_exit(1), "variable %s not found.", "exitval"); + exitval = (int)nv_getnum(np); + nv_close(np); + + return (exitval); +} diff --git a/usr/src/cmd/ksh/builtins/alias.sh b/usr/src/cmd/ksh/builtins/alias.sh deleted file mode 100644 index e59558d3d0..0000000000 --- a/usr/src/cmd/ksh/builtins/alias.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/ksh93 - -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# - -# -# Copyright 2008 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -# Get name of builtin -builtin basename -typeset cmd="$(basename "$0")" - -# If the requested command is not an alias load it explicitly -# to make sure it is not bound to a path (those built-ins which -# are mapped via shell aliases point to commands which are -# "special shell built-ins" which cannot be bound to a specific -# PATH element) - otherwise we may execute the wrong command -# if an executable with the same name sits in a PATH element -# before /usr/bin (e.g. /usr/xpg4/bin/ls would be executed -# before /usr/bin/ls if would look like -# PATH=/usr/xpg4/bin:/usr/bin). -if [[ "${cmd}" != ~(Elr)(alias|unalias|command) ]] && ! alias "${cmd}" >/dev/null 2>&1 ; then - builtin "${cmd}" -fi - -# command is a keyword and needs to be handled separately -if [[ "${cmd}" == "command" ]] ; then - command "$@" -else - "${cmd}" "$@" -fi |
