diff options
author | Brad King <brad.king@kitware.com> | 2003-07-07 09:12:34 -0400 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2003-07-07 09:12:34 -0400 |
commit | b5fec4a3c8fac315b1279abbe26df352780870bb (patch) | |
tree | d3f3f3e8494e906e1761177c1a502bdb260903b0 /Source/kwsys | |
parent | 2b8bfb3b5d152d07f2d9d059b98680f6313b3050 (diff) | |
download | cmake-b5fec4a3c8fac315b1279abbe26df352780870bb.tar.gz |
ENH: Implemented SetWorkingDirectory method.
Diffstat (limited to 'Source/kwsys')
-rw-r--r-- | Source/kwsys/Process.h.in | 7 | ||||
-rw-r--r-- | Source/kwsys/ProcessUNIX.c | 17 |
2 files changed, 20 insertions, 4 deletions
diff --git a/Source/kwsys/Process.h.in b/Source/kwsys/Process.h.in index cc45299457..7fb681928e 100644 --- a/Source/kwsys/Process.h.in +++ b/Source/kwsys/Process.h.in @@ -99,10 +99,11 @@ kwsysEXPORT void kwsysProcess_SetCommand(kwsysProcess* cp, kwsysEXPORT void kwsysProcess_SetTimeout(kwsysProcess* cp, double timeout); /** - * Set the working directory for the child process. The working directory can - * be absolute or relative to the current directory. + * Set the working directory for the child process. The working + * directory can be absolute or relative to the current directory. */ -kwsysEXPORT void kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, const char* dir); +kwsysEXPORT void kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, + const char* dir); /** * Get the current state of the Process instance. Possible states are: diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c index 96b8300077..64abb4cacd 100644 --- a/Source/kwsys/ProcessUNIX.c +++ b/Source/kwsys/ProcessUNIX.c @@ -167,6 +167,7 @@ void kwsysProcess_Delete(kwsysProcess* cp) /* Free memory. */ kwsysProcess_SetCommand(cp, 0); + kwsysProcess_SetWorkingDirectory(cp, 0); free(cp); } @@ -227,7 +228,7 @@ void kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, const char* dir) } if(dir) { - cp->WorkingDirectory = (char*) malloc(strlen(dir) + 1); + cp->WorkingDirectory = (char*)malloc(strlen(dir) + 1); strcpy(cp->WorkingDirectory, dir); } } @@ -345,6 +346,20 @@ void kwsysProcess_Execute(kwsysProcess* cp) /* Restore all default signal handlers. */ kwsysProcessRestoreDefaultSignalHandlers(); + /* Change to the working directory specified, if any. */ + if(cp->WorkingDirectory) + { + /* Some platforms specify that the chdir call may be + interrupted. Repeat the call until it finishes. */ + int r; + while(((r = chdir(cp->WorkingDirectory)) < 0) && (errno == EINTR)); + if(r < 0) + { + /* Failure. Report error to parent and terminate. */ + kwsysProcessChildErrorExit(cp); + } + } + /* Execute the real process. If successful, this does not return. */ execvp(cp->Command[0], cp->Command); |