diff options
Diffstat (limited to 'meta/recipes-devtools/rpm/files/0004-build-pack.c-remove-static-local-variables-from-buil.patch')
-rw-r--r-- | meta/recipes-devtools/rpm/files/0004-build-pack.c-remove-static-local-variables-from-buil.patch | 337 |
1 files changed, 337 insertions, 0 deletions
diff --git a/meta/recipes-devtools/rpm/files/0004-build-pack.c-remove-static-local-variables-from-buil.patch b/meta/recipes-devtools/rpm/files/0004-build-pack.c-remove-static-local-variables-from-buil.patch new file mode 100644 index 0000000000..64a5651f7e --- /dev/null +++ b/meta/recipes-devtools/rpm/files/0004-build-pack.c-remove-static-local-variables-from-buil.patch | |||
@@ -0,0 +1,337 @@ | |||
1 | From ec305795a302d226343e69031ff2024dfcde69c0 Mon Sep 17 00:00:00 2001 | ||
2 | From: Alexander Kanavin <alex.kanavin@gmail.com> | ||
3 | Date: Thu, 8 Jun 2017 17:08:09 +0300 | ||
4 | Subject: [PATCH 3/3] build/pack.c: remove static local variables from | ||
5 | buildHost() and getBuildTime() | ||
6 | |||
7 | Their use is causing difficult to diagnoze data races when building multiple | ||
8 | packages in parallel, and is a bad idea in general, as it also makes it more | ||
9 | difficult to reason about code. | ||
10 | |||
11 | Upstream-Status: Submitted [https://github.com/rpm-software-management/rpm/pull/226] | ||
12 | Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com> | ||
13 | |||
14 | |||
15 | Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com> | ||
16 | --- | ||
17 | build/build.c | 54 ++++++++++++++++++++++++++++-- | ||
18 | build/pack.c | 84 +++++++++-------------------------------------- | ||
19 | build/rpmbuild_internal.h | 8 +++-- | ||
20 | 3 files changed, 74 insertions(+), 72 deletions(-) | ||
21 | |||
22 | diff --git a/build/build.c b/build/build.c | ||
23 | index 5f99c8db7..09a1311c5 100644 | ||
24 | --- a/build/build.c | ||
25 | +++ b/build/build.c | ||
26 | @@ -6,6 +6,8 @@ | ||
27 | #include "system.h" | ||
28 | |||
29 | #include <errno.h> | ||
30 | +#include <netdb.h> | ||
31 | +#include <time.h> | ||
32 | #include <sys/wait.h> | ||
33 | |||
34 | #include <rpm/rpmlog.h> | ||
35 | @@ -16,6 +18,50 @@ | ||
36 | |||
37 | #include "debug.h" | ||
38 | |||
39 | +static rpm_time_t getBuildTime(void) | ||
40 | +{ | ||
41 | + rpm_time_t buildTime = 0; | ||
42 | + char *srcdate; | ||
43 | + time_t epoch; | ||
44 | + char *endptr; | ||
45 | + | ||
46 | + srcdate = getenv("SOURCE_DATE_EPOCH"); | ||
47 | + if (srcdate) { | ||
48 | + errno = 0; | ||
49 | + epoch = strtol(srcdate, &endptr, 10); | ||
50 | + if (srcdate == endptr || *endptr || errno != 0) | ||
51 | + rpmlog(RPMLOG_ERR, _("unable to parse SOURCE_DATE_EPOCH\n")); | ||
52 | + else | ||
53 | + buildTime = (int32_t) epoch; | ||
54 | + } else | ||
55 | + buildTime = (int32_t) time(NULL); | ||
56 | + | ||
57 | + return buildTime; | ||
58 | +} | ||
59 | + | ||
60 | +static char * buildHost(void) | ||
61 | +{ | ||
62 | + char* hostname; | ||
63 | + struct hostent *hbn; | ||
64 | + char *bhMacro; | ||
65 | + | ||
66 | + bhMacro = rpmExpand("%{?_buildhost}", NULL); | ||
67 | + if (strcmp(bhMacro, "") != 0) { | ||
68 | + rasprintf(&hostname, "%s", bhMacro); | ||
69 | + } else { | ||
70 | + hostname = rcalloc(1024, sizeof(*hostname)); | ||
71 | + (void) gethostname(hostname, 1024); | ||
72 | + hbn = gethostbyname(hostname); | ||
73 | + if (hbn) | ||
74 | + strcpy(hostname, hbn->h_name); | ||
75 | + else | ||
76 | + rpmlog(RPMLOG_WARNING, | ||
77 | + _("Could not canonicalize hostname: %s\n"), hostname); | ||
78 | + } | ||
79 | + free(bhMacro); | ||
80 | + return(hostname); | ||
81 | +} | ||
82 | + | ||
83 | /** | ||
84 | */ | ||
85 | static rpmRC doRmSource(rpmSpec spec) | ||
86 | @@ -203,6 +249,9 @@ static rpmRC buildSpec(BTA_t buildArgs, rpmSpec spec, int what) | ||
87 | rpmRC rc = RPMRC_OK; | ||
88 | int test = (what & RPMBUILD_NOBUILD); | ||
89 | char *cookie = buildArgs->cookie ? xstrdup(buildArgs->cookie) : NULL; | ||
90 | + const char* host = buildHost(); | ||
91 | + rpm_time_t buildTime = getBuildTime(); | ||
92 | + | ||
93 | |||
94 | if (rpmExpandNumeric("%{?source_date_epoch_from_changelog}") && | ||
95 | getenv("SOURCE_DATE_EPOCH") == NULL) { | ||
96 | @@ -271,11 +320,11 @@ static rpmRC buildSpec(BTA_t buildArgs, rpmSpec spec, int what) | ||
97 | goto exit; | ||
98 | |||
99 | if (((what & RPMBUILD_PACKAGESOURCE) && !test) && | ||
100 | - (rc = packageSources(spec, &cookie))) | ||
101 | + (rc = packageSources(spec, &cookie, buildTime, host))) | ||
102 | return rc; | ||
103 | |||
104 | if (((what & RPMBUILD_PACKAGEBINARY) && !test) && | ||
105 | - (rc = packageBinaries(spec, cookie, (didBuild == 0)))) | ||
106 | + (rc = packageBinaries(spec, cookie, (didBuild == 0), buildTime, host))) | ||
107 | goto exit; | ||
108 | |||
109 | if ((what & RPMBUILD_CLEAN) && | ||
110 | @@ -295,6 +344,7 @@ static rpmRC buildSpec(BTA_t buildArgs, rpmSpec spec, int what) | ||
111 | (void) unlink(spec->specFile); | ||
112 | |||
113 | exit: | ||
114 | + free(host); | ||
115 | free(cookie); | ||
116 | spec->rootDir = NULL; | ||
117 | if (rc != RPMRC_OK && rpmlogGetNrecs() > 0) { | ||
118 | diff --git a/build/pack.c b/build/pack.c | ||
119 | index ed5b9ab4e..62427065a 100644 | ||
120 | --- a/build/pack.c | ||
121 | +++ b/build/pack.c | ||
122 | @@ -6,8 +6,6 @@ | ||
123 | #include "system.h" | ||
124 | |||
125 | #include <errno.h> | ||
126 | -#include <netdb.h> | ||
127 | -#include <time.h> | ||
128 | #include <sys/wait.h> | ||
129 | |||
130 | #include <rpm/rpmlib.h> /* RPMSIGTAG*, rpmReadPackageFile */ | ||
131 | @@ -151,57 +149,6 @@ exit: | ||
132 | return rc; | ||
133 | } | ||
134 | |||
135 | -static rpm_time_t * getBuildTime(void) | ||
136 | -{ | ||
137 | - static rpm_time_t buildTime[1]; | ||
138 | - char *srcdate; | ||
139 | - time_t epoch; | ||
140 | - char *endptr; | ||
141 | - | ||
142 | - if (buildTime[0] == 0) { | ||
143 | - srcdate = getenv("SOURCE_DATE_EPOCH"); | ||
144 | - if (srcdate) { | ||
145 | - errno = 0; | ||
146 | - epoch = strtol(srcdate, &endptr, 10); | ||
147 | - if (srcdate == endptr || *endptr || errno != 0) | ||
148 | - rpmlog(RPMLOG_ERR, _("unable to parse SOURCE_DATE_EPOCH\n")); | ||
149 | - else | ||
150 | - buildTime[0] = (int32_t) epoch; | ||
151 | - } else | ||
152 | - buildTime[0] = (int32_t) time(NULL); | ||
153 | - } | ||
154 | - | ||
155 | - return buildTime; | ||
156 | -} | ||
157 | - | ||
158 | -static const char * buildHost(void) | ||
159 | -{ | ||
160 | - static char hostname[1024]; | ||
161 | - static int oneshot = 0; | ||
162 | - struct hostent *hbn; | ||
163 | - char *bhMacro; | ||
164 | - | ||
165 | - if (! oneshot) { | ||
166 | - bhMacro = rpmExpand("%{?_buildhost}", NULL); | ||
167 | - if (strcmp(bhMacro, "") != 0 && strlen(bhMacro) < 1024) { | ||
168 | - strcpy(hostname, bhMacro); | ||
169 | - } else { | ||
170 | - if (strcmp(bhMacro, "") != 0) | ||
171 | - rpmlog(RPMLOG_WARNING, _("The _buildhost macro is too long\n")); | ||
172 | - (void) gethostname(hostname, sizeof(hostname)); | ||
173 | - hbn = gethostbyname(hostname); | ||
174 | - if (hbn) | ||
175 | - strcpy(hostname, hbn->h_name); | ||
176 | - else | ||
177 | - rpmlog(RPMLOG_WARNING, | ||
178 | - _("Could not canonicalize hostname: %s\n"), hostname); | ||
179 | - } | ||
180 | - free(bhMacro); | ||
181 | - oneshot = 1; | ||
182 | - } | ||
183 | - return(hostname); | ||
184 | -} | ||
185 | - | ||
186 | static rpmRC processScriptFiles(rpmSpec spec, Package pkg) | ||
187 | { | ||
188 | struct TriggerFileEntry *p; | ||
189 | @@ -308,7 +255,8 @@ static int haveRichDep(Package pkg) | ||
190 | } | ||
191 | |||
192 | static rpmRC writeRPM(Package pkg, unsigned char ** pkgidp, | ||
193 | - const char *fileName, char **cookie) | ||
194 | + const char *fileName, char **cookie, | ||
195 | + rpm_time_t buildTime, const char* buildHost) | ||
196 | { | ||
197 | FD_t fd = NULL; | ||
198 | char * rpmio_flags = NULL; | ||
199 | @@ -397,7 +345,7 @@ static rpmRC writeRPM(Package pkg, unsigned char ** pkgidp, | ||
200 | |||
201 | /* Create and add the cookie */ | ||
202 | if (cookie) { | ||
203 | - rasprintf(cookie, "%s %d", buildHost(), (int) (*getBuildTime())); | ||
204 | + rasprintf(cookie, "%s %d", buildHost, buildTime); | ||
205 | headerPutString(pkg->header, RPMTAG_COOKIE, *cookie); | ||
206 | } | ||
207 | |||
208 | @@ -546,7 +494,7 @@ static rpmRC checkPackages(char *pkgcheck) | ||
209 | return RPMRC_OK; | ||
210 | } | ||
211 | |||
212 | -static rpmRC packageBinary(rpmSpec spec, Package pkg, const char *cookie, int cheating, char** filename) | ||
213 | +static rpmRC packageBinary(rpmSpec spec, Package pkg, const char *cookie, int cheating, char** filename, rpm_time_t buildTime, const char* buildHost) | ||
214 | { | ||
215 | const char *errorString; | ||
216 | rpmRC rc = RPMRC_OK; | ||
217 | @@ -565,8 +513,8 @@ static rpmRC packageBinary(rpmSpec spec, Package pkg, const char *cookie, int ch | ||
218 | headerCopyTags(spec->packages->header, pkg->header, copyTags); | ||
219 | |||
220 | headerPutString(pkg->header, RPMTAG_RPMVERSION, VERSION); | ||
221 | - headerPutString(pkg->header, RPMTAG_BUILDHOST, buildHost()); | ||
222 | - headerPutUint32(pkg->header, RPMTAG_BUILDTIME, getBuildTime(), 1); | ||
223 | + headerPutString(pkg->header, RPMTAG_BUILDHOST, buildHost); | ||
224 | + headerPutUint32(pkg->header, RPMTAG_BUILDTIME, &buildTime, 1); | ||
225 | |||
226 | if (spec->sourcePkgId != NULL) { | ||
227 | headerPutBin(pkg->header, RPMTAG_SOURCEPKGID, spec->sourcePkgId,16); | ||
228 | @@ -604,7 +552,7 @@ static rpmRC packageBinary(rpmSpec spec, Package pkg, const char *cookie, int ch | ||
229 | free(binRpm); | ||
230 | } | ||
231 | |||
232 | - rc = writeRPM(pkg, NULL, *filename, NULL); | ||
233 | + rc = writeRPM(pkg, NULL, *filename, NULL, buildTime, buildHost); | ||
234 | if (rc == RPMRC_OK) { | ||
235 | /* Do check each written package if enabled */ | ||
236 | char *pkgcheck = rpmExpand("%{?_build_pkgcheck} ", *filename, NULL); | ||
237 | @@ -624,7 +572,7 @@ struct binaryPackageTaskData | ||
238 | struct binaryPackageTaskData *next; | ||
239 | }; | ||
240 | |||
241 | -static struct binaryPackageTaskData* runBinaryPackageTasks(rpmSpec spec, const char *cookie, int cheating) | ||
242 | +static struct binaryPackageTaskData* runBinaryPackageTasks(rpmSpec spec, const char *cookie, int cheating, rpm_time_t buildTime, char* buildHost) | ||
243 | { | ||
244 | struct binaryPackageTaskData *tasks = NULL; | ||
245 | struct binaryPackageTaskData *task = NULL; | ||
246 | @@ -636,7 +584,7 @@ static struct binaryPackageTaskData* runBinaryPackageTasks(rpmSpec spec, const c | ||
247 | if (pkg == spec->packages) { | ||
248 | // the first package needs to be processed ahead of others, as they copy | ||
249 | // changelog data from it, and so otherwise data races would happen | ||
250 | - task->result = packageBinary(spec, pkg, cookie, cheating, &(task->filename)); | ||
251 | + task->result = packageBinary(spec, pkg, cookie, cheating, &(task->filename), buildTime, buildHost); | ||
252 | rpmlog(RPMLOG_NOTICE, _("Finished binary package job, result %d, filename %s\n"), task->result, task->filename); | ||
253 | tasks = task; | ||
254 | } | ||
255 | @@ -653,7 +601,7 @@ static struct binaryPackageTaskData* runBinaryPackageTasks(rpmSpec spec, const c | ||
256 | if (task != tasks) | ||
257 | #pragma omp task | ||
258 | { | ||
259 | - task->result = packageBinary(spec, task->pkg, cookie, cheating, &(task->filename)); | ||
260 | + task->result = packageBinary(spec, task->pkg, cookie, cheating, &(task->filename), buildTime, buildHost); | ||
261 | rpmlog(RPMLOG_NOTICE, _("Finished binary package job, result %d, filename %s\n"), task->result, task->filename); | ||
262 | } | ||
263 | } | ||
264 | @@ -671,11 +619,11 @@ static void freeBinaryPackageTasks(struct binaryPackageTaskData* tasks) | ||
265 | } | ||
266 | } | ||
267 | |||
268 | -rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating) | ||
269 | +rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating, rpm_time_t buildTime, char* buildHost) | ||
270 | { | ||
271 | char *pkglist = NULL; | ||
272 | |||
273 | - struct binaryPackageTaskData *tasks = runBinaryPackageTasks(spec, cookie, cheating); | ||
274 | + struct binaryPackageTaskData *tasks = runBinaryPackageTasks(spec, cookie, cheating, buildTime, buildHost); | ||
275 | |||
276 | for (struct binaryPackageTaskData *task = tasks; task != NULL; task = task->next) { | ||
277 | if (task->result == RPMRC_OK) { | ||
278 | @@ -702,22 +650,22 @@ rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating) | ||
279 | return RPMRC_OK; | ||
280 | } | ||
281 | |||
282 | -rpmRC packageSources(rpmSpec spec, char **cookie) | ||
283 | +rpmRC packageSources(rpmSpec spec, char **cookie, rpm_time_t buildTime, char* buildHost) | ||
284 | { | ||
285 | Package sourcePkg = spec->sourcePackage; | ||
286 | rpmRC rc; | ||
287 | |||
288 | /* Add some cruft */ | ||
289 | headerPutString(sourcePkg->header, RPMTAG_RPMVERSION, VERSION); | ||
290 | - headerPutString(sourcePkg->header, RPMTAG_BUILDHOST, buildHost()); | ||
291 | - headerPutUint32(sourcePkg->header, RPMTAG_BUILDTIME, getBuildTime(), 1); | ||
292 | + headerPutString(sourcePkg->header, RPMTAG_BUILDHOST, buildHost); | ||
293 | + headerPutUint32(sourcePkg->header, RPMTAG_BUILDTIME, &buildTime, 1); | ||
294 | |||
295 | /* XXX this should be %_srpmdir */ | ||
296 | { char *fn = rpmGetPath("%{_srcrpmdir}/", spec->sourceRpmName,NULL); | ||
297 | char *pkgcheck = rpmExpand("%{?_build_pkgcheck_srpm} ", fn, NULL); | ||
298 | |||
299 | spec->sourcePkgId = NULL; | ||
300 | - rc = writeRPM(sourcePkg, &spec->sourcePkgId, fn, cookie); | ||
301 | + rc = writeRPM(sourcePkg, &spec->sourcePkgId, fn, cookie, buildTime, buildHost); | ||
302 | |||
303 | /* Do check SRPM package if enabled */ | ||
304 | if (rc == RPMRC_OK && pkgcheck[0] != ' ') { | ||
305 | diff --git a/build/rpmbuild_internal.h b/build/rpmbuild_internal.h | ||
306 | index 8351a6a34..797337ca7 100644 | ||
307 | --- a/build/rpmbuild_internal.h | ||
308 | +++ b/build/rpmbuild_internal.h | ||
309 | @@ -408,19 +408,23 @@ rpmRC processSourceFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags); | ||
310 | * @param spec spec file control structure | ||
311 | * @param cookie build identifier "cookie" or NULL | ||
312 | * @param cheating was build shortcircuited? | ||
313 | + * @param buildTime the build timestamp that goes into packages | ||
314 | + * @param buildHost the hostname where the build is happening | ||
315 | * @return RPMRC_OK on success | ||
316 | */ | ||
317 | RPM_GNUC_INTERNAL | ||
318 | -rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating); | ||
319 | +rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating, rpm_time_t buildTime, char* buildHost); | ||
320 | |||
321 | /** \ingroup rpmbuild | ||
322 | * Generate source package. | ||
323 | * @param spec spec file control structure | ||
324 | * @retval cookie build identifier "cookie" or NULL | ||
325 | + * @param buildTime the build timestamp that goes into packages | ||
326 | + * @param buildHost the hostname where the build is happening | ||
327 | * @return RPMRC_OK on success | ||
328 | */ | ||
329 | RPM_GNUC_INTERNAL | ||
330 | -rpmRC packageSources(rpmSpec spec, char **cookie); | ||
331 | +rpmRC packageSources(rpmSpec spec, char **cookie, rpm_time_t buildTime, char* buildHost); | ||
332 | |||
333 | RPM_GNUC_INTERNAL | ||
334 | int addLangTag(rpmSpec spec, Header h, rpmTagVal tag, | ||
335 | -- | ||
336 | 2.11.0 | ||
337 | |||