Reputation: 381
I am developing a shared-library L
which is used by an other system service S
. In my program I need to call a small program P
, which uses Oracle shared libraries.
The small program P
is packaged and installed correctly, and the environment variables, such as PATH
,LD_LIBRARY_PATH
and ORACLE_HOME
are set correctly. I can run P
on command line without any problem.
But when service S
call my library L
which runs the small program P
via system()
, it gives me a return code 127
. I've googled, people says it's a command not found
error, probably a PATH
issue, so I've tried with absolute path like the following
int status = system("/usr/bin/myprog --args");
if (status < 0) { ... }
ret = WEXITSTATUS(status);
ret
still equals 127
.
Any idea please ? Thank you.
Update
It turns out that the service S
is launched via command daemon
, in its init.d
script, I have found the following line:
daemon /usr/bin/myserv
if I export
explicitly all my environment variables (PATH
, ORACLE_HOME
and LD_LIBRARY_PATH
), it works. I don't know if daemon
eliminates my environment variables.
Upvotes: 1
Views: 2237
Reputation: 16550
this excerpt from the man page for system()
-----------------------------------------------------------------
The value returned is -1 on error (e.g., fork(2) failed), and the
return status of the command otherwise.
This latter return status is
in the format specified in wait(2).
Thus, the exit code of the command
will be WEXITSTATUS(status).
In case /bin/sh could not be executed,
the exit status will be that of a command that does exit(127)."
-----------------------------------------------------------------
indicates the 127 means that /bin/sh
could not be executed.
Upvotes: 1
Reputation: 381
Well, I have found the answer:How to make unix service see environment variables?,the environment variables are removed in init.d script.
Upvotes: 0