summaryrefslogtreecommitdiffstats
path: root/src/conf.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2025-09-15 09:58:01 +0200
committerGravatar Nikias Bassen2025-09-15 09:58:01 +0200
commit2efa75a0a9ca73f2a5b6ec71e5ae6cb43cdab580 (patch)
tree9948c2e3d6fcf58433dbab033b0b0406b972b75c /src/conf.c
parent08f4cd9ef0e664128bf221cc17d400cbc2650c7f (diff)
downloadusbmuxd-2efa75a0a9ca73f2a5b6ec71e5ae6cb43cdab580.tar.gz
usbmuxd-2efa75a0a9ca73f2a5b6ec71e5ae6cb43cdab580.tar.bz2
Allow specifying configuration directory to use
Diffstat (limited to 'src/conf.c')
-rw-r--r--src/conf.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/conf.c b/src/conf.c
index 532dedc..5d2411d 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -35,10 +35,6 @@
35#include <sys/stat.h> 35#include <sys/stat.h>
36#include <errno.h> 36#include <errno.h>
37 37
38#ifdef WIN32
39#include <shlobj.h>
40#endif
41
42#include <libimobiledevice-glue/utils.h> 38#include <libimobiledevice-glue/utils.h>
43#include <plist/plist.h> 39#include <plist/plist.h>
44 40
@@ -47,6 +43,8 @@
47#include "log.h" 43#include "log.h"
48 44
49#ifdef WIN32 45#ifdef WIN32
46#include <shlobj.h>
47
50#define DIR_SEP '\\' 48#define DIR_SEP '\\'
51#define DIR_SEP_S "\\" 49#define DIR_SEP_S "\\"
52#else 50#else
@@ -180,13 +178,26 @@ static int mkdir_with_parents(const char *dir, int mode)
180/** 178/**
181 * Creates a freedesktop compatible configuration directory. 179 * Creates a freedesktop compatible configuration directory.
182 */ 180 */
183static void config_create_config_dir(void) 181static int config_create_config_dir(void)
184{ 182{
185 const char *config_path = config_get_config_dir(); 183 const char *config_path = config_get_config_dir();
186 struct stat st; 184 struct stat st;
187 if (stat(config_path, &st) != 0) { 185 int res = stat(config_path, &st);
188 mkdir_with_parents(config_path, 0755); 186 if (res != 0) {
187 res = mkdir_with_parents(config_path, 0755);
189 } 188 }
189 return res;
190}
191
192int config_set_config_dir(const char* path)
193{
194 if (!path) {
195 return -1;
196 }
197 free(__config_dir);
198 __config_dir = strdup(path);
199 usbmuxd_log(LL_DEBUG, "Setting config_dir to %s", __config_dir);
200 return config_create_config_dir();
190} 201}
191 202
192static int get_rand(int min, int max) 203static int get_rand(int min, int max)
@@ -270,7 +281,10 @@ static int config_set_value(const char *key, plist_t value)
270 char *config_file = NULL; 281 char *config_file = NULL;
271 282
272 /* Make sure config directory exists */ 283 /* Make sure config directory exists */
273 config_create_config_dir(); 284 if (config_create_config_dir() < 0) {
285 usbmuxd_log(LL_ERROR, "ERROR: Failed to create config directory\n");
286 return -1;
287 }
274 288
275 config_path = config_get_config_dir(); 289 config_path = config_get_config_dir();
276 config_file = string_concat(config_path, DIR_SEP_S, CONFIG_FILE, NULL); 290 config_file = string_concat(config_path, DIR_SEP_S, CONFIG_FILE, NULL);
@@ -342,7 +356,10 @@ int config_has_device_record(const char *udid)
342 if (!udid) return 0; 356 if (!udid) return 0;
343 357
344 /* ensure config directory exists */ 358 /* ensure config directory exists */
345 config_create_config_dir(); 359 if (config_create_config_dir() < 0) {
360 usbmuxd_log(LL_ERROR, "ERROR: Failed to create config directory\n");
361 return -1;
362 }
346 363
347 /* build file path */ 364 /* build file path */
348 const char *config_path = config_get_config_dir(); 365 const char *config_path = config_get_config_dir();
@@ -422,7 +439,10 @@ int config_set_device_record(const char *udid, char* record_data, uint64_t recor
422 } 439 }
423 440
424 /* ensure config directory exists */ 441 /* ensure config directory exists */
425 config_create_config_dir(); 442 if (config_create_config_dir() < 0) {
443 usbmuxd_log(LL_ERROR, "ERROR: Failed to create config directory\n");
444 return -1;
445 }
426 446
427 /* build file path */ 447 /* build file path */
428 const char *config_path = config_get_config_dir(); 448 const char *config_path = config_get_config_dir();
@@ -458,7 +478,10 @@ int config_get_device_record(const char *udid, char **record_data, uint64_t *rec
458 int res = 0; 478 int res = 0;
459 479
460 /* ensure config directory exists */ 480 /* ensure config directory exists */
461 config_create_config_dir(); 481 if (config_create_config_dir() < 0) {
482 usbmuxd_log(LL_ERROR, "ERROR: Failed to create config directory\n");
483 return -1;
484 }
462 485
463 /* build file path */ 486 /* build file path */
464 const char *config_path = config_get_config_dir(); 487 const char *config_path = config_get_config_dir();