From: Angus Leeming Date: Sat, 16 Feb 2002 12:39:47 +0000 (+0000) Subject: We don't currently use fork anywhere (or if we do it's by mistake!), so X-Git-Tag: 1.6.10~19842 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=59e18b17aec378d71ca7d8ef3e566be40c35aaf1;p=features.git We don't currently use fork anywhere (or if we do it's by mistake!), so this patch strips down syscall.[Ch] so it now contains only the system call interface. This interface is very, very simple! At the same time I've taken the opportunity to remove syscontr.[Ch] and syssingleton.C, again because they aren't used. The rest of the changes are due to the change of name in the Systemcall::Starttype enum. System is now Wait, and SystemDontWait is DontWait Paves the way for resurrecting a proper forked calls controller. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3553 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index 3c00e6dccb..7554898725 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,20 @@ +2002-02-16 Angus Leeming + + * Chktex.C: + * buffer.C: + remove #include "support/syscall.h" as it's redundant. Always has been. + + * Chktex.C: + * LaTeX.C: + * LyXSendto.C: + * converter.C: + * lyx_cb.C: + * vc-backend.C: + change Systemcalls::System to Systemcalls::Wait and + change Systemcalls::SystemDontWait to Systemcalls::DontWait. + No change of functionality, just reflects the stripped down Systemcalls + class. + 2002-02-16 Angus Leeming * debug.[Ch]: add a GRAPHICS type to the enum. diff --git a/src/Chktex.C b/src/Chktex.C index 1193c7590a..74ee7ac09a 100644 --- a/src/Chktex.C +++ b/src/Chktex.C @@ -26,7 +26,6 @@ #include "support/FileInfo.h" #include "support/filetools.h" #include "support/syscall.h" -#include "support/syscontr.h" #include "support/path.h" #include "support/lstrings.h" @@ -51,7 +50,7 @@ int Chktex::run(TeXErrors &terr) string log = OnlyFilename(ChangeExtension(file, ".log")); string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log; Systemcalls one; - int result= one.startscript(Systemcalls::System, tmp); + int result= one.startscript(Systemcalls::Wait, tmp); if (result == 0) { result = scanLogFile(terr); } else { diff --git a/src/LaTeX.C b/src/LaTeX.C index 8c812a389f..1ceeda1b00 100644 --- a/src/LaTeX.C +++ b/src/LaTeX.C @@ -25,7 +25,6 @@ #include "debug.h" #include "support/lyxlib.h" #include "support/syscall.h" -#include "support/syscontr.h" #include "support/path.h" #include "support/LRegex.h" #include "support/LSubstring.h" @@ -360,7 +359,7 @@ int LaTeX::operator()() string tmp = cmd + ' ' + file + " > nul"; #endif Systemcalls one; - return one.startscript(Systemcalls::System, tmp); + return one.startscript(Systemcalls::Wait, tmp); } @@ -377,7 +376,7 @@ bool LaTeX::runMakeIndex(string const & f) string tmp = "makeindex -c -q "; tmp += f; Systemcalls one; - one.startscript(Systemcalls::System, tmp); + one.startscript(Systemcalls::Wait, tmp); return true; } @@ -508,7 +507,7 @@ bool LaTeX::runBibTeX(vector const & bibtex_info) string tmp = "bibtex "; tmp += OnlyFilename(ChangeExtension(it->aux_file, string())); Systemcalls one; - one.startscript(Systemcalls::System, tmp); + one.startscript(Systemcalls::Wait, tmp); } // Return whether bibtex was run return result; diff --git a/src/LyXSendto.C b/src/LyXSendto.C index d457dc7fa1..99022c6ae1 100644 --- a/src/LyXSendto.C +++ b/src/LyXSendto.C @@ -95,7 +95,7 @@ void SendtoApplyCB(FL_OBJECT *, long) // create the .txt file in tmp_dir if this filetype is requested if (fl_get_button(fd_form_sendto->radio_ftype_ascii)) buffer->writeFileAscii(fname, lyxrc.ascii_linelen); - Systemcalls one(Systemcalls::System, command); + Systemcalls one(Systemcalls::Wait, command); } diff --git a/src/buffer.C b/src/buffer.C index c6a41f503c..e888e3588e 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -89,7 +89,6 @@ #include "support/filetools.h" #include "support/path.h" #include "support/os.h" -#include "support/syscall.h" #include "support/lyxlib.h" #include "support/FileInfo.h" #include "support/lyxmanip.h" diff --git a/src/converter.C b/src/converter.C index d9f0f72cf7..17a5d90e19 100644 --- a/src/converter.C +++ b/src/converter.C @@ -196,7 +196,7 @@ bool Formats::view(Buffer const * buffer, string const & filename, Path p(OnlyPath(filename)); Systemcalls one; - int const res = one.startscript(Systemcalls::SystemDontWait, command); + int const res = one.startscript(Systemcalls::DontWait, command); if (res) { Alert::alert(_("Cannot view file"), @@ -645,7 +645,7 @@ bool Converters::convert(Buffer const * buffer, ShowMessage(buffer, _("Executing command:"), command); Systemcalls::Starttype type = (dummy) - ? Systemcalls::SystemDontWait : Systemcalls::System; + ? Systemcalls::DontWait : Systemcalls::Wait; Systemcalls one; int res; if (conv.original_dir && buffer) { @@ -659,7 +659,7 @@ bool Converters::convert(Buffer const * buffer, string const command2 = conv.parselog + " < " + QuoteName(infile2 + ".out") + " > " + QuoteName(logfile); - one.startscript(Systemcalls::System, command2); + one.startscript(Systemcalls::Wait, command2); if (!scanLog(buffer, command, logfile)) return false; } diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index faf995cad8..e01a81ed0c 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,11 @@ +2002-02-16 Angus Leeming + + * Liason.C: + change Systemcalls::System to Systemcalls::Wait and + change Systemcalls::SystemDontWait to Systemcalls::DontWait. + No change of functionality, just reflects the stripped down Systemcalls + class. + 2002-01-14 Jean-Marc Lasgouttes * Liason.C (printBuffer): use Buffer::filePath diff --git a/src/frontends/Liason.C b/src/frontends/Liason.C index f1fe2c8dcb..e038c8b3f3 100644 --- a/src/frontends/Liason.C +++ b/src/frontends/Liason.C @@ -134,13 +134,13 @@ bool printBuffer(Buffer * buffer, PrinterParams const & pp) command2 += QuoteName(psname); // First run dvips. // If successful, then spool command - res = one.startscript(Systemcalls::System, command); + res = one.startscript(Systemcalls::Wait, command); if (res == 0) - res = one.startscript(Systemcalls::SystemDontWait, + res = one.startscript(Systemcalls::DontWait, command2); } else // case 2 - res = one.startscript(Systemcalls::SystemDontWait, + res = one.startscript(Systemcalls::DontWait, command + QuoteName(dviname)); break; @@ -149,7 +149,7 @@ bool printBuffer(Buffer * buffer, PrinterParams const & pp) command += lyxrc.print_to_file + QuoteName(MakeAbsPath(pp.file_name, path)); command += ' ' + QuoteName(dviname); - res = one.startscript(Systemcalls::SystemDontWait, command); + res = one.startscript(Systemcalls::DontWait, command); break; } return res == 0; diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index bc13a121d2..f5cc9fcf9b 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,12 @@ +2002-02-16 Angus Leeming + + * ControlGraphics.C: remove #include "support/syscall.h" as it's not + used. + * ControlTexinfo.C: + change Systemcalls::System to Systemcalls::Wait and + No change of functionality, just reflects the stripped down Systemcalls + class. + 2002-02-06 Herbert Voss * ControlGraphics.[C] (readBB): search also in diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index 5b94c7b66b..5c0972bfb8 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -35,8 +35,7 @@ #include "support/FileInfo.h" // for FileInfo #include "helper_funcs.h" // for browseFile #include "support/lstrings.h" -#include "support/filetools.h" // for AddName -#include "support/syscall.h" // for zippedFile() +#include "support/filetools.h" // for AddName, zippedFile #include "BufferView.h" using std::pair; diff --git a/src/frontends/controllers/ControlTexinfo.C b/src/frontends/controllers/ControlTexinfo.C index 19a2291a34..9a266a985f 100644 --- a/src/frontends/controllers/ControlTexinfo.C +++ b/src/frontends/controllers/ControlTexinfo.C @@ -44,7 +44,7 @@ void ControlTexinfo::rescanStyles() const { // Run rescan in user lyx directory Path p(user_lyxdir); - Systemcalls one(Systemcalls::System, + Systemcalls one(Systemcalls::Wait, LibFileSearch("scripts", "TeXFiles.sh")); p.pop(); } @@ -56,7 +56,7 @@ void ControlTexinfo::runTexhash() const Path p(user_lyxdir); //path to texhash through system - Systemcalls one(Systemcalls::System,"texhash"); + Systemcalls one(Systemcalls::Wait, "texhash"); p.pop(); // Alert::alert(_("texhash run!"), // _("rebuilding of the TeX-tree could only be successfull"), diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 4dba209bcb..2bbe4a3347 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -537,7 +537,7 @@ void Reconfigure(BufferView * bv) // Run configure in user lyx directory Path p(user_lyxdir); - Systemcalls one(Systemcalls::System, + Systemcalls one(Systemcalls::Wait, AddName(system_lyxdir, "configure")); p.pop(); bv->owner()->message(_("Reloading configuration...")); diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 71840dee64..75f3791ee5 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,8 @@ +2002-02-16 Angus Leeming + + * formula.C: change Systemcalls::System to Systemcalls::Wait and + No change of functionality, just reflects the stripped down Systemcalls + class. 2002-02-08 André Pönitz diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 1fb6fdb7a0..19b36006ff 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -60,7 +60,7 @@ namespace { string outfile = lyx::tempName(string(), "mathextern"); string full = "echo '" + data + "' | (" + cmd + ") > " + outfile; lyxerr << "calling: " << full << "\n"; - Systemcalls dummy(Systemcalls::System, full, 0); + Systemcalls dummy(Systemcalls::Wait, full); string out = GetFileContents(outfile); lyx::unlink(outfile); lyxerr << "result: '" << out << "'\n"; diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 3e5c6baded..d431f31fa7 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,12 @@ +2002-02-16 Angus Leeming + + * syscontr.[Ch]: + * syssingleton.C: files removed. + + * syscall.[Ch]: remove the forked calls interface, as nothing, nowhere + uses it. Strip down the Systemcalls interface to make it brutally + obvious how unsophisticated it is. + 2002-02-08 Herbert Voss * filetools.C: (getExtFromContents) adding TGIF-format diff --git a/src/support/Makefile.am b/src/support/Makefile.am index 8338d04995..319d68fd9e 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -65,9 +65,6 @@ libsupport_la_SOURCES = \ sstream.h \ $(REGEX) syscall.C \ syscall.h \ - syscontr.C \ - syscontr.h \ - syssingleton.C \ tempname.C \ textutils.h \ translator.h \ diff --git a/src/support/filetools.C b/src/support/filetools.C index a31cb981c0..c8b405d6bb 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -1056,7 +1056,7 @@ string const unzipFile(string const & zipped_file) string const tempfile = lyx::tempName(string(), file); // Run gunzip string const command = "gunzip -c "+zipped_file+" > "+tempfile; - Systemcalls one(Systemcalls::System, command); + Systemcalls one(Systemcalls::Wait, command); // test that command was executed successfully return tempfile; } diff --git a/src/support/syscall.C b/src/support/syscall.C index 597dd362de..9a9e1ecc54 100644 --- a/src/support/syscall.C +++ b/src/support/syscall.C @@ -1,214 +1,42 @@ +/** + * \file syscall.C + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author Asger Alstrup + * + * Interface cleaned up by + * \author Angus Leeming + * + * Class Systemcalls uses "system" to launch the child process. + * The user can choose to wait or not wait for the process to complete, but no + * callback is invoked upon completion of the child. + * + * The child process is not killed when the Systemcall instance goes out of + * scope. + */ + #include #ifdef __GNUG__ #pragma implementation #endif -#include -#include -#include -#include -#include -#include -#include "debug.h" #include "syscall.h" -#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 -} - -Systemcalls::Systemcalls(Starttype how, string const & what, Callbackfct cback) -{ - startscript(how, what, cback); -} - -Systemcalls::~Systemcalls() { -#if 0 - // If the child is alive, we have to brutally kill it - if (getpid() != 0) { - lyx::kill(getpid(), SIGKILL); - } -#endif -} - -// Start a childprocess -// -// if child runs in background, add information to global controller. - -int Systemcalls::startscript() { - retval = 0; - switch (start) { - case System: - case SystemDontWait: - retval = ::system(command.c_str()); - callback(); - break; - case Wait: - pid = fork(); - if (pid>0) { // Fork succesful. Wait for child - waitForChild(); - callback(); - } else - retval = 1; - break; - case DontWait: - pid = fork(); - if (pid>0) { - // Now integrate into Controller - SystemcallsSingletoncontroller::Startcontroller starter; - SystemcallsSingletoncontroller * contr = starter.getController(); - // Add this to controller - contr->addCall(*this); - } else - retval = 1; - break; - } - return retval; -} - -void Systemcalls::kill(int /*tolerance*/) { - if (getpid() == 0) { - lyxerr << "LyX: Can't kill non-existing process." << endl; - return; - } - int ret = lyx::kill(getpid(), SIGHUP); - bool wait_for_death = true; - if (ret != 0) { - if (errno == ESRCH) { - // The process is already dead! - wait_for_death = false; - } else { - // Something is rotten - maybe we lost permissions? - } - } - if (wait_for_death) { - // Here, we should add the PID to a list of - // waiting processes to kill if they are not - // dead within tolerance seconds - - // CHECK Implement this using the timer of - // the singleton systemcontroller (Asger) - - } -} - - -// Wait for child process to finish. Returns returncode from child. -void Systemcalls::waitForChild() { - // We'll pretend that the child returns 1 on all errorconditions. - retval = 1; - int status; - bool wait = true; - while (wait) { - pid_t waitrpid = waitpid(pid, &status, WUNTRACED); - if (waitrpid == -1) { - lyxerr << "LyX: Error waiting for child:" - << strerror(errno) << endl; - wait = false; - } else if (WIFEXITED(status)) { - // Child exited normally. Update return value. - retval = WEXITSTATUS(status); - wait = false; - } else if (WIFSIGNALED(status)) { - lyxerr << "LyX: Child didn't catch signal " - << WTERMSIG(status) - << "and died. Too bad." << endl; - wait = false; - } else if (WIFSTOPPED(status)) { - lyxerr << "LyX: Child (pid: " << pid - << ") stopped on signal " - << WSTOPSIG(status) - << ". Waiting for child to finish." << endl; - } else { - lyxerr << "LyX: Something rotten happened while " - "waiting for child " << pid << endl; - wait = false; - } - } -} +#include "os.h" - -// generate child in background - -pid_t Systemcalls::fork() +Systemcalls::Systemcalls(Starttype how, string const & what) { - #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 - string rest = split(command, childcommand, ' '); - const int MAX_ARGV = 255; - char *syscmd = 0; - char *argv[MAX_ARGV]; - int index = 0; - bool more = true; - while (more) { - childcommand = frontStrip(childcommand); - if (syscmd == 0) { - syscmd = new char[childcommand.length() + 1]; - childcommand.copy(syscmd, childcommand.length()); - syscmd[childcommand.length()] = '\0'; - } - if (!childcommand.empty()) { - char * tmp = new char[childcommand.length() + 1]; - childcommand.copy(tmp, childcommand.length()); - tmp[childcommand.length()] = '\0'; - argv[index++] = tmp; - } - - // reinit - more = !rest.empty(); - if (more) - rest = split(rest, childcommand, ' '); - } - 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(" << syscmd << ") failed: " - << strerror(errno) << endl; - } else if (cpid < 0) { // error -#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; - } - return 0; + startscript(how, what); } // Reuse of instance - -int Systemcalls::startscript(Starttype how, string const & what, - Callbackfct cback) +int Systemcalls::startscript(Starttype how, string const & what) { - start = how; - command = what; - cbk = cback; - pid = static_cast(0); // yet no child - retval = 0; + string command = what; - if (how == SystemDontWait) { + if (how == DontWait) { if (os::shell() == os::UNIX) { command += " &"; } else { @@ -216,41 +44,5 @@ int Systemcalls::startscript(Starttype how, string const & what, } } - return startscript(); + return ::system(command.c_str()); } - - - -// -// Mini-Test-environment for script-classes -// -#ifdef TEST_MAIN -#include - - -int SimulateTimer; -void back(string cmd, int retval) -{ - ::printf("Done: %s gave %d\n", cmd.c_str(), retval); - SimulateTimer = 0; -} - - -int main(int, char **) -{ - - SystemcallsSingletoncontroller::Startcontroller starter; - SystemcallsSingletoncontroller *contr= starter.GetController(); - - Systemcalls one(Systemcalls::System, "ls -ltag", back); - Systemcalls two(Systemcalls::Wait, "ls -ltag", back); - SimulateTimer = 1; - Systemcalls three(Systemcalls::DontWait , "ls -ltag", back); - // Simulation of timer - while (SimulateTimer) - { - sleep(1); - contr->Timer(); - } -} -#endif diff --git a/src/support/syscall.h b/src/support/syscall.h index dd014ae112..598fbc13dc 100644 --- a/src/support/syscall.h +++ b/src/support/syscall.h @@ -1,5 +1,24 @@ // -*- C++ -*- -#include +/** + * \file syscall.h + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author Asger Alstrup + * + * Interface cleaned up by + * \author Angus Leeming + * + * Class Systemcalls uses "system" to launch the child process. + * The user can choose to wait or not wait for the process to complete, but no + * callback is invoked upon completion of the child. + * + * The child process is not killed when the Systemcall instance goes out of + * scope. + */ + +#ifndef SYSCALL_H +#define SYSCALL_H #include "LString.h" @@ -7,108 +26,29 @@ #pragma interface #endif -/** - This class can be used to start child processes. - - An instance of the class represents a child process. - You should use this class if you need to start an external program in LyX. - If you wish, you can have a callback function executed when the process - finishes. - You can chose between three kinds of child processes: - 1) System processes, which are initiated with the "system" call, - where the main thread waits for the system call to return. - 2) Wait for child process, which are forked, but the main thread waits for - the child to end. - 3) Don't wait, which are forked, but the main thread is not stopped. - The process can be considered a background process. - A timer will make sure that any callback function is called when - the child process ends. - - Notice that any callback associated with a process is called whatever - the kind of child process. - */ class Systemcalls { public: /// enum Starttype { - /// Uses system() which uses /bin/sh - System, - /// Uses system() which uses /bin/sh - SystemDontWait, - /// Uses fork() and execvp() + /// Wait, - /// Uses fork() and execvp() + /// DontWait }; - /// Callback function gets commandline and return value from child - typedef void (*Callbackfct)(string cmd, int retval); - /// - Systemcalls(); + Systemcalls() {} /** Generate instance and start child process. - The string "what" contains a commandline with arguments separated - by spaces. - When the requested program finishes, the callback-function is - called with the commandline and the return value from the program. - The instance is automatically added to a timer check if starttype - is DontWait (i.e. background execution). When a background child - finishes, the timer check will automatically call the callback - function. - */ - Systemcalls(Starttype how, string const & what, Callbackfct call = 0); - - /// - ~Systemcalls(); - - /** Start childprocess. "what" contains a command at system level. - This is for reuse of the Systemcalls instance. - */ - int startscript(Starttype how, string const & what, - Callbackfct call = 0); - - /** gets PID of childprocess. - Used by timer - */ - pid_t getpid() { return pid; } - - /// Start callback - void callback() { if (cbk) cbk(command, retval); } - - /** Set return value. Used by timer */ - void setRetValue(int r) { retval = r; } - - /** Kill child prematurely. - First, a SIGHUP is sent to the child. - If that does not end the child process within "tolerance" - seconds, the SIGKILL signal is sent to the child. - When the child is dead, the callback is called. - */ - void kill(int tolerance = 5); - -private: - /// Type of execution: system, wait for child or background - Starttype start; - - /// Callback function - Callbackfct cbk; - - /// Commmand line - string command; - - /// Process ID of child - pid_t pid; - - /// Return value from child - int retval; - - /// - int startscript(); - - /// - pid_t fork(); - - /// Wait for child process to finish. Updates returncode from child. - void waitForChild(); + * The string "what" contains a commandline with arguments separated + * by spaces. + */ + Systemcalls(Starttype how, string const & what); + + /** Start child process. + * This is for reuse of the Systemcalls instance. + */ + int startscript(Starttype how, string const & what); }; + +#endif // SYSCALL_H diff --git a/src/support/syscontr.C b/src/support/syscontr.C deleted file mode 100644 index e15294fcdc..0000000000 --- a/src/support/syscontr.C +++ /dev/null @@ -1,112 +0,0 @@ -#include - -#include -#include -#include -#include -#include "syscontr.h" -#include "syscall.h" -#include "debug.h" - -#ifdef __GNUG__ -#pragma implementation -#endif - - -using std::endl; - -#ifndef CXX_GLOBAL_CSTD -using std::strerror; -#endif - -// -// Default constructor -// - -SystemcallsSingletoncontroller::SystemcallsSingletoncontroller() -{ - sysCalls = 0; -} - -// -// Destructor -// -// destroy structs for leaving program -// open question: should we stop childs here? -// Asger says no: I like to have my xdvi open after closing LyX. Maybe -// I want to print or something. - -SystemcallsSingletoncontroller::~SystemcallsSingletoncontroller() -{ - ControlledCalls *next; - while (sysCalls) - { - next = sysCalls->next; - delete sysCalls; - sysCalls = next; - } - -} - -// -// Add child process information into controlled list -// - -void -SystemcallsSingletoncontroller::addCall(Systemcalls const &newcall) { - ControlledCalls * newCall = new ControlledCalls; - if (newCall == 0) // sorry, no idea - return; - newCall->next = sysCalls; - newCall->call = new Systemcalls(newcall); - sysCalls = newCall; -} - -// -// Timer-call -// -// Check list, if there is a stopped child. If yes, call-back. -// - -void -SystemcallsSingletoncontroller::timer() { - lyxerr << "Tick" << endl; - // check each entry of our list, if it's finished - ControlledCalls *prev = 0; - for (ControlledCalls *actCall= sysCalls; actCall; actCall= actCall->next) - { - pid_t pid= actCall->call->getpid(); - int stat_loc; - int waitrpid = waitpid(pid, &stat_loc, WNOHANG); - if (waitrpid == -1) { - lyxerr << "LyX: Error waiting for child:" - << strerror(errno) << endl; - } else if (WIFEXITED(stat_loc) || WIFSIGNALED(stat_loc)) { - if (WIFEXITED(stat_loc)) { - // Ok, the return value goes into retval. - actCall->call->setRetValue(WEXITSTATUS(stat_loc)); - } else { - // Child died, so pretend it returned 1 - actCall->call->setRetValue(1); - } - // Callback and release - actCall->call->callback(); - if (actCall == sysCalls) { - sysCalls = actCall->next; - } else { - prev->next = actCall->next; - } - delete actCall; - actCall = prev; - } else if (WIFSTOPPED(stat_loc)) { - lyxerr << "LyX: Child (pid: " << pid - << ") stopped on signal " - << WSTOPSIG(stat_loc) - << ". Waiting for child to finish." << endl; - } else { - lyxerr << "LyX: Something rotten happened while " - "waiting for child " << pid << endl; - } - prev = actCall; - } -} diff --git a/src/support/syscontr.h b/src/support/syscontr.h deleted file mode 100644 index 4066d84b0f..0000000000 --- a/src/support/syscontr.h +++ /dev/null @@ -1,50 +0,0 @@ -// -*- C++ -*- - -#ifdef __GNUG__ -#pragma interface -#endif - -#include "LString.h" - - -class Systemcalls; - -/// -class SystemcallsSingletoncontroller { -public: - /// - class Startcontroller { - public: - /// - Startcontroller(); - /// - ~Startcontroller(); - /// - static SystemcallsSingletoncontroller * getController(); - /// - void reduceRefcount() { --refcount; } - private: - /// - static SystemcallsSingletoncontroller * contr; - /// - static int refcount; - }; - /// - ~SystemcallsSingletoncontroller(); - /// - void addCall(Systemcalls const & newcall); - /// - void timer(); - /// private: // DEC cxx does not like that (JMarc) - SystemcallsSingletoncontroller(); -private: - /// - struct ControlledCalls { - /// - Systemcalls * call; - /// - ControlledCalls * next; - }; - /// - ControlledCalls * sysCalls; -}; diff --git a/src/support/syssingleton.C b/src/support/syssingleton.C deleted file mode 100644 index 3b713877e2..0000000000 --- a/src/support/syssingleton.C +++ /dev/null @@ -1,38 +0,0 @@ -#include - -#include "syscontr.h" - - -//---------------------------------------------------------------------- -// Ensure, that only one controller exist inside process -//---------------------------------------------------------------------- - -// global controller variable -SystemcallsSingletoncontroller * -SystemcallsSingletoncontroller::Startcontroller:: -contr = 0; - -// reference count -int SystemcallsSingletoncontroller::Startcontroller:: -refcount = 0; - -SystemcallsSingletoncontroller::Startcontroller:: -Startcontroller() { -} - -SystemcallsSingletoncontroller::Startcontroller:: -~Startcontroller() { -} - -// Give reference to global controller-instance -// -SystemcallsSingletoncontroller * -SystemcallsSingletoncontroller::Startcontroller::getController() -{ - if (!contr) { - // Create the global controller - contr = new SystemcallsSingletoncontroller; - } - ++refcount; - return contr; -} diff --git a/src/vc-backend.C b/src/vc-backend.C index c2d022344e..78405f16a8 100644 --- a/src/vc-backend.C +++ b/src/vc-backend.C @@ -17,6 +17,7 @@ #include "support/path.h" #include "support/filetools.h" #include "support/lstrings.h" +#include "support/syscall.h" #include @@ -29,7 +30,7 @@ int VCS::doVCCommand(string const & cmd, string const & path) lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl; Systemcalls one; Path p(path); - int const ret = one.startscript(Systemcalls::System, cmd); + int const ret = one.startscript(Systemcalls::Wait, cmd); return ret; }