Dr. Werner Fink 2012-10-23 16:04:15 +00:00 committed by Git OBS Bridge
parent 8f37f5f00b
commit d282bb808d
3 changed files with 202 additions and 0 deletions

View File

@ -1,3 +1,12 @@
-------------------------------------------------------------------
Tue Oct 23 13:23:12 UTC 2012 - werner@suse.de
- Add a workaround for filled /tmp file systems (bnc#786134)
- Check for subshell if tmp file can be used otherwise use a
a pipe (bnc#786134)
- Restore shell variables before any outpur will be placed in
a temp file or buffer (bnc#786134)
-------------------------------------------------------------------
Fri Oct 19 15:06:50 UTC 2012 - werner@suse.de

View File

@ -112,6 +112,7 @@ Patch26: ksh93-read-dont-ignore-esc.dif
Patch27: astksh_builtin_poll20120806_001.diff
Patch28: ksh93-env.dif
Patch29: ksh93-zerofill.dif
Patch30: ksh93-pathtemp.dif
Patch42: ksh-locale.patch
%description
@ -197,6 +198,7 @@ fi
%patch27
%patch28
%patch29
%patch30
%build
#

191
ksh93-pathtemp.dif Normal file
View File

@ -0,0 +1,191 @@
--- src/cmd/ksh93/include/defs.h
+++ src/cmd/ksh93/include/defs.h 2012-10-23 15:42:45.466344876 +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:05.970344416 +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/bltins/trap.c
+++ src/cmd/ksh93/bltins/trap.c 2012-10-23 15:45:36.794417080 +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/sh/subshell.c
+++ src/cmd/ksh93/sh/subshell.c 2012-10-23 14:45:56.622344699 +0000
@@ -35,6 +35,8 @@
#include "jobs.h"
#include "variables.h"
#include "path.h"
+#include <sys/statfs.h>
+#include <errno.h>
#ifndef PIPE_BUF
# define PIPE_BUF 512
@@ -99,6 +101,20 @@ static struct subshell
static int subenv;
+static inline int leftspace(const int fd)
+{
+ struct statfs st;
+ int ret;
+ if (fd < 0)
+ return 0;
+ do
+ ret = fstatfs(fd, &st);
+ while (ret < 0 && errno == EINTR);
+
+ if (ret < 0 || st.f_bavail < 2)
+ return 0;
+ return 1;
+}
/*
* This routine will turn the sftmp() file into a real /tmp file or pipe
@@ -122,7 +138,7 @@ void sh_subtmpfile(Shell_t *shp)
errormsg(SH_DICT,ERROR_system(1),e_toomany);
/* popping a discipline forces a /tmp file create */
sfdisc(sfstdout,SF_POPDISC);
- if((fd=sffileno(sfstdout))<0)
+ if((fd=sffileno(sfstdout))<0 || !leftspace(fd))
{
/* unable to create the /tmp file so use a pipe */
int fds[3];
@@ -455,7 +471,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 +544,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 +619,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 +684,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 +702,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-23 12:59:09.542344910 +0000
@@ -73,15 +73,32 @@
#include <ls.h>
#include <tv.h>
#include <tm.h>
+#include <sys/statfs.h>
+#include <errno.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 leftspace(const char *dir)
+{
+ struct statfs st;
+ int ret;
+ if (!dir || !*dir)
+ return 0;
+ do
+ ret = statfs(dir, &st);
+ while (ret < 0 && errno == EINTR);
+
+ if (ret < 0 || st.f_bavail < 2)
+ return 0;
+ return 1;
+}
+
+#define VALID(d) (*(d)&&!eaccess(d,W_OK|X_OK)&&leftspace(d))
static struct
{
@@ -182,7 +199,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 && (eaccess(d, W_OK|X_OK) || !leftspace(d))))
{
if (!tmp.vec)
{
@@ -227,7 +244,8 @@ 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)) || eaccess(d, W_OK|X_OK) || !leftspace(d)) &&
+ (eaccess(d = TMP1, W_OK|X_OK) || !leftspace(d)) && (eaccess(d = TMP2, W_OK|X_OK) || !leftspace(d)))
return 0;
}
if (!len)