2

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?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
jianhui
  • 133
  • 6

1 Answers1

0

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Could you please more particular, how to make the view to be started and what could be done after get the full dynamic view path? thank you! – jianhui Nov 16 '15 at 13:14
  • @jianhui for the starting part: http://stackoverflow.com/a/31866188/6309 (as mentioned in my answer) – VonC Nov 16 '15 at 13:15
  • @jianhui "what could be done after get the full dynamic view path": nothing, you just make sure to use that path in your daemon process. – VonC Nov 16 '15 at 13:16