1 diff -ruN rpm-4.1/lib/psm.c rpm-4.1-9/lib/psm.c
2 --- rpm-4.1/lib/psm.c Tue Sep 17 16:18:50 2002
3 +++ rpm-4.1-9/lib/psm.c Mon Oct 7 12:36:35 2002
5 (void) sigaddset(&caught, signum);
9 - pid_t reaped = waitpid(0, &status, WNOHANG);
13 - for (i = 0; i < psmtbl.npsms; i++) {
14 - rpmpsm psm = psmtbl.psms[i];
15 - if (psm->child != reaped)
16 - /*@innercontinue@*/ continue;
19 + pid_t reaped = waitpid(0, &status, WNOHANG);
23 + /*@innerbreak@*/ break;
26 + for (i = 0; i < psmtbl.npsms; i++) {
27 + rpmpsm psm = psmtbl.psms[i];
28 + if (psm->child != reaped)
29 + /*@innercontinue@*/ continue;
37 - psm->reaped = reaped;
38 - psm->status = status;
39 - /*@innerbreak@*/ break;
40 + psm->reaped = reaped;
41 + psm->status = status;
42 + /*@innerbreak@*/ break;
45 - } /*@switchbreak@*/ break;
46 + /*@switchbreak@*/ break;
48 /*@switchbreak@*/ break;
54 - * Fork a new process.
55 - * @param psm package state machine data
56 - * @return fork(2) pid
58 -static pid_t psmFork(rpmpsm psm)
59 - /*@globals fileSystem, internalState @*/
60 - /*@modifies fileSystem, internalState @*/
64 - if ((pid = fork()) != 0) {
67 -fprintf(stderr, " Fork: %p[%d:%d:%d] = %p child %d\n", psmtbl.psms, 0, psmtbl.npsms, psmtbl.nalloced, psm, pid);
74 * Register a child reaper, then fork a child.
75 * @param psm package state machine data
79 empty = psmtbl.npsms++;
82 if (psmtbl.psms) /* XXX can't happen */
83 psmtbl.psms[empty] = rpmpsmLink(psm, "psmRegister");
88 (void) enableSignal(SIGCHLD);
91 + if ((psm->child = fork()) != 0) {
94 +fprintf(stderr, " Fork: %p[%d:%d:%d] = %p child %d\n", psmtbl.psms, 0, psmtbl.npsms, psmtbl.nalloced, psm, psm->child);
98 (void) sigprocmask(SIG_SETMASK, &oldMask, NULL);
100 - return psmFork(psm);
105 * Unregister a child reaper.
107 -static int psmUnregister(rpmpsm psm, pid_t child)
108 +static int psmWaitUnregister(rpmpsm psm, pid_t child)
109 /*@globals psmtbl, fileSystem, internalState @*/
110 /*@modifies psmtbl, fileSystem, internalState @*/
113 (void) sigfillset(&newMask); /* block all signals */
114 (void) sigprocmask(SIG_BLOCK, &newMask, &oldMask);
117 + while (psm->reaped != psm->child) {
118 + (void) sigprocmask(SIG_SETMASK, &oldMask, NULL);
120 + (void) sigprocmask(SIG_BLOCK, &newMask, &oldMask);
126 +fprintf(stderr, " Wait: %p[%d:%d:%d] = %p child %d\n", psmtbl.psms, 0, psmtbl.npsms, psmtbl.nalloced, psm, psm->child);
130 for (i = 0; i < psmtbl.npsms; i++) {
131 if (psmtbl.psms[i] == NULL)
136 - * Return reaped pid safely (i.e. with signals blocked).
137 - * @param psm package state machine data
140 -static inline pid_t psmGetReaped(rpmpsm psm)
141 - /*@globals fileSystem @*/
142 - /*@modifies fileSystem @*/
144 - sigset_t newMask, oldMask;
147 - (void) sigfillset(&newMask); /* block all signals */
148 - (void) sigprocmask(SIG_BLOCK, &newMask, &oldMask);
149 - reaped = psm->reaped;
150 - (void) sigprocmask(SIG_SETMASK, &oldMask, NULL);
155 * Wait for child process to be reaped.
156 * @param psm package state machine data
159 /*@modifies psm, fileSystem, internalState @*/
163 - while (psmGetReaped(psm) == 0)
168 -fprintf(stderr, " Wait: %p[%d:%d:%d] = %p child %d\n", psmtbl.psms, 0, psmtbl.npsms, psmtbl.nalloced, psm, psm->child);
170 - (void) psmUnregister(psm, psm->child);
171 + (void) psmWaitUnregister(psm, psm->child);
174 psm->reaped = waitpid(psm->child, &psm->status, 0);
178 const char *n, *v, *r;
181 if (progArgv == NULL && script == NULL)
183 @@ -1119,8 +1097,7 @@
184 if (out == NULL) return RPMRC_FAIL; /* XXX can't happen */
187 - pid = psmRegisterFork(psm);
189 + (void) psmRegisterFork(psm);
190 if (psm->child == 0) {
191 const char * rootDir;
194 diff -ruN rpm-4.1/rpmio/rpmlog.c rpm-4.1-9/rpmio/rpmlog.c
195 --- rpm-4.1/rpmio/rpmlog.c Wed Jul 3 01:54:38 2002
196 +++ rpm-4.1-9/rpmio/rpmlog.c Fri Sep 20 18:33:06 2002
200 msgbuf = xrealloc(msgbuf, msgnb);
203 msgbuf[msgnb - 1] = '\0';
205 diff -ruN rpm-4.1/tools/sections.c rpm-4.1-9/tools/sections.c
206 --- rpm-4.1/tools/sections.c Thu Aug 22 19:57:41 2002
207 +++ rpm-4.1-9/tools/sections.c Sun Oct 6 07:30:41 2002
212 - Elf32_Off orig_e_shoff;
213 - Elf32_Off n_sections;
214 + Elf64_Off orig_e_shoff;
215 + Elf64_Off n_sections;
216 UnstripInfoSection64 sections[1];
220 +elf_32_to_file (uint32_t x, int file_is_little_endian)
222 + volatile uint32_t out;
223 + unsigned char *outbytes;
225 + outbytes = (unsigned char *)&out;
226 + if (file_is_little_endian)
228 + outbytes[0] = (x >> 0) & 0xff;
229 + outbytes[1] = (x >> 8) & 0xff;
230 + outbytes[2] = (x >> 16) & 0xff;
231 + outbytes[3] = (x >> 24) & 0xff;
233 + else /* big endian */
235 + outbytes[0] = (x >> 24) & 0xff;
236 + outbytes[1] = (x >> 16) & 0xff;
237 + outbytes[2] = (x >> 8) & 0xff;
238 + outbytes[3] = (x >> 0) & 0xff;
245 +elf_64_to_file (uint64_t x, int file_is_little_endian)
247 + volatile uint64_t out;
248 + unsigned char *outbytes;
251 + outbytes = (unsigned char *)&out;
252 + if (file_is_little_endian)
254 + for (i = 0; i < 8; i++)
255 + outbytes[i] = (x >> (8*i)) & 0xff;
257 + else /* big endian */
259 + for (i = 0; i < 8; i++)
260 + outbytes[7-i] = (x >> (8*i)) & 0xff;
267 word32_to_file (Elf32_Word x, Elf *elf)
269 - /* FIXME: implement */
271 + Elf32_Ehdr *ehdr = elf32_getehdr (elf);
272 + return elf_32_to_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
276 off32_to_file (Elf32_Off x, Elf *elf)
278 - /* FIXME: implement */
280 + Elf32_Ehdr *ehdr = elf32_getehdr (elf);
281 + return elf_32_to_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
285 +word64_to_file (Elf64_Word x, Elf *elf)
287 + Elf64_Ehdr *ehdr = elf64_getehdr (elf);
288 + return elf_32_to_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
292 +off64_to_file (Elf64_Off x, Elf *elf)
294 + Elf64_Ehdr *ehdr = elf64_getehdr (elf);
295 + return elf_64_to_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
299 +elf_32_from_file (uint32_t x, int file_is_little_endian)
301 + unsigned char *inbytes;
303 + inbytes = (unsigned char *)&x;
304 + if (file_is_little_endian)
307 + (inbytes[0] << 0) |
308 + (inbytes[1] << 8) |
309 + (inbytes[2] << 16) |
310 + (inbytes[3] << 24);
312 + else /* big endian */
315 + (inbytes[0] << 24) |
316 + (inbytes[1] << 16) |
317 + (inbytes[2] << 8) |
323 +elf_64_from_file (uint64_t x, int file_is_little_endian)
325 + unsigned char *inbytes;
327 + inbytes = (unsigned char *)&x;
328 + if (file_is_little_endian)
331 + ((uint64_t)inbytes[0] << 0) |
332 + ((uint64_t)inbytes[1] << 8) |
333 + ((uint64_t)inbytes[2] << 16) |
334 + ((uint64_t)inbytes[3] << 24) |
335 + ((uint64_t)inbytes[4] << 32) |
336 + ((uint64_t)inbytes[5] << 40) |
337 + ((uint64_t)inbytes[6] << 48) |
338 + ((uint64_t)inbytes[7] << 56);
340 + else /* big endian */
343 + ((uint64_t)inbytes[0] << 56) |
344 + ((uint64_t)inbytes[1] << 48) |
345 + ((uint64_t)inbytes[2] << 40) |
346 + ((uint64_t)inbytes[3] << 32) |
347 + ((uint64_t)inbytes[4] << 24) |
348 + ((uint64_t)inbytes[5] << 16) |
349 + ((uint64_t)inbytes[6] << 8) |
350 + ((uint64_t)inbytes[7] << 0);
355 word32_from_file (Elf32_Word x, Elf *elf)
357 - /* FIXME: implement */
359 + Elf32_Ehdr *ehdr = elf32_getehdr (elf);
360 + return elf_32_from_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
364 off32_from_file (Elf32_Off x, Elf *elf)
366 - /* FIXME: implement */
368 + Elf32_Ehdr *ehdr = elf32_getehdr (elf);
369 + return elf_32_from_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
373 +word64_from_file (Elf64_Word x, Elf *elf)
375 + Elf64_Ehdr *ehdr = elf64_getehdr (elf);
376 + return elf_32_from_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
380 +off64_from_file (Elf64_Off x, Elf *elf)
382 + Elf64_Ehdr *ehdr = elf64_getehdr (elf);
383 + return elf_64_from_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
391 + UnstripInfo64 *info64;
397 + /* orig_e_shoff */ sizeof (Elf64_Off) +
398 + /* n_sections */ sizeof (Elf64_Off) +
399 + /* sections */ info->n_sections * sizeof (UnstripInfoSection64);
401 + data->d_buf = calloc (1, data->d_size);
403 + info64 = (UnstripInfo64 *) data->d_buf;
405 + info64->orig_e_shoff = off64_to_file (info->orig_e_shoff, elf);
406 + info64->n_sections = off64_to_file (info->n_sections, elf);
408 + for (i = 0; i < info->n_sections; i++)
410 + info64->sections[i].debug_section = word64_to_file (info->sections[i].debug_section, elf);
411 + info64->sections[i].name = word64_to_file (info->sections[i].name, elf);
412 + info64->sections[i].orig_offset = off64_to_file (info->sections[i].orig_offset, elf);
417 @@ -101,11 +253,18 @@
423 data->d_type = ELF_T_BYTE;
426 - /* FIXME: use right version */
427 - unstrip_info_to_data32 (info, elf, data);
428 + gelf_getehdr (elf, &ehdr);
429 + if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
430 + unstrip_info_to_data32 (info, elf, data);
431 + else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64)
432 + unstrip_info_to_data64 (info, elf, data);
434 + fprintf (stderr, "Warning. unsupported elf class\n");
438 @@ -130,23 +289,49 @@
443 +unstrip_info_from_data64 (UnstripInfo *info,
447 + UnstripInfo64 *info64;
450 + info64 = (UnstripInfo64 *) data->d_buf;
452 + info->orig_e_shoff = off64_from_file (info64->orig_e_shoff, elf);
453 + info->n_sections = off64_from_file (info64->n_sections, elf);
455 + info->sections = calloc (info->n_sections, sizeof (UnstripInfoSection));
456 + for (i = 0; i < info->n_sections; i++)
458 + info->sections[i].debug_section = word64_from_file (info64->sections[i].debug_section, elf);
459 + info->sections[i].name = word64_from_file (info64->sections[i].name, elf);
460 + info->sections[i].orig_offset = off64_from_file (info64->sections[i].orig_offset, elf);
465 unstrip_info_from_data (Elf *elf,
472 info = malloc (sizeof (UnstripInfo));
474 - /* FIXME: use right version */
475 - unstrip_info_from_data32 (info,
478 + gelf_getehdr (elf, &ehdr);
479 + if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
480 + unstrip_info_from_data32 (info, elf, data);
481 + else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64)
482 + unstrip_info_from_data64 (info, elf, data);
484 + fprintf (stderr, "Warning. unsupported elf class\n");
491 debug_link_to_data32 (DebugLink *debuglink,
493 @@ -169,17 +354,47 @@
494 p = data->d_buf + namelen_aligned;
496 *(Elf32_Word *)p = word32_to_file (debuglink->checksum, elf);
497 - p += sizeof (Elf32_Word);
501 +debug_link_to_data64 (DebugLink *debuglink,
505 + size_t namelen_aligned;
510 + namelen_aligned = align_up (strlen(debuglink->filename) + 1, 4);
513 + /* name */ namelen_aligned +
514 + /* checksum */ sizeof (Elf64_Word);
516 + data->d_buf = calloc (1, data->d_size);
518 + strcpy (data->d_buf, debuglink->filename);
519 + p = data->d_buf + namelen_aligned;
521 + *(Elf64_Word *)p = word64_to_file (debuglink->checksum, elf);
525 debug_link_to_data (DebugLink *debuglink, Elf *elf, Elf_Data *data)
529 data->d_type = ELF_T_BYTE;
532 - /* FIXME: use right version */
533 - debug_link_to_data32 (debuglink, elf, data);
534 + gelf_getehdr (elf, &ehdr);
535 + if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
536 + debug_link_to_data32 (debuglink, elf, data);
537 + else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64)
538 + debug_link_to_data64 (debuglink, elf, data);
540 + fprintf (stderr, "Warning. unsupported elf class\n");
544 @@ -197,21 +412,41 @@
545 p = data->d_buf + namelen_aligned;
547 debuglink->checksum = word32_from_file (*(Elf32_Word *)p, elf);
548 - p += sizeof (Elf32_Word);
552 +debug_link_from_data64 (DebugLink *debuglink,
556 + size_t namelen_aligned;
559 + debuglink->filename = strdup (data->d_buf);
561 + namelen_aligned = align_up (strlen (debuglink->filename) + 1, 4);
563 + p = data->d_buf + namelen_aligned;
565 + debuglink->checksum = word64_from_file (*(Elf64_Word *)p, elf);
570 debug_link_from_data (Elf *elf, Elf_Data *data)
573 DebugLink *debuglink;
575 debuglink = malloc (sizeof (DebugLink));
577 - /* FIXME: use right version */
578 - debug_link_from_data32 (debuglink,
581 + gelf_getehdr (elf, &ehdr);
582 + if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
583 + debug_link_from_data32 (debuglink, elf, data);
584 + else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64)
585 + debug_link_from_data64 (debuglink, elf, data);
587 + fprintf (stderr, "Warning. unsupported elf class\n");
591 diff -ruN rpm-4.1/tools/striptofile.c rpm-4.1-9/tools/striptofile.c
592 --- rpm-4.1/tools/striptofile.c Thu Aug 22 21:08:25 2002
593 +++ rpm-4.1-9/tools/striptofile.c Sun Oct 6 07:30:41 2002
595 /* Update section header stringtab ref */
596 gelf_getehdr (out_elf, &out_ehdr);
597 out_ehdr.e_shstrndx = section_map[out_ehdr.e_shstrndx];
598 - out_ehdr.e_shoff = align_up (last_offset, 4);
599 + out_ehdr.e_shoff = align_up (last_offset, 8);
600 gelf_update_ehdr(out_elf, &out_ehdr);
602 /* Update section header links */
606 const char *origname;
607 + char *origname_base;
608 char *debugname, *strippedname;
609 DebugLink *debuglink;
610 poptContext optCon; /* context for parsing command-line options */
611 @@ -433,14 +434,13 @@
616 - const char * bn = strrchr(origname, '/');
617 - if ((bn = strrchr(origname, '/')) != NULL)
621 - debugname = strconcat (output_dir, "/", bn, ".debug", NULL);
625 + origname_base = path_basename (origname);
626 + debugname = strconcat (output_dir, "/", origname_base, ".debug", NULL);
627 + free (origname_base);
630 debugname = strconcat (origname, ".debug", NULL);
632 strippedname = strconcat (origname, ".XXXXXX", NULL);