texlive[62013] Build/source/texk/xdvik: cleaner fix for Mac reload
commits+karl at tug.org
commits+karl at tug.org
Sun Feb 13 23:53:37 CET 2022
Revision: 62013
http://tug.org/svn/texlive?view=revision&revision=62013
Author: karl
Date: 2022-02-13 23:53:37 +0100 (Sun, 13 Feb 2022)
Log Message:
-----------
cleaner fix for Mac reload problem (aka fseek error), from Paul V
Modified Paths:
--------------
trunk/Build/source/texk/xdvik/ChangeLog
trunk/Build/source/texk/xdvik/dvi-init.c
trunk/Build/source/texk/xdvik/util.c
trunk/Build/source/texk/xdvik/util.h
Modified: trunk/Build/source/texk/xdvik/ChangeLog
===================================================================
--- trunk/Build/source/texk/xdvik/ChangeLog 2022-02-13 21:55:34 UTC (rev 62012)
+++ trunk/Build/source/texk/xdvik/ChangeLog 2022-02-13 22:53:37 UTC (rev 62013)
@@ -1,3 +1,13 @@
+2022-02-13 Paul Vojta <vojta at math.berkeley.edu>
+
+ * dvi-init.c (make_backup_fp): call new try_dup, and existing
+ try_fdopen, before fseek.
+ * util.c (try_dup): define new fn.
+ * util.h (try_dup): declare it.
+ This resolves xdvi crashing under MacOS after hitting `R' in some
+ situations (the preceding change did as well, in a clunkier way).
+ https://tug.org/pipermail/tlbuild/2022q1/005140.html ff.
+
2022-02-01 John Hawkinson <jhawk at alum.mit.edu>
* dvi-init.c (make_backup_fp): check returns from fseeks,
Modified: trunk/Build/source/texk/xdvik/dvi-init.c
===================================================================
--- trunk/Build/source/texk/xdvik/dvi-init.c 2022-02-13 21:55:34 UTC (rev 62012)
+++ trunk/Build/source/texk/xdvik/dvi-init.c 2022-02-13 22:53:37 UTC (rev 62013)
@@ -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;
Modified: trunk/Build/source/texk/xdvik/util.c
===================================================================
--- trunk/Build/source/texk/xdvik/util.c 2022-02-13 21:55:34 UTC (rev 62012)
+++ trunk/Build/source/texk/xdvik/util.c 2022-02-13 22:53:37 UTC (rev 62013)
@@ -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
@@ -281,7 +281,21 @@
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;
+}
+
/*
* invoked on SIGSEGV: try to stop gs before aborting, to prevent gs
* running on with 100% CPU consumption - this can be annoying during
Modified: trunk/Build/source/texk/xdvik/util.h
===================================================================
--- trunk/Build/source/texk/xdvik/util.h 2022-02-13 21:55:34 UTC (rev 62012)
+++ trunk/Build/source/texk/xdvik/util.h 2022-02-13 22:53:37 UTC (rev 62013)
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002-2015 the xdvik development team
+ * Copyright (c) 2002-2022 the xdvik development team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@@ -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 tex-live-commits
mailing list.