]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd-id128.xml
test-execute: Add tests for new PassEnvironment= directive
[thirdparty/systemd.git] / man / sd-id128.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <!--
6 This file is part of systemd.
7
8 Copyright 2012 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 -->
23
24 <refentry id="sd-id128"
25 xmlns:xi="http://www.w3.org/2001/XInclude">
26
27 <refentryinfo>
28 <title>sd-id128</title>
29 <productname>systemd</productname>
30
31 <authorgroup>
32 <author>
33 <contrib>Developer</contrib>
34 <firstname>Lennart</firstname>
35 <surname>Poettering</surname>
36 <email>lennart@poettering.net</email>
37 </author>
38 </authorgroup>
39 </refentryinfo>
40
41 <refmeta>
42 <refentrytitle>sd-id128</refentrytitle>
43 <manvolnum>3</manvolnum>
44 </refmeta>
45
46 <refnamediv>
47 <refname>sd-id128</refname>
48 <refname>sd_id128_t</refname>
49 <refname>SD_ID128_MAKE</refname>
50 <refname>SD_ID128_CONST_STR</refname>
51 <refname>SD_ID128_FORMAT_STR</refname>
52 <refname>SD_ID128_FORMAT_VAL</refname>
53 <refname>sd_id128_equal</refname>
54 <refpurpose>APIs for processing 128-bit IDs</refpurpose>
55 </refnamediv>
56
57 <refsynopsisdiv>
58 <funcsynopsis>
59 <funcsynopsisinfo>#include &lt;systemd/sd-id128.h&gt;</funcsynopsisinfo>
60 </funcsynopsis>
61
62 <cmdsynopsis>
63 <command>pkg-config --cflags --libs libsystemd</command>
64 </cmdsynopsis>
65
66 </refsynopsisdiv>
67
68 <refsect1>
69 <title>Description</title>
70
71 <para><filename>sd-id128.h</filename> provides APIs to process and
72 generate 128-bit ID values. The 128-bit ID values processed and
73 generated by these APIs are a generalization of OSF UUIDs as
74 defined by <ulink url="https://tools.ietf.org/html/rfc4122">RFC
75 4122</ulink> but use a simpler string format. These functions
76 impose no structure on the used IDs, much unlike OSF UUIDs or
77 Microsoft GUIDs, but are fully compatible with those types of IDs.
78 </para>
79
80 <para>See
81 <citerefentry><refentrytitle>sd_id128_to_string</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
82 <citerefentry><refentrytitle>sd_id128_randomize</refentrytitle><manvolnum>3</manvolnum></citerefentry>
83 and
84 <citerefentry><refentrytitle>sd_id128_get_machine</refentrytitle><manvolnum>3</manvolnum></citerefentry>
85 for more information about the implemented functions.</para>
86
87 <para>A 128-bit ID is implemented as the following
88 union type:</para>
89
90 <programlisting>typedef union sd_id128 {
91 uint8_t bytes[16];
92 uint64_t qwords[2];
93 } sd_id128_t;</programlisting>
94
95 <para>This union type allows accessing the 128-bit ID as 16
96 separate bytes or two 64-bit words. It is generally safer to
97 access the ID components by their 8-bit array to avoid endianness
98 issues. This union is intended to be passed call-by-value (as
99 opposed to call-by-reference) and may be directly manipulated by
100 clients.</para>
101
102 <para>A couple of macros are defined to denote and decode 128-bit
103 IDs:</para>
104
105 <para><function>SD_ID128_MAKE()</function> may be used to denote a
106 constant 128-bit ID in source code. A commonly used idiom is to
107 assign a name to a 128-bit ID using this macro:</para>
108
109 <programlisting>#define SD_MESSAGE_COREDUMP SD_ID128_MAKE(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1)</programlisting>
110
111 <para><function>SD_ID128_CONST_STR()</function> may be used to
112 convert constant 128-bit IDs into constant strings for output. The
113 following example code will output the string
114 "fc2e22bc6ee647b6b90729ab34a250b1":</para>
115 <programlisting>int main(int argc, char *argv[]) {
116 puts(SD_ID128_CONST_STR(SD_MESSAGE_COREDUMP));
117 }</programlisting>
118
119 <para><function>SD_ID128_FORMAT_STR</function> and
120 <function>SD_ID128_FORMAT_VAL()</function> may be used to format a
121 128-bit ID in a
122 <citerefentry project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry>
123 format string, as shown in the following example:</para>
124
125 <programlisting>int main(int argc, char *argv[]) {
126 sd_id128_t id;
127 id = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
128 printf("The ID encoded in this C file is " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(id));
129 return 0;
130 }</programlisting>
131
132 <para>Use <function>sd_id128_equal()</function> to compare two 128-bit IDs:</para>
133
134 <programlisting>int main(int argc, char *argv[]) {
135 sd_id128_t a, b, c;
136 a = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
137 b = SD_ID128_MAKE(f2,28,88,9c,5f,09,44,15,9d,d7,04,77,58,cb,e7,3e);
138 c = a;
139 assert(sd_id128_equal(a, c));
140 assert(!sd_id128_equal(a, b));
141 return 0;
142 }</programlisting>
143
144 <para>Note that new, randomized IDs may be generated with
145 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
146 <option>--new-id</option> option.</para>
147 </refsect1>
148
149 <xi:include href="libsystemd-pkgconfig.xml" />
150
151 <refsect1>
152 <title>See Also</title>
153 <para>
154 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
155 <citerefentry><refentrytitle>sd_id128_to_string</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
156 <citerefentry><refentrytitle>sd_id128_randomize</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
157 <citerefentry><refentrytitle>sd_id128_get_machine</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
158 <citerefentry project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
159 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
160 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
161 <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
162 <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>
163 </para>
164 </refsect1>
165
166 </refentry>