211 lines
5.7 KiB
Plaintext
211 lines
5.7 KiB
Plaintext
--- src/cmd/ksh93/bltins/trap.c
|
|
+++ src/cmd/ksh93/bltins/trap.c 2012-10-23 15:45:37.000000000 +0000
|
|
@@ -102,6 +102,7 @@ int b_trap(int argc,char *argv[],Shbltin
|
|
/* internal traps */
|
|
if(sig&SH_TRAP)
|
|
{
|
|
+ char **trap = (shp->st.otrap?shp->st.otrap:shp->st.trap);
|
|
sig &= ~SH_TRAP;
|
|
if(sig>SH_DEBUGTRAP)
|
|
{
|
|
@@ -110,10 +111,11 @@ int b_trap(int argc,char *argv[],Shbltin
|
|
}
|
|
if(pflag)
|
|
{
|
|
- if(arg=shp->st.trap[sig])
|
|
+ if(arg=trap[sig])
|
|
sfputr(sfstdout,sh_fmtq(arg),'\n');
|
|
continue;
|
|
}
|
|
+ shp->st.otrap = 0;
|
|
if(shp->st.trap[sig])
|
|
free(shp->st.trap[sig]);
|
|
shp->st.trap[sig] = 0;
|
|
@@ -402,7 +404,7 @@ static void sig_list(register Shell_t *s
|
|
}
|
|
for(sig=SH_DEBUGTRAP; sig>=0; sig--)
|
|
{
|
|
- if(!(trap=shp->st.trap[sig]))
|
|
+ if(!(trap=shp->st.otrap?shp->st.otrap[sig]:shp->st.trap[sig]))
|
|
continue;
|
|
sfprintf(sfstdout,trapfmt,sh_fmtq(trap),traps[sig]);
|
|
}
|
|
--- src/cmd/ksh93/include/defs.h
|
|
+++ src/cmd/ksh93/include/defs.h 2012-10-23 15:42:45.000000000 +0000
|
|
@@ -90,6 +90,7 @@ struct sh_scoped
|
|
int ioset;
|
|
unsigned short trapmax;
|
|
char *trap[SH_DEBUGTRAP+1];
|
|
+ char **otrap;
|
|
char **trapcom;
|
|
char **otrapcom;
|
|
void *timetrap;
|
|
--- src/cmd/ksh93/include/shnodes.h
|
|
+++ src/cmd/ksh93/include/shnodes.h 2012-10-23 14:23:06.000000000 +0000
|
|
@@ -211,7 +211,7 @@ union Shnode_u
|
|
|
|
extern void sh_freeup(Shell_t*);
|
|
extern void sh_funstaks(struct slnod*,int);
|
|
-extern Sfio_t *sh_subshell(Shell_t*,Shnode_t*, int, int);
|
|
+extern Sfio_t *sh_subshell(Shell_t*,Shnode_t*, volatile int, int);
|
|
#if defined(__EXPORT__) && defined(_BLD_DLL) && defined(_BLD_shell)
|
|
__EXPORT__
|
|
#endif
|
|
--- src/cmd/ksh93/sh/subshell.c
|
|
+++ src/cmd/ksh93/sh/subshell.c 2012-10-25 10:09:34.574345265 +0000
|
|
@@ -455,7 +455,7 @@ void sh_subjobcheck(pid_t pid)
|
|
* output of command <t>. Otherwise, NULL will be returned.
|
|
*/
|
|
|
|
-Sfio_t *sh_subshell(Shell_t *shp,Shnode_t *t, int flags, int comsub)
|
|
+Sfio_t *sh_subshell(Shell_t *shp,Shnode_t *t, volatile int flags, int comsub)
|
|
{
|
|
struct subshell sub_data;
|
|
register struct subshell *sp = &sub_data;
|
|
@@ -528,6 +528,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
|
|
sh_stats(STAT_SUBSHELL);
|
|
/* save trap table */
|
|
shp->st.otrapcom = 0;
|
|
+ shp->st.otrap = savst.trap;
|
|
if((nsig=shp->st.trapmax*sizeof(char*))>0 || shp->st.trapcom[0])
|
|
{
|
|
nsig += sizeof(char*);
|
|
@@ -602,6 +603,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
|
|
}
|
|
if(!shp->savesig)
|
|
shp->savesig = -1;
|
|
+ nv_restore(sp);
|
|
if(comsub)
|
|
{
|
|
/* re-enable job control */
|
|
@@ -666,7 +668,6 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
|
|
{
|
|
int n;
|
|
shp->options = sp->options;
|
|
- nv_restore(sp);
|
|
if(sp->salias)
|
|
{
|
|
shp->alias_tree = dtview(sp->salias,0);
|
|
@@ -685,6 +686,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
|
|
memset(&shp->st.trapcom[savst.trapmax],0,n*sizeof(char*));
|
|
shp->st = savst;
|
|
shp->curenv = savecurenv;
|
|
+ shp->st.otrap = 0;
|
|
if(nsig)
|
|
{
|
|
memcpy((char*)&shp->st.trapcom[0],savsig,nsig);
|
|
--- src/lib/libast/path/pathtemp.c
|
|
+++ src/lib/libast/path/pathtemp.c 2012-10-25 10:35:14.510345073 +0000
|
|
@@ -73,15 +73,49 @@
|
|
#include <ls.h>
|
|
#include <tv.h>
|
|
#include <tm.h>
|
|
+#include <error.h>
|
|
|
|
#define ATTEMPT 10
|
|
|
|
#define TMP_ENV "TMPDIR"
|
|
#define TMP_PATH_ENV "TMPPATH"
|
|
#define TMP1 "/tmp"
|
|
-#define TMP2 "/usr/tmp"
|
|
+#define TMP2 "/var/tmp"
|
|
|
|
-#define VALID(d) (*(d)&&!eaccess(d,W_OK|X_OK))
|
|
+static inline int xaccess(const char *path, int mode)
|
|
+{
|
|
+ static size_t pgsz;
|
|
+ struct statvfs vfs;
|
|
+ int ret;
|
|
+
|
|
+ if (!pgsz)
|
|
+ pgsz = strtoul(astconf("PAGESIZE",NiL,NiL),NiL,0);
|
|
+
|
|
+ if (!path || !*path)
|
|
+ {
|
|
+ errno = EFAULT;
|
|
+ goto err;
|
|
+ }
|
|
+
|
|
+ do
|
|
+ ret = statvfs(path, &vfs);
|
|
+ while (ret < 0 && errno == EINTR);
|
|
+
|
|
+ if (ret < 0)
|
|
+ goto err;
|
|
+
|
|
+ if (vfs.f_frsize*vfs.f_bavail < pgsz)
|
|
+ {
|
|
+ errno = ENOSPC;
|
|
+ goto err;
|
|
+ }
|
|
+
|
|
+ return eaccess(path, mode);
|
|
+err:
|
|
+ return -1;
|
|
+}
|
|
+
|
|
+#define VALID(d) (*(d)&&!xaccess(d,W_OK|X_OK))
|
|
|
|
static struct
|
|
{
|
|
@@ -182,7 +216,7 @@ pathtemp(char* buf, size_t len, const ch
|
|
tv.tv_nsec = 0;
|
|
else
|
|
tvgettime(&tv);
|
|
- if (!(d = (char*)dir) || *d && eaccess(d, W_OK|X_OK))
|
|
+ if (!(d = (char*)dir) || (*d && xaccess(d, W_OK|X_OK)))
|
|
{
|
|
if (!tmp.vec)
|
|
{
|
|
@@ -227,7 +261,7 @@ pathtemp(char* buf, size_t len, const ch
|
|
tmp.dir = tmp.vec;
|
|
d = *tmp.dir++;
|
|
}
|
|
- if (!d && (!*(d = astconf("TMP", NiL, NiL)) || eaccess(d, W_OK|X_OK)) && eaccess(d = TMP1, W_OK|X_OK) && eaccess(d = TMP2, W_OK|X_OK))
|
|
+ if (!d && (!*(d = astconf("TMP", NiL, NiL)) || xaccess(d, W_OK|X_OK)) && xaccess(d = TMP1, W_OK|X_OK) && xaccess(d = TMP2, W_OK|X_OK))
|
|
return 0;
|
|
}
|
|
if (!len)
|
|
--- src/lib/libast/sfio/sftmp.c
|
|
+++ src/lib/libast/sfio/sftmp.c 2012-10-25 12:09:18.026344912 +0000
|
|
@@ -20,6 +20,14 @@
|
|
* *
|
|
***********************************************************************/
|
|
#include "sfhdr.h"
|
|
+#if _PACKAGE_ast
|
|
+# if defined(__linux__) && _lib_statfs
|
|
+# include <sys/statfs.h>
|
|
+# ifndef TMPFS_MAGIC
|
|
+# define TMPFS_MAGIC 0x01021994
|
|
+# endif
|
|
+# endif
|
|
+#endif
|
|
|
|
/* Create a temporary stream for read/write.
|
|
** The stream is originally created as a memory-resident stream.
|
|
@@ -207,7 +215,24 @@ Sfio_t* f;
|
|
int fd;
|
|
|
|
#if _PACKAGE_ast
|
|
+# if defined(__linux__) && _lib_statfs
|
|
+ /*
|
|
+ * Use the area of POSIX shared memory objects for the new temporary file descriptor
|
|
+ * that is do not access HD or SSD but only the memory based tmpfs of the POSIX SHM
|
|
+ */
|
|
+ static int doshm;
|
|
+ static char *shm = "/dev/shm";
|
|
+ if (!doshm)
|
|
+ {
|
|
+ struct statfs fs;
|
|
+ if (statfs(shm, &fs) < 0 || fs.f_type != TMPFS_MAGIC || eaccess(shm, W_OK|X_OK))
|
|
+ shm = NiL;
|
|
+ doshm++;
|
|
+ }
|
|
+ if(!(file = pathtemp(NiL,PATH_MAX,shm,"sf",&fd)))
|
|
+# else
|
|
if(!(file = pathtemp(NiL,PATH_MAX,NiL,"sf",&fd)))
|
|
+# endif
|
|
return -1;
|
|
_rmtmp(f, file);
|
|
free(file);
|