Skip to content

Commit

Permalink
libast: sfio(3) fixes from ksh 93v- beta
Browse files Browse the repository at this point in the history
These fixes were backported by OpenSUSE. Original patch:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-sfio.dif
  • Loading branch information
McDutchie committed Feb 2, 2021
1 parent 6397948 commit 1bd0620
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 30 deletions.
12 changes: 7 additions & 5 deletions src/lib/libast/include/sfio_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define _SFIO_PRIVATE \
Sfoff_t extent; /* current file size */ \
Sfoff_t here; /* current physical location */ \
unsigned char unused_1;/* unused #1 */ \
unsigned char ngetr; /* sfgetr count */ \
unsigned char tiny[1];/* for unbuffered read stream */ \
unsigned short bits; /* private flags */ \
unsigned int mode; /* current io mode */ \
Expand Down Expand Up @@ -82,7 +82,7 @@
(ssize_t)(-1), /* val */ \
(Sfoff_t)0, /* extent */ \
(Sfoff_t)0, /* here */ \
0, /* getr */ \
0, /* ngetr */ \
{0}, /* tiny */ \
0, /* bits */ \
(unsigned int)(((type)&(SF_RDWR))|SF_INIT), /* mode */ \
Expand All @@ -93,7 +93,8 @@
(mutex), /* mutex */ \
(Void_t*)0, /* stdio */ \
(Sfoff_t)0, /* lpos */ \
(size_t)0 /* iosz */ \
(size_t)0, /* iosz */ \
0 /* getr */ \
}

/* function to clear an Sfio_t structure */
Expand All @@ -110,7 +111,7 @@
(f)->val = (ssize_t)(-1), /* val */ \
(f)->extent = (Sfoff_t)(-1), /* extent */ \
(f)->here = (Sfoff_t)0, /* here */ \
(f)->getr = 0, /* getr */ \
(f)->ngetr = 0, /* ngetr */ \
(f)->tiny[0] = 0, /* tiny */ \
(f)->bits = 0, /* bits */ \
(f)->mode = 0, /* mode */ \
Expand All @@ -121,7 +122,8 @@
(f)->mutex = (mtx), /* mutex */ \
(f)->stdio = (Void_t*)0, /* stdio */ \
(f)->lpos = (Sfoff_t)0, /* lpos */ \
(f)->iosz = (size_t)0 /* iosz */ \
(f)->iosz = (size_t)0, /* iosz */ \
(f)->getr = 0 /* getr */ \
)

/* expose next stream inside discipline function; state saved in int f */
Expand Down
20 changes: 12 additions & 8 deletions src/lib/libast/sfio/sfmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ reg Sfio_t* f; /* stream to close */
#endif
{
Sfproc_t* p;
int pid, status;
int status;

if(!(p = f->proc))
return -1;
Expand All @@ -279,7 +279,7 @@ reg Sfio_t* f; /* stream to close */
sigcritical(SIG_REG_EXEC|SIG_REG_PROC);
#endif
status = -1;
while ((pid = waitpid(p->pid,&status,0)) == -1 && errno == EINTR)
while (waitpid(p->pid,&status,0) == -1 && errno == EINTR)
;
#if _PACKAGE_ast
status = status == -1 ?
Expand Down Expand Up @@ -404,13 +404,17 @@ reg int local; /* a local call */

if(f->mode&SF_GETR)
{ f->mode &= ~SF_GETR;
#if defined(MAP_TYPE) && (_ptr_bits < 64)
if((f->bits&SF_MMAP) && (f->tiny[0] += 1) >= (4*SF_NMAP) )
{ /* turn off mmap to avoid page faulting */
sfsetbuf(f,(Void_t*)f->tiny,(size_t)SF_UNBOUND);
f->tiny[0] = 0;
#ifdef MAP_TYPE
if(f->bits&SF_MMAP)
{
if (!++f->ngetr)
f->tiny[0]++;
if(((f->tiny[0]<<8)|f->ngetr) >= (4*SF_NMAP) )
{ /* turn off mmap to avoid page faulting */
sfsetbuf(f,(Void_t*)f->tiny,(size_t)SF_UNBOUND);
f->ngetr = f->tiny[0] = 0;
}
}
else
#endif
if(f->getr)
{ f->next[-1] = f->getr;
Expand Down
6 changes: 5 additions & 1 deletion src/lib/libast/sfio/sfmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ reg int rc; /* record separator */

/* try reading a block of data */
direct = 0;
if((r = fr->endb - (next = fr->next)) <= 0)
if(fr->rsrv && (r = -fr->rsrv->slen) > 0)
{ fr->rsrv->slen = 0;
next = fr->rsrv->data;
}
else if((r = fr->endb - (next = fr->next)) <= 0)
{ /* amount of data remained to be read */
if((w = n > MAX_SSIZE ? MAX_SSIZE : (ssize_t)n) < 0)
{ if(fr->extent < 0)
Expand Down
9 changes: 5 additions & 4 deletions src/lib/libast/sfio/sfpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int tm; /* time in millisecs for select/poll */
while((np = SFPOLL(fds,m,tm)) < 0 )
{ if(errno == eintr || errno == EAGAIN)
errno = 0;
else break;
else goto report;
}
if(np > 0) /* poll succeeded */
np = c;
Expand All @@ -147,14 +147,14 @@ int tm; /* time in millisecs for select/poll */
{ f = fa[check[r]];

if((f->flags&SF_WRITE) && !WRREADY(f) )
{ if(fds[m].revents&POLLOUT)
{ if(fds[m].revents&(POLLOUT|POLLHUP|POLLERR))
status[check[r]] |= SF_WRITE;
}

if((f->flags&SF_READ) && !RDREADY(f))
{ if((f->mode&SF_WRITE) && HASAUXFD(f))
m += 1;
if(fds[m].revents&POLLIN)
if(fds[m].revents&(POLLIN|POLLHUP|POLLERR))
status[check[r]] |= SF_READ;
}
}
Expand Down Expand Up @@ -200,7 +200,7 @@ int tm; /* time in millisecs for select/poll */
while((np = select(m+1,&rd,&wr,NIL(fd_set*),tmp)) < 0 )
{ if(errno == eintr)
errno = 0;
else break;
else goto report;
}
if(np > 0)
np = c;
Expand All @@ -227,6 +227,7 @@ int tm; /* time in millisecs for select/poll */
}
#endif /*_lib_select*/

report:
for(r = c = 0; c < n; ++c)
{ if(status[c] == 0)
continue;
Expand Down
18 changes: 9 additions & 9 deletions src/lib/libast/sfio/sfsetbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,15 @@ size_t size; /* buffer size, -1 for default size */
#endif
}

/* set page size, this is also the desired default buffer size */
if(_Sfpage <= 0)
{
#if _lib_getpagesize
if((_Sfpage = (size_t)getpagesize()) <= 0)
#endif
_Sfpage = SF_PAGE;
}

#if SFSETLINEMODE
if(init)
f->flags |= sfsetlinemode();
Expand Down Expand Up @@ -308,15 +317,6 @@ size_t size; /* buffer size, -1 for default size */
(void)_sfpopen(f,-1,-1,1);
}
}

/* set page size, this is also the desired default buffer size */
if(_Sfpage <= 0)
{
#if _lib_getpagesize
if((_Sfpage = (size_t)getpagesize()) <= 0)
#endif
_Sfpage = SF_PAGE;
}
}

#ifdef MAP_TYPE
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/string/stropt.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ stropt(const char* as, const void* tab, int siz, int(*f)(void*, const void*, int
{
for (p = (char**)tab; t = *p; p = (char**)((char*)p + siz))
{
for (v = s; *t && *t++ == *v; v++);
for (v = s; *t && *t == *v; t++, v++);
if (!*t || isspace(*v) || *v == ',' || *v == '=')
break;
if (*v == ':' && *(v + 1) == '=')
Expand Down
9 changes: 7 additions & 2 deletions src/lib/libast/vmalloc/vmopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,22 @@ int mode; /* type of region */
Block_t *bp, *np;
Seg_t *seg;
Vmuchar_t *addr;
int rv;
int rv, mt;

if(!meth || !disc || !disc->memoryf )
return NIL(Vmalloc_t*);

GETPAGESIZE(_Vmpagesize);

mode = (mode&VM_FLAGS) | meth->meth; /* start with user-settable flags */

vmp = &vmproto; /* avoid memory allocation here! */
memset(vmp, 0, sizeof(Vmalloc_t));
memcpy(&vmp->meth, meth, sizeof(Vmethod_t));
mt = vmp->meth.meth;
vmp->meth.meth = 0;
vmp->disc = disc;

mode &= VM_FLAGS; /* start with user-settable flags */
size = 0;

if(disc->exceptf)
Expand Down Expand Up @@ -155,6 +158,8 @@ int mode; /* type of region */
seg->free = bp;
else vd->wild = bp;

vmp->meth.meth = mt;

done: /* now make the region handle */
if(vd->mode&VM_MEMORYF)
vm = &init->vm.vm;
Expand Down

0 comments on commit 1bd0620

Please sign in to comment.