1 |
vapier 14/11/01 08:11:46 |
2 |
|
3 |
Added: ccache-3.1.10-size-on-disk.patch |
4 |
ccache-3.1.10-real-temp-files.patch |
5 |
Log: |
6 |
Fix temp file usage to not rely on pids (fixes running in pid namespaces). Fix disk usage checks #456178 by Richard Yao. Always use /usr/lib/ccache/bin/ #509956 by Michał Górny. |
7 |
|
8 |
(Portage version: 2.2.14/cvs/Linux x86_64, signed Manifest commit with key D2E96200) |
9 |
|
10 |
Revision Changes Path |
11 |
1.1 dev-util/ccache/files/ccache-3.1.10-size-on-disk.patch |
12 |
|
13 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-util/ccache/files/ccache-3.1.10-size-on-disk.patch?rev=1.1&view=markup |
14 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-util/ccache/files/ccache-3.1.10-size-on-disk.patch?rev=1.1&content-type=text/plain |
15 |
|
16 |
Index: ccache-3.1.10-size-on-disk.patch |
17 |
=================================================================== |
18 |
https://bugs.gentoo.org/56178 |
19 |
|
20 |
stick to the size of files on disk rather than their byte size. |
21 |
this func is only used for stats management, so this should be safe. |
22 |
|
23 |
--- a/util.c |
24 |
+++ b/util.c |
25 |
@@ -845,12 +845,7 @@ file_size(struct stat *st) |
26 |
#ifdef _WIN32 |
27 |
return (st->st_size + 1023) & ~1023; |
28 |
#else |
29 |
- size_t size = st->st_blocks * 512; |
30 |
- if ((size_t)st->st_size > size) { |
31 |
- /* probably a broken stat() call ... */ |
32 |
- size = (st->st_size + 1023) & ~1023; |
33 |
- } |
34 |
- return size; |
35 |
+ return st->st_blocks * 512; |
36 |
#endif |
37 |
} |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
1.1 dev-util/ccache/files/ccache-3.1.10-real-temp-files.patch |
43 |
|
44 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-util/ccache/files/ccache-3.1.10-real-temp-files.patch?rev=1.1&view=markup |
45 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-util/ccache/files/ccache-3.1.10-real-temp-files.patch?rev=1.1&content-type=text/plain |
46 |
|
47 |
Index: ccache-3.1.10-real-temp-files.patch |
48 |
=================================================================== |
49 |
https://lists.samba.org/archive/ccache/2014q4/001246.html |
50 |
|
51 |
From 5d0f507a4162ac89e05ca633dbc8056454b798f5 Mon Sep 17 00:00:00 2001 |
52 |
From: Mike Frysinger <vapier@g.o> |
53 |
Date: Mon, 15 Sep 2014 18:15:02 -0400 |
54 |
Subject: [PATCH] do not rely on pids being unique |
55 |
|
56 |
Linux supports creating pid namespaces cheaply and running processes |
57 |
inside of them. When you try to share a single cache among multiple |
58 |
such runs, the fact that the code relies on pid numbers as globally |
59 |
unique values quickly fails. Instead, switch to standard mkstemp to |
60 |
generate temp files for us. |
61 |
|
62 |
Signed-off-by: Mike Frysinger <vapier@g.o> |
63 |
--- |
64 |
ccache.c | 12 ++++++------ |
65 |
ccache.h | 2 +- |
66 |
manifest.c | 2 +- |
67 |
stats.c | 10 +++++++++- |
68 |
util.c | 13 ++++++++----- |
69 |
5 files changed, 25 insertions(+), 14 deletions(-) |
70 |
|
71 |
diff --git a/ccache.c b/ccache.c |
72 |
index 02dbdfa..1dc0a06 100644 |
73 |
--- a/ccache.c |
74 |
+++ b/ccache.c |
75 |
@@ -526,8 +526,11 @@ to_cache(struct args *args) |
76 |
unsigned added_files = 0; |
77 |
|
78 |
tmp_stdout = format("%s.tmp.stdout.%s", cached_obj, tmp_string()); |
79 |
+ create_empty_file(tmp_stdout); |
80 |
tmp_stderr = format("%s.tmp.stderr.%s", cached_obj, tmp_string()); |
81 |
+ create_empty_file(tmp_stderr); |
82 |
tmp_obj = format("%s.tmp.%s", cached_obj, tmp_string()); |
83 |
+ create_empty_file(tmp_obj); |
84 |
|
85 |
args_add(args, "-o"); |
86 |
args_add(args, tmp_obj); |
87 |
@@ -579,7 +582,7 @@ to_cache(struct args *args) |
88 |
int fd_result; |
89 |
char *tmp_stderr2; |
90 |
|
91 |
- tmp_stderr2 = format("%s.tmp.stderr2.%s", cached_obj, tmp_string()); |
92 |
+ tmp_stderr2 = format("%s.2", tmp_stderr); |
93 |
if (x_rename(tmp_stderr, tmp_stderr2)) { |
94 |
cc_log("Failed to rename %s to %s: %s", tmp_stderr, tmp_stderr2, |
95 |
strerror(errno)); |
96 |
@@ -808,6 +808,7 @@ get_object_name_from_cpp(struct args *args, struct mdfour *hash) |
97 |
} |
98 |
|
99 |
path_stderr = format("%s/tmp.cpp_stderr.%s", temp_dir, tmp_string()); |
100 |
+ create_empty_file(path_stderr); |
101 |
add_pending_tmp_file(path_stderr); |
102 |
|
103 |
time_of_compilation = time(NULL); |
104 |
@@ -815,6 +816,7 @@ get_object_name_from_cpp(struct args *args, struct mdfour *hash) |
105 |
if (!direct_i_file) { |
106 |
path_stdout = format("%s/%s.tmp.%s.%s", |
107 |
temp_dir, input_base, tmp_string(), i_extension); |
108 |
+ create_empty_file(path_stdout); |
109 |
add_pending_tmp_file(path_stdout); |
110 |
|
111 |
/* run cpp on the input file to obtain the .i */ |
112 |
@@ -838,11 +843,6 @@ get_object_name_from_cpp(struct args *args, struct mdfour *hash) |
113 |
can skip the cpp stage and directly form the |
114 |
correct i_tmpfile */ |
115 |
path_stdout = input_file; |
116 |
- if (create_empty_file(path_stderr) != 0) { |
117 |
- cc_log("Failed to create %s: %s", path_stderr, strerror(errno)); |
118 |
- stats_update(STATS_ERROR); |
119 |
- failed(); |
120 |
- } |
121 |
status = 0; |
122 |
} |
123 |
|
124 |
diff --git a/ccache.h b/ccache.h |
125 |
index 2bc7c87..43ef98d 100644 |
126 |
--- a/ccache.h |
127 |
+++ b/ccache.h |
128 |
@@ -130,7 +130,7 @@ size_t file_size(struct stat *st); |
129 |
int safe_open(const char *fname); |
130 |
char *x_realpath(const char *path); |
131 |
char *gnu_getcwd(void); |
132 |
-int create_empty_file(const char *fname); |
133 |
+int create_empty_file(char *fname); |
134 |
const char *get_home_directory(void); |
135 |
char *get_cwd(); |
136 |
bool same_executable_name(const char *s1, const char *s2); |
137 |
diff --git a/manifest.c b/manifest.c |
138 |
index 7f02ede..47566d5 100644 |
139 |
--- a/manifest.c |
140 |
+++ b/manifest.c |
141 |
@@ -633,7 +633,7 @@ manifest_put(const char *manifest_path, struct file_hash *object_hash, |
142 |
} |
143 |
|
144 |
tmp_file = format("%s.tmp.%s", manifest_path, tmp_string()); |
145 |
- fd2 = safe_open(tmp_file); |
146 |
+ fd2 = mkstemp(tmp_file); |
147 |
if (fd2 == -1) { |
148 |
cc_log("Failed to open %s", tmp_file); |
149 |
goto out; |
150 |
diff --git a/stats.c b/stats.c |
151 |
index 2111b65..4ed39c2 100644 |
152 |
--- a/stats.c |
153 |
+++ b/stats.c |
154 |
@@ -126,11 +126,18 @@ stats_write(const char *path, struct counters *counters) |
155 |
size_t i; |
156 |
char *tmp_file; |
157 |
FILE *f; |
158 |
+ int fd; |
159 |
|
160 |
tmp_file = format("%s.tmp.%s", path, tmp_string()); |
161 |
- f = fopen(tmp_file, "wb"); |
162 |
+ fd = mkstemp(tmp_file); |
163 |
+ if (fd == -1) { |
164 |
+ cc_log("Failed to open %s", tmp_file); |
165 |
+ goto end; |
166 |
+ } |
167 |
+ f = fdopen(fd, "wb"); |
168 |
if (!f) { |
169 |
cc_log("Failed to open %s", tmp_file); |
170 |
+ close(fd); |
171 |
goto end; |
172 |
} |
173 |
for (i = 0; i < counters->size; i++) { |
174 |
@@ -138,6 +145,7 @@ stats_write(const char *path, struct counters *counters) |
175 |
fatal("Failed to write to %s", tmp_file); |
176 |
} |
177 |
} |
178 |
+ /* This also implicitly closes the fd. */ |
179 |
fclose(f); |
180 |
x_rename(tmp_file, path); |
181 |
|
182 |
diff --git a/util.c b/util.c |
183 |
index 3b472de..cc630a6 100644 |
184 |
--- a/util.c |
185 |
+++ b/util.c |
186 |
@@ -195,7 +195,7 @@ copy_file(const char *src, const char *dest, int compress_dest) |
187 |
struct stat st; |
188 |
int errnum; |
189 |
|
190 |
- tmp_name = format("%s.%s.XXXXXX", dest, tmp_string()); |
191 |
+ tmp_name = format("%s.%s", dest, tmp_string()); |
192 |
cc_log("Copying %s to %s via %s (%s)", |
193 |
src, dest, tmp_name, compress_dest ? "compressed": "uncompressed"); |
194 |
|
195 |
@@ -427,7 +427,7 @@ tmp_string(void) |
196 |
static char *ret; |
197 |
|
198 |
if (!ret) { |
199 |
- ret = format("%s.%u", get_hostname(), (unsigned)getpid()); |
200 |
+ ret = format("%s.%u.XXXXXX", get_hostname(), (unsigned)getpid()); |
201 |
} |
202 |
|
203 |
return ret; |
204 |
@@ -884,12 +884,13 @@ gnu_getcwd(void) |
205 |
|
206 |
/* create an empty file */ |
207 |
int |
208 |
-create_empty_file(const char *fname) |
209 |
+create_empty_file(char *fname) |
210 |
{ |
211 |
int fd; |
212 |
|
213 |
- fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 0666); |
214 |
+ fd = mkstemp(fname); |
215 |
if (fd == -1) { |
216 |
+ cc_log("Failed to create %s: %s", fname, strerror(errno)); |
217 |
return -1; |
218 |
} |
219 |
close(fd); |
220 |
@@ -1134,7 +1135,9 @@ x_unlink(const char *path) |
221 |
goto out; |
222 |
} |
223 |
if (unlink(tmp_name) == -1) { |
224 |
- result = -1; |
225 |
+ /* If it was released in a race, that's OK. */ |
226 |
+ if (errno != ENOENT) |
227 |
+ result = -1; |
228 |
} |
229 |
out: |
230 |
free(tmp_name); |
231 |
-- |
232 |
2.1.2 |