3 * This file is part of the KDE project, module kdesu.
4 * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
6 * This is free software; you can use this library under the GNU Library
7 * General Public License, version 2. See the file "COPYING.LIB" for the
8 * exact licensing terms.
10 * stub.cpp: Conversation with kdesu_stub.
19 #include <kapplication.h>
26 StubProcess::StubProcess()
29 m_Scheduler
= SchedNormal
;
31 m_pCookie
= new KCookie
;
36 StubProcess::~StubProcess()
42 void StubProcess::setPriority(int prio
)
53 QByteArray
StubProcess::commaSeparatedList(const QList
<QByteArray
> &lst
)
56 for (int i
= 0; i
< lst
.count(); ++i
) {
64 * Conversation with kdesu_stub. This is how we pass the authentication
65 * tokens (X11) and other stuff to kdesu_stub.
66 * return values: -1 = error, 0 = ok, 1 = kill me
69 int StubProcess::ConverseStub(int check
)
78 if (line
== "kdesu_stub")
80 // This makes parsing a lot easier.
81 enableLocalEcho(false);
82 if (check
) writeLine("stop");
84 } else if (line
== "display") {
86 } else if (line
== "display_auth") {
88 writeLine(displayAuth());
92 } else if (line
== "command") {
94 } else if (line
== "path") {
95 QByteArray path
= getenv("PATH");
96 if (!path
.isEmpty() && path
[0] == ':')
100 path
= "/sbin:/bin:/usr/sbin:/usr/bin:" + path
;
102 path
= "/sbin:/bin:/usr/sbin:/usr/bin";
104 } else if (line
== "user") {
106 } else if (line
== "priority") {
107 tmp
.setNum(m_Priority
);
109 } else if (line
== "scheduler") {
110 if (m_Scheduler
== SchedRealtime
) writeLine("realtime");
111 else writeLine("normal");
112 } else if (line
== "xwindows_only") {
113 if (m_bXOnly
) writeLine("no");
114 else writeLine("yes");
115 } else if (line
== "app_startup_id") {
116 QList
<QByteArray
> env
= environment();
118 for(int i
= 0; i
< env
.count(); ++i
)
120 const char startup_env
[] = "DESKTOP_STARTUP_ID=";
121 if (env
.at(i
).startsWith(startup_env
))
122 tmp
= env
.at(i
).mid(sizeof(startup_env
) - 1);
127 } else if (line
== "app_start_pid") { // obsolete
128 tmp
.setNum(getpid());
130 } else if (line
== "environment") { // additional env vars
131 QList
<QByteArray
> env
= environment();
132 for (int i
= 0; i
< env
.count(); ++i
)
133 writeLine(env
.at(i
));
135 } else if (line
== "end") {
139 kWarning(900) << k_lineinfo
<< "Unknown request: -->" << line
149 void StubProcess::virtual_hook( int id
, void* data
)
150 { PtyProcess::virtual_hook( id
, data
); }