On Son, 02 Okt 2005, Karl Berry wrote: > It's up to you, but I don't advise it. It reverts many declarations to > K&R form (i.e., a much older texindex.c). Aside from that, it also > reverts at least one bug fix I made regarding initials (years ago). > > Perhaps you or someone could work on just making a patch which fixes the > race condition without all the other extraneous (and undesirable) changes. > That would help me.
Can you please comment on my first try on this, attached. I removed all the unneccessary stuff I found, and it still compiles. Please comment. Best wishes Norbert ------------------------------------------------------------------------------- Dr. Norbert Preining <preining AT logic DOT at> Università di Siena sip:[EMAIL PROTECTED] +43 (0) 59966-690018 gpg DSA: 0x09C5B094 fp: 14DF 2E6C 0307 BE6D AD76 A9C0 D2BF 4AA3 09C5 B094 ------------------------------------------------------------------------------- SCORRIER (n.) A small hunting dog trained to snuffle amongst your private parts. --- Douglas Adams, The Meaning of Liff
--- /src/debian-tex/pkg-texlive/texinfo/branches/upstream/4.8/util/texindex.c 2004-04-11 19:56:47.000000000 +0200 +++ util/texindex.c 2005-10-02 23:47:05.000000000 +0200 @@ -99,6 +99,9 @@ /* Directory to use for temporary files. On Unix, it ends with a slash. */ char *tempdir; +/* Start of filename to use for temporary files. */ +char *tempbase; + /* Number of last temporary file. */ int tempcount; @@ -144,7 +147,7 @@ void fatal (const char *format, const char *arg); void error (const char *format, const char *arg); void *xmalloc (), *xrealloc (); -char *concat (char *s1, char *s2); +char *concat (char *s1, char *s2, char *s3); void flush_tempfiles (int to_count); #define MAX_IN_CORE_SORT 500000 @@ -190,6 +193,11 @@ decode_command (argc, argv); + /* XXX mkstemp not appropriate, as we need to have somewhat predictable + * names. But race condition was fixed, see maketempname. + */ + tempbase = mktemp (concat ("txiXXXXXX", "", "")); + /* Process input files completely, one by one. */ for (i = 0; i < num_infiles; i++) @@ -220,7 +228,7 @@ outfile = outfiles[i]; if (!outfile) - outfile = concat (infiles[i], "s"); + outfile = concat (infiles[i], "s", ""); need_initials = 0; first_initial = '\0'; @@ -318,7 +326,7 @@ if (tempdir == NULL) tempdir = DEFAULT_TMPDIR; else - tempdir = concat (tempdir, "/"); + tempdir = concat (tempdir, "/", ""); keep_tempfiles = 0; @@ -384,26 +392,25 @@ usage (1); } -/* Return a name for temporary file COUNT. */ +/* Return a name for a temporary file. */ static char * maketempname (int count) { - static char *tempbase = NULL; char tempsuffix[10]; + char *name; + int fd; - if (!tempbase) + sprintf (tempsuffix, ".%d", count); + name = concat (tempdir, tempbase, tempsuffix); + fd = open (name, O_CREAT|O_EXCL|O_WRONLY, 0666); + if (fd == -1) + return NULL; + else { - int fd; - tempbase = concat (tempdir, "txidxXXXXXX"); - - fd = mkstemp (tempbase); - if (fd == -1) - pfatal_with_name (tempbase); + close(fd); + return(name); } - - sprintf (tempsuffix, ".%d", count); - return concat (tempbase, tempsuffix); } @@ -931,6 +938,8 @@ for (i = 0; i < ntemps; i++) { char *newtemp = maketempname (++tempcount); + if (!newtemp) + pfatal_with_name("temp file"); sort_in_core (tempfiles[i], MAX_IN_CORE_SORT, newtemp); if (!keep_tempfiles) unlink (tempfiles[i]); @@ -1401,6 +1410,8 @@ if (i + 1 == ntemps) nf = nfiles - i * MAX_DIRECT_MERGE; tempfiles[i] = maketempname (++tempcount); + if (!tempfiles[i]) + pfatal_with_name("temp file"); value |= merge_direct (&infiles[i * MAX_DIRECT_MERGE], nf, tempfiles[i]); } @@ -1615,14 +1626,15 @@ /* Return a newly-allocated string concatenating S1 and S2. */ char * -concat (char *s1, char *s2) +concat (char *s1, char *s2, char *s3) { - int len1 = strlen (s1), len2 = strlen (s2); - char *result = (char *) xmalloc (len1 + len2 + 1); + int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); + char *result = (char *) xmalloc (len1 + len2 + len3 + 1); strcpy (result, s1); strcpy (result + len1, s2); - *(result + len1 + len2) = 0; + strcpy (result + len1 + len2, s3); + *(result + len1 + len2 + len3) = 0; return result; }