commit: 464f18e17938787e9b910afe159d8ee9058a9c2b
parent: 061993b096148afde151c9277db5804eab11a383
author: Brian Callahan <bcallah@openbsd.org>
date: Fri, 12 Jan 2018 22:45:57 -0500
Add check for confstr() and minimal portable implementation of it.
This fixes the build on Android termux, at least.
6 files changed, 139 insertions(+), 66 deletions(-)
diff --git a/CVS/Entries b/CVS/Entries
@@ -1,46 +1,46 @@
/config.h/1.17/Result of merge//
/history.c/1.78/Result of merge//
/main.c/1.86/Result of merge//
-/CONTRIBUTORS/1.10/Fri Jan 12 00:53:51 2018//
-/LEGAL/1.2/Fri Jan 12 00:53:51 2018//
-/Makefile/1.38/Fri Jan 12 00:54:17 2018//
-/NOTES/1.15/Fri Jan 12 00:54:17 2018//
-/PROJECTS/1.9/Fri Jan 12 00:54:17 2018//
-/alloc.c/1.18/Fri Jan 12 00:53:51 2018//
-/c_ksh.c/1.56/Fri Jan 12 00:53:51 2018//
-/c_sh.c/1.62/Fri Jan 12 00:53:51 2018//
-/c_test.c/1.24/Fri Jan 12 00:53:51 2018//
-/c_test.h/1.4/Fri Jan 12 00:53:51 2018//
-/c_ulimit.c/1.24/Fri Jan 12 00:53:51 2018//
-/edit.c/1.61/Fri Jan 12 00:53:51 2018//
-/edit.h/1.11/Fri Jan 12 00:53:51 2018//
/emacs.c/1.82/Result of merge//
-/eval.c/1.57/Fri Jan 12 00:53:51 2018//
-/exec.c/1.70/Fri Jan 12 00:53:51 2018//
-/expand.h/1.15/Fri Jan 12 00:53:51 2018//
-/expr.c/1.32/Fri Jan 12 00:53:51 2018//
-/io.c/1.35/Fri Jan 12 00:53:51 2018//
-/jobs.c/1.58/Fri Jan 12 00:54:18 2018//
-/ksh.1/1.197/Fri Jan 12 00:53:51 2018//
-/lex.c/1.77/Fri Jan 12 00:53:51 2018//
-/lex.h/1.20/Fri Jan 12 00:53:51 2018//
-/mail.c/1.22/Fri Jan 12 00:53:51 2018//
-/misc.c/1.65/Fri Jan 12 00:53:51 2018//
-/path.c/1.22/Fri Jan 12 00:53:51 2018//
-/sh.1/1.146/Fri Jan 12 00:53:51 2018//
-/sh.h/1.68/Fri Jan 12 00:53:51 2018//
-/shf.c/1.31/Fri Jan 12 00:53:51 2018//
-/shf.h/1.8/Fri Jan 12 00:53:51 2018//
-/syn.c/1.38/Fri Jan 12 00:53:51 2018//
-/table.c/1.24/Fri Jan 12 00:53:51 2018//
-/table.h/1.13/Fri Jan 12 00:53:51 2018//
-/trap.c/1.30/Fri Jan 12 00:53:51 2018//
-/tree.c/1.30/Fri Jan 12 00:53:51 2018//
-/tree.h/1.12/Fri Jan 12 00:53:51 2018//
-/tty.c/1.16/Fri Jan 12 00:53:51 2018//
-/tty.h/1.6/Fri Jan 12 00:53:51 2018//
-/var.c/1.63/Fri Jan 12 00:53:51 2018//
-/version.c/1.12/Fri Jan 12 00:53:51 2018//
-/vi.c/1.53/Fri Jan 12 00:53:51 2018//
-/README/1.16/Fri Jan 12 02:59:19 2018//
+/CONTRIBUTORS/1.10/Fri Jan 12 20:53:58 2018//
+/LEGAL/1.2/Fri Jan 12 20:53:58 2018//
+/NOTES/1.16/Fri Jan 12 20:54:17 2018//
+/PROJECTS/1.9/Fri Jan 12 20:53:58 2018//
+/alloc.c/1.18/Fri Jan 12 20:53:58 2018//
+/c_ksh.c/1.56/Fri Jan 12 20:53:58 2018//
+/c_sh.c/1.62/Fri Jan 12 20:53:58 2018//
+/c_test.c/1.24/Fri Jan 12 20:53:58 2018//
+/c_test.h/1.4/Fri Jan 12 20:53:58 2018//
+/c_ulimit.c/1.24/Fri Jan 12 20:53:58 2018//
+/edit.c/1.61/Fri Jan 12 20:53:58 2018//
+/edit.h/1.11/Fri Jan 12 20:53:58 2018//
+/eval.c/1.57/Fri Jan 12 20:53:58 2018//
+/exec.c/1.70/Fri Jan 12 20:53:58 2018//
+/expand.h/1.15/Fri Jan 12 20:53:58 2018//
+/expr.c/1.32/Fri Jan 12 20:53:58 2018//
+/io.c/1.35/Fri Jan 12 20:53:58 2018//
+/jobs.c/1.58/Fri Jan 12 20:53:58 2018//
+/ksh.1/1.197/Fri Jan 12 20:53:58 2018//
+/lex.c/1.77/Fri Jan 12 20:53:58 2018//
+/lex.h/1.20/Fri Jan 12 20:53:58 2018//
+/mail.c/1.22/Fri Jan 12 20:53:58 2018//
+/misc.c/1.65/Fri Jan 12 20:53:58 2018//
+/path.c/1.22/Fri Jan 12 20:53:58 2018//
+/sh.1/1.146/Fri Jan 12 20:53:58 2018//
+/sh.h/1.68/Fri Jan 12 20:53:58 2018//
+/shf.c/1.31/Fri Jan 12 20:53:58 2018//
+/shf.h/1.8/Fri Jan 12 20:53:58 2018//
+/syn.c/1.38/Fri Jan 12 20:53:58 2018//
+/table.c/1.24/Fri Jan 12 20:53:58 2018//
+/table.h/1.13/Fri Jan 12 20:53:58 2018//
+/trap.c/1.30/Fri Jan 12 20:53:58 2018//
+/tree.c/1.30/Fri Jan 12 20:53:58 2018//
+/tree.h/1.12/Fri Jan 12 20:53:58 2018//
+/tty.c/1.16/Fri Jan 12 20:53:58 2018//
+/tty.h/1.6/Fri Jan 12 20:53:58 2018//
+/var.c/1.63/Fri Jan 12 20:53:58 2018//
+/version.c/1.12/Fri Jan 12 20:53:58 2018//
+/Makefile/1.38/Sat Jan 13 03:28:07 2018//
+/README/1.16/Sat Jan 13 03:28:07 2018//
+/vi.c/1.54/Sat Jan 13 03:28:07 2018//
D
diff --git a/NOTES b/NOTES
@@ -1,4 +1,4 @@
-$OpenBSD: NOTES,v 1.15 2018/01/08 13:39:06 jca Exp $
+$OpenBSD: NOTES,v 1.16 2018/01/12 14:20:57 jca Exp $
General features of at&t ksh88 that are not (yet) in pdksh:
- exported aliases and functions (not in ksh93).
@@ -6,12 +6,10 @@ General features of at&t ksh88 that are not (yet) in pdksh:
- signals/traps not cleared during functions.
- trap DEBUG, local ERR and EXIT traps in functions.
- ERRNO parameter.
- - use of an `agent' to execute unreadable/setuid/setgid shell scripts
- (don't ask).
- read/select aren't hooked in to the command line editor
- the last command of a pipeline is not run in the parent shell
-Known bugs (see also BUG-REPORTS and PROJECTS files):
+Known bugs (see also PROJECTS files):
Variable parsing, Expansion:
- some specials behave differently when unset (eg, IFS behaves like
" \t\n") others lose their special meaning. IFS/PATH taken care of,
@@ -25,9 +23,9 @@ Known bugs (see also BUG-REPORTS and PROJECTS files):
Commands,Execution:
- setting special parameters that have side effects when
changed/restored (ie, HISTFILE, OPTIND, RANDOM) in front
- of a command (eg, HISTFILE=/foo/bar echo hi) effects the parent
+ of a command (eg, HISTFILE=/foo/bar echo hi) affects the parent
shell. Note that setting other (not so special) parameters
- does not effect the parent shell.
+ does not affect the parent shell.
- `echo hi | exec cat -n' causes at&t to exit, `exec echo hi | cat -n'
does not. pdksh exits for neither. Don't think POSIX requires
an exit, but not sure.
@@ -239,8 +237,8 @@ Oddities in ksh (pd & at&t):
- when tracing (set -x), and a command's stderr is redirected, the trace
output is also redirected. so "set -x; echo foo 2> /tmp/O > /dev/null"
will create /tmp/foo with the lines "+ > /dev/null" and "+ echo foo".
- - undocumented at&t ksh feature: FPATH is searched after PATH if no
- executable is found, even if typeset -uf wasn't used.
+ - undocumented at&t ksh88, documented in ksh93: FPATH is searched
+ after PATH if no executable is found, even if typeset -uf wasn't used.
POSIX sh questions (references are to POSIX 1003.2-1992)
- arithmetic expressions: how are empty expressions treated?
@@ -276,9 +274,6 @@ POSIX sh bugs (references are to POSIX 1003.2-1992)
functions don't do the save/restore automatically). Restoring
OPTIND is kind of dumb since getopts may have been in the middle
of parsing a group of flags (eg, -abc).
- - unclear whether arithmetic expressions (eg, $((..))) should
- understand C integer constants (ie, 0x123, 0177). at&t ksh doesn't
- and neither does pdksh.
- `...` definition (3.6.3) says nothing about backslash followed by
a newline, which sh and at&t ksh strip out completely. e.g.,
$ show-args `echo 'X
diff --git a/configure b/configure
@@ -36,6 +36,21 @@ EOF
return 1
}
+confstrcheck() {
+ cat << EOF > conftest.c
+#include <unistd.h>
+int main(void){confstr(0,NULL,0);return 0;}
+EOF
+ $cc $tflags -o conftest conftest.c > /dev/null 2>&1
+ if [ $? -eq 0 ] ; then
+ rm -f conftest conftest.c
+ return 0
+ else
+ rm -f conftest conftest.c
+ return 1
+ fi
+}
+
pledgecheck() {
cat << EOF > conftest.c
#include <unistd.h>
@@ -300,6 +315,15 @@ cat << EOF > pconfig.h
EOF
+printf "checking for confstr... "
+confstrcheck
+if [ $? -eq 0 ] ; then
+ echo "#define HAVE_CONFSTR" >> pconfig.h
+ echo "yes"
+else
+ echo "no"
+fi
+
printf "checking for pledge... "
pledgecheck
if [ $? -eq 0 ] ; then
@@ -412,7 +436,8 @@ PROG = oksh
OBJS = alloc.o c_ksh.o c_sh.o c_test.o c_ulimit.o edit.o emacs.o eval.o \\
exec.o expr.o history.o io.o jobs.o lex.o mail.o main.o misc.o \\
path.o shf.o syn.o table.o trap.o tree.o tty.o var.o version.o vi.o \\
- reallocarray.o signame.o strlcat.o strlcpy.o strtonum.o unvis.o vis.o
+ confstr.o reallocarray.o signame.o strlcat.o strlcpy.o strtonum.o \\
+ unvis.o vis.o
ETS = \`grep -w \${PREFIX}/bin/\${PROG} /etc/shells > /dev/null; \\
[ \$\$? -ne 0 ] && echo "\${PREFIX}/bin/\${PROG}" >> /etc/shells\`
diff --git a/confstr.c b/confstr.c
@@ -0,0 +1,45 @@
+/* $OpenBSD: confstr.c,v 1.10 2013/03/07 06:00:18 guenther Exp $ */
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "portable.h"
+
+#ifndef HAVE_CONFSTR
+
+#include <paths.h>
+#include <string.h>
+
+size_t
+confstr(int name, char *buf, size_t len)
+{
+
+ return (strlcpy(buf, _PATH_STDPATH, len) + 1);
+}
+
+#endif /* !HAVE_CONFSTR */
diff --git a/portable.h b/portable.h
@@ -36,11 +36,15 @@
#ifndef CHILD_MAX
#define CHILD_MAX 80
-#endif /* CHILD_MAX */
+#endif /* !CHILD_MAX */
+
+#ifndef _CS_PATH
+#define _CS_PATH 1
+#endif /* !CS_PATH */
#ifndef O_EXLOCK
#define O_EXLOCK 0
-#endif /* O_EXLOCK */
+#endif /* !O_EXLOCK */
#ifndef _PW_NAME_LEN
#ifdef __linux__
@@ -48,19 +52,19 @@
#else
#define _PW_NAME_LEN MAXLOGNAME - 1
#endif /* __linux__ */
-#endif /* _PW_NAME_LEN */
+#endif /* !_PW_NAME_LEN */
#ifndef RLIMIT_RSS
#define RLIMIT_RSS 5 /* resident set size */
-#endif /* RLIMIT_RSS */
+#endif /* !RLIMIT_RSS */
#ifndef RLIMIT_MEMLOCK
#define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */
-#endif /* RLIMIT_MEMLOCK */
+#endif /* !RLIMIT_MEMLOCK */
#ifndef RLIMIT_NPROC
#define RLIMIT_NPROC 7 /* number of processes */
-#endif /* RLIMIT_NPROC */
+#endif /* !RLIMIT_NPROC */
/* Convert clock_gettime() to clock_get_time() on Max OS X */
#ifdef __APPLE__
@@ -94,7 +98,7 @@
/* Cygwin already has a sys_signame but we want to use our own */
#ifdef __CYGWIN__
#define sys_signame esys_signame
-#endif
+#endif /* __CYGWIN__ */
/* From OpenBSD sys/time.h */
#ifndef __OpenBSD__
@@ -118,6 +122,10 @@
* Prototypes
*/
+#ifndef HAVE_CONFSTR
+size_t confstr(int, char *, size_t);
+#endif /* !HAVE_CONFSTR */
+
#ifndef HAVE_REALLOCARRAY
void *reallocarray(void *, size_t, size_t);
#endif /* !HAVE_REALLOCARRAY */
diff --git a/vi.c b/vi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vi.c,v 1.53 2018/01/06 16:28:58 millert Exp $ */
+/* $OpenBSD: vi.c,v 1.54 2018/01/13 02:06:54 schwarze Exp $ */
/*
* vi command editing
@@ -61,7 +61,7 @@ static void display(char *, char *, int);
static void ed_mov_opt(int, char *);
static int expand_word(int);
static int complete_word(int, int);
-static int print_expansions(struct edstate *, int);
+static int print_expansions(struct edstate *);
static int char_len(int);
static void x_vi_zotc(int);
static void vi_pprompt(int);
@@ -648,7 +648,7 @@ vi_insert(int ch)
break;
case CTRL('e'):
- print_expansions(es, 0);
+ print_expansions(es);
break;
case CTRL('i'):
@@ -1125,7 +1125,7 @@ vi_cmd(int argcnt, const char *cmd)
case '=': /* at&t ksh */
case CTRL('e'): /* Nonstandard vi/ksh */
- print_expansions(es, 1);
+ print_expansions(es);
break;
@@ -2052,7 +2052,7 @@ complete_word(int command, int count)
/* Undo previous completion */
if (command == 0 && expanded == COMPLETE && buf) {
- print_expansions(buf, 0);
+ print_expansions(buf);
expanded = PRINT;
return 0;
}
@@ -2143,7 +2143,7 @@ complete_word(int command, int count)
}
static int
-print_expansions(struct edstate *e, int command)
+print_expansions(struct edstate *e)
{
int nwords;
int start, end;