From f301a108f1d9d1ccd28c54c64eb495284f371026 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 28 Apr 2015 13:52:35 +0200 Subject: ... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/bus.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/bus.c b/src/bus.c index 5737fd7..6c90500 100644 --- a/src/bus.c +++ b/src/bus.c @@ -40,6 +40,19 @@ +#ifdef BUS_SEMAPHORES_ARE_SYNCHRONOUS_ME_EVEN_HARDER +# ifndef BUS_SEMAPHORES_ARE_SYNCHRONOUS_ME_HARDER +# define BUS_SEMAPHORES_ARE_SYNCHRONOUS_ME_HARDER +# endif +#endif +#ifdef BUS_SEMAPHORES_ARE_SYNCHRONOUS_ME_HARDER +# ifndef BUS_SEMAPHORES_ARE_SYNCHRONOUS +# define BUS_SEMAPHORES_ARE_SYNCHRONOUS +# endif +#endif + + + /** * Semaphore used to signal `bus_write` that `bus_read` is ready */ @@ -60,6 +73,7 @@ */ #define Q 3 +#ifndef BUS_SEMAPHORES_ARE_SYNCHRONOUS_ME_EVEN_HARDER /** * Semaphore used to notify `bus_read` that it may restore `S` */ @@ -69,6 +83,9 @@ * The number of semaphores in the semaphore array */ #define BUS_SEMAPHORES 5 +#else +#define BUS_SEMAPHORES 4 +#endif @@ -621,7 +638,7 @@ fail: * @return 0 on success, -1 on error */ int -bus_write(const bus_t *bus, const char *message, int flags /* TODO document in man page */) +bus_write(const bus_t *bus, const char *message, int flags) { int saved_errno; #ifndef BUS_SEMAPHORES_ARE_SYNCHRONOUS @@ -692,7 +709,9 @@ bus_read(const bus_t *bus, int (*callback)(const char *message, void *user_data) t(release_semaphore(bus, W, SEM_UNDO)); state++; t(acquire_semaphore(bus, S, SEM_UNDO)); state++; t(zero_semaphore(bus, S, 0)); +#ifndef BUS_SEMAPHORES_ARE_SYNCHRONOUS_ME_HARDER t(zero_semaphore(bus, N, 0)); +#endif t(release_semaphore(bus, S, SEM_UNDO)); state--; t(acquire_semaphore(bus, W, SEM_UNDO)); state--; } @@ -760,3 +779,37 @@ fail: return NULL; } + +int +bus_chown(const char *file, uid_t owner, gid_t group) +{ + bus_t bus; + t(bus_open(&bus, file, -1)); + t(chown(file, owner, group)); + /* TODO chown sem */ + /* TODO chown shm */ + return 0; +fail: + return -1; +} + + +int +bus_chmod(const char *file, mode_t mode) +{ + bus_t bus; + mode_t fmode; + mode = (mode & S_IRWXU) ? (mode | S_IRWXU) : (mode & ~S_IRWXU); + mode = (mode & S_IRWXG) ? (mode | S_IRWXG) : (mode & ~S_IRWXG); + mode = (mode & S_IRWXO) ? (mode | S_IRWXO) : (mode & ~S_IRWXO); + mode &= (S_IWUSR | S_IWGRP | S_IWOTH | S_IRUSR | S_IRGRP | S_IROTH); + fmode = mode & ~(S_IWGRP | S_IWOTH); + t(bus_open(&bus, file, -1)); + t(chmod(file, fmode)); + /* TODO chmod sem */ + /* TODO chmod shm */ + return 0; +fail: + return -1; +} + -- cgit v1.2.3-70-g09d2