more symlink(7) nonexistence support code

This commit is contained in:
tg 2012-05-04 22:05:02 +00:00
parent 401116766b
commit fef3808126
5 changed files with 23 additions and 8 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.560 2012/05/04 21:57:36 tg Exp $' srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.561 2012/05/04 22:04:58 tg Exp $'
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012 # 2011, 2012
@ -502,6 +502,7 @@ BSD/OS)
;; ;;
Coherent) Coherent)
oswarn="; it has major issues" oswarn="; it has major issues"
add_cppflags -DMKSH__NO_SYMLINK
check_categories="$check_categories nosymlink" check_categories="$check_categories nosymlink"
add_cppflags -DMKSH__NO_SETEUGID add_cppflags -DMKSH__NO_SETEUGID
;; ;;
@ -1408,7 +1409,7 @@ else
#define EXTERN #define EXTERN
#define MKSH_INCLUDES_ONLY #define MKSH_INCLUDES_ONLY
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.560 2012/05/04 21:57:36 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.561 2012/05/04 22:04:58 tg Exp $");
int main(void) { printf("Hello, World!\n"); return (0); } int main(void) { printf("Hello, World!\n"); return (0); }
EOF EOF
case $cm in case $cm in

4
eval.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.117 2012/04/22 21:50:31 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/eval.c,v 1.118 2012/05/04 22:05:00 tg Exp $");
/* /*
* string expansion * string expansion
@ -1437,7 +1437,7 @@ globit(XString *xs, /* dest string */
struct stat lstatb, statb; struct stat lstatb, statb;
int stat_done = 0; /* -1: failed, 1 ok */ int stat_done = 0; /* -1: failed, 1 ok */
if (lstat(Xstring(*xs, xp), &lstatb) < 0) if (mksh_lstat(Xstring(*xs, xp), &lstatb) < 0)
return; return;
/* /*
* special case for systems which strip trailing * special case for systems which strip trailing

View File

@ -38,7 +38,7 @@
#endif #endif
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.216 2012/05/04 21:47:01 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.217 2012/05/04 22:05:00 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
/* /*
@ -2943,7 +2943,11 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
/* -h or -L */ /* -h or -L */
case TO_FILSYM: case TO_FILSYM:
#ifdef MKSH__NO_SYMLINK
return (0);
#else
return (lstat(opnd1, &b1) == 0 && S_ISLNK(b1.st_mode)); return (lstat(opnd1, &b1) == 0 && S_ISLNK(b1.st_mode));
#endif
/* -S */ /* -S */
case TO_FILSOCK: case TO_FILSOCK:

6
misc.c
View File

@ -30,7 +30,7 @@
#include <grp.h> #include <grp.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.190 2012/05/04 21:57:38 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.191 2012/05/04 22:05:02 tg Exp $");
/* type bits for unsigned char */ /* type bits for unsigned char */
unsigned char chtypes[UCHAR_MAX + 1]; unsigned char chtypes[UCHAR_MAX + 1];
@ -1389,7 +1389,7 @@ do_realpath(const char *upath)
*xp = '\0'; *xp = '\0';
/* lstat the current output, see if it's a symlink */ /* lstat the current output, see if it's a symlink */
if (lstat(Xstring(xs, xp), &sb)) { if (mksh_lstat(Xstring(xs, xp), &sb)) {
/* lstat failed */ /* lstat failed */
if (errno == ENOENT) { if (errno == ENOENT) {
/* because the pathname does not exist */ /* because the pathname does not exist */
@ -1406,6 +1406,7 @@ do_realpath(const char *upath)
goto notfound; goto notfound;
} }
#ifndef MKSH__NO_SYMLINK
/* check if we encountered a symlink? */ /* check if we encountered a symlink? */
if (S_ISLNK(sb.st_mode)) { if (S_ISLNK(sb.st_mode)) {
/* reached maximum recursion depth? */ /* reached maximum recursion depth? */
@ -1456,6 +1457,7 @@ do_realpath(const char *upath)
} }
} }
} }
#endif
/* otherwise (no symlink) merely go on */ /* otherwise (no symlink) merely go on */
} }

10
sh.h
View File

@ -152,7 +152,7 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.555 2012/05/04 21:47:03 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.556 2012/05/04 22:05:02 tg Exp $");
#endif #endif
#define MKSH_VERSION "R40 2012/04/27" #define MKSH_VERSION "R40 2012/04/27"
@ -358,6 +358,14 @@ extern int __cdecl setegid(gid_t);
#define mksh_TIME(tv) gettimeofday(&(tv), NULL) #define mksh_TIME(tv) gettimeofday(&(tv), NULL)
#endif #endif
#ifdef MKSH__NO_SYMLINK
#undef S_ISLNK
#define S_ISLNK(m) (/* CONSTCOND */ 0)
#define mksh_lstat stat
#else
#define mksh_lstat lstat
#endif
/* remove redundancies */ /* remove redundancies */
#if defined(MirBSD) && (MirBSD >= 0x08A8) && !defined(MKSH_OPTSTATIC) #if defined(MirBSD) && (MirBSD >= 0x08A8) && !defined(MKSH_OPTSTATIC)