Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, i need to make a program, which "emulates" a file (char device) to another program (which would run as child process).
the data coming from stdin should go to that file (if the child process reads from that file) and the output of the child written into that file should go to stdout.
or, to simulate a char device (this example would forward the webcam device over network via ssh):
$ mkfifo fifo1 fifo2
$ ssh -c "cat /dev/video0" host > fifo1 &
$ ssh -c "cat > /dev/video0" host < fifo2 &
$ cat fifo1 | emufile /dev/video0 cheese | cat fifo2
so, what i try to do is something like padsp (which simulates a OSS (/dev/dsp) device in an PulseAudio environment), but not for a specific file, and i also have to "forward" stdio from/to that file.
i looked at the padsp sources, and it seems that it defines custom fopen/fwrite/fclose/etc... syscalls, and somehow uses them as wrappers for his child process.
if anyone knows howto do that, or knows an tutorial/howto on simulating files to child processes, please tell me.
can make use a pseudotty called /dev/video0 and pipe stdin of an process to it, and stdout of it to another process? if yes, then it could work...
but i thought of making a real "virtual file", which is not on the harddisk or ramdisk, but only exists in an wrapper function which overwrites the stdio of the child process. i mean if using pseudo-tty is so simple, why should padsp then replace syscalls?
oh, i have an idea: could it be possible to compile a modified version of iostream.h into a lib, and then just call my "child process" with LD_PRELOAD or LD_LIBRARY_PATH (or how that environment variable is called), so it uses my modifies lib for file access?
i just got another idea using the Unix98PTY: i could create an PTY, then create a symlink to the name the file should be called, run the program, wait for the program quitting, remove the symlink and then close the PTY.
do you think this can be done in a bash script? because i like bash scripting more than coding C/C++ for such "small" tasks.
if you compile it, run like this: "a.out virtualFile1 virtualFile2" (when a.out is the binary).
it does create 2 PTYs, and symlinks to virtualFile1 and virtualFile2.
but what i want (in the while loops) is that it "connects" the two PTYs (so that input from pty1 goes to pty2's output and input from pty2 will be put out on pty1). it does'nt work.
i tried "cat > virtualFile1" on one xterm while doing "cat virtualFile2" in the other one, then typed into the first one, but the input didn't appear in the second one or in the debug lines
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.