0

I'm trying to open a fifo pipe, into which one thread writes, the synchronization is all good. However, for understandable reasons I need it to be opened in append mode.

When I open it as follow:

        ret_val = mkfifo(lpipename.c_str(), 0666);
        if((pipehandler = open(lpipename.c_str(), O_RDWR)) < 1) 
    {
        perror("Failed to open pipe file");
        syslog(LOG_ERR, "Failed to open pipe file");
        exit(1);
    }

I don't have any problems and I can see the pipe marked in yellow when 'ls'-ing my folder

But when I try to open the pipe as follows, in append mode:

    ret_val = mkfifo(lpipename.c_str(), 0666);
    if((pipehandler = open(lpipename.c_str(), O_RDWR| O_APPEND)) < 1) 
    {
        perror("Failed to open pipe file");
        syslog(LOG_ERR, "Failed to open pipe file");
        exit(1);
    }

I can't see the pipe in folder at all. For the record, I get an error in NEITHER one of the options Does anyone have any idea of why?

Thanks

Alon_T
  • 1,430
  • 4
  • 26
  • 47
  • Note that rather than explicitly printing to stderr with perror, you can add `LOG_PERROR` to the option flag of openlog() on most unixen. (You would need to invoke strerror() to get the same text as perror.) – William Pursell Nov 06 '12 at 17:14

2 Answers2

0

O_APPEND may lead to corrupted files on NFS file systems if more than one process appends data to a file at once. This is because NFS does not support appending to a file, so the client kernel has to simulate it, which can't be done without a race condition.

It may be due to this,for more details look into the below link

http://www.kernel.org/doc/man-pages/online/pages/man2/open.2.html

Dileep
  • 2,399
  • 4
  • 26
  • 39
  • As it is not giving any errors, so i guessed it may due to this. Let me do some more intensive googling, hopefully i will come up with something more useful. – Dileep Nov 06 '12 at 13:54
  • "I'm trying to open a fifo pipe, into which multiple threads write" . Please ensure at a time only one process write to file. – Dileep Nov 06 '12 at 14:00
  • Thank you, and I just corrected my depiction. There's only one thread and appending is a must. in the first scheme it overrides the data already in the pipe right? – Alon_T Nov 06 '12 at 14:48
  • i think O_RDWR appends to old one. http://stackoverflow.com/questions/7801315/open-with-o-rdwr-how-to-overwrite ." in the first scheme it overrides the data already in the pipe right?" the answer must be no then. – Dileep Nov 07 '12 at 04:53
0

It's a FIFO. How could it do anything else but append? I believe appending is the norm, thus it will always append no matter how you open it.

jtgd
  • 1