[tlbuild] dvi test?
Paul Vojta
vojta at math.berkeley.edu
Sun Feb 13 05:15:13 CET 2022
Super! Thank you, John and Bruno, for helping track down this bug.
Karl, could you please apply the attached patch to the current TeXLive tree?
Thanks!
Sincerely,
Paul Vojta
On Sat, Feb 12, 2022 at 01:03:30PM +0100, Bruno Voisin wrote:
> Paul wrote:
>
> > Could someone try this out (on a Mac) and check whether the seek operation
> > still fails? (This is relative to the latest dvi-init.c in the TeX Live
> > repository, from about 10 days ago.)
>
> John answered:
>
> > Yes, it does! That is, without the patch, r61850 produces:
> >
> > jhawk at lrr xdvik % TEXMFROOT=/usr/local/texlive/2021 TEXMFCNF=$TEXMFROOT/texmf-dist/web2c ./xdvi-bin t2a
> > xdvi-bin: Error: Couldn't seek to start of file /var/folders/m2/16zlwjgj2p5d3qdy99z2gzf40000gn/T/xdvi-oAjS3R: Invalid argument - disabling `useTempFp'; target_fp: 0x1dfbeed40.
> >
> > And adding your patch to use dup() then produces no such output.
>
> I can confirm this (on macOS 12.3 Beta 2, M1 chip, Xcode 13.2.1):
>
> - Getting the latest sources and compiling them as is, I get
>
> % env TEXMFROOT=/usr/local/texlive/2021 TEXMFCNF=/usr/local/texlive/2021/texmf-dist/web2c ./xdvi-bin ~/Desktop/Test/t2a.dvi
> [...]
> xdvi-bin: Error: Couldn't seek to start of file /var/folders/1r/dhdtft1s4qgfjwbcpkfhqf5c0000gn/T/xdvi-uAeCcl: Invalid argument - disabling `useTempFp'; target_fp: 0x1fdb51780.
>
> - Applying your patch and compiling again, the error message vanishes.
>
> Bruno
>
-------------- next part --------------
--- dvi-init.c.orig 2022-02-01 18:05:30.000000000 -0800
+++ dvi-init.c 2022-02-12 19:21:57.472560593 -0800
@@ -1,6 +1,6 @@
/*========================================================================*\
-Copyright (c) 1990-2013 Paul Vojta
+Copyright (c) 1990-2022 Paul Vojta
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
@@ -1185,18 +1185,33 @@
ASSERT(target_fp != NULL, "");
ASSERT(source_fp != NULL, "");
- if (fseek(target_fp, 0L, SEEK_SET)) {
+ tmp_fd = try_dup(fileno(target_fp));
+ if (tmp_fd == -1) {
+ XDVI_ERROR((stderr, "Couldn't duplicate descriptor of file %s: %s - disabling `useTempFp'; target_fp: %p.",
+ m_tmp_dvi_name, strerror(errno), target_fp));
+ goto fclose_and_fail;
+ }
+
+ fclose(target_fp);
+
+ if (lseek(tmp_fd, 0L, SEEK_SET) == -1) {
XDVI_ERROR((stderr, "Couldn't seek to start of file %s: %s - disabling `useTempFp'; target_fp: %p.",
m_tmp_dvi_name, strerror(errno), target_fp));
- goto fclose_and_fail;
+ goto fail;
}
#if HAVE_FTRUNCATE
if (ftruncate(tmp_fd, 0) < 0) {
XDVI_ERROR((stderr, "Couldn't truncate file %s: %s - disabling `useTempFp'; target_fp: %p.",
m_tmp_dvi_name, strerror(errno), target_fp));
- goto fclose_and_fail;
+ goto fail;
}
#endif
+
+ if ((target_fp = try_fdopen(tmp_fd, "wb+")) == NULL) {
+ XDVI_ERROR((stderr, "error opening temporary file (%s) - disabling `useTempFp'.", strerror(errno)));
+ goto fail;
+ }
+
if (fseek(source_fp, 0L, SEEK_SET)) {
perror("fseek of source_fp");
goto fclose_and_fail;
--- util.c.orig 2020-03-01 11:07:53.000000000 -0800
+++ util.c 2022-02-12 19:20:39.001805119 -0800
@@ -1,6 +1,6 @@
/*========================================================================*\
-Copyright (c) 1990-2015 Paul Vojta and others
+Copyright (c) 1990-2022 Paul Vojta and others
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
@@ -280,6 +280,20 @@
}
return fd;
}
+
+/*
+ * Like try_fopen(), for dup().
+ */
+int
+try_dup(int oldfd)
+{
+ int fd = dup(oldfd);
+ if (fd < 0 && (errno == EMFILE || errno == ENFILE)) {
+ close_a_file();
+ fd = dup(oldfd);
+ }
+ return fd;
+}
/*
--- util.h.orig 2016-04-05 15:50:13.000000000 -0700
+++ util.h 2022-02-12 19:21:24.379424206 -0800
@@ -51,6 +51,7 @@
FILE *try_fdopen(int fd, const char *mode);
int try_open(const char *fname, int flags);
int try_open_mode(const char *fname, int flags, mode_t mode);
+int try_dup(int oldfd);
extern int xdvi_temp_fd(char **tempfilename);
extern void xdvi_assert(const char *version,
More information about the tlbuild
mailing list.