]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/confile_utils.h
utils: improve lxc_switch_uid_gid()
[mirror_lxc.git] / src / lxc / confile_utils.h
1 /* liblxcapi
2 *
3 * Copyright © 2017 Christian Brauner <christian.brauner@ubuntu.com>.
4 * Copyright © 2017 Canonical Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef __LXC_CONFILE_UTILS_H
21 #define __LXC_CONFILE_UTILS_H
22
23 #include "config.h"
24
25 #include <stdbool.h>
26
27 #include "conf.h"
28 #include "confile_utils.h"
29
30 #define strprint(str, inlen, ...) \
31 do { \
32 if (str) \
33 len = snprintf(str, inlen, ##__VA_ARGS__); \
34 else \
35 len = snprintf((char *){""}, 0, ##__VA_ARGS__); \
36 if (len < 0) { \
37 SYSERROR("failed to create string"); \
38 return -1; \
39 }; \
40 fulllen += len; \
41 if (inlen > 0) { \
42 if (str) \
43 str += len; \
44 inlen -= len; \
45 if (inlen < 0) \
46 inlen = 0; \
47 } \
48 } while (0);
49
50 extern int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
51 unsigned long *hostid, unsigned long *range);
52
53 extern bool lxc_config_value_empty(const char *value);
54 extern struct lxc_netdev *lxc_network_add(struct lxc_list *networks, int idx,
55 bool tail);
56 extern struct lxc_netdev *
57 lxc_get_netdev_by_idx(struct lxc_conf *conf, unsigned int idx, bool allocate);
58 extern void lxc_log_configured_netdevs(const struct lxc_conf *conf);
59 extern bool lxc_remove_nic_by_idx(struct lxc_conf *conf, unsigned int idx);
60 extern void lxc_free_networks(struct lxc_list *networks);
61 extern int lxc_macvlan_mode_to_flag(int *mode, const char *value);
62 extern char *lxc_macvlan_flag_to_mode(int mode);
63
64 extern int set_config_string_item(char **conf_item, const char *value);
65 extern int set_config_string_item_max(char **conf_item, const char *value,
66 size_t max);
67 extern int set_config_path_item(char **conf_item, const char *value);
68 extern int config_ip_prefix(struct in_addr *addr);
69 extern int network_ifname(char *valuep, const char *value, size_t size);
70 extern void rand_complete_hwaddr(char *hwaddr);
71 extern bool lxc_config_net_hwaddr(const char *line);
72 extern void update_hwaddr(const char *line);
73 extern bool new_hwaddr(char *hwaddr);
74 extern int lxc_get_conf_str(char *retv, int inlen, const char *value);
75 extern int lxc_get_conf_bool(struct lxc_conf *c, char *retv, int inlen, bool v);
76 extern int lxc_get_conf_int(struct lxc_conf *c, char *retv, int inlen, int v);
77 extern int lxc_get_conf_size_t(struct lxc_conf *c, char *retv, int inlen, size_t v);
78 extern int lxc_get_conf_uint64(struct lxc_conf *c, char *retv, int inlen, uint64_t v);
79 extern bool parse_limit_value(const char **value, rlim_t *res);
80 extern int lxc_inherit_namespace(const char *lxcname_or_pid,
81 const char *lxcpath, const char *namespace);
82 extern int sig_parse(const char *signame);
83
84 #endif /* __LXC_CONFILE_UTILS_H */