bool config_sync(meshlink_handle_t *mesh, const char *conf_subdir) {
assert(conf_subdir);
- if(!mesh->confbase) {
+ if(!mesh->confbase || mesh->storage_policy == MESHLINK_STORAGE_DISABLED) {
return true;
}
}
/// Lock the main configuration file. Creates confbase if necessary.
-bool main_config_lock(meshlink_handle_t *mesh) {
+bool main_config_lock(meshlink_handle_t *mesh, const char *lock_filename) {
if(!mesh->confbase) {
return true;
}
+ assert(lock_filename);
+
if(mkdir(mesh->confbase, 0700) && errno != EEXIST) {
logger(NULL, MESHLINK_ERROR, "Cannot create configuration directory %s: %s", mesh->confbase, strerror(errno));
meshlink_close(mesh);
return NULL;
}
- char path[PATH_MAX];
- snprintf(path, sizeof(path), "%s" SLASH "meshlink.lock", mesh->confbase);
-
- mesh->lockfile = fopen(path, "w+");
+ mesh->lockfile = fopen(lock_filename, "w+");
if(!mesh->lockfile) {
- logger(NULL, MESHLINK_ERROR, "Cannot not open %s: %s\n", path, strerror(errno));
+ logger(NULL, MESHLINK_ERROR, "Cannot not open %s: %s\n", lock_filename, strerror(errno));
meshlink_errno = MESHLINK_ESTORAGE;
return false;
}
#else
if(flock(fileno(mesh->lockfile), LOCK_EX | LOCK_NB) != 0) {
- logger(NULL, MESHLINK_ERROR, "Cannot lock %s: %s\n", path, strerror(errno));
+ logger(NULL, MESHLINK_ERROR, "Cannot lock %s: %s\n", lock_filename, strerror(errno));
fclose(mesh->lockfile);
mesh->lockfile = NULL;
meshlink_errno = MESHLINK_EBUSY;