Operating System - HP-UX
1825768 Members
2077 Online
109687 Solutions
New Discussion

/sbin/sh versus command ! in vi

 
SOLVED
Go to solution
Alfonso_15
Advisor

/sbin/sh versus command ! in vi

Good Morning:
I have a program in c++ calling a function in OCI oracle (olog). When I run the program from command shell it ends by Memory Fault (coredump) error:
root # ./cprog
declaring my connection
Just Before olog
Memory fault(coredump)
root #

But I when I callt his program from editor vi with command !, the program ends without memory fault:
from editor vi

~
~
:!./cprog
declaring my connection
Just Before olog
Not Connected ,returning from olog
[Hit return to continue]

So, anycase my olog function is not connecting, but when I run the program from vi, it returns and ends without problem.

Somebody can explainme whta is the difference between the process ran from /sbin/sh and from command ! in vi.

Thanks in advance for you information.
alfonsoarias
6 REPLIES 6
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: /sbin/sh versus command ! in vi

One fundamental difference is that when you ! in vi, it invokes the system() function which forks and does an exec of /usr/bin/sh rather than /sbin/sh. It's almost certainly not the fault of the shell but more a function of how your buggy code is executed. Also, note that under vi you are executing the child of a child process rather than simply a child process.

You are really attacking the problem all wrong. You need to fix the fundamental problem -- your code. Use gdb to do a stack trace. If you will recompile/relink with -g you can zero in on the offending line.
If it ain't broke, I can fix that.
Alfonso_15
Advisor

Re: /sbin/sh versus command ! in vi

Thanks Clay.
It's clearr your explanation. I am trying to solve this problem:
If I call olog routine from the main() function in my program, it works fine and connects with oracle. But if I call olog from a function member of a class, it doesn't connects with oracle and outputs the memory fault (coredump) from /sbin/sh.
For problem isolation, I simplify the class to only one member function calling olog in the same way that in function main() but does works. Do you have any suggestion about that?
Thanks again for your help

alfonsoarias
Alfonso_15
Advisor

Re: /sbin/sh versus command ! in vi

Sorry Clay I rewrite last paragraph:
For problem isolation, I simplify the class to only one member function calling olog in the same way that in function main() but doesn't works. Do you have any suggestion about that?
Thanks again for your help
alfonsoarias
A. Clay Stephenson
Acclaimed Contributor

Re: /sbin/sh versus command ! in vi

I'll take a VERY wild guess and say that you have a bug in your constructor (or you are using the default constructor for your class and random values are killing you) but the real answer is a stack trace. Learn to use the debugger and then you won't need to use "The Force".
If it ain't broke, I can fix that.
Alfonso_15
Advisor

Re: /sbin/sh versus command ! in vi

Clay, thanks for your answers.
I am attaching my programs and the results of gdb, as you can see there I am doing the same code in the class as in the main function, but when I call the function member in the class the programs ends with Memory fault(coredump), but from main() function it execute successfully.
Do you have any idea why that is happening?
Thanks IN ADVANCE
alfonsoarias
A. Clay Stephenson
Acclaimed Contributor

Re: /sbin/sh versus command ! in vi

Okay, I copied your source and split out the header file. I reproduced your error and made these changes in both main and inside your class and all was well.

ub4 hda[HDA_SIZE/sizeof(ub4)];
change to:
ub4 hda[HDA_SIZE];

--------------------------------------
memset(hda,'\0',HDA_SIZE/sizeof(ub4));
change to:
memset((void *) hda,(int) '\0',sizeof(hda));

After doing this I saw your "Yes Connected from main()" and your "Yes Connected from class" probes. And what is this printf stuff doing in C++; it ought to be cout.

This was a little difficult to do in a stack trace because the actual segmentation violation was occurring in a shared library which was not compiled with debugger info but the problem appeared to be that your hda array was too small. The call in main() was really working by accident.
If it ain't broke, I can fix that.