Skip to content

Commit

Permalink
[LibOS] Ignore O_TRUNC flag for FIFO files
Browse files Browse the repository at this point in the history
Signed-off-by: Sonali Saha <sonali.saha@intel.com>
  • Loading branch information
sahason authored and Dmitrii Kuvaiskii committed Jun 19, 2023
1 parent 514df18 commit 42bd145
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions libos/src/fs/libos_namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ int dentry_open(struct libos_handle* hdl, struct libos_dentry* dent, int flags)
/* truncate regular writable file if O_TRUNC is given */
if ((flags & O_TRUNC) && ((flags & O_RDWR) | (flags & O_WRONLY))
&& (dent->inode->type != S_IFDIR)
&& (dent->inode->type != S_IFIFO)
&& (dent->inode->type != S_IFLNK)) {

if (!(fs->fs_ops && fs->fs_ops->truncate))
Expand Down
2 changes: 1 addition & 1 deletion libos/src/fs/pipe/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static int fifo_open(struct libos_handle* hdl, struct libos_dentry* dent, int fl
* one end (read or write) in our emulation, so we treat such FIFOs as read-only. This
* covers most apps seen in the wild (in particular, LTP apps). */
log_warning("FIFO (named pipe) '%s' cannot be opened in read-write mode in Gramine. "
"Treating it as read-only.", dent->mount->path);
"Treating it as read-only.", dent->name);
flags = (flags & ~O_ACCMODE) | O_RDONLY;
}

Expand Down
4 changes: 2 additions & 2 deletions libos/test/regression/mkfifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ int main(int argc, char** argv) {
/* server */
fd = -1;
while (fd < 0) {
/* wait until client is ready for read */
/* wait until client is ready for read (O_TRUNC flag here is only for testing) */
errno = 0;
fd = open(FIFO_PATH, O_NONBLOCK | O_WRONLY);
fd = open(FIFO_PATH, O_NONBLOCK | O_WRONLY | O_TRUNC);
if (fd < 0 && errno != ENXIO) {
perror("[parent] open error");
return 1;
Expand Down

0 comments on commit 42bd145

Please sign in to comment.