version 1.33, 2017/04/12 14:49:05 |
version 1.34, 2018/01/21 20:18:20 |
|
|
|
|
__dead void done(int); |
__dead void done(int); |
void dooutput(void); |
void dooutput(void); |
void doshell(void); |
void doshell(char *); |
void fail(void); |
void fail(void); |
void finish(int); |
void finish(int); |
void scriptflush(int); |
void scriptflush(int); |
|
|
struct sigaction sa; |
struct sigaction sa; |
struct winsize win; |
struct winsize win; |
char ibuf[BUFSIZ]; |
char ibuf[BUFSIZ]; |
|
char *cmd; |
ssize_t cc, off; |
ssize_t cc, off; |
int aflg, ch; |
int aflg, ch; |
|
|
|
cmd = NULL; |
aflg = 0; |
aflg = 0; |
while ((ch = getopt(argc, argv, "a")) != -1) |
while ((ch = getopt(argc, argv, "ac:")) != -1) |
switch(ch) { |
switch(ch) { |
case 'a': |
case 'a': |
aflg = 1; |
aflg = 1; |
break; |
break; |
|
case 'c': |
|
cmd = optarg; |
|
break; |
default: |
default: |
fprintf(stderr, "usage: %s [-a] [file]\n", __progname); |
fprintf(stderr, "usage: %s [-a] [-c command] [file]\n", |
|
__progname); |
exit(1); |
exit(1); |
} |
} |
argc -= optind; |
argc -= optind; |
|
|
if (child) |
if (child) |
dooutput(); |
dooutput(); |
else |
else |
doshell(); |
doshell(cmd); |
} |
} |
|
|
bzero(&sa, sizeof sa); |
bzero(&sa, sizeof sa); |
|
|
done(sigdeadstatus); |
done(sigdeadstatus); |
} |
} |
|
|
/* ARGSUSED */ |
|
void |
void |
finish(int signo) |
finish(int signo) |
{ |
{ |
|
|
errno = save_errno; |
errno = save_errno; |
} |
} |
|
|
/* ARGSUSED */ |
|
void |
void |
handlesigwinch(int signo) |
handlesigwinch(int signo) |
{ |
{ |
|
|
done(0); |
done(0); |
} |
} |
|
|
/* ARGSUSED */ |
|
void |
void |
scriptflush(int signo) |
scriptflush(int signo) |
{ |
{ |
|
|
} |
} |
|
|
void |
void |
doshell(void) |
doshell(char *cmd) |
{ |
{ |
char *shell; |
char *shell; |
|
char *argp[] = {"sh", "-c", NULL, NULL}; |
|
|
shell = getenv("SHELL"); |
shell = getenv("SHELL"); |
if (shell == NULL) |
if (shell == NULL) |
|
|
(void)close(master); |
(void)close(master); |
(void)fclose(fscript); |
(void)fclose(fscript); |
login_tty(slave); |
login_tty(slave); |
execl(shell, shell, "-i", (char *)NULL); |
|
warn("%s", shell); |
if (cmd != NULL) { |
|
argp[2] = cmd; |
|
execv(_PATH_BSHELL, argp); |
|
warn("unable to execute %s", _PATH_BSHELL); |
|
} else { |
|
execl(shell, shell, "-i", (char *)NULL); |
|
warn("%s", shell); |
|
} |
fail(); |
fail(); |
} |
} |
|
|