]>
git.proxmox.com Git - systemd.git/blob - src/shared/specifier.c
2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include <sys/utsname.h>
29 #include "alloc-util.h"
30 #include "hostname-util.h"
32 #include "specifier.h"
33 #include "string-util.h"
36 * Generic infrastructure for replacing %x style specifiers in
37 * strings. Will call a callback for each replacement.
41 int specifier_printf(const char *text
, const Specifier table
[], void *userdata
, char **_ret
) {
58 for (f
= text
; *f
; f
++, l
--) {
66 for (i
= table
; i
->specifier
; i
++)
67 if (i
->specifier
== *f
)
71 _cleanup_free_
char *w
= NULL
;
75 r
= i
->lookup(i
->specifier
, i
->data
, userdata
, &w
);
84 n
= new(char, j
+ k
+ l
+ 1);
104 } else if (*f
== '%')
115 /* Generic handler for simple string replacements */
117 int specifier_string(char specifier
, void *data
, void *userdata
, char **ret
) {
120 n
= strdup(strempty(data
));
128 int specifier_machine_id(char specifier
, void *data
, void *userdata
, char **ret
) {
133 r
= sd_id128_get_machine(&id
);
141 *ret
= sd_id128_to_string(id
, n
);
145 int specifier_boot_id(char specifier
, void *data
, void *userdata
, char **ret
) {
150 r
= sd_id128_get_boot(&id
);
158 *ret
= sd_id128_to_string(id
, n
);
162 int specifier_host_name(char specifier
, void *data
, void *userdata
, char **ret
) {
165 n
= gethostname_malloc();
173 int specifier_kernel_release(char specifier
, void *data
, void *userdata
, char **ret
) {
182 n
= strdup(uts
.release
);