On Wed, 20 Feb 2008, j.chitte wrote:
> Hi,
>
> I would like some confirmation of what I think is happening with an
> exit value.
>
> I have a cgi that is written in C and a control prog based on
> adc_logger also in C. These both then run on the ARM.
>
>
> char get_portA ()
> {
> return(*portA_dr);
> }
>
> ....
>
> pump_state=get_portA();
>
> .....
>
> fprintf(stderr,"pump_state on return=%d",pump_state);
> if (state_request) exit(get_portA());
I'm assuming you are returning the value of get_portA as the exit value of
the program - i.e. its status?
> ...
> } // end of main
>
>
> I call this from my cgi responder:
>
> strcpy(cmd,"./adc_logger -s");
> if ( 0>(resp=system(cmd)) ) { // -1 fork failed
> ...
> } else {
> printf(text_head);
> printf("pump_state=%d\n",resp);
> exit(0);
>
>
> Now the error log shows pump_state=23 , which was correct but by the
> time it gets back the browser on x86 it's 5888 , as hex 1700 !
>
> So there seems to be byte reversal.
No I don't think so. This is normal. Check out the man page for the system
call. On my debain box this says that the system call return value...
The value returned is -1 on error (e.g. fork failed), and
the return status of the command otherwise. This latter
return status is in the format specified in wait(2).
man 2 wait, has quite a bit to say on its return value including the
recommendation to use various macros to get at the return status of the
command. The main 2 being....
WIFEXITED(status)
is non-zero if the child exited normally.
WEXITSTATUS(status)
evaluates to the least significant eight bits of
the return code of the child which terminated,
which may have been set as the argument to a call
to exit() or as the argument for a return statement
in the main program. This macro can only be evalu
ated if WIFEXITED returned non-zero.
I believe that in many unixlike systems the return value of system()
is (program_return_value<<8)+SomeOtherStuffToDoWithWhetherShellRanCmdOK
So use the macros provided and all will be as expected.
> Is this due to archectecture differences?! I dont think I need to
> know the hardware to get the correct answer so why is this happening?
>
> BTW , I call the cgi via an xhttp object in javascript.
>
> Thanks for any help.
>
> /jacques.
>
>
>
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|