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 (m_User == "root")
00123 if (!path.isEmpty())
00124 path = "/sbin:/usr/sbin:" + path;
00125 else
00126 path = "/sbin:/usr/sbin";
00127 writeLine(path);
00128 } else if (line == "user") {
00129 writeLine(m_User);
00130 } else if (line == "priority") {
00131 tmp.setNum(m_Priority);
00132 writeLine(tmp);
00133 } else if (line == "scheduler") {
00134 if (m_Scheduler == SchedRealtime) writeLine("realtime");
00135 else writeLine("normal");
00136 } else if (line == "xwindows_only") {
00137 if (m_bXOnly) writeLine("no");
00138 else writeLine("yes");
00139 } else if (line == "app_startup_id") {
00140 QCStringList env = environment();
00141 QCString tmp;
00142 for( QCStringList::ConstIterator it = env.begin();
00143 it != env.end();
00144 ++it )
00145 {
00146 if( (*it).find( "DESKTOP_STARTUP_ID=" ) == 0 )
00147 tmp = (*it).mid( strlen( "DESKTOP_STARTUP_ID=" ));
00148 }
00149 if( tmp.isEmpty())
00150 tmp = "0";
00151 writeLine(tmp);
00152 } else if (line == "app_start_pid") {
00153 tmp.setNum(getpid());
00154 writeLine(tmp);
00155 } else if (line == "environment") {
00156 QCStringList env = environment();
00157 for( QCStringList::ConstIterator it = env.begin();
00158 it != env.end();
00159 ++it )
00160 writeLine( *it );
00161 writeLine( "" );
00162 } else if (line == "end") {
00163 return 0;
00164 } else
00165 {
00166 kdWarning(900) << k_lineinfo << "Unknown request: -->" << line
00167 << "<--\n";
00168 return 1;
00169 }
00170 }
00171
00172 return 0;
00173 }
00174
00175
00176 void StubProcess::notifyTaskbar(const QString &)
00177 {
00178 kdWarning(900) << "Obsolete StubProcess::notifyTaskbar() called!" << endl;
00179 }
00180
00181 void StubProcess::virtual_hook( int id, void* data )
00182 { PtyProcess::virtual_hook( id, data ); }
|