You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi
I found the zlog_rotater_trylock has been reimplemented in version 1.2.17, and the file lock funtion for process protection has been replaced by lock_file function
static int zlog_rotater_trylock(zlog_rotater_t *a_rotater)
{
int rc;
rc = pthread_mutex_trylock(&(a_rotater->lock_mutex));
if (rc == EBUSY) {
zc_warn("pthread_mutex_trylock fail, as lock_mutex is locked by other threads");
return -1;
} else if (rc != 0) {
zc_error("pthread_mutex_trylock fail, rc[%d]", rc);
return -1;
}
a_rotater->lock_fd = lock_file(a_rotater->lock_file);
if (a_rotater->lock_fd == INVALID_LOCK_FD) {
return -1;
}
return 0;
}
But I found the lock_file function only call open in linux, How it implements the multi process file lock protectioin function? please help explain it。 thanks very much
@deemar Hi , I know linux use fcntl API for file lock, but I can't find any code to call fcntl function in version 1.2.17.
the lock_file function only call open function.
zlog_rotater_trylock--->lock_file--->open
LOCK_FD fd = open(path, O_RDWR | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
Hi
I found the zlog_rotater_trylock has been reimplemented in version 1.2.17, and the file lock funtion for process protection has been replaced by lock_file function
static int zlog_rotater_trylock(zlog_rotater_t *a_rotater)
{
int rc;
}
But I found the lock_file function only call open in linux, How it implements the multi process file lock protectioin function? please help explain it。 thanks very much
LOCK_FD lock_file(char* path) {
if (!path || strlen(path) <= 0) {
return INVALID_LOCK_FD;
}
#ifdef _WIN32
LOCK_FD fd = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (fd == INVALID_LOCK_FD) {
DWORD err = GetLastError();
zc_error("lock file error : %d ", err);
}
#else
LOCK_FD fd = open(path, O_RDWR | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
if (fd == INVALID_LOCK_FD) {
zc_error("lock file error : %s ", strerror(errno));
}
#endif
return fd;
}
The text was updated successfully, but these errors were encountered: