diff options
author | Bernard Normier <bernard@zeroc.com> | 2003-12-04 21:09:32 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2003-12-04 21:09:32 +0000 |
commit | 7d155020e7c95b9be072e70e4ab0b2a27c609ab5 (patch) | |
tree | 342abc215a72d742eb7a903c26be2ec87633990f /cpp/src | |
parent | fix (diff) | |
download | ice-7d155020e7c95b9be072e70e4ab0b2a27c609ab5.tar.bz2 ice-7d155020e7c95b9be072e70e4ab0b2a27c609ab5.tar.xz ice-7d155020e7c95b9be072e70e4ab0b2a27c609ab5.zip |
Switch from exit to _exit when execvp fails, and cleanup between fork and
exec
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Glacier/StarterI.cpp | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/cpp/src/Glacier/StarterI.cpp b/cpp/src/Glacier/StarterI.cpp index 80a56e487b2..d712d56e32a 100644 --- a/cpp/src/Glacier/StarterI.cpp +++ b/cpp/src/Glacier/StarterI.cpp @@ -249,14 +249,21 @@ Glacier::StarterI::startRouter(const string& userId, const string& password, Byt } } -/* - StringSeq::iterator seqElem = args.begin(); - while(seqElem != args.end()) - { - cerr << *seqElem << endl; - seqElem++; - } -*/ + // + // Convert to standard argc/argv. + // + int argc = static_cast<int>(args.size()) + 1; + char** argv = static_cast<char**>(malloc((argc + 1) * sizeof(char*))); + StringSeq::iterator p; + int i; + for(p = args.begin(), i = 1; p != args.end(); ++p, ++i) + { + assert(i < argc); + argv[i] = strdup(p->c_str()); + } + assert(i == argc); + argv[0] = strdup(path.c_str()); + argv[argc] = 0; // // Start a router. @@ -284,6 +291,10 @@ Glacier::StarterI::startRouter(const string& userId, const string& password, Byt if(pid == 0) // Child process. { + // + // Until exec, we can only use async-signal safe functions + // + #ifdef __linux // // Create a process group for this child, to be able to send @@ -307,22 +318,6 @@ Glacier::StarterI::startRouter(const string& userId, const string& password, Byt } // - // Convert to standard argc/argv. - // - int argc = static_cast<int>(args.size()) + 1; - char** argv = static_cast<char**>(malloc((argc + 1) * sizeof(char*))); - StringSeq::iterator p; - int i; - for(p = args.begin(), i = 1; p != args.end(); ++p, ++i) - { - assert(i < argc); - argv[i] = strdup(p->c_str()); - } - assert(i == argc); - argv[0] = strdup(path.c_str()); - argv[argc] = 0; - - // // Try to start the router. // if(execvp(argv[0], argv) == -1) @@ -331,11 +326,20 @@ Glacier::StarterI::startRouter(const string& userId, const string& password, Byt // Send any errors to the parent process, using the write // end of the pipe. // - string msg = "can't execute `" + path + "': " + strerror(errno); - write(fds[1], msg.c_str(), msg.length()); + char msg[500]; + strcpy(msg, "can't execute `"); + strcat(msg, argv[0]); + strcat(msg, "': "); + strcat(msg, strerror(errno)); + + write(fds[1], msg, strlen(msg)); close(fds[1]); - //sleep(100000); //XXX - exit(EXIT_FAILURE); + + // + // _exit instead of exit to avoid interferences with + // the parent process + // + _exit(EXIT_FAILURE); } } else // Parent process. |