Inter Sys
Inter Sys

Reputation: 139

receiving stdin with a call to open a regular file in linux

I have a program which opens a static file with sys_open() and wants to receive a file descriptor equals to zero (=stdin). I have the ability to write to the file, remove it or modify it, so I tried to create a symbolic link to /dev/stdin from the static file name. It opens stdin, but returns with the lowest available fd (not equal to zero). How can I cause the syscall to return zero, without hooking the syscall or modifying the program itself? it that even possible?

(It's part of a challenge, not a real case scenario)

Thank you as always

Upvotes: 0

Views: 131

Answers (1)

that other guy
that other guy

Reputation: 123470

Posix guarantees that the lowest available FD will be returned. Therefore you can just invoke the program with stdin closed:

./myprogram 0>&-

Upvotes: 2

Related Questions