diff options
author | David Härdeman <david@hardeman.nu> | 2020-07-12 14:04:40 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-07-12 14:04:40 +0200 |
commit | 6586ea650597ae0563c4234a7658499ce1e0117b (patch) | |
tree | be99b63c29a21b2492a35d0bc9cd2ade93388405 /minecctl/server.c | |
parent | 714c267f5e4af98fd986c3563fc0e8e82a3dae1f (diff) |
Teach minecproxy to use same dirs as minecctl, step 1
Diffstat (limited to 'minecctl/server.c')
-rw-r--r-- | minecctl/server.c | 46 |
1 files changed, 6 insertions, 40 deletions
diff --git a/minecctl/server.c b/minecctl/server.c index 3acc537..e50e10c 100644 --- a/minecctl/server.c +++ b/minecctl/server.c @@ -9,63 +9,29 @@ #include "minecctl.h" #include "server.h" #include "misc.h" -#include "config.h" #define INVALID(msg) do { *error = (msg); return false; } while(0) -static DIR *__open_dir(int (*base_dir)(bool nofail), const char *fallback) -{ - _cleanup_close_ int xfd = -1; - _cleanup_close_ int mfd = -1; - DIR *dir; - - /* First, attempt per-user config dir... */ - xfd = base_dir(false); - if (xfd < 0) - goto fallback; - - mfd = openat(xfd, "minecproxy", O_CLOEXEC | O_DIRECTORY | O_RDONLY); - if (mfd < 0) - goto fallback; - - dir = fdopendir(mfd); - if (dir) - mfd = -1; - return dir; - - /* ...and fallback on the system dir */ -fallback: - return opendir(fallback); -} - -static inline DIR *open_cfg_dir() -{ - return __open_dir(open_xdg_cfg_dir, DEFAULT_CFG_DIR); -} - -static inline DIR *open_data_dir() -{ - return __open_dir(open_xdg_data_dir, DEFAULT_DATA_DIR); -} - void server_load_all_known(struct cfg *cfg) { struct dirent *dent; + _cleanup_free_ char *cpath = NULL; + _cleanup_free_ char *dpath = NULL; if (cfg->server_list_loaded) return; cfg->server_list_loaded = true; - cfg->cfg_dir = open_cfg_dir(); + cfg->cfg_dir = open_cfg_dir(NULL, &cpath); if (!cfg->cfg_dir) { - error("Failed to open config directory"); + error("Failed to open config directory %s", cpath); return; } - cfg->data_dir = open_data_dir(); + cfg->data_dir = open_data_dir(NULL, &dpath); if (!cfg->data_dir) { - error("Failed to open server directory"); + error("Failed to open server directory %s", dpath); return; } |