Roland Mainz
2013-08-10 02:55:17 UTC
Hi!
----
Attached (as "astksh20130807_solaris_cd_fixes001.diff.txt") is a patch
(technically the 4th or 5th attempt to submit this patch... ;-( ) to
get cd(1) fixed on platforms like Solaris/AIX/etc.
* Issues fixed:
- cd -@ shoud use correct error handling
- |rehash()| is a libc function on some systems and causes issues on
such platforms... the patch renames |rehash()| to
|rehash_relpathbindings()|
- Don't use |fstat()| to test for directory if we have |O_DIRECTORY|.
Fixes Solaris's samfs
- src/cmd/ksh93/include/shell.h - add a comment for |shp->pwdfd| to
explain which functions should be used to obtain this file descriptor
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
-------------- next part --------------
diff -r -u original/src/cmd/ksh93/bltins/cd_pwd.c build_cdfix/src/cmd/ksh93/bltins/cd_pwd.c
--- src/cmd/ksh93/bltins/cd_pwd.c 2013-07-22 20:59:06.000000000 +0200
+++ src/cmd/ksh93/bltins/cd_pwd.c 2013-08-10 04:34:50.715023380 +0200
@@ -41,7 +41,7 @@
/*
* Invalidate path name bindings to relative paths
*/
-static void rehash(register Namval_t *np,void *data)
+static void rehash_relpathbindings(register Namval_t *np,void *data)
{
Pathcomp_t *pp = (Pathcomp_t*)np->nvalue.cp;
NOT_USED(data);
@@ -49,6 +49,10 @@
_nv_unset(np,0);
}
+#if _ast_O_LOCAL && O_DIRECTORY >= _ast_O_LOCAL
+#define O_DIRECTORY_EMULATED 1
+#endif
+
/*
* Obtain a file handle to the directory "path" relative to directory
* "dir", or open a NFSv4 xattr directory handle for file dir/path.
@@ -56,8 +60,10 @@
int sh_diropenat(Shell_t *shp, int dir, const char *path, bool xattr)
{
int fd,shfd;
- int savederrno=errno;
+ int savederrno;
+#ifdef O_DIRECTORY_EMULATED
struct stat fs;
+#endif
#ifndef O_XATTR
NOT_USED(xattr);
#endif
@@ -70,7 +76,9 @@
if((apfd = openat(dir, path, O_RDONLY|O_NONBLOCK|O_CLOEXEC))>=0)
{
fd = openat(apfd, e_dot, O_XATTR|O_CLOEXEC);
+ savederrno=errno
close(apfd);
+ errno=savederrno;
}
}
else
@@ -79,12 +87,15 @@
if(fd < 0)
return fd;
+/* Only stat the fd if we don't have a native O_DIRECTORY */
+#ifdef O_DIRECTORY_EMULATED
if (!fstat(fd, &fs) && !S_ISDIR(fs.st_mode))
{
close(fd);
errno = ENOTDIR;
return -1;
}
+#endif
/* Move fd to a number > 10 and register the fd number with the shell */
shfd = sh_fcntl(fd, F_DUPFD_CLOEXEC, 10);
@@ -418,7 +429,7 @@
nv_putval(pwdnod,dir,NV_RDONLY);
nv_onattr(pwdnod,NV_NOFREE|NV_EXPORT);
shp->pwd = pwdnod->nvalue.cp;
- nv_scan(shp->track_tree,rehash,(void*)0,NV_TAGGED,NV_TAGGED);
+ nv_scan(shp->track_tree,rehash_relpathbindings,(void*)0,NV_TAGGED,NV_TAGGED);
path_newdir(shp,shp->pathlist);
path_newdir(shp,shp->cdpathlist);
if(oldpwd)
diff -r -u original/src/cmd/ksh93/include/shell.h build_cdfix/src/cmd/ksh93/include/shell.h
--- src/cmd/ksh93/include/shell.h 2013-07-23 03:12:23.000000000 +0200
+++ src/cmd/ksh93/include/shell.h 2013-08-10 04:34:50.716023502 +0200
@@ -155,7 +155,7 @@
char shcomp; /* set when runing shcomp */
short subshell; /* set for virtual subshell */
Stk_t *stk; /* stack poiter */
- int pwdfd; /* file descriptor for pwd */
+ int pwdfd; /* file descriptor for pwd (must be from sh_diropenat()/sh_fcntl()!) */
#ifdef _SH_PRIVATE
_SH_PRIVATE
#endif /* _SH_PRIVATE */
----
Attached (as "astksh20130807_solaris_cd_fixes001.diff.txt") is a patch
(technically the 4th or 5th attempt to submit this patch... ;-( ) to
get cd(1) fixed on platforms like Solaris/AIX/etc.
* Issues fixed:
- cd -@ shoud use correct error handling
- |rehash()| is a libc function on some systems and causes issues on
such platforms... the patch renames |rehash()| to
|rehash_relpathbindings()|
- Don't use |fstat()| to test for directory if we have |O_DIRECTORY|.
Fixes Solaris's samfs
- src/cmd/ksh93/include/shell.h - add a comment for |shp->pwdfd| to
explain which functions should be used to obtain this file descriptor
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
-------------- next part --------------
diff -r -u original/src/cmd/ksh93/bltins/cd_pwd.c build_cdfix/src/cmd/ksh93/bltins/cd_pwd.c
--- src/cmd/ksh93/bltins/cd_pwd.c 2013-07-22 20:59:06.000000000 +0200
+++ src/cmd/ksh93/bltins/cd_pwd.c 2013-08-10 04:34:50.715023380 +0200
@@ -41,7 +41,7 @@
/*
* Invalidate path name bindings to relative paths
*/
-static void rehash(register Namval_t *np,void *data)
+static void rehash_relpathbindings(register Namval_t *np,void *data)
{
Pathcomp_t *pp = (Pathcomp_t*)np->nvalue.cp;
NOT_USED(data);
@@ -49,6 +49,10 @@
_nv_unset(np,0);
}
+#if _ast_O_LOCAL && O_DIRECTORY >= _ast_O_LOCAL
+#define O_DIRECTORY_EMULATED 1
+#endif
+
/*
* Obtain a file handle to the directory "path" relative to directory
* "dir", or open a NFSv4 xattr directory handle for file dir/path.
@@ -56,8 +60,10 @@
int sh_diropenat(Shell_t *shp, int dir, const char *path, bool xattr)
{
int fd,shfd;
- int savederrno=errno;
+ int savederrno;
+#ifdef O_DIRECTORY_EMULATED
struct stat fs;
+#endif
#ifndef O_XATTR
NOT_USED(xattr);
#endif
@@ -70,7 +76,9 @@
if((apfd = openat(dir, path, O_RDONLY|O_NONBLOCK|O_CLOEXEC))>=0)
{
fd = openat(apfd, e_dot, O_XATTR|O_CLOEXEC);
+ savederrno=errno
close(apfd);
+ errno=savederrno;
}
}
else
@@ -79,12 +87,15 @@
if(fd < 0)
return fd;
+/* Only stat the fd if we don't have a native O_DIRECTORY */
+#ifdef O_DIRECTORY_EMULATED
if (!fstat(fd, &fs) && !S_ISDIR(fs.st_mode))
{
close(fd);
errno = ENOTDIR;
return -1;
}
+#endif
/* Move fd to a number > 10 and register the fd number with the shell */
shfd = sh_fcntl(fd, F_DUPFD_CLOEXEC, 10);
@@ -418,7 +429,7 @@
nv_putval(pwdnod,dir,NV_RDONLY);
nv_onattr(pwdnod,NV_NOFREE|NV_EXPORT);
shp->pwd = pwdnod->nvalue.cp;
- nv_scan(shp->track_tree,rehash,(void*)0,NV_TAGGED,NV_TAGGED);
+ nv_scan(shp->track_tree,rehash_relpathbindings,(void*)0,NV_TAGGED,NV_TAGGED);
path_newdir(shp,shp->pathlist);
path_newdir(shp,shp->cdpathlist);
if(oldpwd)
diff -r -u original/src/cmd/ksh93/include/shell.h build_cdfix/src/cmd/ksh93/include/shell.h
--- src/cmd/ksh93/include/shell.h 2013-07-23 03:12:23.000000000 +0200
+++ src/cmd/ksh93/include/shell.h 2013-08-10 04:34:50.716023502 +0200
@@ -155,7 +155,7 @@
char shcomp; /* set when runing shcomp */
short subshell; /* set for virtual subshell */
Stk_t *stk; /* stack poiter */
- int pwdfd; /* file descriptor for pwd */
+ int pwdfd; /* file descriptor for pwd (must be from sh_diropenat()/sh_fcntl()!) */
#ifdef _SH_PRIVATE
_SH_PRIVATE
#endif /* _SH_PRIVATE */