X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Ffs-util.c;h=426ad97612167c0445b0c0579d5cb4fdecb8815c;hb=71227310a62a616a0d9356fe0506e01f47c76eb3;hp=a677fc571188273a8529499ff21f28948990e9f6;hpb=b96ed50e3493103d075ff2ce4c3fbad8f26b2e22;p=elogind.git diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index a677fc571..426ad9761 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -1,5 +1,3 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - /*** This file is part of systemd. @@ -19,16 +17,30 @@ along with systemd; If not, see . ***/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "alloc-util.h" #include "dirent-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" +//#include "log.h" +//#include "macro.h" +//#include "missing.h" #include "mkdir.h" #include "parse-util.h" #include "path-util.h" #include "string-util.h" #include "strv.h" +//#include "time-util.h" #include "user-util.h" #include "util.h" @@ -43,8 +55,7 @@ int unlink_noerrno(const char *path) { return 0; } -/// UNNEEDED by elogind -#if 0 +#if 0 /// UNNEEDED by elogind int rmdir_parents(const char *path, const char *stop) { size_t l; int r = 0; @@ -171,8 +182,7 @@ int readlink_malloc(const char *p, char **ret) { return readlinkat_malloc(AT_FDCWD, p, ret); } -/// UNNEEDED by elogind -#if 0 +#if 0 /// UNNEEDED by elogind int readlink_value(const char *p, char **ret) { _cleanup_free_ char *link = NULL; char *value; @@ -194,7 +204,6 @@ int readlink_value(const char *p, char **ret) { return 0; } -#endif // 0 int readlink_and_make_absolute(const char *p, char **r) { _cleanup_free_ char *target = NULL; @@ -216,8 +225,6 @@ int readlink_and_make_absolute(const char *p, char **r) { return 0; } -/// UNNEEDED by elogind -#if 0 int readlink_and_canonicalize(const char *p, char **r) { char *t, *s; int j; @@ -280,24 +287,6 @@ int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid) { return 0; } -int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid) { - assert(fd >= 0); - - /* Under the assumption that we are running privileged we - * first change the access mode and only then hand out - * ownership to avoid a window where access is too open. */ - - if (mode != MODE_INVALID) - if (fchmod(fd, mode) < 0) - return -errno; - - if (uid != UID_INVALID || gid != GID_INVALID) - if (fchown(fd, uid, gid) < 0) - return -errno; - - return 0; -} - int fchmod_umask(int fd, mode_t m) { mode_t u; int r; @@ -336,7 +325,8 @@ int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gi if (parents) mkdir_parents(path, 0755); - fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, mode > 0 ? mode : 0644); + fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, + (mode == 0 || mode == MODE_INVALID) ? 0644 : mode); if (fd < 0) return -errno; @@ -370,6 +360,7 @@ int touch(const char *path) { return touch_file(path, false, USEC_INFINITY, UID_INVALID, GID_INVALID, MODE_INVALID); } +#if 0 /// UNNEEDED by elogind int symlink_idempotent(const char *from, const char *to) { _cleanup_free_ char *p = NULL; int r; @@ -455,6 +446,7 @@ int mkfifo_atomic(const char *path, mode_t mode) { return 0; } +#endif // 0 int get_files_in_directory(const char *path, char ***list) { _cleanup_closedir_ DIR *d = NULL; @@ -476,7 +468,7 @@ int get_files_in_directory(const char *path, char ***list) { errno = 0; de = readdir(d); - if (!de && errno != 0) + if (!de && errno > 0) return -errno; if (!de) break; @@ -507,3 +499,19 @@ int get_files_in_directory(const char *path, char ***list) { return n; } + +#if 0 /// UNNEEDED by elogind +int inotify_add_watch_fd(int fd, int what, uint32_t mask) { + char path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1]; + int r; + + /* This is like inotify_add_watch(), except that the file to watch is not referenced by a path, but by an fd */ + xsprintf(path, "/proc/self/fd/%i", what); + + r = inotify_add_watch(fd, path, mask); + if (r < 0) + return -errno; + + return r; +} +#endif // 0