I’ve done some more investigation of
this. It appears that stdout is being closed and re-opened when the
vxWorks startup script completes. Does anyone know if this is true?
If so, I don’t understand why. I can understand why stdin may be
reopened, changing from the startup script to the console. But why
stdout? Is there a way to open a file descriptor to the console that will
not be closed and re-opened when the startup script completes?
Thanks,
Mark
From: Mark Rivers
Sent: Wednesday, July 16, 2008
7:07 PM
To: EPICS tech-talk
Subject: stdout being changed in
EPICS
Folks,
I have run into a problem with the value of stdout being
changed some time after iocInit is called. This is happening at least on
vxWorks, I have not checked other platforms.
This is a real problem, because I have a vendor library that
assigns a file descriptor to the value of stdout before iocInit is run, and
then does fprintf() to that file descriptor for logging purposes. This
works fine until just after iocInit is called, at which point that file
descriptor is invalid (fprintf returns an error), and the value of stdout has
changed to a new value.
One can easily reproduce this problem with the example
application that EPICS base generates. I just added this small global
function show_stdout() to the end of devXxxSoft.c
corvette> tail devXxxSoft.c
/*If return was succesful then set
undefined false*/
if(!status) pxxx->udf = FALSE;
return(0);
}
int show_stdout()
{
printf("stdout=%p\n", stdout);
return(0);
}
Here is what I see at the end of the st.cmd file, to which I
added calls to show_stdout just before and after iocInit:
****************************************************************************************************
show_stdout
stdout=0x1d0e290
value = 0 = 0x0
iocInit()
Starting iocInit
############################################################################
### EPICS IOC CORE built on Jun 9 2008
### EPICS R3.14.8.2 $R3-14-8-2$ $2006/01/06 15:55:13$
############################################################################
iocInit: All initialization complete
value = 0 = 0x0
show_stdout
stdout=0x1d0e290
value = 0 = 0x0
## Start any sequence programs
seq &sncExample,"user=epics"
SEQ Version 2.0.11: Mon Jun 9 16:03:45 2008
Spawning state program "sncExample", thread
0x1c2e7c0: "sncExample"
value = 29550528 = 0x1c2e7c0
Done executing startup script
/home/epics/devel/example/iocBoot/iocexample/st.cmd
iocexample> show_stdout
stdout=0x1ffe738
value = 0 = 0x0
******************************************************************************************
Note that the value of stdout is 0x1d0e290 before the call
to iocInit, and just after iocInit returns. However, the value has
changed to 0x1ffe738 when I type the show_stdout command manually a few seconds
after I get the vxWorks prompt. This happens whether or not the SNL
program is run (comment out the seq call).
Does anyone know why the value of stdout is changing?
It is a real problem for software that uses the value of stdout through a
call to iocInit.
Thanks,
Mark