aboutsummaryrefslogtreecommitdiff
path: root/src/platform/posix/posix_file.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-03-05 17:27:04 -0800
committerGarrett D'Amore <garrett@damore.org>2018-03-05 19:39:15 -0800
commitc4da7817b4c8dd71b2a07d4d1c46b486ec57eeb4 (patch)
treeb1166d49e6673fcbad28c0bd65630f5af37a86ab /src/platform/posix/posix_file.c
parentb6298c28473acbed2f1429176c7cae4fb514d98b (diff)
downloadnng-c4da7817b4c8dd71b2a07d4d1c46b486ec57eeb4.tar.gz
nng-c4da7817b4c8dd71b2a07d4d1c46b486ec57eeb4.tar.bz2
nng-c4da7817b4c8dd71b2a07d4d1c46b486ec57eeb4.zip
fixes #265 nngcat should support persistent ZT nodes
fixes #267 zerotier transport should lock ZT_HOME
Diffstat (limited to 'src/platform/posix/posix_file.c')
-rw-r--r--src/platform/posix/posix_file.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/platform/posix/posix_file.c b/src/platform/posix/posix_file.c
index 7863fdee..83d045fa 100644
--- a/src/platform/posix/posix_file.c
+++ b/src/platform/posix/posix_file.c
@@ -260,6 +260,33 @@ nni_plat_file_basename(const char *path)
return (path);
}
+int
+nni_plat_file_lock(const char *path, nni_plat_flock *lk)
+{
+ int fd;
+ if ((fd = open(path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) < 0) {
+ return (nni_plat_errno(errno));
+ }
+ if (lockf(fd, F_TLOCK, 0) < 0) {
+ int rv = errno;
+ close(fd);
+ if (rv == EAGAIN) {
+ return (NNG_EBUSY);
+ }
+ return (nni_plat_errno(rv));
+ }
+ lk->fd = fd;
+ return (0);
+}
+
+void
+nni_plat_file_unlock(nni_plat_flock *lk)
+{
+ int fd = lk->fd;
+ lk->fd = -1;
+ (void) close(fd);
+}
+
char *
nni_plat_temp_dir(void)
{