File ash-5.1-linux.patch of Package ash
Index: sh-5.1/Makefile.linux
===================================================================
--- /dev/null
+++ sh-5.1/Makefile.linux
@@ -0,0 +1,89 @@
+#
+# Makefile.linux for ash
+#
+
+PROG= ash
+SHSRCS= alias.c cd.c echo.c error.c eval.c exec.c expand.c \
+ histedit.c input.c jobs.c mail.c main.c memalloc.c miscbltin.c \
+ mystring.c options.c parser.c redir.c show.c trap.c output.c var.c \
+ test.c kill.c syntax.c printf.c
+GENSRCS=arith.c arith_lex.c builtins.c init.c nodes.c
+GENHDRS=arith.h builtins.h nodes.h token.h
+SRCS= $(SHSRCS) $(GENSRCS)
+OBJS= $(SRCS:.c=.o)
+DPSRCS+=${GENHDRS}
+
+YACC = bison -y -d
+LEX = flex -8
+TOOL_AWK = awk
+TOOL_SED = sed
+HOST_SH = sh
+
+# Environment for scripts executed during build.
+SCRIPT_ENV= \
+ AWK=$(TOOL_AWK) \
+ SED=$(TOOL_SED)
+
+# The .depend file can get references to these temporary files
+#.OPTIONAL: lex.yy.c y.tab.c
+
+CFLAGS+=-DSHELL -I. -Dlint -DSMALL -D_GNU_SOURCE -D_LARGEFILE64_SOURCE
+CFLAGS+= $(RPM_OPT_FLAGS)
+
+#XXX: For testing only.
+#CPPFLAGS+=-DDEBUG=2
+#COPTS+=-g
+#CFLAGS+=-funsigned-char
+#TARGET_CHARFLAG?= -DTARGET_CHAR="unsigned char" -funsigned-char
+
+VPATH = bltin
+
+all: $(PROG)
+
+install: all
+ install -d $(DESTDIR)/bin
+ install $(PROG) $(DESTDIR)/bin/$(PROG)
+ install -d $(DESTDIR)/usr/share/man/man1
+ install -m 644 sh.1 $(DESTDIR)/usr/share/man/man1/ash.1
+
+$(PROG): $(OBJS)
+ $(CC) $(CFLAGS) -o $(PROG) $(OBJS)
+
+$(OBJS): $(SRCS)
+
+CLEANFILES+= ${GENSRCS} ${GENHDRS} y.tab.h
+CLEANFILES+= trace
+
+clean:
+ rm -f $(PROG) *.o $(CLEANFILES)
+
+token.h: mktokens
+ ${SCRIPT_ENV} ${HOST_SH} $^
+
+builtins.h builtins.c: mkbuiltins shell.h builtins.def
+ ${SCRIPT_ENV} ${HOST_SH} $^ ${PWD}
+ [ -f builtins.h ]
+
+init.c: mkinit.sh ${SHSRCS}
+ ${SCRIPT_ENV} ${HOST_SH} $^
+
+nodes.c nodes.h: mknodes.sh nodetypes nodes.c.pat
+ ${_MKTARGET_CREATE}
+ ${SCRIPT_ENV} ${HOST_SH} $^ ${PWD}
+ [ -f nodes.h ]
+
+parser.c: token.h
+
+arith.c arith.h: arith.y
+ $(YACC) $^
+ mv y.tab.c arith.c
+ mv y.tab.h arith.h
+
+arith_lex.c: arith_lex.l arith.h
+ $(LEX) -o $@ $<
+
+$(OBJS): %.o: %.c
+ $(CC) -c $(CFLAGS) $< -o $@
+
+$(BLTIN): %.o: bltin/%.c
+ $(CC) -c $(CFLAGS) $< -o $@
Index: sh-5.1/error.h
===================================================================
--- sh-5.1.orig/error.h
+++ sh-5.1/error.h
@@ -113,7 +113,13 @@ void sh_exit(int) __attribute__((__noret
* so we use _setjmp instead.
*/
-#if defined(BSD) && !defined(__SVR4)
+#if defined(BSD) && !defined(__SVR4) && !defined(__linux__)
#define setjmp(jmploc) _setjmp(jmploc)
#define longjmp(jmploc, val) _longjmp(jmploc, val)
#endif
+
+#if defined(__linux__)
+#ifndef __dead
+#define __dead
+#endif
+#endif
Index: sh-5.1/eval.c
===================================================================
--- sh-5.1.orig/eval.c
+++ sh-5.1/eval.c
@@ -613,17 +613,17 @@ static const char *
syspath(void)
{
static char *sys_path = NULL;
- static int mib[] = {CTL_USER, USER_CS_PATH};
static char def_path[] = "PATH=/usr/bin:/bin:/usr/sbin:/sbin";
- size_t len;
if (sys_path == NULL) {
- if (sysctl(mib, 2, 0, &len, 0, 0) != -1 &&
- (sys_path = ckmalloc(len + 5)) != NULL &&
- sysctl(mib, 2, sys_path + 5, &len, 0, 0) != -1) {
- memcpy(sys_path, "PATH=", 5);
+ char *env_path;
+
+ env_path = getenv("PATH");
+ if (env_path) {
+ sys_path = ckmalloc(strlen(env_path) + 6);
+ strcpy(sys_path,"PATH=");
+ strcat(sys_path, env_path);
} else {
- ckfree(sys_path);
/* something to keep things happy */
sys_path = def_path;
}
@@ -1007,8 +1007,10 @@ normal_fork:
/* initialize nextopt */
argptr = argv + 1;
optptr = NULL;
+#ifndef __linux__
/* and getopt */
optreset = 1;
+#endif
optind = 1;
exitstatus = cmdentry.u.bltin(argc, argv);
} else {
@@ -1217,7 +1219,7 @@ conv_time(clock_t ticks, char *seconds,
if (seconds[0] == '6' && seconds[1] == '0') {
/* 59.99995 got rounded up... */
mins++;
- strlcpy(seconds, "0.0", l);
+ strncpy(seconds, "0.0", l);
return mins;
}
Index: sh-5.1/jobs.c
===================================================================
--- sh-5.1.orig/jobs.c
+++ sh-5.1/jobs.c
@@ -54,6 +54,9 @@ __RCSID("$NetBSD: jobs.c,v 1.68 2008/12/
#include <sys/time.h>
#include <sys/resource.h>
#endif
+#ifdef __linux__
+#include <sys/wait.h>
+#endif
#include <sys/ioctl.h>
#include "shell.h"
Index: sh-5.1/trap.c
===================================================================
--- sh-5.1.orig/trap.c
+++ sh-5.1/trap.c
@@ -60,6 +60,11 @@ __RCSID("$NetBSD: trap.c,v 1.34 2008/02/
#include "mystring.h"
#include "var.h"
+#ifdef __linux__
+#define __GNU_SOURCE
+#include <string.h>
+#define sys_signame sys_siglist
+#endif
/*
* Sigmode records the current value of the signal handlers for the various
Index: sh-5.1/syntax.c
===================================================================
--- sh-5.1.orig/syntax.c
+++ sh-5.1/syntax.c
@@ -1,7 +1,11 @@
/* $NetBSD: syntax.c,v 1.2 2007/12/12 22:55:43 lukem Exp $ */
#include <sys/cdefs.h>
+#ifndef lint
+#if 0
__RCSID("$NetBSD: syntax.c,v 1.2 2007/12/12 22:55:43 lukem Exp $");
+#endif
+#endif
#include "shell.h"
#include "syntax.h"
Index: sh-5.1/syntax.h
===================================================================
--- sh-5.1.orig/syntax.h
+++ sh-5.1/syntax.h
@@ -36,6 +36,9 @@
#include <ctype.h>
/* Syntax classes */
+#ifdef CEOF
+#undef CEOF
+#endif
#define CWORD 0 /* character is nothing special */
#define CNL 1 /* newline character */
#define CBACK 2 /* a backslash character */
Index: sh-5.1/arith.y
===================================================================
--- sh-5.1.orig/arith.y
+++ sh-5.1/arith.y
@@ -56,6 +56,7 @@ intmax_t arith_result;
const char *arith_buf, *arith_startbuf;
void yyerror(const char *);
+int yyerrstatus;
#ifdef TESTARITH
int main(int , char *[]);
int error(char *);
Index: sh-5.1/bltin/kill.c
===================================================================
--- sh-5.1.orig/bltin/kill.c
+++ sh-5.1/bltin/kill.c
@@ -57,13 +57,16 @@ __RCSID("$NetBSD: kill.c,v 1.26 2009/10/
#include <locale.h>
#include <sys/ioctl.h>
+#ifdef __linux__
+#define __GNU_SOURCE
+#include <string.h>
+#endif
+
#ifdef SHELL /* sh (aka ash) builtin */
#define main killcmd
#include "bltin/bltin.h"
#endif /* SHELL */
-extern const char *sys_signame[];
-
static void nosig(char *);
static void printsignals(FILE *);
static int signame_to_signum(char *);
@@ -104,7 +107,7 @@ main(int argc, char *argv[])
/* and whether it fits into signals range */
if (numsig <= 0 || numsig >= NSIG)
nosig(*argv);
- printf("%s\n", sys_signame[(int) numsig]);
+ printf("%s\n", sys_siglist[(int) numsig]);
exit(0);
}
printsignals(stdout);
@@ -194,7 +197,7 @@ signame_to_signum(char *sig)
if (strncasecmp(sig, "sig", 3) == 0)
sig += 3;
for (n = 1; n < NSIG; n++) {
- if (!strcasecmp(sys_signame[n], sig))
+ if (!strcasecmp(sys_siglist[n], sig))
return (n);
}
return (-1);
@@ -225,7 +228,7 @@ printsignals(FILE *fp)
}
for (len = 0, sig = 1; sig < NSIG; sig++) {
- name = sys_signame[sig];
+ name = sys_siglist[sig];
nl = 1 + strlen(name);
if (len + nl >= termwidth) {
Index: sh-5.1/error.c
===================================================================
--- sh-5.1.orig/error.c
+++ sh-5.1/error.c
@@ -134,7 +134,7 @@ exvwarning(int sv_errno, const char *msg
if (commandname)
outfmt(&errout, "%s: ", commandname);
else
- outfmt(&errout, "%s: ", getprogname());
+ outfmt(&errout, "%s: ", arg0);
if (msg != NULL) {
doformat(&errout, msg, ap);
if (sv_errno >= 0)
Index: sh-5.1/parser.c
===================================================================
--- sh-5.1.orig/parser.c
+++ sh-5.1/parser.c
@@ -1609,7 +1609,7 @@ synerror(const char *msg)
if (commandname)
outfmt(&errout, "%s: %d: ", commandname, startlinno);
else
- outfmt(&errout, "%s: ", getprogname());
+ outfmt(&errout, "%s: ", arg0);
outfmt(&errout, "Syntax error: %s\n", msg);
error((char *)NULL);
/* NOTREACHED */
Index: sh-5.1/miscbltin.c
===================================================================
--- sh-5.1.orig/miscbltin.c
+++ sh-5.1/miscbltin.c
@@ -66,6 +66,34 @@ __RCSID("$NetBSD: miscbltin.c,v 1.38 200
#undef rflag
+#ifdef __linux__
+#ifndef ALLPERMS
+#define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) /* 0666 */
+#endif
+
+void *
+setmode(const char *str)
+{
+ mode_t *mp = malloc(sizeof(mode_t));
+
+ *mp = strtoul(str, NULL, 8);
+
+ return mp;
+}
+
+mode_t
+getmode(const void *mp, mode_t mode)
+{
+ mode_t m;
+
+ m = *((const mode_t *)mp);
+
+ mode &= ~ALLPERMS; /* input mode less RWX permissions */
+ m &= ALLPERMS; /* new RWX permissions */
+
+ return m | mode;
+}
+#endif
/*