diff --git a/src/djumbai_dequeue/djumbai_dequeue.c b/src/djumbai_dequeue/djumbai_dequeue.c index 5a2a5f6..668c57f 100644 --- a/src/djumbai_dequeue/djumbai_dequeue.c +++ b/src/djumbai_dequeue/djumbai_dequeue.c @@ -20,13 +20,13 @@ int main() { } // Open the FIFO for reading - if (mkfifo(message_queue_path, 0420) == -1) { + if (mkfifo(message_queue_path, 0620) == -1) { perror("mkfifo"); exit(EXIT_FAILURE); } - int message_queue_fd; - message_queue_fd = open(message_queue_path, O_RDONLY); - if (message_queue_fd == -1) { + FILE *message_queue_fd; + message_queue_fd = fopen(message_queue_path, O_RDONLY); + if (message_queue_fd == NULL) { if (errno == ENOENT) { // FIFO does not exist printf("FIFO '%s' does not exist. Exiting...\n", message_queue_path); @@ -39,9 +39,9 @@ int main() { // Open the FIFO for writing const char *send_fifo_path = "/djumbai/fifos/send_fifo"; - int send_fifo_fd; - send_fifo_fd = open(send_fifo_path, O_WRONLY); - if (send_fifo_fd == -1) { + FILE *send_fifo_fd; + send_fifo_fd = fopen(send_fifo_path, O_WRONLY); + if (send_fifo_fd == NULL) { if (errno == ENOENT) { // FIFO does not exist printf("FIFO '%s' does not exist. Exiting...\n", send_fifo_path); @@ -54,12 +54,12 @@ int main() { unsigned char buffer[MESSAGE_SIZE]; while (1) { - read(message_queue_fd, buffer, MESSAGE_SIZE); - write(send_fifo_fd, buffer, MESSAGE_SIZE); + fread(buffer, 1, MESSAGE_SIZE, message_queue_fd); + fwrite(buffer, 1, MESSAGE_SIZE,send_fifo_fd); memset(buffer, 0, MESSAGE_SIZE); } - close(message_queue_fd); + fclose(message_queue_fd); unlink(message_queue_path); - close(send_fifo_fd); + fclose(send_fifo_fd); } diff --git a/src/djumbai_enqueue/djumbai_enqueue.c b/src/djumbai_enqueue/djumbai_enqueue.c index 2a6b653..0491c18 100644 --- a/src/djumbai_enqueue/djumbai_enqueue.c +++ b/src/djumbai_enqueue/djumbai_enqueue.c @@ -2,14 +2,12 @@ int main() { - printf("RUNNING AS UID: %d, EUID %d, GID %d, and EGID %d\n",getuid(),geteuid(),getgid(),getegid()); - const char *message_queue_path = - "/djumbai/fifos/message_queue"; + const char *message_queue_path = "/djumbai/fifos/message_queue"; // Open the FIFO for writing - int queue_fd; - queue_fd = open(message_queue_path, O_WRONLY); - if (queue_fd == -1) { + FILE *queue_fd; + queue_fd = fopen(message_queue_path, O_WRONLY); + if (queue_fd == NULL) { if (errno == ENOENT) { // FIFO does not exist printf("FIFO '%s' does not exist. Exiting...\n", message_queue_path); @@ -25,6 +23,6 @@ int main() { read(0, buffer, MESSAGE_SIZE); // Write message to message queue - write(queue_fd, buffer, MESSAGE_SIZE); - close(queue_fd); + fwrite(buffer, 1, MESSAGE_SIZE, queue_fd); + fclose(queue_fd); } diff --git a/src/djumbai_send/djumbai_send.c b/src/djumbai_send/djumbai_send.c index b943a04..5965b4f 100644 --- a/src/djumbai_send/djumbai_send.c +++ b/src/djumbai_send/djumbai_send.c @@ -31,9 +31,9 @@ int main() { exit(EXIT_FAILURE); } - int send_fifo_fd; - send_fifo_fd = open(send_fifo_path, O_RDONLY); - if (send_fifo_fd == -1) { + FILE *send_fifo_fd; + send_fifo_fd = fopen(send_fifo_path, O_RDONLY); + if (send_fifo_fd == NULL) { if (errno == ENOENT) { // FIFO does not exist printf("FIFO '%s' does not exist. Exiting...\n", send_fifo_path); @@ -47,7 +47,7 @@ int main() { while (1) { // Read message from the send_fifo unsigned char buffer[MESSAGE_SIZE]; - read(send_fifo_fd, buffer, MESSAGE_SIZE); + fread(buffer, 1, MESSAGE_SIZE, send_fifo_fd); // Deserialize the message message msg; deserialize_message(buffer, MESSAGE_SIZE, &msg); @@ -129,6 +129,6 @@ int main() { wait(NULL); } } - close(send_fifo_fd); + fclose(send_fifo_fd); unlink(send_fifo_path); }