[tlbuild] dvi test?
John Hawkinson
jhawk at alum.mit.edu
Mon Jan 31 14:05:56 CET 2022
Bruno Haible <bruno at clisp.org> wrote on Mon, 31 Jan 2022
at 05:49:31 EST in <7195388.V25eIC5XRa at omega>:
> Before this printout, it would be useful to also print the position
> of the underlying file descriptor:
> printf ("debug fd position: %ld, ", (long) lseek (fileno (fp), 0, SEEK_CUR));
No change. Although something prompted me to do this before *and* after Karl's test fread(), and it's a little unexpected to me that stdio buffers in 2184 bytes (the file length!) when things are good and 4906 (4k) when they are bad.
I also added a teeny bit of instrumentation to util.c's try_fopen() to track what's on which file descriptor.
This suggests to me that the complicated code around make_backup_fp(), globals.dvi_file.bak_fp, and duplicate file descriptors and soforth is involved, and I don't really understand what is going on with all that.
Anyhow, so, with these patches:
--- a/texk/xdvik/dvi-init.c
+++ b/texk/xdvik/dvi-init.c
@@ -777,6 +777,22 @@ process_preamble(FILE *fp, dviErrFlagT *errflag)
static char job_id[300];
TRACE_FILES((stderr, "process_preamble: fp = %p, errflag = %d", (void *)fp, *errflag));
+
+ fprintf(stderr, "debug fileno is %d\n", fileno(fp));
+ fprintf(stderr, "debug fd position: %ld, \n", (long) lseek (fileno (fp), 0, SEEK_CUR));
+ static char buf[8];
+ int rv = fread(&buf, sizeof(buf), 1, fp);
+ if (!rv) {
+ perror("fread");
+ }
+ fprintf(stderr, "debug fd position: %ld, \n", (long) lseek (fileno (fp), 0, SEEK_CUR));
+ fprintf(stderr, "debug read %d bytes from fp: %d %d %d %d %d %d %d %d \n", rv*sizeof(buf),
+ buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
+ rv = fseek(fp, 0, SEEK_SET);
+ if (rv == -1) {
+ perror("fseek");
+ }
+
--- a/texk/xdvik/util.c
+++ b/texk/xdvik/util.c
@@ -234,7 +234,16 @@ try_fopen(const char *fname, const char *mode)
if (fp == NULL && (errno == EMFILE || errno == ENFILE)) {
close_a_file();
fp = fopen(fname, mode);
+ fprintf(stderr, "3debug try_fopen swapped things %s\n", fname);
+ } else if (fp == NULL) {
+ perror("fopen");
+ fprintf(stderr, "3debug while try_fopen %s\n", fname);
}
+
+ if (fp != NULL) {
+ fprintf(stderr, "3debug try_fopen %s for fd %d\n", fname, fileno(fp));
+ }
+
return fp;
}
Then I get this:
jhawk at lrr xdvik % TEXMFROOT=/usr/local/texlive/2021 TEXMFCNF=$TEXMFROOT/texmf-dist/web2c ./xdvi-bin t2a.dvi
3debug try_fopen t2a.dvi for fd 4
3debug try_fopen /Users/jhawk/src/xdvik-22.87.05/Work/texk/xdvik/t2a.dvi for fd 5
debug fileno is 5
debug fd position: 0,
debug fd position: 2184,
debug read 8 bytes from fp: -9 2 1 -125 -110 -64 28 59
3debug try_fopen /usr/local/texlive/2021/texmf-config/dvips/config/config.ps for fd 5
fopen: No such file or directory
3debug while try_fopen /Users/jhawk/.dvipsrc
3debug try_fopen /usr/local/texlive/2021/texmf-dist/dvips/xdvi/config.xdvi for fd 5
3debug try_fopen /usr/local/texlive/2021/texmf-var/fonts/map/dvips/updmap/psfonts.map for fd 5
3debug try_fopen /Users/jhawk/src/xdvik-22.87.05/Work/texk/xdvik/t2a.dvi for fd 4
debug fileno is 6
debug fd position: 0,
debug fd position: 2184,
debug read 8 bytes from fp: -9 2 1 -125 -110 -64 28 59
3debug try_fopen /usr/local/texlive/2021/texmf-dist/dvips/l3backend/l3backend-dvips.pro for fd 8
3debug try_fopen /usr/local/texlive/2021/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb for fd 8
3debug try_fopen /usr/local/texlive/2021/texmf-dist/fonts/type1/public/amsfonts/cm/cmcsc10.pfb for fd 9
3debug try_fopen /usr/local/texlive/2021/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb for fd 10
debug fileno is 4
debug fd position: 0,
debug fd position: 2184,
debug read 8 bytes from fp: -9 2 1 -125 -110 -64 28 59
3debug try_fopen /Users/jhawk/src/xdvik-22.87.05/Work/texk/xdvik/t2a.dvi for fd 4
debug fileno is 6
debug fd position: 0,
debug fd position: 4096,
debug read 8 bytes from fp: 0 0 0 0 0 0 0 0
xdvi-bin: set_no_char: attempt to set character of unknown font, offset 42
xdvi-bin 22.87.05 (Xaw toolkit): ../../../texk/xdvik/dvi-draw.c:488: Shouldn't happen: I'll abort now, to help you debugging this.
zsh: abort TEXMFROOT=/usr/local/texlive/2021 TEXMFCNF=$TEXMFROOT/texmf-dist/web2c
jhawk at lrr xdvik %
The file position and fd# debugging doesn't seem to tell us much.
I spent quite a while last night before going to bed trying to figure out why we are messing around with fd 6, which has not been opened recently, at least not by try_fopen(). It looks loke it's a mkstemp() -style temprorary file from the aforementioned backup fd stuff. Here's what lsof says right when we're stopped at abort() in the debugger:
jhawk at lrr xdvik % lsof -p 61772
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
xdvi-bin 61772 jhawk cwd DIR 1,17 1792 6247860 /Users/jhawk/src/xdvik-22.87.05/Work/texk/xdvik
xdvi-bin 61772 jhawk txt REG 1,17 2033461 6310429 /Users/jhawk/src/xdvik-22.87.05/Work/texk/xdvik/xdvi-bin
xdvi-bin 61772 jhawk txt REG 1,17 2160672 1152921500312812725 /usr/lib/dyld
xdvi-bin 61772 jhawk txt REG 1,17 1063744 2362445 /opt/X11/lib/libXt.6.dylib
xdvi-bin 61772 jhawk txt REG 1,17 418608 2362427 /opt/X11/lib/libXmu.6.dylib
xdvi-bin 61772 jhawk txt REG 1,17 411184 2362373 /opt/X11/lib/libICE.6.dylib
xdvi-bin 61772 jhawk txt REG 1,17 345008 2362411 /opt/X11/lib/libXext.6.dylib
xdvi-bin 61772 jhawk txt REG 1,17 271200 2362377 /opt/X11/lib/libSM.6.dylib
xdvi-bin 61772 jhawk txt REG 1,17 323104 2362430 /opt/X11/lib/libXpm.4.dylib
xdvi-bin 61772 jhawk txt REG 1,17 218000 2362387 /opt/X11/lib/libXau.6.dylib
xdvi-bin 61772 jhawk txt REG 1,17 1224880 2362397 /opt/X11/lib/libXaw7.7.dylib
xdvi-bin 61772 jhawk txt REG 1,17 573344 2362551 /opt/X11/lib/libxcb.1.dylib
xdvi-bin 61772 jhawk txt REG 1,17 3496912 2362381 /opt/X11/lib/libX11.6.dylib
xdvi-bin 61772 jhawk 0r CHR 16,22 0t0 861 /dev/ttys022
xdvi-bin 61772 jhawk 1w CHR 16,22 0t0 861 /dev/ttys022
xdvi-bin 61772 jhawk 2w CHR 16,22 0t1717 861 /dev/ttys022
xdvi-bin 61772 jhawk 3u unix 0x3b942ee6304fda1b 0t0 ->0x3b942ee6304fdae3
xdvi-bin 61772 jhawk 5r REG 1,17 5178477 2877215 /usr/local/texlive/2021/texmf-var/fonts/map/dvips/updmap/psfonts_t1.map
xdvi-bin 61772 jhawk 6u REG 1,17 4274 6310987 /private/var/folders/m2/16zlwjgj2p5d3qdy99z2gzf40000gn/T/xdvi-qQ69Al
xdvi-bin 61772 jhawk 8r REG 1,17 32080 2797103 /usr/local/texlive/2021/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb
xdvi-bin 61772 jhawk 9r REG 1,17 32001 2797119 /usr/local/texlive/2021/texmf-dist/fonts/type1/public/amsfonts/cm/cmcsc10.pfb
xdvi-bin 61772 jhawk 10r REG 1,17 35752 2797151 /usr/local/texlive/2021/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb
(Hrmm, not sure how to suppress the shared libraries from lsof output. Oh well, whatever.)
Probably running down a blind alley but I don't know it yet.
--
jhawk at alum.mit.edu
John Hawkinson
More information about the tlbuild
mailing list.