I am programming a Linux distribution C program. When daemon process read a MSG from the client, it will fork a child process, then mount a "NFS" dir to local host and do the compute task on this NFS dir.
However this is NFS is IBM ClearCase dynamic view which is called "MVFS" rather than "NFS".
So I have to exec "cleartool setview xxyyzz
" to mount this view.
But I tried several methods such as fork() + execvp
, system(shell)
, but never succeed.
Below is the code and shell:
void my_system();
int main(int argc, char** argv)
{
pid_t pid=fork();
if(pid!=0) exit(0);
if(setsid()==-1)
{
printf("setsid failed.");
exit(-1);
}
umask(0);
chdir("/tmp");
int i;
for(i=0;i<3;i++)
close(i);
FILE* logfd=fopen("/tmp/ccdcc.log","a+");
dup2(fileno(logfd),STDOUT_FILENO);
dup2(fileno(logfd),STDERR_FILENO);
fclose(logfd);
my_system(); //method1
system("/tmp/ccdccshell"); //method2
sleep(SEVERALTIME);
}
void my_system()
{
pid_t pid=fork();
if(pid!=0) return;
char *arg1[]={"cleartool","setview","zzzzzz"};
char *arg2[]={"cd","/proj/layer/mak"};
char *arg3[]={"mycmd"};
execvp("cleartool",arg1);
execvp("cd",arg2);
execvp("mycmd",NULL);
}
xxx@yyy> cat /tmp/ccdccshell
#!/bin/sh
#this command will mount a dynamic view and source some profile.
cleartool setview zzzzzz
#this path is under the mounted path
cd /proj/layer/mak
#to test where we are
pwd
#call my prog.
mycmd
I failed "cleartool....
" everytime. There's no view been mounted.
"pwd
" always return the path "/
".
Could you tell me how to finish my program?
Don't use cleartool setview
: it spawns a subshell which would not be visible from your sameon.
Simply use the full dynamic view path:
/view/myDynView
# under which you would see:
/view/myDynView/vobs/MyVob
All you need is for the view to be started.