From 1a05bc5d54045d0f14cbd396fcb7329397f6d767 Mon Sep 17 00:00:00 2001 From: afonso Date: Sun, 12 May 2024 21:19:06 +0100 Subject: [PATCH] Added write access check --- src/djumbai_dequeue/djumbai_dequeue.c | 13 +++++++++++-- src/djumbai_enqueue/djumbai_enqueue.c | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/djumbai_dequeue/djumbai_dequeue.c b/src/djumbai_dequeue/djumbai_dequeue.c index b6a61a3..174d3fc 100644 --- a/src/djumbai_dequeue/djumbai_dequeue.c +++ b/src/djumbai_dequeue/djumbai_dequeue.c @@ -10,7 +10,7 @@ int main() { const char *message_queue_path = "/djumbai/fifos/message_queue"; - if (faccessat(AT_FDCWD,message_queue_path, F_OK,AT_EACCESS) != -1) { + if (faccessat(AT_FDCWD, message_queue_path, F_OK, AT_EACCESS) != -1) { // FIFO exists, delete it if (unlink(message_queue_path) == -1) { perror("unlink"); @@ -37,9 +37,18 @@ int main() { } } - // Open the FIFO for writing const char *send_fifo_path = "/djumbai/fifos/send_fifo"; + + // Check if I have write permissions on the FIFO + if (faccessat(AT_FDCWD, send_fifo_path, W_OK, AT_EACCESS) != -1) { + printf("You have write access to the FIFO.\n"); + } else { + perror("Error"); + exit(EXIT_FAILURE); + } + int send_fifo_fd; + // Open the FIFO for writing send_fifo_fd = open(send_fifo_path, O_WRONLY); if (send_fifo_fd == -1) { if (errno == ENOENT) { diff --git a/src/djumbai_enqueue/djumbai_enqueue.c b/src/djumbai_enqueue/djumbai_enqueue.c index 2a6b653..c9f1e2a 100644 --- a/src/djumbai_enqueue/djumbai_enqueue.c +++ b/src/djumbai_enqueue/djumbai_enqueue.c @@ -1,4 +1,5 @@ #include "djumbai_enqueue.h" +#include int main() { @@ -6,6 +7,14 @@ int main() { const char *message_queue_path = "/djumbai/fifos/message_queue"; + //Check if I have write permissions on the FIFO + if (faccessat(AT_FDCWD, message_queue_path,W_OK,AT_EACCESS) != -1) { + printf("You have write access to the FIFO.\n"); + } else { + perror("Error"); + exit(EXIT_FAILURE); + } + // Open the FIFO for writing int queue_fd; queue_fd = open(message_queue_path, O_WRONLY);