• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdesu
 

tdesu

  • tdesu
stub.cpp
1/*
2 *
3 * $Id$
4 *
5 * This file is part of the KDE project, module tdesu.
6 * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
7 *
8 * This is free software; you can use this library under the GNU Library
9 * General Public License, version 2. See the file "COPYING.LIB" for the
10 * exact licensing terms.
11 *
12 * stub.cpp: Conversation with tdesu_stub.
13 */
14
15#include <config.h>
16#include <stdlib.h>
17#include <unistd.h>
18
19#include <tqglobal.h>
20#include <tqcstring.h>
21#include <kdatastream.h>
22
23#include <tdeapplication.h>
24#include <kdebug.h>
25#include <dcopclient.h>
26
27#include "stub.h"
28#include "kcookie.h"
29
30
31StubProcess::StubProcess()
32{
33 m_User = "root";
34 m_Scheduler = SchedNormal;
35 m_Priority = 50;
36 m_pCookie = new KCookie;
37 m_bXOnly = true;
38 m_bDCOPForwarding = false;
39}
40
41
42StubProcess::~StubProcess()
43{
44 delete m_pCookie;
45}
46
47
48void StubProcess::setPriority(int prio)
49{
50 if (prio > 100)
51 m_Priority = 100;
52 else if (prio < 0)
53 m_Priority = 0;
54 else
55 m_Priority = prio;
56}
57
58
59TQCString StubProcess::commaSeparatedList(QCStringList lst)
60{
61 if (lst.count() == 0)
62 return TQCString("");
63
64 QCStringList::Iterator it = lst.begin();
65 TQCString str = *it;
66 for (it++; it!=lst.end(); it++)
67 {
68 str += ',';
69 str += *it;
70 }
71 return str;
72}
73
74/*
75 * Conversation with tdesu_stub. This is how we pass the authentication
76 * tokens (X11, DCOP) and other stuff to tdesu_stub.
77 * return values: -1 = error, 0 = ok, 1 = kill me
78 */
79
80int StubProcess::ConverseStub(int check)
81{
82 TQCString line, tmp;
83 while (1)
84 {
85 line = readLine();
86 if (line.isNull())
87 return -1;
88
89 if (line == "tdesu_stub")
90 {
91 // This makes parsing a lot easier.
92 enableLocalEcho(false);
93 if (check) writeLine("stop");
94 else writeLine("ok");
95 } else if (line == "display") {
96 writeLine(display());
97 } else if (line == "display_auth") {
98#ifdef TQ_WS_X11
99 writeLine(displayAuth());
100#else
101 writeLine("");
102#endif
103 } else if (line == "dcopserver") {
104 if (m_bDCOPForwarding)
105 writeLine(dcopServer());
106 else
107 writeLine("no");
108 } else if (line == "dcop_auth") {
109 if (m_bDCOPForwarding)
110 writeLine(dcopAuth());
111 else
112 writeLine("no");
113 } else if (line == "ice_auth") {
114 if (m_bDCOPForwarding)
115 writeLine(iceAuth());
116 else
117 writeLine("no");
118 } else if (line == "command") {
119 writeLine(m_Command);
120 } else if (line == "path") {
121 TQCString path = getenv("PATH");
122 if (!path.isEmpty() && path[0] == ':')
123 path = path.mid(1);
124 if (m_User == "root")
125 if (!path.isEmpty())
126 path = "/usr/local/sbin:/usr/sbin:/sbin:" + path;
127 else
128 if (strcmp(__TDE_BINDIR, "/usr/bin") == 0) {
129 path = "/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin";
130 }
131 else {
132 path = "/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:" __TDE_BINDIR ":/usr/bin:/bin";
133 }
134 writeLine(path);
135 } else if (line == "user") {
136 writeLine(m_User);
137 } else if (line == "priority") {
138 tmp.setNum(m_Priority);
139 writeLine(tmp);
140 } else if (line == "scheduler") {
141 if (m_Scheduler == SchedRealtime) writeLine("realtime");
142 else writeLine("normal");
143 } else if (line == "xwindows_only") {
144 if (m_bXOnly) writeLine("no");
145 else writeLine("yes");
146 } else if (line == "app_startup_id") {
147 QCStringList env = environment();
148 TQCString tmp;
149 for( QCStringList::ConstIterator it = env.begin();
150 it != env.end();
151 ++it )
152 {
153 if( (*it).find( "DESKTOP_STARTUP_ID=" ) == 0 )
154 tmp = (*it).mid( strlen( "DESKTOP_STARTUP_ID=" ));
155 }
156 if( tmp.isEmpty())
157 tmp = "0";
158 writeLine(tmp);
159 } else if (line == "app_start_pid") { // obsolete
160 tmp.setNum(getpid());
161 writeLine(tmp);
162 } else if (line == "environment") { // additional env vars
163 QCStringList env = environment();
164 for( QCStringList::ConstIterator it = env.begin();
165 it != env.end();
166 ++it )
167 writeLine( *it );
168 writeLine( "" );
169 } else if (line == "end") {
170 return 0;
171 } else
172 {
173 kdWarning(900) << k_lineinfo << "Unknown request: -->" << line
174 << "<--\n";
175 return 1;
176 }
177 }
178
179 return 0;
180}
181
182
183void StubProcess::notifyTaskbar(const TQString &)
184{
185 kdWarning(900) << "Obsolete StubProcess::notifyTaskbar() called!" << endl;
186}
187
188void StubProcess::virtual_hook( int id, void* data )
189{ PtyProcess::virtual_hook( id, data ); }
KCookie
Utility class to access the authentication tokens needed to run a KDE program (X11 and DCOP cookies).
Definition: kcookie.h:28
PtyProcess::writeLine
void writeLine(const TQCString &line, bool addNewline=true)
Writes a line of text to the program's standard in.
Definition: process.cpp:302
PtyProcess::readLine
TQCString readLine(bool block=true)
Reads a line from the program's standard out.
Definition: process.cpp:175
PtyProcess::enableLocalEcho
int enableLocalEcho(bool enable=true)
Enables/disables local echo on the pseudo tty.
Definition: process.cpp:451
StubProcess::display
virtual TQCString display()
This virtual function can be overloaded when special behavior is desired.
Definition: stub.h:100
StubProcess::setPriority
void setPriority(int prio)
Set the priority of the process.
Definition: stub.cpp:48
StubProcess::notifyTaskbar
void notifyTaskbar(const TQString &suffix)
Notify the taskbar that a new application has been started.
Definition: stub.cpp:183
StubProcess::dcopAuth
virtual TQCString dcopAuth()
See display.
Definition: stub.h:114
StubProcess::ConverseStub
int ConverseStub(int check)
Exchange all parameters with tdesu_stub.
Definition: stub.cpp:80
StubProcess::dcopServer
virtual TQCString dcopServer()
See display.
Definition: stub.h:110
StubProcess::iceAuth
virtual TQCString iceAuth()
See display.
Definition: stub.h:118

tdesu

Skip menu "tdesu"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdesu

Skip menu "tdesu"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdesu by doxygen 1.9.4
This website is maintained by Timothy Pearson.