From f113f202af7f070c9ff02b0f6fd86c31fe2881d4 Mon Sep 17 00:00:00 2001 From: Siteshwar Vashisht Date: Wed, 2 May 2018 21:25:00 +0200 Subject: [PATCH 1/5] Enable test cases for standard command builtins Since these builtins are now built by default we should enable their test cases. Related: #499 --- src/cmd/ksh93/tests/basic.sh | 2 +- src/cmd/ksh93/tests/builtins.sh | 42 ++++----- src/cmd/ksh93/tests/locale.sh | 35 ++++--- src/cmd/ksh93/tests/path.sh | 5 +- src/lib/libast/include/fts.h | 156 +------------------------------- 5 files changed, 42 insertions(+), 198 deletions(-) diff --git a/src/cmd/ksh93/tests/basic.sh b/src/cmd/ksh93/tests/basic.sh index fd2cebe57d6a..bc045be225a7 100755 --- a/src/cmd/ksh93/tests/basic.sh +++ b/src/cmd/ksh93/tests/basic.sh @@ -644,7 +644,7 @@ float sec=SECONDS file=$TEST_DIR/foobar log_info "TODO: Skipping call to builtin cat" -#builtin cat +builtin cat for ((n=0; n < 1000; n++)) do > $file diff --git a/src/cmd/ksh93/tests/builtins.sh b/src/cmd/ksh93/tests/builtins.sh index 8057e651b9b0..e8d4b068ea28 100755 --- a/src/cmd/ksh93/tests/builtins.sh +++ b/src/cmd/ksh93/tests/builtins.sh @@ -797,27 +797,26 @@ IFS=',' read -S a b c <<<'foo,"""title"" data",bar' [[ $b == '"title" data' ]] || log_error '"" inside "" not handled correctly with read -S' PATH=/bin:/usr/bin -log_info 'TODO: Enable these tests when the custom builtins of external commands are available.' -#basename=$(whence -p basename) -#cmp=$(whence -p cmp) -#.sh.op_astbin=/opt/ast/bin -#PATH=/opt/ast/bin:$PATH -#PATH=/opt/ast/bin:/bin:/usr/bin -#[[ ${SH_OPTIONS} == *astbin=/opt/ast/bin* ]] || log_error "SH_OPTIONS=${SH_OPTIONS} but should contain astbin=/opt/ast/bin" -#[[ $(whence basename) == /opt/ast/bin/basename ]] || log_error "basename bound to $(whence basename) but should be bound to /opt/ast/bin/basename" -#[[ $(whence cmp) == /opt/ast/bin/cmp ]] || log_error "cmp bound to $(whence cmp) but should be bound to /opt/ast/bin/cmp" -#.sh.op_astbin=/bin -#SH_OPTIONS=astbin=/bin -#[[ ${SH_OPTIONS} == *astbin=/bin* ]] || log_error "SH_OPTIONS=${SH_OPTIONS} but should contain astbin=/bin" -#[[ $(whence basename) == "$basename" ]] || log_error "basename bound to $(whence basename) but should be bound to $basename" -#[[ $(whence cmp) == "$cmp" ]] || log_error "cmp bound to $(whence cmp) but should be bound to $cmp" -#.sh.op_astbin=/opt/ast/bin -#[[ $(whence basename) == /opt/ast/bin/basename ]] || log_error "basename bound to $(whence basename) but should be rebound to /opt/ast/bin/basename" -#[[ $(whence cmp) == /opt/ast/bin/cmp ]] || log_error "cmp bound to $(whence cmp) but should be rebound to /opt/ast/bin/cmp" -#PATH=/bin:/usr/bin:/opt/ast/bin -#[[ $(whence basename) == "$basename" ]] || log_error "basename bound to $(whence basename) but should be bound to $basename when PATH=$PATH" -#[[ $(whence cmp) == "$cmp" ]] || log_error "cmp bound to $(whence cmp) but should be bound to $cmp when PATH=$PATH" -# +basename=$(whence -p basename) +cmp=$(whence -p cmp) +.sh.op_astbin=/opt/ast/bin +PATH=/opt/ast/bin:$PATH +PATH=/opt/ast/bin:/bin:/usr/bin +[[ ${SH_OPTIONS} == *astbin=/opt/ast/bin* ]] || log_error "SH_OPTIONS=${SH_OPTIONS} but should contain astbin=/opt/ast/bin" +[[ $(whence basename) == /opt/ast/bin/basename ]] || log_error "basename bound to $(whence basename) but should be bound to /opt/ast/bin/basename" +[[ $(whence cmp) == /opt/ast/bin/cmp ]] || log_error "cmp bound to $(whence cmp) but should be bound to /opt/ast/bin/cmp" +.sh.op_astbin=/bin +SH_OPTIONS=astbin=/bin +[[ ${SH_OPTIONS} == *astbin=/bin* ]] || log_error "SH_OPTIONS=${SH_OPTIONS} but should contain astbin=/bin" +[[ $(whence basename) == "$basename" ]] || log_error "basename bound to $(whence basename) but should be bound to $basename" +[[ $(whence cmp) == "$cmp" ]] || log_error "cmp bound to $(whence cmp) but should be bound to $cmp" +.sh.op_astbin=/opt/ast/bin +[[ $(whence basename) == /opt/ast/bin/basename ]] || log_error "basename bound to $(whence basename) but should be rebound to /opt/ast/bin/basename" +[[ $(whence cmp) == /opt/ast/bin/cmp ]] || log_error "cmp bound to $(whence cmp) but should be rebound to /opt/ast/bin/cmp" +PATH=/bin:/usr/bin:/opt/ast/bin +[[ $(whence basename) == "$basename" ]] || log_error "basename bound to $(whence basename) but should be bound to $basename when PATH=$PATH" +[[ $(whence cmp) == "$cmp" ]] || log_error "cmp bound to $(whence cmp) but should be bound to $cmp when PATH=$PATH" + unset y expect='outside f, 1, 2, 3, outside f' actual=$( @@ -977,7 +976,6 @@ then fi chmod +x $TEST_DIR/a/b # so the test temp dir can be removed when the test completes - # -s flag writes to history file if print -s 'print hello world' 2> /dev/null then diff --git a/src/cmd/ksh93/tests/locale.sh b/src/cmd/ksh93/tests/locale.sh index 6aec6092445c..4940cb90cabf 100755 --- a/src/cmd/ksh93/tests/locale.sh +++ b/src/cmd/ksh93/tests/locale.sh @@ -113,24 +113,23 @@ set -- $($SHELL -c " ") got=$* [[ $got == $exp ]] || log_error "command wc LC_ALL default failed -- expected '$exp', got '$got'" -log_info 'TODO: Enable when custom builtins of external commands is working.' -#set -- $($SHELL -c " -# if builtin wc 2>/dev/null || builtin -f cmd wc 2>/dev/null -# then -# unset LC_CTYPE -# export LANG=$locale -# export LC_ALL=C -# wc -m < $TEST_DIR/two_euro_chars.txt -# unset LC_ALL -# wc -m < $TEST_DIR/two_euro_chars.txt -# export LC_ALL=C -# wc -m < $TEST_DIR/two_euro_chars.txt -# fi - -#") -#got=$* -#[[ $got == $exp ]] || log_error "builtin wc LC_ALL default failed -- expected '$exp', got '$got'" -# +set -- $($SHELL -c " + if builtin wc 2>/dev/null || builtin -f cmd wc 2>/dev/null + then + unset LC_CTYPE + export LANG=$locale + export LC_ALL=C + wc -m < $TEST_DIR/two_euro_chars.txt + unset LC_ALL + wc -m < $TEST_DIR/two_euro_chars.txt + export LC_ALL=C + wc -m < $TEST_DIR/two_euro_chars.txt + fi + +") +got=$* +[[ $got == $exp ]] || log_error "builtin wc LC_ALL default failed -- expected '$exp', got '$got'" + # multibyte char straddling buffer boundary # See https://github.com/att/ast/issues/177 diff --git a/src/cmd/ksh93/tests/path.sh b/src/cmd/ksh93/tests/path.sh index ab593a1fa302..90f76554aecb 100755 --- a/src/cmd/ksh93/tests/path.sh +++ b/src/cmd/ksh93/tests/path.sh @@ -256,9 +256,8 @@ typeset foo=$(PATH=/xyz:/abc :) y=$(whence rm) [[ $x != "$y" ]] && log_error 'PATH not restored after command substitution' whence getconf > /dev/null && log_error 'getconf should not be found' -log_info "TODO: If and when builtins are supported uncomment the next two lines and remove the third." -#builtin /bin/getconf -#PATH=/bin +builtin /bin/getconf +PATH=/bin PATH=$path PATH="$(getconf PATH)" x=$(whence ls) diff --git a/src/lib/libast/include/fts.h b/src/lib/libast/include/fts.h index d685cd2d0ed7..c263713bd3cc 100644 --- a/src/lib/libast/include/fts.h +++ b/src/lib/libast/include/fts.h @@ -1,160 +1,8 @@ -/*********************************************************************** - * * - * This software is part of the ast package * - * Copyright (c) 1985-2013 AT&T Intellectual Property * - * and is licensed under the * - * Eclipse Public License, Version 1.0 * - * by AT&T Intellectual Property * - * * - * A copy of the License is available at * - * http://www.eclipse.org/org/documents/epl-v10.html * - * (with md5 checksum b35adb5213ca9657e911e9befb180842) * - * * - * Information and Software Systems Research * - * AT&T Research * - * Florham Park NJ * - * * - * Glenn Fowler * - * David Korn * - * Phong Vo * - * * - ***********************************************************************/ -/* - * Glenn Fowler - * David Korn - * Phong Vo - * AT&T Research - * - * fts interface definitions - */ - #ifndef _FTS_H #define _FTS_H -#include -#include - -/* - * fts_open flags - */ - -#define FTS_LOGICAL 0 /* logical traversal, follow symlinks */ -#define FTS_META 0x00000001 /* follow top dir symlinks even if phys */ -#define FTS_NOCHDIR 0x00000002 /* don't chdir */ -#define FTS_NOPOSTORDER 0x00000004 /* no postorder visits */ -#define FTS_NOPREORDER 0x00000008 /* no preorder visits */ -#define FTS_NOSEEDOTDIR 0x00000800 /* never retain leading . dir */ -#define FTS_NOSTAT 0x00000010 /* don't stat children */ -#define FTS_ONEPATH 0x00000020 /* pathnames arg is one const char* */ -#define FTS_PHYSICAL 0x00000040 /* physical traversal, don't follow */ -#define FTS_SEEDOT 0x00000080 /* return . and .. */ -#define FTS_SEEDOTDIR 0x00000400 /* always retain leading . dir */ -#define FTS_TOP 0x00000100 /* don't traverse subdirectories */ -#define FTS_XDEV 0x00000200 /* don't cross mount points */ -#define FTS_WALK 0x00001000 /* 8 ftwalk() compatibility flag bits */ -#define FTS_XATTR 0x00100000 /* traverse extended attributes too */ - -#define FTS_COMFOLLOW FTS_META - -/* - * fts_info flags - */ - -#define FTS_DEFAULT 0 /* ok, someone must have wanted this */ - -#define FTS_NS 0x0001 /* stat failed */ -#define FTS_F 0x0002 /* file - not directory or symbolic link*/ -#define FTS_SL 0x0004 /* symbolic link */ -#define FTS_D 0x0008 /* directory - pre-order visit */ - -#define FTS_C 0x0010 /* causes cycle */ -#define FTS_ERR 0x0020 /* some other error */ -#define FTS_DD 0x0040 /* . or .. */ -#define FTS_NR 0x0080 /* cannot read */ -#define FTS_NX 0x0100 /* cannot search */ -#define FTS_OK 0x0200 /* no info but otherwise ok */ -#define FTS_P 0x0400 /* post-order visit */ -#define FTS_XR 0x0800 /* xattr dir */ -#define FTS_XC 0x1000 /* xattr child */ - -#define FTS_DC (FTS_D | FTS_C) /* dir - would cause cycle */ -#define FTS_DNR (FTS_D | FTS_NR) /* dir - no read permission */ -#define FTS_DNX (FTS_D | FTS_NX) /* dir - no search permission */ -#define FTS_DOT (FTS_D | FTS_DD) /* . or .. */ -#define FTS_DP (FTS_D | FTS_P) /* dir - post-order visit */ -#define FTS_NSOK (FTS_NS | FTS_OK) /* no stat (because you asked) */ -#define FTS_SLNONE (FTS_SL | FTS_NS) /* symlink - to nowhere */ - -/* - * fts_set flags - */ - -#define FTS_AGAIN FTS_TOP /* process entry again */ -#define FTS_FOLLOW FTS_META /* follow FTS_SL symlink */ -#define FTS_SKIP FTS_NOSTAT /* skip FTS_D directory */ -#define FTS_STAT FTS_PHYSICAL /* stat() done by user */ - -typedef struct Fts_s FTS; -typedef struct Ftsent_s FTSENT; - -struct Ftsent_s { - char *fts_accpath; /* path relative to . */ - char *fts_name; /* file name */ - char *fts_path; /* path relative to top dir */ - FTSENT *fts_cycle; /* offender if cycle */ - FTSENT *fts_link; /* next child */ - FTSENT *fts_parent; /* parent directory */ - struct stat *fts_statp; /* stat info */ -#ifdef _FTSENT_LOCAL_PRIVATE_ - _FTSENT_LOCAL_PRIVATE_ -#else - void *fts_pointer; /* local pointer value */ -#endif - long fts_number; /* local numeric value */ - int fts_errno; /* errno for this entry */ - unsigned short fts_info; /* info flags */ - - unsigned short _fts_namelen; /* old fts_namelen */ - unsigned short _fts_pathlen; /* old fts_pathlen */ - short _fts_level; /* old fts_level */ - - short _fts_status; /* compatibility */ - struct stat _fts_statb; /* compatibility */ - - FTS *fts; /* fts_open() handle */ - size_t fts_namelen; /* strlen(fts_name) */ - size_t fts_pathlen; /* strlen(fts_path) */ - ssize_t fts_level; /* file tree depth, 0 at top */ - int fts_dirfd; /* containing directory fd */ - -#ifdef _FTSENT_PRIVATE_ - _FTSENT_PRIVATE_ -#endif -}; - -struct Fts_s { - int fts_errno; /* last errno */ - void *fts_handle; /* user defined handle */ - -#ifdef _FTS_PRIVATE_ - _FTS_PRIVATE_ -#endif -}; - -#if _BLD_ast && defined(__EXPORT__) -#define extern __EXPORT__ -#endif - -extern FTSENT *fts_children(FTS *, int); -extern int fts_close(FTS *); -extern int fts_flags(void); -extern int fts_local(FTSENT *); -extern int fts_notify(int (*)(FTS *, FTSENT *, void *), void *); -extern FTS *fts_open(char *const *, int, int (*)(FTSENT *const *, FTSENT *const *)); -extern FTS *fts_openat(int, char *const *, int, int (*)(FTSENT *const *, FTSENT *const *)); -extern FTSENT *fts_read(FTS *); -extern int fts_set(FTS *, FTSENT *, int); +#include -#undef extern +extern int fts_flags(); #endif From 0badeceab233487cc5328ed99f37a849752ef151 Mon Sep 17 00:00:00 2001 From: Siteshwar Vashisht Date: Wed, 2 May 2018 21:26:36 +0200 Subject: [PATCH 2/5] Use standard flags for fts_open() in chmod builtin chmod builtin uses non standard flags provided by libast code. We should use the default flags provided by system libraries. Related: #499 --- src/lib/libast/include/fts.h | 8 -------- src/lib/libast/misc/fts.c | 4 ++-- src/lib/libcmd/chmod.c | 27 ++++++++++++++++++--------- 3 files changed, 20 insertions(+), 19 deletions(-) delete mode 100644 src/lib/libast/include/fts.h diff --git a/src/lib/libast/include/fts.h b/src/lib/libast/include/fts.h deleted file mode 100644 index c263713bd3cc..000000000000 --- a/src/lib/libast/include/fts.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _FTS_H -#define _FTS_H - -#include - -extern int fts_flags(); - -#endif diff --git a/src/lib/libast/misc/fts.c b/src/lib/libast/misc/fts.c index 5f1abccbaea5..133d99c7cdd6 100644 --- a/src/lib/libast/misc/fts.c +++ b/src/lib/libast/misc/fts.c @@ -47,6 +47,6 @@ fts_flags(void) if (streq(s, "logical")) return FTS_LOGICAL; if (streq(s, "physical")) - return FTS_PHYSICAL|FTS_SEEDOTDIR; - return FTS_META|FTS_PHYSICAL|FTS_SEEDOTDIR; + return FTS_PHYSICAL|FTS_SEEDOT; + return FTS_COMFOLLOW|FTS_PHYSICAL|FTS_SEEDOT; } diff --git a/src/lib/libcmd/chmod.c b/src/lib/libcmd/chmod.c index 0c48f975f424..bb700ae2cbdb 100644 --- a/src/lib/libcmd/chmod.c +++ b/src/lib/libcmd/chmod.c @@ -132,9 +132,13 @@ __STDPP__directive pragma pp : hide lchmod #endif #include +#include +#include #include #include +extern int fts_flags(); + #ifndef ENOSYS #define ENOSYS EINVAL #endif @@ -168,9 +172,10 @@ int b_chmod(int argc, char **argv, Shbltin_t *context) { int show = 0; int chlink = 0; struct stat st; + int recursive = 0; cmdinit(argc, argv, context, ERROR_CATALOG, ERROR_NOTIFY); - flags = fts_flags() | FTS_META | FTS_TOP | FTS_NOPOSTORDER | FTS_NOSEEDOTDIR; + flags = fts_flags() | FTS_COMFOLLOW; /* * NOTE: we diverge from the normal optget boilerplate @@ -203,20 +208,22 @@ int b_chmod(int argc, char **argv, Shbltin_t *context) { amode = ""; continue; case 'H': - flags |= FTS_META | FTS_PHYSICAL; + flags |= FTS_COMFOLLOW | FTS_PHYSICAL; logical = 0; continue; case 'L': - flags &= ~(FTS_META | FTS_PHYSICAL); + flags &= ~(FTS_COMFOLLOW | FTS_PHYSICAL); logical = 0; continue; case 'P': - flags &= ~FTS_META; + flags &= ~FTS_COMFOLLOW; flags |= FTS_PHYSICAL; logical = 0; continue; case 'R': - flags &= ~FTS_TOP; + // fts_open() does not support this flag, so instead use a different flag + //flags &= ~FTS_TOP; + recursive = 1; logical = 0; continue; case '?': @@ -229,11 +236,11 @@ int b_chmod(int argc, char **argv, Shbltin_t *context) { if (error_info.errors || !*argv || !amode && !*(argv + 1)) error(ERROR_usage(2), "%s", optusage(NULL)); if (chlink) { - flags &= ~FTS_META; + flags &= ~FTS_COMFOLLOW; flags |= FTS_PHYSICAL; logical = 0; } - if (logical) flags &= ~(FTS_META | FTS_PHYSICAL); + if (logical) flags &= ~(FTS_COMFOLLOW | FTS_PHYSICAL); if (ignore) ignore = umask(0); if (amode) amode = 0; @@ -287,13 +294,15 @@ int b_chmod(int argc, char **argv, Shbltin_t *context) { case FTS_DNR: if (!force) error(ERROR_system(0), "%s: cannot read directory", ent->fts_path); goto anyway; - case FTS_DNX: - if (!force) error(ERROR_system(0), "%s: cannot search directory", ent->fts_path); + case FTS_ERR: + if (!force) error(ERROR_system(0), "%s: %s", ent->fts_path, strerror(ent->fts_errno)); goto anyway; case FTS_NS: if (!force) error(ERROR_system(0), "%s: not found", ent->fts_path); break; } + // Unless '-R' is specified, avoid processing subdirectories. + if (!recursive) break; } fts_close(fts); if (ignore) umask(ignore); From 2eaa5c79f23607609f275eacfdbff21c492bca86 Mon Sep 17 00:00:00 2001 From: Siteshwar Vashisht Date: Wed, 2 May 2018 21:38:00 +0200 Subject: [PATCH 3/5] Reenable builtins for standard commands in several other places. Related: #499 --- src/cmd/ksh93/tests/builtins.sh | 4 ++-- src/cmd/ksh93/tests/coprocess.sh | 2 +- src/cmd/ksh93/tests/exit.sh | 2 +- src/cmd/ksh93/tests/heredoc.sh | 4 ++-- src/cmd/ksh93/tests/io.sh | 2 +- src/cmd/ksh93/tests/subshell.sh | 2 +- src/lib/libcmd/chmod.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cmd/ksh93/tests/builtins.sh b/src/cmd/ksh93/tests/builtins.sh index e8d4b068ea28..53cb674d5c66 100755 --- a/src/cmd/ksh93/tests/builtins.sh +++ b/src/cmd/ksh93/tests/builtins.sh @@ -19,7 +19,7 @@ ######################################################################## # test shell builtin commands -# builtin getconf +builtin getconf : ${foo=bar} || log_error ": failed" [[ $foo == bar ]] || log_error ": side effects failed" set -- - foobar @@ -690,7 +690,7 @@ $SHELL 2> /dev/null -c 'cd ""' && log_error 'cd "" not producing an error' [[ $($SHELL 2> /dev/null -c 'cd "";print hi') != hi ]] && log_error 'cd "" should not terminate script' bincat=$(whence -p cat) -# builtin cat +builtin cat out=$TEST_DIR/seq.out seq 11 >$out cmp -s <(print -- "$($bincat<( $bincat $out ) )") <(print -- "$(cat <( cat $out ) )") || log_error "builtin cat differs from $bincat" diff --git a/src/cmd/ksh93/tests/coprocess.sh b/src/cmd/ksh93/tests/coprocess.sh index 39371adaf731..cf7ce9031429 100755 --- a/src/cmd/ksh93/tests/coprocess.sh +++ b/src/cmd/ksh93/tests/coprocess.sh @@ -38,7 +38,7 @@ function ping # id } bincat=$(whence -p cat) -#builtin cat +builtin cat for cat in cat $bincat do diff --git a/src/cmd/ksh93/tests/exit.sh b/src/cmd/ksh93/tests/exit.sh index 9678ebfdf0ca..4d6999e19d03 100755 --- a/src/cmd/ksh93/tests/exit.sh +++ b/src/cmd/ksh93/tests/exit.sh @@ -33,7 +33,7 @@ function abspath # this for it to succeed. cd $TEST_DIR || { err_exit "cd $TEST_DIR failed"; exit 1; } -# builtin getconf +builtin getconf ABSHELL=$(abspath) print exit 0 >.profile ${ABSHELL} < "$f" <<- '!!!!' - # builtin cat + builtin cat : << EOF $PWD xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx @@ -526,7 +526,7 @@ $SHELL 2> /dev/null -c 'true <<- ++EOF++ || true "$(true)" ) > $f > /dev/null [[ $(<$f) == $'hello\nworld' ]] || log_error 'nested here-document fails' -# builtin cat +builtin cat exp='foo bar baz bork blah blarg' got=$(cat <<<"foo bar baz" 3<&0 <<<"$( in > out exec 1<> out - # builtin cat + builtin cat print -r -- "$( /dev/null [[ $? == 0 ]] || log_error 'builtin cat truncates files' diff --git a/src/cmd/ksh93/tests/subshell.sh b/src/cmd/ksh93/tests/subshell.sh index b2ac9a78e443..708ab6204617 100755 --- a/src/cmd/ksh93/tests/subshell.sh +++ b/src/cmd/ksh93/tests/subshell.sh @@ -18,7 +18,7 @@ # # ######################################################################## -# builtin getconf +builtin getconf bincat=$(PATH=$(getconf PATH) whence -p cat) z=() diff --git a/src/lib/libcmd/chmod.c b/src/lib/libcmd/chmod.c index bb700ae2cbdb..ab6ce607b8ff 100644 --- a/src/lib/libcmd/chmod.c +++ b/src/lib/libcmd/chmod.c @@ -221,7 +221,7 @@ int b_chmod(int argc, char **argv, Shbltin_t *context) { logical = 0; continue; case 'R': - // fts_open() does not support this flag, so instead use a different flag + // Standard fts_open() does not support this flag, so instead use a different flag //flags &= ~FTS_TOP; recursive = 1; logical = 0; From 734abd5ccd76dbefe356fbdbf2c93ab908a5bb2e Mon Sep 17 00:00:00 2001 From: Siteshwar Vashisht Date: Thu, 3 May 2018 15:28:25 +0200 Subject: [PATCH 4/5] Add a feature test for -D_FILE_OFFSET_BITS=64 Older versions of glibc do not have support for -D_FILE_OFFSET_BITS=64 in fts functions. This flag is enabled by default in all meson builds. Add a feature test for this macro and disable it if fts functions do not support it. --- features/fts.c | 4 ++++ features/meson.build | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 features/fts.c diff --git a/features/fts.c b/features/fts.c new file mode 100644 index 000000000000..e66174a6e8d5 --- /dev/null +++ b/features/fts.c @@ -0,0 +1,4 @@ +#include + +int main() { +} diff --git a/features/meson.build b/features/meson.build index 155719105dc6..37533ba9573b 100644 --- a/features/meson.build +++ b/features/meson.build @@ -231,6 +231,17 @@ posix_spawn_feature_result = cc.run(posix_spawn_feature_file, args: feature_test_args) feature_data.set10('_lib_posix_spawn', posix_spawn_feature_result.returncode() == 0) +# Meson adds -D_FILE_OFFSET_BITS=64 flag by default, but it does not work with fts functions in older versions +# of glibc. This feture test undefines it on such systems. +# https://github.com/mesonbuild/meson/issues/3519 +fts_feature_file = files('fts.c') +fts_feature_result = cc.compiles(fts_feature_file, + name: 'Check if -D_FILE_OFFSET_BITS=64 works with fts functions', + args: feature_test_args + ['-D_FILE_OFFSET_BITS=64']) +if not fts_feature_result + add_global_arguments('-U_FILE_OFFSET_BITS', language: 'c') +endif + newgrp = find_program('newgrp', required: false) feature_data.set10('_cmd_newgrp', newgrp.found()) From f90931a9e6ecabf8568c2df6d3531d56f6b1d4ad Mon Sep 17 00:00:00 2001 From: Siteshwar Vashisht Date: Fri, 4 May 2018 12:44:59 +0200 Subject: [PATCH 5/5] Fix expected output of a builtin test case If .sh.op_astbin is changed, shell builtins will be bound to path specified by it. This test case fails on systems that do not have cmp and basename under /bin directory, so fix it's expected output. Related: #499 --- src/cmd/ksh93/tests/builtins.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/ksh93/tests/builtins.sh b/src/cmd/ksh93/tests/builtins.sh index 53cb674d5c66..773fc1f61b7f 100755 --- a/src/cmd/ksh93/tests/builtins.sh +++ b/src/cmd/ksh93/tests/builtins.sh @@ -808,8 +808,8 @@ PATH=/opt/ast/bin:/bin:/usr/bin .sh.op_astbin=/bin SH_OPTIONS=astbin=/bin [[ ${SH_OPTIONS} == *astbin=/bin* ]] || log_error "SH_OPTIONS=${SH_OPTIONS} but should contain astbin=/bin" -[[ $(whence basename) == "$basename" ]] || log_error "basename bound to $(whence basename) but should be bound to $basename" -[[ $(whence cmp) == "$cmp" ]] || log_error "cmp bound to $(whence cmp) but should be bound to $cmp" +[[ $(whence basename) == /bin/basename ]] || log_error "basename bound to $(whence basename) but should be bound to /bin/basename" +[[ $(whence cmp) == /bin/cmp ]] || log_error "cmp bound to $(whence cmp) but should be bound to /bin/cmp" .sh.op_astbin=/opt/ast/bin [[ $(whence basename) == /opt/ast/bin/basename ]] || log_error "basename bound to $(whence basename) but should be rebound to /opt/ast/bin/basename" [[ $(whence cmp) == /opt/ast/bin/cmp ]] || log_error "cmp bound to $(whence cmp) but should be rebound to /opt/ast/bin/cmp"