From 8b0f1f816bf5401dd9402ce3a301ee3a34900c2e Mon Sep 17 00:00:00 2001 From: Manuel Palenzuela Date: Mon, 5 Apr 2021 22:58:01 +0200 Subject: [PATCH] Ports: Added an oksh port Currently has some problems such as not killing jobs when (ctrl + c) and depends on an implementation of sigsuspend. --- Ports/AvailablePorts.md | 1 + Ports/oksh/package.sh | 18 ++++ Ports/oksh/patches/disable_flock.patch | 28 +++++ Ports/oksh/patches/disable_rlimit.patch | 70 ++++++++++++ Ports/oksh/patches/disable_tty.patch | 13 +++ Ports/oksh/patches/implement_isblank.patch | 16 +++ Ports/oksh/patches/remove_issetugid.patch | 28 +++++ .../oksh/patches/remove_redeclarations.patch | 101 ++++++++++++++++++ 8 files changed, 275 insertions(+) create mode 100755 Ports/oksh/package.sh create mode 100644 Ports/oksh/patches/disable_flock.patch create mode 100644 Ports/oksh/patches/disable_rlimit.patch create mode 100644 Ports/oksh/patches/disable_tty.patch create mode 100644 Ports/oksh/patches/implement_isblank.patch create mode 100644 Ports/oksh/patches/remove_issetugid.patch create mode 100644 Ports/oksh/patches/remove_redeclarations.patch diff --git a/Ports/AvailablePorts.md b/Ports/AvailablePorts.md index ce976ef944..1c3add1a29 100644 --- a/Ports/AvailablePorts.md +++ b/Ports/AvailablePorts.md @@ -65,6 +65,7 @@ Please make sure to keep this list up to date when adding and updating ports. :^ | [`nyancat`](nyancat/) | Nyancat | | https://github.com/klange/nyancat | | [`openssh`](openssh/) | OpenSSH | 8.3-9ca7e9c | https://github.com/openssh/openssh-portable | | [`openssl`](openssl/) | OpenSSL | 1.0.2 | https://www.openssl.org/ | +| [`oksh`](oksh/) | oksh | 6.8.1 | https://github.com/ibara/oksh | | [`patch`](patch/) | patch (OpenBSD) | 6.6 | https://github.com/ibara/libpuffy | | [`pcre2`](pcre2/) | Perl-compatible Regular Expressions (PCRE2) | 10.34 | https://www.pcre.org/ | | [`pkgconf`](pkgconf/) | pkgconf | 1.7.3 | https://github.com/pkgconf/pkgconf | diff --git a/Ports/oksh/package.sh b/Ports/oksh/package.sh new file mode 100755 index 0000000000..671ca34856 --- /dev/null +++ b/Ports/oksh/package.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env -S bash ../.port_include.sh +port=oksh +useconfigure=true +version=6.8.1 +depends="ncurses" +workdir=oksh-${version} +files="https://github.com/ibara/oksh/releases/download/oksh-${version}/oksh-${version}.tar.gz oksh-${version}.tar.gz" + +configure() { + export CC=${SERENITY_ROOT}/Toolchain/Local/${SERENITY_ARCH}/bin/${SERENITY_ARCH}-pc-serenity-gcc + export CFLAGS="" + export LDFLAGS="-lncurses" + run ./configure --no-thanks +} + +install() { + run cp oksh "${SERENITY_BUILD_DIR}/Root/bin" +} diff --git a/Ports/oksh/patches/disable_flock.patch b/Ports/oksh/patches/disable_flock.patch new file mode 100644 index 0000000000..814919b3b4 --- /dev/null +++ b/Ports/oksh/patches/disable_flock.patch @@ -0,0 +1,28 @@ +diff --git a/history.c b/history.c +index 59876da..b03cc7a 100644 +--- a/history.c ++++ b/history.c +@@ -23,6 +23,8 @@ + + #include "sh.h" + ++#define SMALL ++ + #if !defined(HAVE_STRAVIS) || !defined(HAVE_STRUNVIS) + #include "vis.h" + #else +@@ -636,12 +638,12 @@ init_histvec(void) + static void + history_lock(int operation) + { +- while (flock(fileno(histfh), operation) != 0) { ++ /*while (flock(fileno(histfh), operation) != 0) { + if (errno == EINTR || errno == EAGAIN) + continue; + else + break; +- } ++ }*/ + } + + /* diff --git a/Ports/oksh/patches/disable_rlimit.patch b/Ports/oksh/patches/disable_rlimit.patch new file mode 100644 index 0000000000..bc8aa79ef4 --- /dev/null +++ b/Ports/oksh/patches/disable_rlimit.patch @@ -0,0 +1,70 @@ +diff --git a/c_ulimit.c b/c_ulimit.c +index 65e0cca..587f08a 100644 +--- a/c_ulimit.c ++++ b/c_ulimit.c +@@ -45,15 +45,15 @@ c_ulimit(char **wp) + { + static const struct limits limits[] = { + /* Do not use options -H, -S or -a or change the order. */ +- { "time(cpu-seconds)", RLIMIT_CPU, 1, 't' }, +- { "file(blocks)", RLIMIT_FSIZE, 512, 'f' }, +- { "coredump(blocks)", RLIMIT_CORE, 512, 'c' }, +- { "data(kbytes)", RLIMIT_DATA, 1024, 'd' }, +- { "stack(kbytes)", RLIMIT_STACK, 1024, 's' }, +- { "lockedmem(kbytes)", RLIMIT_MEMLOCK, 1024, 'l' }, +- { "memory(kbytes)", RLIMIT_RSS, 1024, 'm' }, +- { "nofiles(descriptors)", RLIMIT_NOFILE, 1, 'n' }, +- { "processes", RLIMIT_NPROC, 1, 'p' }, ++ { "time(cpu-seconds)", 1, 1, 't' }, ++ { "file(blocks)", 512, 512, 'f' }, ++ { "coredump(blocks)", 512, 512, 'c' }, ++ { "data(kbytes)", 1024, 1024, 'd' }, ++ { "stack(kbytes)", 1024, 1024, 's' }, ++ { "lockedmem(kbytes)", 1024, 1024, 'l' }, ++ { "memory(kbytes)", 1024, 1024, 'm' }, ++ { "nofiles(descriptors)", 1, 1, 'n' }, ++ { "processes", 1, 1, 'p' }, + { NULL } + }; + const char *options = "HSat#f#c#d#s#l#m#n#p#"; +@@ -133,7 +133,7 @@ c_ulimit(char **wp) + + static int + set_ulimit(const struct limits *l, const char *v, int how) +-{ ++{/* + rlim_t val = 0; + struct rlimit limit; + +@@ -150,7 +150,7 @@ set_ulimit(const struct limits *l, const char *v, int how) + * If this causes problems, will have to add parameter to + * evaluate() to control if unset params are 0 or an error. + */ +- if (!rval && !digit(v[0])) { ++/* if (!rval && !digit(v[0])) { + bi_errorf("invalid limit: %s", v); + return 1; + } +@@ -169,13 +169,13 @@ set_ulimit(const struct limits *l, const char *v, int how) + bi_errorf("bad -%c limit: %s", l->option, + strerror(errno)); + return 1; +- } ++ }*/ + return 0; + } + + static void + print_ulimit(const struct limits *l, int how) +-{ ++{/* + rlim_t val = 0; + struct rlimit limit; + +@@ -189,5 +189,5 @@ print_ulimit(const struct limits *l, int how) + else { + val /= l->factor; + shprintf("%" PRIi64 "\n", (int64_t) val); +- } ++ }*/ + } diff --git a/Ports/oksh/patches/disable_tty.patch b/Ports/oksh/patches/disable_tty.patch new file mode 100644 index 0000000000..4838fe1e4e --- /dev/null +++ b/Ports/oksh/patches/disable_tty.patch @@ -0,0 +1,13 @@ +diff --git a/tty.c b/tty.c +index a72e5cd..96fa904 100644 +--- a/tty.c ++++ b/tty.c +@@ -33,7 +33,7 @@ tty_init(int init_ttystate) + tty_close(); + tty_devtty = 1; + +- tfd = open("/dev/tty", O_RDWR, 0); ++ tfd = open("/dev/tty0", O_RDWR, 0); + if (tfd == -1) { + tty_devtty = 0; + warningf(false, "No controlling tty (open /dev/tty: %s)", diff --git a/Ports/oksh/patches/implement_isblank.patch b/Ports/oksh/patches/implement_isblank.patch new file mode 100644 index 0000000000..48c0a5b652 --- /dev/null +++ b/Ports/oksh/patches/implement_isblank.patch @@ -0,0 +1,16 @@ +diff --git a/charclass.h b/charclass.h +index 5edb2c1..af00709 100644 +--- a/charclass.h ++++ b/charclass.h +@@ -7,6 +7,11 @@ + /* + * POSIX character class support for fnmatch() and glob(). + */ ++int ++isblank(int c) ++{ ++ return (c == ' ' || c == '\t'); ++} + static struct cclass { + const char *name; + int (*isctype)(int); diff --git a/Ports/oksh/patches/remove_issetugid.patch b/Ports/oksh/patches/remove_issetugid.patch new file mode 100644 index 0000000000..99d6940030 --- /dev/null +++ b/Ports/oksh/patches/remove_issetugid.patch @@ -0,0 +1,28 @@ +diff --git a/misc.c b/misc.c +index b440088..1c32061 100644 +--- a/misc.c ++++ b/misc.c +@@ -291,22 +291,7 @@ change_flag(enum sh_flag f, + Flag(f) = newval; + } + } else +- /* Turning off -p? */ +- if (f == FPRIVILEGED && oldval && !newval && issetugid() && +- !dropped_privileges) { +- gid_t gid = getgid(); +- +- setresgid(gid, gid, gid); +- setgroups(1, &gid); +- setresuid(ksheuid, ksheuid, ksheuid); +- +-#ifdef HAVE_PLEDGE +- if (pledge("stdio rpath wpath cpath fattr flock getpw proc " +- "exec tty", NULL) == -1) +- bi_errorf("pledge fail"); +-#endif +- dropped_privileges = 1; +- } else if (f == FPOSIX && newval) { ++ if (f == FPOSIX && newval) { + Flag(FBRACEEXPAND) = 0; + } + /* Changing interactive flag? */ diff --git a/Ports/oksh/patches/remove_redeclarations.patch b/Ports/oksh/patches/remove_redeclarations.patch new file mode 100644 index 0000000000..51c35157f2 --- /dev/null +++ b/Ports/oksh/patches/remove_redeclarations.patch @@ -0,0 +1,101 @@ +diff --git a/jobs.c b/jobs.c +index 121c0cf..b30d105 100644 +--- a/jobs.c ++++ b/jobs.c +@@ -30,6 +30,7 @@ + + #include "sh.h" + #include "tty.h" ++#include "portable.h" + + /* Order important! */ + #define PRUNNING 0 +diff --git a/portable.h b/portable.h +index 899c974..864e112 100644 +--- a/portable.h ++++ b/portable.h +@@ -61,10 +61,8 @@ + #define _PW_NAME_LEN MAXLOGNAME + #elif defined(__sun) + #define _PW_NAME_LEN LOGNAME_MAX +-#elif defined(__hpux) +-#define _PW_NAME_LEN 8 + #else +-#define _PW_NAME_LEN MAXLOGNAME - 1 ++#define _PW_NAME_LEN 8 + #endif /* __linux__ || __CYGWIN__ || _AIX || __NetBSD__ || __sun || __midipix__ || __HAIKU__ */ + #endif /* !_PW_NAME_LEN */ + +@@ -116,6 +114,15 @@ + #define nice(x) (int)0 + #endif /* __HAIKU__ */ + ++#ifdef __serenity__ ++#define _PATH_DEFPATH "/usr/bin:/usr/local/bin" ++#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin:" ++#define _CS_PATH 1 ++#define WCOREFLAG 0200 ++#define WCOREDUMP(x) ((x) & WCOREFLAG) ++#define nice(x) (int)0 ++#endif ++ + #ifndef HAVE_SETRESGID + #define setresgid(x, y, z) setgid(x); setegid(y); setgid(z) + #endif /* !HAVE_SETRESGID */ +@@ -128,30 +135,6 @@ + #define srand_deterministic(x) srand(x) + #endif /* !HAVE_SRAND_DETERMINISTIC */ + +-#ifndef HAVE_TIMERADD +-#define timeradd(tvp, uvp, vvp) \ +- do { \ +- (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ +- (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ +- if ((vvp)->tv_usec >= 1000000) { \ +- (vvp)->tv_sec++; \ +- (vvp)->tv_usec -= 1000000; \ +- } \ +- } while (0) +-#endif /* !HAVE_TIMERADD */ +- +-#ifndef HAVE_TIMERSUB +-#define timersub(tvp, uvp, vvp) \ +- do { \ +- (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ +- (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ +- if ((vvp)->tv_usec < 0) { \ +- (vvp)->tv_sec--; \ +- (vvp)->tv_usec += 1000000; \ +- } \ +- } while (0) +-#endif /* !HAVE_TIMERSUB */ +- + /* struct stat compatibility */ + #ifndef HAVE_ST_MTIM + #ifndef HAVE_ST_MTIMESPEC +@@ -240,9 +223,9 @@ int strunvis(char *, const char *); + #undef NSIG + #endif /* NSIG */ + #define NSIG 33 +-#ifndef HAVE_SIGLIST +-extern const char *const sys_siglist[NSIG]; +-#endif /* !HAVE_SIGLIST */ ++//#ifndef HAVE_SIGLIST ++//extern const char *const sys_siglist[NSIG]; ++//#endif /* !HAVE_SIGLIST */ + #ifndef HAVE_SIGNAME + extern const char *const sys_signame[NSIG]; + #endif /* !HAVE_SIGNAME */ +diff --git a/siglist.c b/siglist.c +index 790d7da..d8e3519 100644 +--- a/siglist.c ++++ b/siglist.c +@@ -30,7 +30,7 @@ + + #include "pconfig.h" + +-#ifndef HAVE_SIGLIST ++#if 0 + + #include +