please work

This commit is contained in:
Afonso Franco 2024-05-12 20:27:11 +01:00
parent 35cde3e290
commit 4438e29454
Signed by: afonso
SSH key fingerprint: SHA256:PQTRDHPH3yALEGtHXnXBp3Orfcn21pK20t0tS1kHg54
3 changed files with 22 additions and 24 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}