MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / posix_lock_file_open

Function posix_lock_file_open

src/daemon/service.c:486–507  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

484}
485
486static int posix_lock_file_open(const posix_log_path_t *path, bool *created_out) {
487 int flags = O_RDWR | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK;
488 int fd = openat(path->dir_fd, path->lock, flags | O_CREAT | O_EXCL, 0600);
489 bool created = fd >= 0;
490 if (fd < 0 && errno == EEXIST) {
491 fd = openat(path->dir_fd, path->lock, flags);
492 }
493 struct stat status;
494 struct stat by_path;
495 if (fd < 0 || !fd_cloexec(fd) || !fd_regular_current_user(fd, &status) ||
496 fchmod(fd, 0600) != 0 ||
497 fstatat(path->dir_fd, path->lock, &by_path, AT_SYMLINK_NOFOLLOW) != 0 ||
498 !S_ISREG(by_path.st_mode) || by_path.st_uid != geteuid() || by_path.st_nlink != 1 ||
499 status.st_dev != by_path.st_dev || status.st_ino != by_path.st_ino) {
500 if (fd >= 0) {
501 (void)close(fd);
502 }
503 return -1;
504 }
505 *created_out = created;
506 return fd;
507}
508
509static bool posix_lock_exclusive(int fd) {
510 while (flock(fd, LOCK_EX) != 0) {

Callers 1

posix_log_appendFunction · 0.85

Calls 2

fd_cloexecFunction · 0.85
fd_regular_current_userFunction · 0.85

Tested by

no test coverage detected