本文整理汇总了C++中parse_env_file函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_env_file函数的具体用法?C++ parse_env_file怎么用?C++ parse_env_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_env_file函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: network_link_get_strv
static int network_link_get_strv(int ifindex, const char *key, char ***ret) {
char path[strlen("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex) + 1];
_cleanup_strv_free_ char **a = NULL;
_cleanup_free_ char *s = NULL;
int r;
assert_return(ifindex > 0, -EINVAL);
assert_return(ret, -EINVAL);
xsprintf(path, "/run/systemd/netif/links/%i", ifindex);
r = parse_env_file(path, NEWLINE, key, &s, NULL);
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s)) {
*ret = NULL;
return 0;
}
a = strv_split(s, " ");
if (!a)
return -ENOMEM;
strv_uniq(a);
r = strv_length(a);
*ret = a;
a = NULL;
return r;
}
开发者ID:vinaykul,项目名称:systemd,代码行数:32,代码来源:sd-network.c
示例2: network_get_strv
static int network_get_strv(const char *key, char ***ret) {
_cleanup_strv_free_ char **a = NULL;
_cleanup_free_ char *s = NULL;
int r;
assert_return(ret, -EINVAL);
r = parse_env_file(NULL, "/run/systemd/netif/state", NEWLINE, key, &s, NULL);
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s)) {
*ret = NULL;
return 0;
}
a = strv_split(s, " ");
if (!a)
return -ENOMEM;
strv_uniq(a);
r = (int) strv_length(a);
*ret = TAKE_PTR(a);
return r;
}
开发者ID:floppym,项目名称:systemd,代码行数:28,代码来源:sd-network.c
示例3: print_status_info
static void print_status_info(StatusInfo *i) {
sd_id128_t mid, bid;
int r;
const char *id = NULL;
_cleanup_free_ char *pretty_name = NULL, *cpe_name = NULL;
struct utsname u;
assert(i);
printf(" Static hostname: %s\n",
strna(i->static_hostname));
if (!isempty(i->pretty_hostname) &&
!streq_ptr(i->pretty_hostname, i->static_hostname))
printf(" Pretty hostname: %s\n",
strna(i->pretty_hostname));
if (!isempty(i->hostname) &&
!streq_ptr(i->hostname, i->static_hostname))
printf("Transient hostname: %s\n",
strna(i->hostname));
printf(" Icon name: %s\n"
" Chassis: %s\n",
strna(i->icon_name),
strna(i->chassis));
r = sd_id128_get_machine(&mid);
if (r >= 0)
printf(" Machine ID: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(mid));
r = sd_id128_get_boot(&bid);
if (r >= 0)
printf(" Boot ID: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(bid));
if (detect_virtualization(&id) > 0)
printf(" Virtualization: %s\n", id);
r = parse_env_file("/etc/os-release", NEWLINE,
"PRETTY_NAME", &pretty_name,
"CPE_NAME", &cpe_name,
NULL);
if (!isempty(pretty_name))
printf(" Operating System: %s\n", pretty_name);
if (!isempty(cpe_name))
printf(" CPE OS Name: %s\n", cpe_name);
assert_se(uname(&u) >= 0);
printf(" Kernel: %s %s\n"
" Architecture: %s\n", u.sysname, u.release, u.machine);
}
开发者ID:kwirk,项目名称:systemd,代码行数:54,代码来源:hostnamectl.c
示例4: get_cgroup_root
static int get_cgroup_root(char **ret) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
_cleanup_free_ char *unit = NULL, *path = NULL;
const char *m;
int r;
if (arg_root) {
char *aux;
aux = strdup(arg_root);
if (!aux)
return log_oom();
*ret = aux;
return 0;
}
if (!arg_machine) {
r = cg_get_root_path(ret);
if (r < 0)
return log_error_errno(r, "Failed to get root control group path: %m");
return 0;
}
m = strjoina("/run/systemd/machines/", arg_machine);
r = parse_env_file(m, NEWLINE, "SCOPE", &unit, NULL);
if (r < 0)
return log_error_errno(r, "Failed to load machine data: %m");
path = unit_dbus_path_from_name(unit);
if (!path)
return log_oom();
r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, false, &bus);
if (r < 0)
return log_error_errno(r, "Failed to create bus connection: %m");
r = sd_bus_get_property_string(
bus,
"org.freedesktop.systemd1",
path,
unit_dbus_interface_from_name(unit),
"ControlGroup",
&error,
ret);
if (r < 0)
return log_error_errno(r, "Failed to query unit control group path: %s", bus_error_message(&error, r));
return 0;
}
开发者ID:Like-all,项目名称:tinysystemd-substrate,代码行数:52,代码来源:cgtop.c
示例5: context_read_data
static int context_read_data(Context *c) {
int r;
struct utsname u;
assert(c);
context_reset(c);
assert_se(uname(&u) >= 0);
c->data[PROP_KERNEL_NAME] = strdup(u.sysname);
c->data[PROP_KERNEL_RELEASE] = strdup(u.release);
c->data[PROP_KERNEL_VERSION] = strdup(u.version);
if (!c->data[PROP_KERNEL_NAME] || !c->data[PROP_KERNEL_RELEASE] ||
!c->data[PROP_KERNEL_VERSION])
return -ENOMEM;
c->data[PROP_HOSTNAME] = gethostname_malloc();
if (!c->data[PROP_HOSTNAME])
return -ENOMEM;
r = read_etc_hostname(NULL, &c->data[PROP_STATIC_HOSTNAME]);
if (r < 0 && r != -ENOENT)
return r;
r = parse_env_file(NULL, "/etc/machine-info",
"PRETTY_HOSTNAME", &c->data[PROP_PRETTY_HOSTNAME],
"ICON_NAME", &c->data[PROP_ICON_NAME],
"CHASSIS", &c->data[PROP_CHASSIS],
"DEPLOYMENT", &c->data[PROP_DEPLOYMENT],
"LOCATION", &c->data[PROP_LOCATION]);
if (r < 0 && r != -ENOENT)
return r;
r = parse_os_release(NULL,
"PRETTY_NAME", &c->data[PROP_OS_PRETTY_NAME],
"CPE_NAME", &c->data[PROP_OS_CPE_NAME],
"HOME_URL", &c->data[PROP_HOME_URL],
NULL);
if (r < 0 && r != -ENOENT)
return r;
r = id128_read("/sys/class/dmi/id/product_uuid", ID128_UUID, &c->uuid);
if (r < 0)
log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,
"Failed to read product UUID, ignoring: %m");
else if (sd_id128_is_null(c->uuid) || sd_id128_is_allf(c->uuid))
log_debug("DMI product UUID " SD_ID128_FORMAT_STR " is all 0x00 or all 0xFF, ignoring.", SD_ID128_FORMAT_VAL(c->uuid));
else
c->has_uuid = true;
return 0;
}
开发者ID:Keruspe,项目名称:systemd,代码行数:52,代码来源:hostnamed.c
示例6: network_link_get_ifindexes
static int network_link_get_ifindexes(int ifindex, const char *key, int **ret) {
char path[strlen("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex) + 1];
_cleanup_free_ int *ifis = NULL;
_cleanup_free_ char *s = NULL;
size_t allocated = 0, c = 0;
const char *x;
int r;
assert_return(ifindex > 0, -EINVAL);
assert_return(ret, -EINVAL);
xsprintf(path, "/run/systemd/netif/links/%i", ifindex);
r = parse_env_file(path, NEWLINE, key, &s, NULL);
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s)) {
*ret = NULL;
return 0;
}
x = s;
for (;;) {
_cleanup_free_ char *word = NULL;
r = extract_first_word(&x, &word, NULL, 0);
if (r < 0)
return r;
if (r == 0)
break;
r = parse_ifindex(word, &ifindex);
if (r < 0)
return r;
if (!GREEDY_REALLOC(ifis, allocated, c + 1))
return -ENOMEM;
ifis[c++] = ifindex;
}
if (!GREEDY_REALLOC(ifis, allocated, c + 1))
return -ENOMEM;
ifis[c] = 0; /* Let's add a 0 ifindex to the end, to be nice*/
*ret = ifis;
ifis = NULL;
return c;
}
开发者ID:AOSC-Dev,项目名称:systemd,代码行数:51,代码来源:sd-network.c
示例7: get_os_name
static int get_os_name(char **_n) {
char *n = NULL;
int r;
r = parse_env_file("/etc/os-release", NEWLINE, "PRETTY_NAME", &n, NULL);
if (r < 0)
return r;
if (!n)
return -ENOENT;
*_n = n;
return 0;
}
开发者ID:chuanchang,项目名称:systemd,代码行数:14,代码来源:analyze.c
示例8: read_data_locale
static int read_data_locale(void) {
int r;
free_data_locale();
r = parse_env_file("/etc/locale.conf", NEWLINE,
"LANG", &data[PROP_LANG],
"LANGUAGE", &data[PROP_LANGUAGE],
"LC_CTYPE", &data[PROP_LC_CTYPE],
"LC_NUMERIC", &data[PROP_LC_NUMERIC],
"LC_TIME", &data[PROP_LC_TIME],
"LC_COLLATE", &data[PROP_LC_COLLATE],
"LC_MONETARY", &data[PROP_LC_MONETARY],
"LC_MESSAGES", &data[PROP_LC_MESSAGES],
"LC_PAPER", &data[PROP_LC_PAPER],
"LC_NAME", &data[PROP_LC_NAME],
"LC_ADDRESS", &data[PROP_LC_ADDRESS],
"LC_TELEPHONE", &data[PROP_LC_TELEPHONE],
"LC_MEASUREMENT", &data[PROP_LC_MEASUREMENT],
"LC_IDENTIFICATION", &data[PROP_LC_IDENTIFICATION],
NULL);
if (r == -ENOENT) {
int p;
/* Fill in what we got passed from systemd. */
for (p = 0; p < _PROP_MAX; p++) {
char *e, *d;
assert(names[p]);
e = getenv(names[p]);
if (e) {
d = strdup(e);
if (!d)
return -ENOMEM;
} else
d = NULL;
free(data[p]);
data[p] = d;
}
r = 0;
}
simplify();
return r;
}
开发者ID:mariux,项目名称:systemd,代码行数:50,代码来源:localed.c
示例9: read_data_vconsole
static int read_data_vconsole(void) {
int r;
free_data_vconsole();
r = parse_env_file("/etc/vconsole.conf", NEWLINE,
"KEYMAP", &state.vc_keymap,
"KEYMAP_TOGGLE", &state.vc_keymap_toggle,
NULL);
if (r < 0 && r != -ENOENT)
return r;
return 0;
}
开发者ID:mariux,项目名称:systemd,代码行数:15,代码来源:localed.c
示例10: vconsole_read_data
static int vconsole_read_data(Context *c) {
int r;
context_free_vconsole(c);
r = parse_env_file("/etc/vconsole.conf", NEWLINE,
"KEYMAP", &c->vc_keymap,
"KEYMAP_TOGGLE", &c->vc_keymap_toggle,
NULL);
if (r < 0 && r != -ENOENT)
return r;
return 0;
}
开发者ID:vlajos,项目名称:systemd,代码行数:15,代码来源:localed.c
示例11: print_overridden_variables
static void print_overridden_variables(void) {
int r;
char *variables[_VARIABLE_LC_MAX] = {};
LocaleVariable j;
bool print_warning = true;
if (detect_container() > 0 || arg_host)
return;
r = parse_env_file(NULL, "/proc/cmdline", WHITESPACE,
"locale.LANG", &variables[VARIABLE_LANG],
"locale.LANGUAGE", &variables[VARIABLE_LANGUAGE],
"locale.LC_CTYPE", &variables[VARIABLE_LC_CTYPE],
"locale.LC_NUMERIC", &variables[VARIABLE_LC_NUMERIC],
"locale.LC_TIME", &variables[VARIABLE_LC_TIME],
"locale.LC_COLLATE", &variables[VARIABLE_LC_COLLATE],
"locale.LC_MONETARY", &variables[VARIABLE_LC_MONETARY],
"locale.LC_MESSAGES", &variables[VARIABLE_LC_MESSAGES],
"locale.LC_PAPER", &variables[VARIABLE_LC_PAPER],
"locale.LC_NAME", &variables[VARIABLE_LC_NAME],
"locale.LC_ADDRESS", &variables[VARIABLE_LC_ADDRESS],
"locale.LC_TELEPHONE", &variables[VARIABLE_LC_TELEPHONE],
"locale.LC_MEASUREMENT", &variables[VARIABLE_LC_MEASUREMENT],
"locale.LC_IDENTIFICATION", &variables[VARIABLE_LC_IDENTIFICATION],
NULL);
if (r < 0 && r != -ENOENT) {
log_warning_errno(r, "Failed to read /proc/cmdline: %m");
goto finish;
}
for (j = 0; j < _VARIABLE_LC_MAX; j++)
if (variables[j]) {
if (print_warning) {
log_warning("Warning: Settings on kernel command line override system locale settings in /etc/locale.conf.\n"
" Command Line: %s=%s", locale_variable_to_string(j), variables[j]);
print_warning = false;
} else
log_warning(" %s=%s", locale_variable_to_string(j), variables[j]);
}
finish:
for (j = 0; j < _VARIABLE_LC_MAX; j++)
free(variables[j]);
}
开发者ID:halfline,项目名称:systemd,代码行数:45,代码来源:localectl.c
示例12: sd_network_get_operational_state
_public_ int sd_network_get_operational_state(char **state) {
_cleanup_free_ char *s = NULL;
int r;
assert_return(state, -EINVAL);
r = parse_env_file("/run/systemd/netif/state", NEWLINE, "OPER_STATE", &s, NULL);
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s))
return -ENODATA;
*state = TAKE_PTR(s);
return 0;
}
开发者ID:davide125,项目名称:systemd,代码行数:18,代码来源:sd-network.c
示例13: sd_session_is_remote
_public_ int sd_session_is_remote(const char *session) {
_cleanup_free_ char *p = NULL, *s = NULL;
int r;
r = file_of_session(session, &p);
if (r < 0)
return r;
r = parse_env_file(p, NEWLINE, "REMOTE", &s, NULL);
if (r == -ENOENT)
return -ENXIO;
if (r < 0)
return r;
if (isempty(s))
return -ENODATA;
return parse_boolean(s);
}
开发者ID:davide125,项目名称:systemd,代码行数:18,代码来源:sd-login.c
示例14: locale_read_data
static int locale_read_data(Context *c) {
int r;
context_free_locale(c);
r = parse_env_file("/etc/locale.conf", NEWLINE,
"LANG", &c->locale[VARIABLE_LANG],
"LANGUAGE", &c->locale[VARIABLE_LANGUAGE],
"LC_CTYPE", &c->locale[VARIABLE_LC_CTYPE],
"LC_NUMERIC", &c->locale[VARIABLE_LC_NUMERIC],
"LC_TIME", &c->locale[VARIABLE_LC_TIME],
"LC_COLLATE", &c->locale[VARIABLE_LC_COLLATE],
"LC_MONETARY", &c->locale[VARIABLE_LC_MONETARY],
"LC_MESSAGES", &c->locale[VARIABLE_LC_MESSAGES],
"LC_PAPER", &c->locale[VARIABLE_LC_PAPER],
"LC_NAME", &c->locale[VARIABLE_LC_NAME],
"LC_ADDRESS", &c->locale[VARIABLE_LC_ADDRESS],
"LC_TELEPHONE", &c->locale[VARIABLE_LC_TELEPHONE],
"LC_MEASUREMENT", &c->locale[VARIABLE_LC_MEASUREMENT],
"LC_IDENTIFICATION", &c->locale[VARIABLE_LC_IDENTIFICATION],
NULL);
if (r == -ENOENT) {
int p;
/* Fill in what we got passed from systemd. */
for (p = 0; p < _VARIABLE_LC_MAX; p++) {
const char *name;
name = locale_variable_to_string(p);
assert(name);
r = free_and_strdup(&c->locale[p], empty_to_null(getenv(name)));
if (r < 0)
return r;
}
r = 0;
}
locale_simplify(c);
return r;
}
开发者ID:davide125,项目名称:systemd,代码行数:43,代码来源:keymap-util.c
示例15: sd_network_link_get_wildcard_domain
_public_ int sd_network_link_get_wildcard_domain(int ifindex) {
int r;
_cleanup_free_ char *p = NULL, *s = NULL;
assert_return(ifindex > 0, -EINVAL);
if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
return -ENOMEM;
r = parse_env_file(p, NEWLINE, "WILDCARD_DOMAIN", &s, NULL);
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s))
return -ENODATA;
return parse_boolean(s);
}
开发者ID:pwaller,项目名称:systemd,代码行数:19,代码来源:sd-network.c
示例16: uid_get_array
static int uid_get_array(uid_t uid, const char *variable, char ***array) {
_cleanup_free_ char *p = NULL, *s = NULL;
char **a;
int r;
if (asprintf(&p, "/run/systemd/users/%lu", (unsigned long) uid) < 0)
return -ENOMEM;
r = parse_env_file(p, NEWLINE,
variable, &s,
NULL);
if (r < 0) {
if (r == -ENOENT) {
if (array)
*array = NULL;
return 0;
}
return r;
}
if (!s) {
if (array)
*array = NULL;
return 0;
}
a = strv_split(s, " ");
if (!a)
return -ENOMEM;
strv_uniq(a);
r = strv_length(a);
if (array)
*array = a;
else
strv_free(a);
return r;
}
开发者ID:chuanchang,项目名称:systemd,代码行数:42,代码来源:sd-login.c
示例17: vconsole_read_data
int vconsole_read_data(Context *c, sd_bus_message *m) {
struct stat st;
usec_t t;
int r;
/* Do not try to re-read the file within single bus operation. */
if (m) {
if (m == c->vc_cache)
return 0;
sd_bus_message_unref(c->vc_cache);
c->vc_cache = sd_bus_message_ref(m);
}
if (stat("/etc/vconsole.conf", &st) < 0) {
if (errno != ENOENT)
return -errno;
c->vc_mtime = USEC_INFINITY;
context_free_vconsole(c);
return 0;
}
/* If mtime is not changed, then we do not need to re-read */
t = timespec_load(&st.st_mtim);
if (c->vc_mtime != USEC_INFINITY && t == c->vc_mtime)
return 0;
c->vc_mtime = t;
context_free_vconsole(c);
r = parse_env_file(NULL, "/etc/vconsole.conf", NEWLINE,
"KEYMAP", &c->vc_keymap,
"KEYMAP_TOGGLE", &c->vc_keymap_toggle,
NULL);
if (r < 0)
return r;
return 0;
}
开发者ID:halfline,项目名称:systemd,代码行数:40,代码来源:keymap-util.c
示例18: locale_read_data
static int locale_read_data(Context *c) {
int r;
context_free_locale(c);
r = parse_env_file("/etc/locale.conf", NEWLINE,
"LANG", &c->locale[LOCALE_LANG],
"LANGUAGE", &c->locale[LOCALE_LANGUAGE],
"LC_CTYPE", &c->locale[LOCALE_LC_CTYPE],
"LC_NUMERIC", &c->locale[LOCALE_LC_NUMERIC],
"LC_TIME", &c->locale[LOCALE_LC_TIME],
"LC_COLLATE", &c->locale[LOCALE_LC_COLLATE],
"LC_MONETARY", &c->locale[LOCALE_LC_MONETARY],
"LC_MESSAGES", &c->locale[LOCALE_LC_MESSAGES],
"LC_PAPER", &c->locale[LOCALE_LC_PAPER],
"LC_NAME", &c->locale[LOCALE_LC_NAME],
"LC_ADDRESS", &c->locale[LOCALE_LC_ADDRESS],
"LC_TELEPHONE", &c->locale[LOCALE_LC_TELEPHONE],
"LC_MEASUREMENT", &c->locale[LOCALE_LC_MEASUREMENT],
"LC_IDENTIFICATION", &c->locale[LOCALE_LC_IDENTIFICATION],
NULL);
if (r == -ENOENT) {
int p;
/* Fill in what we got passed from systemd. */
for (p = 0; p < _LOCALE_MAX; p++) {
assert(names[p]);
r = free_and_copy(&c->locale[p], getenv(names[p]));
if (r < 0)
return r;
}
r = 0;
}
locale_simplify(c);
return r;
}
开发者ID:MOBO-OSS,项目名称:systemd-relative,代码行数:40,代码来源:localed.c
示例19: network_link_get_string
static int network_link_get_string(int ifindex, const char *field, char **ret) {
char path[STRLEN("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex) + 1];
_cleanup_free_ char *s = NULL;
int r;
assert_return(ifindex > 0, -EINVAL);
assert_return(ret, -EINVAL);
xsprintf(path, "/run/systemd/netif/links/%i", ifindex);
r = parse_env_file(path, NEWLINE, field, &s, NULL);
if (r == -ENOENT)
return -ENODATA;
if (r < 0)
return r;
if (isempty(s))
return -ENODATA;
*ret = TAKE_PTR(s);
return 0;
}
开发者ID:davide125,项目名称:systemd,代码行数:22,代码来源:sd-network.c
示例20: sd_session_get_state
_public_ int sd_session_get_state(const char *session, char **state) {
_cleanup_free_ char *p = NULL, *s = NULL;
int r;
assert_return(state, -EINVAL);
r = file_of_session(session, &p);
if (r < 0)
return r;
r = parse_env_file(p, NEWLINE, "STATE", &s, NULL);
if (r == -ENOENT)
return -ENXIO;
if (r < 0)
return r;
if (isempty(s))
return -EIO;
*state = TAKE_PTR(s);
return 0;
}
开发者ID:davide125,项目名称:systemd,代码行数:22,代码来源:sd-login.c
注:本文中的parse_env_file函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论