Skip to content

Commit

Permalink
cleanup: remove dead code handling historic Unix line disciplines
Browse files Browse the repository at this point in the history
In src/cmd/ksh93/include/jobs.h, we find...

    #ifdef FIOLOOKLD
            /* Ninth edition */
            extern int tty_ld, ntty_ld;
    #       define OTTYDISC tty_ld
    #       define NTTYDISC ntty_ld
    #endif /* FIOLOOKLD */

When Googling this FIOLOOKLD symbol, I got eight hits, six of them
ksh93 source code. Two others are ancient UNIX sources hosted at
TUHS. It checks out: UNIX Ninth Edition was from 1986. And sure
enough, the code above was already in ksh86. But it is evident that
no system from the last three decades has that symbol, or Google
woud find some trace of it.

There's quite a bit of code that depends on the OTTYDISC/NTTYDISC
symbols that are only defined if FIOLOOKLD is defined. So all of
that is dead code that is hereby removed.

In addition, in io_prompt() in io.c there was an ioctl call that
depended on the presence of the obsolete symbol TIOCLBIC. (FreeBSD
and macOS have it in a special ioctl_compat.h header). The code in
question, if that symbol exists, is only executed if no line editor
(emacs or vi) is active. Comment says: "re-enable output in case
the user has disabled it. Not needed with edit mode". But, as of
10e4ce5, we enable emacs by default if no editor is chosen. So we
can get rid of this, too. It's not compiled in on most current
systems anyway (if any at all).

And, just like that, all the ioctl(2) calls are gone from the ksh93
directory (none of them were getting compiled in on any recent
system). Which means we can also get rid of a very broken ioctl
wrapper in edit.c, sh_ioctl(), which ioctl was redefined as.
  • Loading branch information
McDutchie committed Aug 7, 2024
1 parent 2c98350 commit 18df203
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 124 deletions.
2 changes: 0 additions & 2 deletions src/cmd/ksh93/data/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ const char is_talias[] = "is a tracked alias for";
const char is_function[] = " is a function";
const char is_ufunction[] = " is an undefined function";
const char e_autoloadfrom[] = " (autoload from %s)";
const char e_newtty[] = "Switching to new tty driver...";
const char e_oldtty[] = "Reverting to old tty driver...";
const char e_no_start[] = "Cannot start job control";
const char e_no_jctl[] = "No job control";
const char e_terminate[] = "You have stopped jobs";
Expand Down
28 changes: 1 addition & 27 deletions src/cmd/ksh93/edit/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1356,35 +1356,9 @@ void *ed_open(void)
}

/*
* ioctl, tcgetattr and tcsetattr are mapped to these versions in terminal.h
* tcgetattr and tcsetattr are mapped to these versions in terminal.h
*/

#undef ioctl
int sh_ioctl(int fd, int cmd, void* val, int sz)
{
int r,err=errno;
if(sz == sizeof(void*))
{
while((r=ioctl(fd,cmd,val)) < 0 && errno==EINTR)
errno = err;
}
else
{
Sflong_t l = (Sflong_t)val;
if(sizeof(val)==sizeof(long))
{
while((r=ioctl(fd,cmd,(unsigned long)l)) < 0 && errno==EINTR)
errno = err;
}
else if(sizeof(int)!=sizeof(long))
{
while((r=ioctl(fd,cmd,(unsigned int)l)) < 0 && errno==EINTR)
errno = err;
}
}
return r;
}

#undef tcgetattr
int sh_tcgetattr(int fd, struct termios *tty)
{
Expand Down
10 changes: 0 additions & 10 deletions src/cmd/ksh93/include/jobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
#ifndef SIGCHLD
# error ksh 93u+m requires SIGCHLD
#endif
#ifdef FIOLOOKLD
/* Ninth edition */
extern int tty_ld, ntty_ld;
# define OTTYDISC tty_ld
# define NTTYDISC ntty_ld
#endif /* FIOLOOKLD */

struct process
{
Expand Down Expand Up @@ -117,10 +111,6 @@ extern const char e_terminate[];
extern const char e_no_jctl[];
extern const char e_signo[];
extern const char e_no_start[];
#ifdef NTTYDISC
extern const char e_newtty[];
extern const char e_oldtty[];
#endif /* NTTYDISC */

/*
* The following are defined in jobs.c
Expand Down
2 changes: 0 additions & 2 deletions src/cmd/ksh93/include/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ extern int sh_ioctl(int,int,void*,int);
extern int sh_tcgetattr(int,struct termios*);
extern int sh_tcsetattr(int,int,struct termios*);

#undef ioctl
#undef tcgetattr
#undef tcsetattr
#define ioctl(a,b,c) sh_ioctl(a,b,c,sizeof(c))
#define tcgetattr(a,b) sh_tcgetattr(a,b)
#define tcsetattr(a,b,c) sh_tcsetattr(a,b,c)

Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/sh.1
Original file line number Diff line number Diff line change
Expand Up @@ -9487,7 +9487,6 @@ The null device.
.IR exec (2),
.IR fork (2),
.IR getpwnam (3),
.IR ioctl (2),
.IR lseek (2),
.IR paste (1),
.IR pathconf (2),
Expand Down
11 changes: 0 additions & 11 deletions src/cmd/ksh93/sh/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2165,17 +2165,6 @@ static int io_prompt(Sfio_t *iop,int flag)
{
int c;
sh_lexopen(sh.lex_context, 0); /* reset lexer state */
#if defined(TIOCLBIC) && defined(LFLUSHO)
if(!sh_isoption(SH_VI) && !sh_isoption(SH_EMACS) && !sh_isoption(SH_GMACS))
{
/*
* re-enable output in case the user has
* disabled it. Not needed with edit mode
*/
int mode = LFLUSHO;
ioctl(sffileno(sfstderr),TIOCLBIC,&mode);
}
#endif /* TIOCLBIC */
cp = sh_mactry(nv_getval(sh_scoped(PS1NOD)));
sh.exitval = 0; /* avoid sending a signal on termination */
for(;c= *cp;cp++)
Expand Down
69 changes: 1 addition & 68 deletions src/cmd/ksh93/sh/jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ static char *job_string;
static void job_unstop(struct process*, int);
static void job_fgrp(struct process*, int);

#ifndef OTTYDISC
# undef NTTYDISC
#endif /* OTTYDISC */

typedef int (*Waitevent_f)(int,long,int);

#if SHOPT_BGX
Expand Down Expand Up @@ -506,22 +502,6 @@ void job_init(int lflag)
init_savelist();
if(!sh_isoption(SH_INTERACTIVE))
return;
/* use new line discipline when available */
#ifdef NTTYDISC
# ifdef FIOLOOKLD
if((job.linedisc = ioctl(JOBTTY, FIOLOOKLD, 0)) <0)
# else
if(ioctl(JOBTTY,TIOCGETD,&job.linedisc) !=0)
# endif /* FIOLOOKLD */
return;
if(job.linedisc!=NTTYDISC && job.linedisc!=OTTYDISC)
{
/* no job control when running with MPX */
return;
}
if(job.linedisc==NTTYDISC)
job.linedisc = -1;
#endif /* NTTYDISC */
job.mypgid = getpgrp();
/* some systems have job control, but not initialized */
if(job.mypgid<=0)
Expand Down Expand Up @@ -560,32 +540,7 @@ void job_init(int lflag)
}
}
}
#ifdef NTTYDISC
/* set the line discipline */
if(job.linedisc>=0)
{
int linedisc = NTTYDISC;
# ifdef FIOPUSHLD
tty_get(JOBTTY,&my_stty);
if (ioctl(JOBTTY, FIOPOPLD, 0) < 0)
return;
if (ioctl(JOBTTY, FIOPUSHLD, &linedisc) < 0)
{
ioctl(JOBTTY, FIOPUSHLD, &job.linedisc);
return;
}
tty_set(JOBTTY,TCSANOW,&my_stty);
# else
if(ioctl(JOBTTY,TIOCSETD,&linedisc) !=0)
return;
# endif /* FIOPUSHLD */
if(lflag==0)
errormsg(SH_DICT,0,e_newtty);
else
job.linedisc = -1;
}
#endif /* NTTYDISC */
if(!possible)
else
return;
/* make sure that we are a process group leader */
setpgid(0,sh.pid);
Expand Down Expand Up @@ -665,28 +620,6 @@ int job_close(void)
job_unlock();
if(job.jobcontrol && setpgid(0,job.mypgid)>=0)
tcsetpgrp(job.fd,job.mypgid);
# ifdef NTTYDISC
if(job.linedisc>=0)
{
/* restore old line discipline */
# ifdef FIOPUSHLD
tty_get(job.fd,&my_stty);
if (ioctl(job.fd, FIOPOPLD, 0) < 0)
return 0;
if (ioctl(job.fd, FIOPUSHLD, &job.linedisc) < 0)
{
job.linedisc = NTTYDISC;
ioctl(job.fd, FIOPUSHLD, &job.linedisc);
return 0;
}
tty_set(job.fd,TCSAFLUSH,&my_stty);
# else
if(ioctl(job.fd,TIOCSETD,&job.linedisc) !=0)
return 0;
# endif /* FIOPUSHLD */
errormsg(SH_DICT,0,e_oldtty);
}
# endif /* NTTYDISC */
# ifdef CNSUSP
if(possible && job.suspend==CNSUSP)
{
Expand Down
3 changes: 0 additions & 3 deletions src/lib/libcmd/stty.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ static const char usage[] =
#include <ccode.h>
#include <ctype.h>
#include <ast_tty.h>
#if _sys_ioctl
#include <sys/ioctl.h>
#endif

#define C(x) ERROR_catalog(x)

Expand Down

0 comments on commit 18df203

Please sign in to comment.