Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reopened fifo still has data #1230

Open
adamdebek opened this issue Nov 12, 2024 · 0 comments
Open

reopened fifo still has data #1230

adamdebek opened this issue Nov 12, 2024 · 0 comments
Labels
bug Something isn't working libphoenix

Comments

@adamdebek
Copy link
Contributor

When all ends of fifo are closed, data should be discarded.
Reproduction:

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <errno.h>

int main(void) {
        int fd_w, fd_r;
        ssize_t ret;
        char *msg = "abcdefghifjklm";

        if (mkfifo("fifo", 0666) < 0) {
                perror("mkfifo");
                exit(EXIT_FAILURE);
        }

        if ((fd_r = open("fifo", O_RDONLY | O_NONBLOCK)) < 0) {
                perror("open");
                exit(EXIT_FAILURE);
        }

        if ((fd_w = open("fifo", O_WRONLY)) < 0) {
                perror("open");
                exit(EXIT_FAILURE);
        }

        if (write(fd_w, msg, strlen(msg)) != strlen(msg)) {
                perror("write");
                exit(EXIT_FAILURE);
        }

        close(fd_r);
        close(fd_w);

        if ((fd_r = open("fifo", O_RDONLY | O_NONBLOCK)) < 0) {
                perror("open");
                exit(EXIT_FAILURE);
        }

        if ((fd_w = open("fifo", O_WRONLY)) < 0) {
                perror("open");
                exit(EXIT_FAILURE);
        }

        if ((ret = read(fd_r, msg, strlen(msg))) < 0) {
                perror("read");
                exit(EXIT_FAILURE);
        }

        printf("read: %zd\n", ret);
        printf("errno: %d\n", errno);

        return 0;
}
@adamdebek adamdebek added the bug Something isn't working label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working libphoenix
Projects
None yet
Development

No branches or pull requests

1 participant