Skip to content

Commit

Permalink
jobs: change p_job variable type from short to int
Browse files Browse the repository at this point in the history
This change addresses an issue where ksh hangs when the number of jobs exceeds `2^15 - 1` (32767), which is the maximum value for a `short`.
  • Loading branch information
vmihalko committed Jul 11, 2024
1 parent 1f86b28 commit 3822f2c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/jobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct process
pid_t p_pid; /* process ID */
pid_t p_pgrp; /* process group */
pid_t p_fgrp; /* process group when stopped */
short p_job; /* job number of process */
int p_job; /* job number of process */
unsigned short p_exit; /* exit value or signal number */
unsigned short p_exitmin; /* minimum exit value for xargs */
unsigned short p_flag; /* flags - see below */
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/ksh93/sh/jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ int job_reap(int sig)
pw->p_flag &= ~P_NOTIFY;
if(job.jobcontrol && pid==pw->p_fgrp && pid==tcgetpgrp(JOBTTY))
{
px = job_byjid((int)pw->p_job);
px = job_byjid(pw->p_job);
for(; px && (px->p_flag&P_DONE); px=px->p_nxtproc);
if(!px)
tcsetpgrp(JOBTTY,job.mypid);
Expand Down Expand Up @@ -1527,7 +1527,7 @@ int job_switch(struct process *pw,int bgflag)
{
const char *msg;
job_lock();
if(!pw || !(pw=job_byjid((int)pw->p_job)))
if(!pw || !(pw=job_byjid(pw->p_job)))
{
job_unlock();
return 1;
Expand All @@ -1541,7 +1541,7 @@ int job_switch(struct process *pw,int bgflag)
}
if(bgflag=='b')
{
sfprintf(outfile,"[%d]\t",(int)pw->p_job);
sfprintf(outfile,"[%d]\t",pw->p_job);
sh.bckpid = pw->p_pid;
pw->p_flag |= P_BG;
msg = "&";
Expand Down Expand Up @@ -1622,7 +1622,7 @@ static struct process *job_unpost(struct process *pwtop,int notify)
sfprintf(sfstderr,"ksh: job line %4d: drop PID=%lld critical=%d PID=%d env=%u\n",__LINE__,(Sflong_t)sh.current_pid,job.in_critical,pwtop->p_pid,pwtop->p_env);
sfsync(sfstderr);
#endif /* DEBUG */
pwtop = pw = job_byjid((int)pwtop->p_job);
pwtop = pw = job_byjid(pwtop->p_job);
if(!pw)
return NULL;
#if SHOPT_BGX
Expand Down Expand Up @@ -1663,7 +1663,7 @@ static struct process *job_unpost(struct process *pwtop,int notify)
sfprintf(sfstderr,"ksh: job line %4d: free PID=%lld critical=%d job=%d\n",__LINE__,(Sflong_t)sh.current_pid,job.in_critical,pwtop->p_job);
sfsync(sfstderr);
#endif /* DEBUG */
job_free((int)pwtop->p_job);
job_free(pwtop->p_job);
return NULL;
}

Expand Down

0 comments on commit 3822f2c

Please sign in to comment.