Changeset d4a75ad


Ignore:
Timestamp:
Jun 8, 2009, 7:36:42 PM (12 years ago)
Author:
Joe Ciccone <jciccone@…>
Branches:
clfs-1.2, clfs-2.1, clfs-3.0.0-systemd, clfs-3.0.0-sysvinit, master, systemd, sysvinit
Children:
b889fe6
Parents:
878afd8
Message:

Update the Multiarch Wrapper after the discussion in ticket #210. Thanks manurootcpp for pointing out an obvious memory leak in the wrapper.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BOOK/final-system/multilib/multiarch_wrapper.xml

    r878afd8 rd4a75ad  
    2929
    3030<screen os="b"><userinput>cat &gt; multiarch_wrapper.c &lt;&lt; "EOF"
     31#define _GNU_SOURCE
     32
     33#include &lt;errno.h&gt;
     34#include &lt;stdio.h&gt;
     35#include &lt;stdlib.h&gt;
     36#include &lt;sys/types.h&gt;
     37#include &lt;sys/wait.h&gt;
    3138#include &lt;unistd.h&gt;
    32 #include &lt;stdlib.h&gt;
    33 #include &lt;errno.h&gt;
    34 #include &lt;string.h&gt;
    3539
    36 #ifndef USE_ARCH
    37 #define USE_ARCH "64"
     40#ifndef DEF_SUFFIX
     41#  define DEF_SUFFIX "64"
    3842#endif
    3943
     
    4145{
    4246  char *filename;
    43   char *use_arch;
     47  char *suffix;
    4448
    45   if(!(use_arch = getenv("USE_ARCH")))
    46     use_arch = USE_ARCH;
     49  if(!(suffix = getenv("USE_ARCH")))
     50    if(!(suffix = getenv("BUILDENV")))
     51      suffix = DEF_SUFFIX;
    4752
    48   filename = (char *) malloc(strlen(argv[0]) + strlen(use_arch) + 2);
    49   strcpy(filename, argv[0]);
    50   strcat(filename, "-");
    51   strcat(filename, use_arch);
     53  if (asprintf(&amp;filename, "%s-%s", argv[0], suffix) &lt; 0) {
     54    perror(argv[0]);
     55    return -1;
     56  }
    5257
    53   execvp(filename, argv);
     58  int status = EXIT_FAILURE;
     59  pid_t pid = fork();
     60
     61  if (pid == 0) {
     62    execvp(filename, argv);
     63    perror(filename);
     64    goto end;
     65  } else if (pid &lt; 0) {
     66    goto end_error;
     67  } else {
     68    if (waitpid(pid, &amp;status, 0) != pid) {
     69      status = EXIT_FAILURE;
     70      goto end_error;
     71    }
     72    status = WEXITSTATUS(status);
     73  }
     74  goto end;
     75
     76end_error:
    5477  perror(argv[0]);
     78end:
    5579  free(filename);
     80
     81  return status;
    5682}
     83
    5784EOF</userinput></screen>
    5885
Note: See TracChangeset for help on using the changeset viewer.