texlive[46686] Build/source/texk/kpathsea: quit if asked to set a

commits+karl at tug.org commits+karl at tug.org
Tue Feb 20 20:15:58 CET 2018


Revision: 46686
          http://tug.org/svn/texlive?view=revision&revision=46686
Author:   karl
Date:     2018-02-20 20:15:58 +0100 (Tue, 20 Feb 2018)
Log Message:
-----------
quit if asked to set a nonexistent program name

Modified Paths:
--------------
    trunk/Build/source/texk/kpathsea/ChangeLog
    trunk/Build/source/texk/kpathsea/progname.c

Modified: trunk/Build/source/texk/kpathsea/ChangeLog
===================================================================
--- trunk/Build/source/texk/kpathsea/ChangeLog	2018-02-20 18:24:46 UTC (rev 46685)
+++ trunk/Build/source/texk/kpathsea/ChangeLog	2018-02-20 19:15:58 UTC (rev 46686)
@@ -1,3 +1,11 @@
+2018-02-20  Karl Berry  <karl at freefriends.org>
+
+	* progname.c (expand_symlinks): make error message on unresolvable
+	symlinks less verbose.
+	(kpathsea_selfdir): exit(1) if name cannot be resolved,
+	instead of failing an assertion. Report from Enrico Gregorio,
+	http://tug.org/pipermail/tex-live/2018-February/041052.html
+
 2018-02-17  TANAKA Takuji  <ttk at t-lab.opal.ne.jp>
 
 	* texmf.cnf ({TEXINPUTS,BIBINPUTS,max_strings}.upbibtex):

Modified: trunk/Build/source/texk/kpathsea/progname.c
===================================================================
--- trunk/Build/source/texk/kpathsea/progname.c	2018-02-20 18:24:46 UTC (rev 46685)
+++ trunk/Build/source/texk/kpathsea/progname.c	2018-02-20 19:15:58 UTC (rev 46686)
@@ -153,8 +153,9 @@
   strcat (a, StripFirst (b));
 }
 
-/* Returns NULL on error.  Prints intermediate results if global
-   `ll_verbose' is nonzero.  */
+/* Returns NULL on error, such as an unresolvable symlink.  Prints
+   intermediate results if global `ll_verbose' is nonzero.  Otherwise,
+   returns a pointer to a static buffer (sorry).  */
 
 #define EMPTY_STRING(s) (*(s) == 0)
 #define EX(s)           (!EMPTY_STRING (s) && strcmp (s, "/") ? "/" : "")
@@ -171,22 +172,6 @@
   struct stat st;
   int done;
 
-  /* Check for symlink loops.  It's difficult to check for all the
-     possibilities ourselves, so let the kernel do it.  And make it
-     conditional so that people can see where the infinite loop is
-     being caused (see engtools#1536).  */
-  /* There used to be a test for a variable |ll_loop| here, but
-     it was initialized to zero and never updated */
-  if (0) {
-    FILE *f = fopen (s, "r");
-    if (!f && errno == ELOOP) {
-      /* Not worried about other errors, we'll get to them in due course.  */
-      perror (s);
-      return NULL;
-    }
-    if (f) fclose (f);
-  }
-
   strcpy (post, s);
   strcpy (pre, "");
 
@@ -194,7 +179,7 @@
     CopyFirst (pre, post);
 
     if (lstat (pre, &st) != 0) {
-      fprintf (stderr, "lstat(%s) failed ...\n", pre);
+      fprintf (stderr, "lstat(%s) failed: ", pre);
       perror (pre);
       return NULL;
     }
@@ -327,14 +312,14 @@
 }
 

 /* Return directory ARGV0 comes from.  Check PATH if ARGV0 is not
-   absolute.  */
+   absolute.  If ARGV0 cannot be found (e.g., --progname=nonesuch), quit.  */
 
 string
 kpathsea_selfdir (kpathsea kpse, const_string argv0)
 {
-  string self = NULL;
   string name;
   string ret;
+  string self = NULL;
 
   if (kpathsea_absolute_p (kpse, argv0, true)) {
     self = xstrdup (argv0);
@@ -394,16 +379,23 @@
   if (!self)
     self = concat3 (".", DIR_SEP_STRING, argv0);
 
-  name = remove_dots (kpse, expand_symlinks (kpse, self));
+  /* If we can't expand symlinks (--progname=nonesuch), give up.  */
+  name = expand_symlinks (kpse, self);
+  if (!name) {
+    fprintf (stderr, "kpathsea: Can't get directory of program name: %s\n",
+             self);
+    exit (1);
+  }
 
+  /* If we have something real, we can resolve ./ and ../ elements.  */
+  name = remove_dots (kpse, name);
+
 #ifndef AMIGA
   free (self);
 #endif
 
   ret = xdirname (name);
-
   free (name);
-
   return ret;
 }
 



More information about the tex-live-commits mailing list