1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation.
3 * Copyright(c) 2012-2014 6WIND S.A.
13 #include <sys/types.h>
16 #include <rte_common.h>
19 #include "eal_private.h"
20 #include "eal_filesystem.h"
22 int eal_create_runtime_dir(void)
24 const char *directory;
25 char run_dir[PATH_MAX];
29 /* from RuntimeDirectory= see systemd.exec */
30 directory = getenv("RUNTIME_DIRECTORY");
31 if (directory == NULL) {
33 * Used standard convention defined in
34 * XDG Base Directory Specification and
35 * Filesystem Hierarchy Standard.
38 directory = "/var/run";
40 directory = getenv("XDG_RUNTIME_DIR") ? : "/tmp";
43 /* create DPDK subdirectory under runtime dir */
44 ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
45 if (ret < 0 || ret == sizeof(tmp)) {
46 RTE_LOG(ERR, EAL, "Error creating DPDK runtime path name\n");
50 /* create prefix-specific subdirectory under DPDK runtime dir */
51 ret = snprintf(run_dir, sizeof(run_dir), "%s/%s",
52 tmp, eal_get_hugefile_prefix());
53 if (ret < 0 || ret == sizeof(run_dir)) {
54 RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n");
58 /* create the path if it doesn't exist. no "mkdir -p" here, so do it
61 ret = mkdir(tmp, 0700);
62 if (ret < 0 && errno != EEXIST) {
63 RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
64 tmp, strerror(errno));
68 ret = mkdir(run_dir, 0700);
69 if (ret < 0 && errno != EEXIST) {
70 RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
71 run_dir, strerror(errno));
75 if (eal_set_runtime_dir(run_dir))
81 /* parse a sysfs (or other) file containing one integer value */
82 int eal_parse_sysfs_value(const char *filename, unsigned long *val)
88 if ((f = fopen(filename, "r")) == NULL) {
89 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
94 if (fgets(buf, sizeof(buf), f) == NULL) {
95 RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
100 *val = strtoul(buf, &end, 0);
101 if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
102 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",