stub.cpp00001
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 <qglobal.h>
00020 #include <qcstring.h>
00021 #include <kdatastream.h>
00022
00023 #include <kapplication.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 QCString StubProcess::commaSeparatedList(QCStringList lst)
00060 {
00061 if (lst.count() == 0)
00062 return QCString("");
00063
00064 QCStringList::Iterator it = lst.begin();
00065 QCString 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 QCString line, tmp;
00083 while (1)
00084 {
00085 line = readLine();
00086 if (line.isNull())
00087 return -1;
00088
00089 if (line == "kdesu_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 QCString 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 = "/sbin:/bin:/usr/sbin:/usr/bin:" + path;
00127 else
00128 path = "/sbin:/bin:/usr/sbin:/usr/bin";
00129 writeLine(path);
00130 } else if (line == "user") {
00131 writeLine(m_User);
00132 } else if (line == "priority") {
00133 tmp.setNum(m_Priority);
00134 writeLine(tmp);
00135 } else if (line == "scheduler") {
00136 if (m_Scheduler == SchedRealtime) writeLine("realtime");
00137 else writeLine("normal");
00138 } else if (line == "xwindows_only") {
00139 if (m_bXOnly) writeLine("no");
00140 else writeLine("yes");
00141 } else if (line == "app_startup_id") {
00142 QCStringList env = environment();
00143 QCString tmp;
00144 for( QCStringList::ConstIterator it = env.begin();
00145 it != env.end();
00146 ++it )
00147 {
00148 if( (*it).find( "DESKTOP_STARTUP_ID=" ) == 0 )
00149 tmp = (*it).mid( strlen( "DESKTOP_STARTUP_ID=" ));
00150 }
00151 if( tmp.isEmpty())
00152 tmp = "0";
00153 writeLine(tmp);
00154 } else if (line == "app_start_pid") {
00155 tmp.setNum(getpid());
00156 writeLine(tmp);
00157 } else if (line == "environment") {
00158 QCStringList env = environment();
00159 for( QCStringList::ConstIterator it = env.begin();
00160 it != env.end();
00161 ++it )
00162 writeLine( *it );
00163 writeLine( "" );
00164 } else if (line == "end") {
00165 return 0;
00166 } else
00167 {
00168 kdWarning(900) << k_lineinfo << "Unknown request: -->" << line
00169 << "<--\n";
00170 return 1;
00171 }
00172 }
00173
00174 return 0;
00175 }
00176
00177
00178 void StubProcess::notifyTaskbar(const QString &)
00179 {
00180 kdWarning(900) << "Obsolete StubProcess::notifyTaskbar() called!" << endl;
00181 }
00182
00183 void StubProcess::virtual_hook( int id, void* data )
00184 { PtyProcess::virtual_hook( id, data ); }
|