| 18 | #include "eal_filesystem.h" |
| 19 | |
| 20 | int eal_create_runtime_dir(void) |
| 21 | { |
| 22 | const char *directory; |
| 23 | char run_dir[PATH_MAX]; |
| 24 | char tmp[PATH_MAX]; |
| 25 | int ret; |
| 26 | |
| 27 | /* from RuntimeDirectory= see systemd.exec */ |
| 28 | directory = getenv("RUNTIME_DIRECTORY"); |
| 29 | if (directory == NULL) { |
| 30 | /* |
| 31 | * Used standard convention defined in |
| 32 | * XDG Base Directory Specification and |
| 33 | * Filesystem Hierarchy Standard. |
| 34 | */ |
| 35 | if (getuid() == 0) |
| 36 | directory = "/var/run"; |
| 37 | else |
| 38 | directory = getenv("XDG_RUNTIME_DIR") ? : "/tmp"; |
| 39 | } |
| 40 | |
| 41 | /* create DPDK subdirectory under runtime dir */ |
| 42 | ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory); |
| 43 | if (ret < 0 || ret == sizeof(tmp)) { |
| 44 | RTE_LOG(ERR, EAL, "Error creating DPDK runtime path name\n"); |
| 45 | return -1; |
| 46 | } |
| 47 | |
| 48 | /* create prefix-specific subdirectory under DPDK runtime dir */ |
| 49 | ret = snprintf(run_dir, sizeof(run_dir), "%s/%s", |
| 50 | tmp, eal_get_hugefile_prefix()); |
| 51 | if (ret < 0 || ret == sizeof(run_dir)) { |
| 52 | RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n"); |
| 53 | return -1; |
| 54 | } |
| 55 | |
| 56 | /* create the path if it doesn't exist. no "mkdir -p" here, so do it |
| 57 | * step by step. |
| 58 | */ |
| 59 | ret = mkdir(tmp, 0700); |
| 60 | if (ret < 0 && errno != EEXIST) { |
| 61 | RTE_LOG(ERR, EAL, "Error creating '%s': %s\n", |
| 62 | tmp, strerror(errno)); |
| 63 | return -1; |
| 64 | } |
| 65 | |
| 66 | ret = mkdir(run_dir, 0700); |
| 67 | if (ret < 0 && errno != EEXIST) { |
| 68 | RTE_LOG(ERR, EAL, "Error creating '%s': %s\n", |
| 69 | run_dir, strerror(errno)); |
| 70 | return -1; |
| 71 | } |
| 72 | |
| 73 | if (eal_set_runtime_dir(run_dir)) |
| 74 | return -1; |
| 75 | |
| 76 | return 0; |
| 77 | } |
no test coverage detected