]> git.lyx.org Git - lyx.git/blobdiff - src/support/syscall.C
lyxserver cleanup patch + andre's small patches
[lyx.git] / src / support / syscall.C
index 46591cc82a7a5dcc52d6a0696e4f571c232b1a92..60afc4293545cf498a58119a2240b5497e49452d 100644 (file)
 #include "syscontr.h"
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
+#include "support/filetools.h"
+#include "support/os.h"
 
 using std::endl;
 
+#ifndef CXX_GLOBAL_CSTD
+using std::strerror;
+#endif
+
 
 Systemcalls::Systemcalls() {
        pid = 0; // No child yet
@@ -108,7 +114,8 @@ void Systemcalls::waitForChild() {
        while (wait) {
                pid_t waitrpid = waitpid(pid, &status, WUNTRACED);
                if (waitrpid == -1) {
-                       lyxerr << "LyX: Error waiting for child:" << strerror(errno) << endl;
+                       lyxerr << "LyX: Error waiting for child:"
+                              << strerror(errno) << endl;
                        wait = false;
                } else if (WIFEXITED(status)) {
                        // Child exited normally. Update return value.
@@ -137,8 +144,10 @@ void Systemcalls::waitForChild() {
 
 pid_t Systemcalls::fork()
 {
+       #ifndef __EMX__
        pid_t cpid= ::fork();
        if (cpid == 0) { // child
+       #endif
                // TODO: Consider doing all of this before the fork, otherwise me
                // might have troubles with multi-threaded access. (Baruch 20010228)
                string childcommand(command); // copy
@@ -169,11 +178,18 @@ pid_t Systemcalls::fork()
                }
                argv[index] = 0;
                // replace by command. Expand using PATH-environment-var.
+#ifndef __EMX__
                execvp(syscmd, argv);
                // If something goes wrong, we end up here:
-               lyxerr << "LyX: execvp failed: " << strerror(errno) << endl;
+               lyxerr << "LyX: execvp failed: "
+                      << strerror(errno) << endl;
        } else if (cpid < 0) { // error
-               lyxerr << "LyX: Could not fork: " << strerror(errno) << endl;
+#else
+       pid_t cpid = spawnvp(P_SESSION|P_DEFAULT|P_MINIMIZE|P_BACKGROUND, syscmd, argv);
+       if (cpid < 0) { // error
+#endif
+               lyxerr << "LyX: Could not fork: "
+                      << strerror(errno) << endl;
        } else { // parent
                return cpid;
        }
@@ -193,25 +209,11 @@ int Systemcalls::startscript(Starttype how, string const & what,
        retval  = 0;
 
        if (how == SystemDontWait) {
-#ifndef __EMX__
-               command += " &";
-#else
-               // OS/2 cmd.exe has another use for '&'
-               // This is not NLS safe, but it's OK, I think.
-               string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
-               if (sh.empty()) {
-                       // COMSPEC is set, unless user unsets 
-                       sh = OnlyFilename(GetEnvPath("COMSPEC"));
-                       if (sh.empty())
-                               sh = "cmd.exe";
-               }
-               sh = lowercase(sh);
-               if (contains(sh, "cmd.exe")
-                   || contains(sh, "4os2.exe"))
-                       command = "start /min/n " + command;
-               else
+               if (os::shell() == os::UNIX) {
                        command += " &";
-#endif
+               } else {
+                       command = "start /min/n " + command;
+               }
        }
 
         return startscript();