1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 30_texindex_racecondition.dpatch by Henry Jensen <jensen@scan-plus.de>
3
## and Norbert Preining <preining@logic.at>
4
## backport of cvs fixes
6
## All lines beginning with `## DP:' are a description of the patch.
10
--- branches/upstream/current/util/texindex.c 2005-09-30 11:28:05.000000000 +0200
11
+++ texinfo-cvs/util/texindex.c 2005-10-06 08:35:26.000000000 +0200
13
/* Directory to use for temporary files. On Unix, it ends with a slash. */
16
+/* Start of filename to use for temporary files. */
19
/* Number of last temporary file. */
23
void fatal (const char *format, const char *arg);
24
void error (const char *format, const char *arg);
25
void *xmalloc (), *xrealloc ();
26
-char *concat (char *s1, char *s2);
27
+static char *concat3 (const char *, const char *, const char *);
28
void flush_tempfiles (int to_count);
30
#define MAX_IN_CORE_SORT 500000
33
decode_command (argc, argv);
35
+ /* XXX mkstemp not appropriate, as we need to have somewhat predictable
36
+ * names. But race condition was fixed, see maketempname.
38
+ tempbase = mktemp (concat3 ("txiXXXXXX", "", ""));
40
/* Process input files completely, one by one. */
42
for (i = 0; i < num_infiles; i++)
45
outfile = outfiles[i];
47
- outfile = concat (infiles[i], "s");
48
+ outfile = concat3 (infiles[i], "s", "");
54
tempdir = DEFAULT_TMPDIR;
56
- tempdir = concat (tempdir, "/");
57
+ tempdir = concat3 (tempdir, "/", "");
65
-/* Return a name for temporary file COUNT. */
66
+/* Return a name for temporary file COUNT, or NULL if failure. */
69
maketempname (int count)
71
- static char *tempbase = NULL;
77
+ sprintf (tempsuffix, ".%d", count);
78
+ name = concat3 (tempdir, tempbase, tempsuffix);
79
+ fd = open (name, O_CREAT|O_EXCL|O_WRONLY, 0600);
85
- tempbase = concat (tempdir, "txidxXXXXXX");
87
- fd = mkstemp (tempbase);
89
- pfatal_with_name (tempbase);
94
- sprintf (tempsuffix, ".%d", count);
95
- return concat (tempbase, tempsuffix);
100
for (i = 0; i < ntemps; i++)
102
char *newtemp = maketempname (++tempcount);
104
+ pfatal_with_name("temp file");
105
sort_in_core (tempfiles[i], MAX_IN_CORE_SORT, newtemp);
107
unlink (tempfiles[i]);
108
@@ -1401,6 +1413,8 @@
110
nf = nfiles - i * MAX_DIRECT_MERGE;
111
tempfiles[i] = maketempname (++tempcount);
113
+ pfatal_with_name("temp file");
114
value |= merge_direct (&infiles[i * MAX_DIRECT_MERGE], nf, tempfiles[i]);
117
@@ -1612,17 +1626,18 @@
121
-/* Return a newly-allocated string concatenating S1 and S2. */
122
+/* Return a newly-allocated string concatenating S1, S2, and S3. */
125
-concat (char *s1, char *s2)
127
+concat3 (const char *s1, const char *s2, const char *s3)
129
- int len1 = strlen (s1), len2 = strlen (s2);
130
- char *result = (char *) xmalloc (len1 + len2 + 1);
131
+ int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
132
+ char *result = (char *) xmalloc (len1 + len2 + len3 + 1);
135
strcpy (result + len1, s2);
136
- *(result + len1 + len2) = 0;
137
+ strcpy (result + len1 + len2, s3);
138
+ *(result + len1 + len2 + len3) = 0;