|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
|
Thread Tools | Display Modes |
|
||||
problem passing /dev/fd/n to programs
I have a perl script that needs to invoke an editor on a temporary file, which is created with File::Temp::tempfile(). What I would like to do, is have it check if there is an accessible /dev/fd or /proc/$$/fd directory on the system: and if so pass the file descriptor to the editor through the file system instead of using the file name; if there is no such directory, bite the bullet and use the filename. I've tried cat, ed, vi, and vim but none seem to work via "/dev/fd/".fileno($fh) here. Then I wrote a small C program that opens a test file, clears the close on exec flag, concatenates the editor, /dev/fd, and the fileno() into a single string, passes it on to system(). For quick testing I set the editor to use as "cat".
On FreeBSD 7, I get '/dev/fd/3: No such file or directory' when attempting to open the file, on OpenBSD 4.4 I get successful access to the temporary file through /dev/fd/.fileno; but on FreeBSD it refuses! I might very well be an idiot, but I don't get it. Does FreeBSD not create /dev/fd/n's greater then the 0,1,2 std{out,in,err} files for a program by default or something? attachments if wanted: snip.pl the portion of perl code, snip.c the super quick c code.
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. Last edited by TerryP; 31st March 2009 at 06:16 AM. |
|
||||
I think I've found the problemo: fd(4) states that devfs only maintains the standard I/O descriptors by default, and points to fdescfs (5).
So that provides a solution to my problem, if not a totally portable one :-/
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. |
|
||||
Hmm, if I mount an fdescfs on /dev/fd, then flick-off the close on exec flag & exec the program on /dev/fd/N, it works.... but the file descriptor is an empty file rather then the content of my temporary file.... which was written out through the open file handle.
Even worse, I can !cat /tmp/thetempfile in ed, and see the content it is supposed to have from opening /dev/fd/N lol.
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. |
Tags |
/dev/fd/3 |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Uncompatable BSD programs and drivers | oscurochu | FreeBSD General | 11 | 25th August 2009 06:22 PM |
Distributed Computing Programs | JMJ_coder | General software and network | 0 | 25th November 2008 08:50 PM |
Passing args to port / make while installing apache | robot | FreeBSD Ports and Packages | 2 | 27th August 2008 01:55 PM |
passing arg from bootloadder to kernel | l2fl2f | FreeBSD General | 16 | 15th May 2008 12:38 PM |
Programs | syrushcw | FreeBSD Security | 1 | 2nd May 2008 05:44 PM |