2020-07-26 07:58:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Odyssey.
|
|
|
|
*
|
|
|
|
* Scalable PostgreSQL connection pooler.
|
|
|
|
*/
|
|
|
|
|
2020-11-27 18:03:42 +00:00
|
|
|
#include <machinarium.h>
|
|
|
|
#include <odyssey.h>
|
|
|
|
|
2020-12-28 10:43:31 +00:00
|
|
|
od_file_lock_t od_get_execution_lock(char *prefix)
|
2020-07-26 07:58:15 +00:00
|
|
|
{
|
|
|
|
char od_exec_lock_name[ODYSSEY_LOCK_MAXPATH - 4];
|
|
|
|
if (prefix == NULL) {
|
2020-12-28 10:43:31 +00:00
|
|
|
sprintf(od_exec_lock_name, "%s/%s:%d", prefix,
|
|
|
|
ODYSSEY_LOCK_PREFIX, ODYSSEY_EXEC_LOCK_HASH);
|
2020-07-26 07:58:15 +00:00
|
|
|
} else {
|
2020-12-28 10:43:31 +00:00
|
|
|
sprintf(od_exec_lock_name, "%s/%s:%d", ODYSSEY_DEFAULT_LOCK_DIR,
|
|
|
|
ODYSSEY_LOCK_PREFIX, ODYSSEY_EXEC_LOCK_HASH);
|
2020-07-26 07:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
od_dbg_printf_on_dvl_lvl(1, "using exec lock %s\n", od_exec_lock_name);
|
|
|
|
|
|
|
|
int fd = open(od_exec_lock_name, O_RDWR | O_CREAT, S_IRWXU | S_IRWXG);
|
|
|
|
|
|
|
|
if (fd == -1) {
|
|
|
|
od_dbg_printf_on_dvl_lvl(
|
2020-12-28 10:43:31 +00:00
|
|
|
1, "failed to get control lock file due error: %d",
|
|
|
|
errno);
|
2020-07-26 07:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2020-12-28 10:43:31 +00:00
|
|
|
od_file_lock_t od_get_control_lock(char *prefix)
|
2020-07-26 07:58:15 +00:00
|
|
|
{
|
|
|
|
char od_control_lock_name[ODYSSEY_LOCK_MAXPATH];
|
|
|
|
if (prefix == NULL) {
|
2020-12-28 10:43:31 +00:00
|
|
|
sprintf(od_control_lock_name, "%s/%s:%d", prefix,
|
|
|
|
ODYSSEY_LOCK_PREFIX, ODYSSEY_CTRL_LOCK_HASH);
|
2020-07-26 07:58:15 +00:00
|
|
|
} else {
|
2020-12-28 10:43:31 +00:00
|
|
|
sprintf(od_control_lock_name, "%s/%s:%d",
|
|
|
|
ODYSSEY_DEFAULT_LOCK_DIR, ODYSSEY_LOCK_PREFIX,
|
|
|
|
ODYSSEY_CTRL_LOCK_HASH);
|
2020-07-26 07:58:15 +00:00
|
|
|
}
|
2020-12-28 10:43:31 +00:00
|
|
|
od_dbg_printf_on_dvl_lvl(1, "using ctrl lock %s\n",
|
|
|
|
od_control_lock_name);
|
2020-07-26 07:58:15 +00:00
|
|
|
|
2020-12-28 10:43:31 +00:00
|
|
|
int fd =
|
|
|
|
open(od_control_lock_name, O_RDWR | O_CREAT, S_IRWXU | S_IRWXG);
|
2020-07-26 07:58:15 +00:00
|
|
|
|
|
|
|
if (fd == -1) {
|
|
|
|
od_dbg_printf_on_dvl_lvl(
|
2020-12-28 10:43:31 +00:00
|
|
|
1, "failed to get control lock file due error: %d",
|
|
|
|
errno);
|
2020-07-26 07:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|