00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <config.h>
00016 #include <stdlib.h>
00017 #include <unistd.h>
00018
00019 #include <tqglobal.h>
00020 #include <tqcstring.h>
00021 #include <kdatastream.h>
00022
00023 #include <tdeapplication.h>
00024 #include <kdebug.h>
00025 #include <dcopclient.h>
00026
00027 #include "stub.h"
00028 #include "kcookie.h"
00029
00030
00031 StubProcess::StubProcess()
00032 {
00033 m_User = "root";
00034 m_Scheduler = SchedNormal;
00035 m_Priority = 50;
00036 m_pCookie = new KCookie;
00037 m_bXOnly = true;
00038 m_bDCOPForwarding = false;
00039 }
00040
00041
00042 StubProcess::~StubProcess()
00043 {
00044 delete m_pCookie;
00045 }
00046
00047
00048 void StubProcess::setPriority(int prio)
00049 {
00050 if (prio > 100)
00051 m_Priority = 100;
00052 else if (prio < 0)
00053 m_Priority = 0;
00054 else
00055 m_Priority = prio;
00056 }
00057
00058
00059 TQCString StubProcess::commaSeparatedList(QCStringList lst)
00060 {
00061 if (lst.count() == 0)
00062 return TQCString("");
00063
00064 QCStringList::Iterator it = lst.begin();
00065 TQCString str = *it;
00066 for (it++; it!=lst.end(); it++)
00067 {
00068 str += ',';
00069 str += *it;
00070 }
00071 return str;
00072 }
00073
00074
00075
00076
00077
00078
00079
00080 int StubProcess::ConverseStub(int check)
00081 {
00082 TQCString line, tmp;
00083 while (1)
00084 {
00085 line = readLine();
00086 if (line.isNull())
00087 return -1;
00088
00089 if (line == "tdesu_stub")
00090 {
00091
00092 enableLocalEcho(false);
00093 if (check) writeLine("stop");
00094 else writeLine("ok");
00095 } else if (line == "display") {
00096 writeLine(display());
00097 } else if (line == "display_auth") {
00098 #ifdef Q_WS_X11
00099 writeLine(displayAuth());
00100 #else
00101 writeLine("");
00102 #endif
00103 } else if (line == "dcopserver") {
00104 if (m_bDCOPForwarding)
00105 writeLine(dcopServer());
00106 else
00107 writeLine("no");
00108 } else if (line == "dcop_auth") {
00109 if (m_bDCOPForwarding)
00110 writeLine(dcopAuth());
00111 else
00112 writeLine("no");
00113 } else if (line == "ice_auth") {
00114 if (m_bDCOPForwarding)
00115 writeLine(iceAuth());
00116 else
00117 writeLine("no");
00118 } else if (line == "command") {
00119 writeLine(m_Command);
00120 } else if (line == "path") {
00121 TQCString path = getenv("PATH");
00122 if (!path.isEmpty() && path[0] == ':')
00123 path = path.mid(1);
00124 if (m_User == "root")
00125 if (!path.isEmpty())
00126 path = "/usr/local/sbin:/usr/sbin:/sbin:" + path;
00127 else
00128 if (strcmp(__TDE_BINDIR, "/usr/bin") == 0) {
00129 path = "/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin";
00130 }
00131 else {
00132 path = "/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:" __TDE_BINDIR ":/usr/bin:/bin";
00133 }
00134 writeLine(path);
00135 } else if (line == "user") {
00136 writeLine(m_User);
00137 } else if (line == "priority") {
00138 tmp.setNum(m_Priority);
00139 writeLine(tmp);
00140 } else if (line == "scheduler") {
00141 if (m_Scheduler == SchedRealtime) writeLine("realtime");
00142 else writeLine("normal");
00143 } else if (line == "xwindows_only") {
00144 if (m_bXOnly) writeLine("no");
00145 else writeLine("yes");
00146 } else if (line == "app_startup_id") {
00147 QCStringList env = environment();
00148 TQCString tmp;
00149 for( QCStringList::ConstIterator it = env.begin();
00150 it != env.end();
00151 ++it )
00152 {
00153 if( (*it).find( "DESKTOP_STARTUP_ID=" ) == 0 )
00154 tmp = (*it).mid( strlen( "DESKTOP_STARTUP_ID=" ));
00155 }
00156 if( tmp.isEmpty())
00157 tmp = "0";
00158 writeLine(tmp);
00159 } else if (line == "app_start_pid") {
00160 tmp.setNum(getpid());
00161 writeLine(tmp);
00162 } else if (line == "environment") {
00163 QCStringList env = environment();
00164 for( QCStringList::ConstIterator it = env.begin();
00165 it != env.end();
00166 ++it )
00167 writeLine( *it );
00168 writeLine( "" );
00169 } else if (line == "end") {
00170 return 0;
00171 } else
00172 {
00173 kdWarning(900) << k_lineinfo << "Unknown request: -->" << line
00174 << "<--\n";
00175 return 1;
00176 }
00177 }
00178
00179 return 0;
00180 }
00181
00182
00183 void StubProcess::notifyTaskbar(const TQString &)
00184 {
00185 kdWarning(900) << "Obsolete StubProcess::notifyTaskbar() called!" << endl;
00186 }
00187
00188 void StubProcess::virtual_hook( int id, void* data )
00189 { PtyProcess::virtual_hook( id, data ); }