mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 08:16:00 +01:00
Use LOCK_{SH,EX} on Hurd
This commit is contained in:
parent
34ee70f3d6
commit
b1ff520277
1 changed files with 11 additions and 4 deletions
|
@ -36,12 +36,19 @@
|
||||||
|
|
||||||
#ifdef __GNU__
|
#ifdef __GNU__
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
|
|
||||||
|
#define FILE_LOCK_WRITE LOCK_EX
|
||||||
|
#define FILE_LOCK_READ LOCK_SH
|
||||||
|
|
||||||
static int
|
static int
|
||||||
file_lock_set(int fd, int cmd)
|
file_lock_set(int fd, int cmd)
|
||||||
{
|
{
|
||||||
return flock(fd, cmd);
|
return flock(fd, cmd);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
#define FILE_LOCK_WRITE F_WRLCK
|
||||||
|
#define FILE_LOCK_READ F_RDLCK
|
||||||
|
|
||||||
static int
|
static int
|
||||||
file_lock_set(int fd, short cmd)
|
file_lock_set(int fd, short cmd)
|
||||||
{
|
{
|
||||||
|
@ -658,7 +665,7 @@ zathura_db_read_key_file_from_file(const char* path)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* and lock it */
|
/* and lock it */
|
||||||
if (file_lock_set(fileno(file), F_WRLCK) != 0) {
|
if (file_lock_set(fileno(file), FILE_LOCK_WRITE) != 0) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -732,7 +739,7 @@ zathura_db_write_key_file_to_file(const char* file, GKeyFile* key_file)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_lock_set(fd, F_WRLCK) != 0 || write(fd, content, strlen(content)) == 0) {
|
if (file_lock_set(fd, FILE_LOCK_READ) != 0 || write(fd, content, strlen(content)) == 0) {
|
||||||
girara_error("Failed to write to %s", file);
|
girara_error("Failed to write to %s", file);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -785,7 +792,7 @@ plain_io_read(GiraraInputHistoryIO* db)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read input history file */
|
/* read input history file */
|
||||||
if (file_lock_set(fileno(file), F_RDLCK) != 0) {
|
if (file_lock_set(fileno(file), FILE_LOCK_READ) != 0) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -819,7 +826,7 @@ plain_io_append(GiraraInputHistoryIO* db, const char* input)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read input history file */
|
/* read input history file */
|
||||||
if (file_lock_set(fileno(file), F_WRLCK) != 0) {
|
if (file_lock_set(fileno(file), FILE_LOCK_WRITE) != 0) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue