static FILE *logfile;
/* Realpath of the config file. */
static char *config_file;
+/* derived from config file path */
+uint32_t ipc_key;
/** The read end of the signal pipe */
static int signal_pipe;
/** Process id of current pre-create-hook/rsync/post-create-hook process. */
config_file = arg;
}
DSS_DEBUG_LOG(("config file: %s\n", config_file));
+ ipc_key = super_fast_hash((uint8_t *)config_file,
+ strlen(config_file), 0) >> 1;
}
static int send_signal(int sig, bool wait)
{
pid_t pid;
- int ret = get_dss_pid(config_file, &pid);
+ int ret = get_dss_pid(ipc_key, &pid);
unsigned ms = 32;
struct timespec ts;
static void lock_dss_or_die(void)
{
- int ret = lock_dss(config_file);
+ int ret = lock_dss(ipc_key);
if (ret < 0) {
DSS_EMERG_LOG(("failed to lock: %s\n", dss_strerror(-ret)));
DSS_ERROR_LOG(("dry run not supported by this command\n"));
return -E_SYNTAX;
}
- ret = get_dss_pid(config_file, &pid);
+ ret = get_dss_pid(ipc_key, &pid);
if (ret >= 0) {
DSS_ERROR_LOG(("pid %d\n", (int)pid));
return -E_ALREADY_RUNNING;
* SuperFastHash, by Paul Hsieh.
* http://www.azillionmonkeys.com/qed/hash.html
*/
-static uint32_t super_fast_hash(const uint8_t *data, uint32_t len, uint32_t hash)
+uint32_t super_fast_hash(const uint8_t *data, uint32_t len, uint32_t hash)
{
uint32_t tmp;
int rem = len & 3;
return hash;
}
-static int get_key_or_die(const char *config_file)
-{
- assert(config_file);
- return super_fast_hash((uint8_t *)config_file, strlen(config_file), 0) >> 1;
-}
-
static int mutex_get(key_t key, int flags)
{
int ret;
return false;
}
-int lock_dss(char *config_file)
+int lock_dss(uint32_t key)
{
int ret, id;
struct sembuf sops[4];
- key_t key = get_key_or_die(config_file);
ret = mutex_get(key, IPC_CREAT | 0600);
if (ret < 0)
return do_semop(id, sops, 4);
}
-int get_dss_pid(char *config_file, pid_t *pid)
+int get_dss_pid(uint32_t key, pid_t *pid)
{
int ret, semid;
- key_t key = get_key_or_die(config_file);
if (pid)
*pid = 0;
/* SPDX-License-Identifier: GPL-2.0 */
-int lock_dss(char *config_file);
-int get_dss_pid(char *config_file, pid_t *pid);
+uint32_t super_fast_hash(const uint8_t *data, uint32_t len, uint32_t hash);
+int lock_dss(uint32_t key);
+int get_dss_pid(uint32_t key, pid_t *pid);