Done until djumbai-send
This commit is contained in:
parent
83bd6fb796
commit
da345fc422
8 changed files with 135 additions and 36 deletions
|
|
@ -1,3 +1,54 @@
|
|||
int main(){
|
||||
#include "../../libs/protocol/protocol.h"
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main() {
|
||||
|
||||
// Open the FIFO for writing
|
||||
const char *send_fifo_path = "fifos/send_fifo";
|
||||
if (access(send_fifo_path, F_OK) != -1) {
|
||||
// FIFO exists, delete it
|
||||
if (unlink(send_fifo_path) == -1) {
|
||||
perror("unlink");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("Existing FIFO deleted.\n");
|
||||
}
|
||||
|
||||
// Open the FIFO for reading
|
||||
if (mkfifo(send_fifo_path, 0420) == -1) {
|
||||
perror("mkfifo");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int send_fifo_fd;
|
||||
send_fifo_fd = open(send_fifo_path, O_RDONLY);
|
||||
if (send_fifo_fd == -1) {
|
||||
if (errno == ENOENT) {
|
||||
// FIFO does not exist
|
||||
printf("FIFO '%s' does not exist. Exiting...\n", send_fifo_path);
|
||||
return 1;
|
||||
} else {
|
||||
perror("open");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char buffer[MESSAGE_SIZE];
|
||||
while (1) {
|
||||
read(send_fifo_fd, buffer, MESSAGE_SIZE);
|
||||
|
||||
// SPAWN THE CHILD PROCESS TO PUT THE MESSAGE IN THE USER'S QUEUE
|
||||
// CHECK IF THE MESSAGE IS DESTINED TO A GROUP
|
||||
// IF IT IS DESTINED TO A GROUP, START THE CHILD PROCESS WITH THE UID OF THE SENDER AND GID OF THE GROUP
|
||||
// THE SENDER MUST BE PART OF THE GROUP
|
||||
|
||||
memset(buffer, 0, MESSAGE_SIZE);
|
||||
}
|
||||
close(send_fifo_fd);
|
||||
unlink(send_fifo_path);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue