[tlbuild] dvi test?

Paul Vojta vojta at math.berkeley.edu
Sat Feb 12 05:17:16 CET 2022


On Wed, Feb 02, 2022 at 10:13:15AM -0500, John Hawkinson wrote:
> 
> 
> Paul Vojta <vojta at math.berkeley.edu> wrote on Tue,  1 Feb 2022
> at 23:08:58 EST in <YfoD2q6SXifEqpoj at math.berkeley.edu>:
> 
> > Most notably, probably it would be a good idea to call fseek() and fflush() 
> > before ftruncate().
> 
> As previously reported, calling fseek() before ftruncate() does not resolve the matter, and fseek() returns an error which we now check in TeXLive as of r61850. It does so regardless of whether fseek() is called after ftruncate() [as it is now], or before ftruncate() [as I tested yesterday]:
> 

Oops, my bad.

I have another idea (see the patch below).

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.)

Also, I noticed that reading the pages from the dvi file is done entirely,
or at least mostly, with kernel calls (read() and lseek()), so I guess
it's not surprising that the libc state is corrupted.

--Paul


--- xdvik/texk/xdvik/dvi-init.c.orig	2022-02-01 18:05:30.000000000 -0800
+++ xdvik/texk/xdvik/dvi-init.c	2022-02-11 20:07:38.590598865 -0800
@@ -1185,18 +1185,33 @@
 	ASSERT(target_fp != NULL, "");
 	ASSERT(source_fp != NULL, "");
 
-	if (fseek(target_fp, 0L, SEEK_SET)) {
+	tmp_fd = dup(fileno(target_fp));	/* this should really be try_dup() */
+	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;





More information about the tlbuild mailing list.