source: BOOK/final-system/multilib/multiarch_wrapper.xml@ 2093cd5

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 2093cd5 was d4a75ad, checked in by Joe Ciccone <jciccone@…>, 16 years ago

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

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[5accd22]1<?xml version="1.0" encoding="ISO-8859-1"?>
[aa18ac0]2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
[5accd22]4 <!ENTITY % general-entities SYSTEM "../../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="ch-system-multiarch-wrapper" role="wrap">
9 <?dbhtml filename="multiarch_wrapper.html"?>
10
[72ed305]11 <title>Creating a Multiarch Wrapper</title>
[5accd22]12
13 <indexterm zone="ch-system-multiarch-wrapper">
14 <primary sortas="a-File">Multiarch Wrapper</primary>
15 </indexterm>
16
17 <sect2 role="package">
18 <title/>
19
20 <para>The Multiarch Wrapper is used to wrap certain binaries that have
21 hardcoded paths to libraries or are architecture specific.</para>
22
23 </sect2>
24
25 <sect2 role="installation">
26 <title>Installation of The Multiarch Wrapper</title>
27
28 <para os="a">Create the source file:</para>
29
30<screen os="b"><userinput>cat &gt; multiarch_wrapper.c &lt;&lt; "EOF"
[d4a75ad]31#define _GNU_SOURCE
32
[5accd22]33#include &lt;errno.h&gt;
[d4a75ad]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;
38#include &lt;unistd.h&gt;
[5accd22]39
[d4a75ad]40#ifndef DEF_SUFFIX
41# define DEF_SUFFIX "64"
[5accd22]42#endif
43
[5fb43ca]44int main(int argc, char **argv)
[5accd22]45{
[5fb43ca]46 char *filename;
[d4a75ad]47 char *suffix;
48
49 if(!(suffix = getenv("USE_ARCH")))
50 if(!(suffix = getenv("BUILDENV")))
51 suffix = DEF_SUFFIX;
52
53 if (asprintf(&amp;filename, "%s-%s", argv[0], suffix) &lt; 0) {
54 perror(argv[0]);
55 return -1;
56 }
57
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:
[5fb43ca]77 perror(argv[0]);
[d4a75ad]78end:
[5accd22]79 free(filename);
[d4a75ad]80
81 return status;
[5accd22]82}
[d4a75ad]83
[5accd22]84EOF</userinput></screen>
85
86 <para os="c">Compile and Install the Multiarch Wrapper:</para>
87
88<screen os="d"><userinput>gcc ${BUILD64} multiarch_wrapper.c -o /usr/bin/multiarch_wrapper</userinput></screen>
89
90 <para os="e">This multiarch wrapper is going to be used later on in the book
[a7fa075]91 with Perl. It will also be very useful outside of the base CLFS system.</para>
[5accd22]92
[a7fa075]93 <para os="f">Create a testcase:</para>
[5accd22]94
95<screen os="g"><userinput>echo 'echo "32bit Version"' &gt; test-32
96echo 'echo "64bit Version"' &gt; test-64
97chmod 755 test-32 test-64
98ln -sv /usr/bin/multiarch_wrapper test</userinput></screen>
99
[a7fa075]100 <para os="h">Test the wrapper:</para>
[5accd22]101
102<screen os="i"><userinput>USE_ARCH=32 ./test
103USE_ARCH=64 ./test</userinput></screen>
104
105 <para os="j">The output of the above command should be:</para>
106
[32c37aa8]107<screen os="k" role="nodump"><userinput>32bit Version
[5accd22]10864bit Version</userinput></screen>
109
110 </sect2>
111
112 <sect2 id="contents-multiarch-wrapper" role="content">
113 <title>Contents of The Multiarch Wrapper</title>
114
115 <segmentedlist>
116 <segtitle>Installed programs</segtitle>
117
118 <seglistitem>
119 <seg>multiarch_wrapper</seg>
120 </seglistitem>
121 </segmentedlist>
122
123 <variablelist>
124 <bridgehead renderas="sect3">Short Descriptions</bridgehead>
125 <?dbfo list-presentation="list"?>
126 <?dbhtml list-presentation="table"?>
127
128 <varlistentry id="multiarch_wrapper">
129 <term><command>multiarch_wrapper</command></term>
130 <listitem>
131 <para>Will execute a different program based on the
132 <envar>USE_ARCH</envar> variable. The <envar>USE_ARCH</envar>
133 variable will be the suffix of the executed program.</para>
134 <indexterm zone="ch-system-multiarch-wrapper multiarch_wrapper">
135 <primary sortas="b-multiarch_wrapper">multiarch_wrapper</primary>
136 </indexterm>
137 </listitem>
138 </varlistentry>
139
140 </variablelist>
141
142 </sect2>
143
144</sect1>
Note: See TracBrowser for help on using the repository browser.