27 #include <tdeapplication.h>
28 #include <tdelocale.h>
31 #include "shellprocess.moc"
34 TQCString ShellProcess::mShellName;
35 TQCString ShellProcess::mShellPath;
36 bool ShellProcess::mInitialised =
false;
37 bool ShellProcess::mAuthorised =
false;
41 : KShellProcess(shellName()),
55 mStatus = UNAUTHORISED;
58 KShellProcess::operator<<(mCommand);
59 connect(
this, TQ_SIGNAL(wroteStdin(TDEProcess*)), TQ_SLOT(writtenStdin(TDEProcess*)));
60 connect(
this, TQ_SIGNAL(processExited(TDEProcess*)), TQ_SLOT(slotExited(TDEProcess*)));
61 if (!KShellProcess::start(TDEProcess::NotifyOnExit, comm))
75 void ShellProcess::slotExited(TDEProcess* proc)
77 kdDebug(5950) <<
"ShellProcess::slotExited()\n";
80 if (!proc->normalExit())
82 kdWarning(5950) <<
"ShellProcess::slotExited(" << mCommand <<
") " << mShellName <<
": died/killed\n";
88 int status = proc->exitStatus();
89 if ((mShellName ==
"bash" && (
status == 126 ||
status == 127))
90 || (mShellName ==
"ksh" &&
status == 127))
92 kdWarning(5950) <<
"ShellProcess::slotExited(" << mCommand <<
") " << mShellName <<
": not found or not executable\n";
104 TQCString scopy(buffer, bufflen+1);
105 bool write = mStdinQueue.isEmpty();
106 mStdinQueue.append(scopy);
108 TDEProcess::writeStdin(mStdinQueue.first(), mStdinQueue.first().length());
117 void ShellProcess::writtenStdin(TDEProcess* proc)
119 mStdinQueue.pop_front();
120 if (!mStdinQueue.isEmpty())
121 proc->writeStdin(mStdinQueue.first(), mStdinQueue.first().length());
131 if (mStdinQueue.isEmpty())
146 return i18n(
"Failed to execute command (shell access not authorized):");
149 return i18n(
"Failed to execute command:");
151 return i18n(
"Command execution error:");
167 if (mShellPath.isEmpty())
170 mShellPath =
"/bin/sh";
171 TQCString envshell = TQCString(getenv(
"SHELL")).stripWhiteSpace();
172 if (!envshell.isEmpty())
174 struct stat fileinfo;
175 if (stat(envshell.data(), &fileinfo) != -1
176 && !S_ISDIR(fileinfo.st_mode)
177 && !S_ISCHR(fileinfo.st_mode)
178 && !S_ISBLK(fileinfo.st_mode)
180 && !S_ISSOCK(fileinfo.st_mode)
182 && !S_ISFIFO(fileinfo.st_mode)
183 && !access(envshell.data(), X_OK))
184 mShellPath = envshell;
188 int i = mShellPath.findRev(
'/');
190 mShellName = mShellPath.mid(i + 1);
192 mShellName = mShellPath;
204 mAuthorised = kapp->authorize(
"shell_access");
Status status() const
Returns the current status of the shell process.
static bool authorised()
Returns whether the user is authorised to run shell commands.
void stdinExit()
Tell the process to exit once any outstanding STDIN strings have been written.
void shellExited(ShellProcess *)
Signal emitted when the shell process execution completes.
TQString errorMessage() const
Returns the error message corresponding to the command exit status.
ShellProcess(const TQString &command)
Constructor.
void writeStdin(const char *buffer, int bufflen)
Writes a string to the process's STDIN.
bool start(Communication comm=NoCommunication)
Executes the configured command.
static const TQCString & shellPath()
Determines which shell to use.