summaryrefslogtreecommitdiff
path: root/minecctl/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'minecctl/server.c')
-rw-r--r--minecctl/server.c46
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;
}