Script Hanging
Stephen Schaefer
schaefer at bgsuvax.UUCP
Wed May 14 05:24:40 AEST 1986
I suppose I should be quicker with my "f" key. Here are fixes to
three different problems with script, building from the code
distributed with 4.2BSD:
% rlog script.c
RCS file: RCS/script.c,v; Working file: script.c
head: 1.5
locks: root: 1.5; strict
access list:
symbolic names:
comment leader: " * "
total revisions: 5; selected revisions: 5
description:
As received from Berkeley.
----------------------------
revision 1.5 locked by: root;
date: 86/05/13 15:07:58; author: root; state: Exp; lines added/del: 3/0
Disable the following, which CBREAK was not passing through as desired:
t_flushc (toggles throwing away output), t_lnextc (quotes characters -
I hope nothing needs this now), and ^M (which was being translated to
^J on input, to ^M^J on output). I hope I haven't missed anything...
----------------------------
revision 1.4
date: 86/01/28 16:53:17; author: root; state: Exp; lines added/del: 13/1
Changed real terminal mode to CBREAK while running, setting the
real terminals interrupt generating characters undefined. All
this to handle control-s/control-q.
----------------------------
revision 1.3
date: 85/12/10 17:17:28; author: root; state: Exp; lines added/del: 13/5
Problem: script would open /dev/ptyXX for which it did not have
suitable permissions on the corresponding /dev/ttyXX.
Fix: in getmaster(), try the next line if /dev/ttyXX does not have
suitable permissions, as returned by stat(2).
----------------------------
revision 1.2
date: 85/12/05 14:02:48; author: root; state: Exp; lines added/del: 15/6
Problem: script would occasionally hang when exiting its subshell.
Caused by a race condition when the script child performed a "read"
system call, which either would or would not return <=0 when the shell
child died.
Fix: changed the routing which handles the SIGCHLD signal in the script
child to perform proper cleanup - named "finish2".
----------------------------
revision 1.1
date: 85/12/05 13:55:54; author: root; state: Exp;
Initial revision
=============================================================================
% rcsdiff -r1.1 script.c
RCS file: RCS/script.c,v
retrieving revision 1.1
diff -r1.1 script.c
15a16,18
> #define READ_PERM 4
> #define WRITE_PERM 2
>
24a28
> int finish2();
75c79,80
< f = fork();
---
> (void) signal(SIGCHLD, finish2);
> f = fork();
109a115,125
> finish2()
> {
> time_t tvec;
>
> tvec = time((time_t *)0);
> fprintf(fscript,"\nscript done on %s", ctime(&tvec));
> (void) fclose(fscript);
> (void) close(master);
> exit(0);
> }
>
126,130c142
< tvec = time((time_t *)0);
< fprintf(fscript,"\nscript done on %s", ctime(&tvec));
< (void) fclose(fscript);
< (void) close(master);
< exit(0);
---
> finish2();
156a169,170
> struct tchars tbuf;
> struct ltchars lbuf;
159c173
< sbuf.sg_flags |= RAW;
---
> sbuf.sg_flags |= CBREAK;
160a175
> sbuf.sg_flags &= ~CRMOD;
161a177,186
> tbuf = tc;
> tbuf.t_intrc = -1;
> tbuf.t_quitc = -1;
> ioctl(0, TIOCSETC, (char *)&tbuf);
> lbuf = lc;
> lbuf.t_suspc = -1;
> lbuf.t_dsuspc = -1;
> lbuf.t_flushc = -1;
> lbuf.t_lnextc = -1;
> ioctl(0, TIOCSLTC, (char *)&lbuf);
174a200,201
> ioctl(0, TIOCSETC, (char *)&tc);
> ioctl(0, TIOCSLTC, (char *)&lc);
184a212
> line[strlen("/dev/")] = 't';
186,189c214
< line[strlen("/dev/pty")] = c;
< line[strlen("/dev/ptyp")] = '0';
< if (stat(line, &stb) < 0)
< break;
---
> line[strlen("/dev/tty")] = c;
191c216,222
< line[strlen("/dev/ptyp")] = "0123456789abcdef"[i];
---
> line[strlen("/dev/ttyp")] = "0123456789abcdef"[i];
> if (stat(line, &stb) < 0) /* does line exist? */
> continue;
> if (((READ_PERM | WRITE_PERM) & (stb.st_mode)) !=
> (READ_PERM | WRITE_PERM)) /* protected? */
> continue;
> line[strlen("/dev/")] = 'p';
200a232
> line[strlen("/dev/")] = 't';
--
Stephen P. Schaefer
Systems Programmer
schaefer at bgsu
...!cbosgd!osu-eddie!bgsuvax!schaefer
More information about the Comp.unix.wizards
mailing list