please work
This commit is contained in:
parent
35cde3e290
commit
4438e29454
3 changed files with 22 additions and 24 deletions
|
@ -20,13 +20,13 @@ int main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the FIFO for reading
|
// Open the FIFO for reading
|
||||||
if (mkfifo(message_queue_path, 0420) == -1) {
|
if (mkfifo(message_queue_path, 0620) == -1) {
|
||||||
perror("mkfifo");
|
perror("mkfifo");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
int message_queue_fd;
|
FILE *message_queue_fd;
|
||||||
message_queue_fd = open(message_queue_path, O_RDONLY);
|
message_queue_fd = fopen(message_queue_path, O_RDONLY);
|
||||||
if (message_queue_fd == -1) {
|
if (message_queue_fd == NULL) {
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
// FIFO does not exist
|
// FIFO does not exist
|
||||||
printf("FIFO '%s' does not exist. Exiting...\n", message_queue_path);
|
printf("FIFO '%s' does not exist. Exiting...\n", message_queue_path);
|
||||||
|
@ -39,9 +39,9 @@ int main() {
|
||||||
|
|
||||||
// Open the FIFO for writing
|
// Open the FIFO for writing
|
||||||
const char *send_fifo_path = "/djumbai/fifos/send_fifo";
|
const char *send_fifo_path = "/djumbai/fifos/send_fifo";
|
||||||
int send_fifo_fd;
|
FILE *send_fifo_fd;
|
||||||
send_fifo_fd = open(send_fifo_path, O_WRONLY);
|
send_fifo_fd = fopen(send_fifo_path, O_WRONLY);
|
||||||
if (send_fifo_fd == -1) {
|
if (send_fifo_fd == NULL) {
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
// FIFO does not exist
|
// FIFO does not exist
|
||||||
printf("FIFO '%s' does not exist. Exiting...\n", send_fifo_path);
|
printf("FIFO '%s' does not exist. Exiting...\n", send_fifo_path);
|
||||||
|
@ -54,12 +54,12 @@ int main() {
|
||||||
|
|
||||||
unsigned char buffer[MESSAGE_SIZE];
|
unsigned char buffer[MESSAGE_SIZE];
|
||||||
while (1) {
|
while (1) {
|
||||||
read(message_queue_fd, buffer, MESSAGE_SIZE);
|
fread(buffer, 1, MESSAGE_SIZE, message_queue_fd);
|
||||||
write(send_fifo_fd, buffer, MESSAGE_SIZE);
|
fwrite(buffer, 1, MESSAGE_SIZE,send_fifo_fd);
|
||||||
memset(buffer, 0, MESSAGE_SIZE);
|
memset(buffer, 0, MESSAGE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(message_queue_fd);
|
fclose(message_queue_fd);
|
||||||
unlink(message_queue_path);
|
unlink(message_queue_path);
|
||||||
close(send_fifo_fd);
|
fclose(send_fifo_fd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,12 @@
|
||||||
|
|
||||||
int main() {
|
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
|
// Open the FIFO for writing
|
||||||
int queue_fd;
|
FILE *queue_fd;
|
||||||
queue_fd = open(message_queue_path, O_WRONLY);
|
queue_fd = fopen(message_queue_path, O_WRONLY);
|
||||||
if (queue_fd == -1) {
|
if (queue_fd == NULL) {
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
// FIFO does not exist
|
// FIFO does not exist
|
||||||
printf("FIFO '%s' does not exist. Exiting...\n", message_queue_path);
|
printf("FIFO '%s' does not exist. Exiting...\n", message_queue_path);
|
||||||
|
@ -25,6 +23,6 @@ int main() {
|
||||||
read(0, buffer, MESSAGE_SIZE);
|
read(0, buffer, MESSAGE_SIZE);
|
||||||
|
|
||||||
// Write message to message queue
|
// Write message to message queue
|
||||||
write(queue_fd, buffer, MESSAGE_SIZE);
|
fwrite(buffer, 1, MESSAGE_SIZE, queue_fd);
|
||||||
close(queue_fd);
|
fclose(queue_fd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,9 +31,9 @@ int main() {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int send_fifo_fd;
|
FILE *send_fifo_fd;
|
||||||
send_fifo_fd = open(send_fifo_path, O_RDONLY);
|
send_fifo_fd = fopen(send_fifo_path, O_RDONLY);
|
||||||
if (send_fifo_fd == -1) {
|
if (send_fifo_fd == NULL) {
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
// FIFO does not exist
|
// FIFO does not exist
|
||||||
printf("FIFO '%s' does not exist. Exiting...\n", send_fifo_path);
|
printf("FIFO '%s' does not exist. Exiting...\n", send_fifo_path);
|
||||||
|
@ -47,7 +47,7 @@ int main() {
|
||||||
while (1) {
|
while (1) {
|
||||||
// Read message from the send_fifo
|
// Read message from the send_fifo
|
||||||
unsigned char buffer[MESSAGE_SIZE];
|
unsigned char buffer[MESSAGE_SIZE];
|
||||||
read(send_fifo_fd, buffer, MESSAGE_SIZE);
|
fread(buffer, 1, MESSAGE_SIZE, send_fifo_fd);
|
||||||
// Deserialize the message
|
// Deserialize the message
|
||||||
message msg;
|
message msg;
|
||||||
deserialize_message(buffer, MESSAGE_SIZE, &msg);
|
deserialize_message(buffer, MESSAGE_SIZE, &msg);
|
||||||
|
@ -129,6 +129,6 @@ int main() {
|
||||||
wait(NULL);
|
wait(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(send_fifo_fd);
|
fclose(send_fifo_fd);
|
||||||
unlink(send_fifo_path);
|
unlink(send_fifo_path);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue