diff options
| author | Magnus Ahltorp <map@kth.se> | 2014-09-25 01:35:33 +0200 |
|---|---|---|
| committer | Magnus Ahltorp <map@kth.se> | 2014-09-25 01:35:33 +0200 |
| commit | ae9f673d35ec0140a7276297cee002bfd3a15852 (patch) | |
| tree | ea33f6ab2fdc35fe359f0067763db756885e7ac9 /c_src/fsynchelper.c | |
| parent | 0b253574667acde453a50a2b61cf46d6f7a6c86e (diff) | |
Permanent storage implementation
Diffstat (limited to 'c_src/fsynchelper.c')
| -rw-r--r-- | c_src/fsynchelper.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/c_src/fsynchelper.c b/c_src/fsynchelper.c new file mode 100644 index 0000000..e6a04be --- /dev/null +++ b/c_src/fsynchelper.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2014 Kungliga Tekniska Högskolan + * (KTH Royal Institute of Technology, Stockholm, Sweden). + */ + +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> + +#include <sys/time.h> +#include <sys/select.h> + +#include "erlport.h" + +static int +dosync(int fd) +{ +#ifdef F_FULLFSYNC + int ret = fcntl(fd, F_FULLFSYNC); +#else + int ret = fsync(fd); +#endif + return ret; +} + +int +main() +{ + char buf[100]; + ssize_t len; + + /* XXX: exits when command size is 0 */ + + while ((len = read_command(buf, sizeof(buf)-1)) > 0) { + buf[len] = '\0'; + while (1) { + int fd; + + fd = open(buf, O_RDONLY); + if (fd == -1) { + /* XXX: better errors */ + write_status("openerror"); + break; + } + + if (dosync(fd) == 0) { + write_status("ok"); + } else if (errno == EBADF) { + write_status("ebadf"); + } else if (errno == EINTR) { + close(fd); + continue; + } else { + write_status("fsyncerror"); + } + + close(fd); + break; + } + } + + return 0; +} |
