I am writing a service script for a C project that I am working on and it executes a few utilities on startup. I want to capture all of the output using a logging utility. I have something like the following in /etc/rc5/myscript
#!/bin/bash
#save fd 1 in fd 3 for use later
exec 3<&1
$SERVICESCRIPT | logger
The logger merely reads from stdin until it hits EOF. The second script is where it checks if a bunch of utilities are running and fires off a few of its own. Among these utilities, there is one which forks and becomes a daemon process. Now since I am running it from the script it inherits all of the scripts fds. This causes the script never to return back to command line after being invoked.
I have tried to counter this in a few ways:
First, in my script which kicks of the daemon process I have done the following:
(
exec 4<&-
exec 3<&-
$daemon_process
)
This should launch a subscript, close 3 and 4 (used for storing stdout and piped output respectively) and run the program. but I still get a hang when attempting to come back to command line which leads me to believe that the pipe was not closed. Upon further investigation, if I put an echo after the close and redirect them to the fd which was piped to the logger I do see them in the log telling me that the fd is indeed still in tact. If I do a close on fds 2-4 in the c program I see it return back to command line, however this is a very messy and unpleasant fix.
Second I tried the following:
$daemon_process 4<&- 3<&-
which should close the fds when calling the program, but alas I see the same result of the script never coming back to the command line.
When the script hands I can "CTRL-C" it to get it back to command line, but this is by no means a solution.
Any ideas?
THANKS!!!!