27 #include <kapplication.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, TQT_SIGNAL(wroteStdin(KProcess*)), TQT_SLOT(writtenStdin(KProcess*)));
60 connect(
this, TQT_SIGNAL(processExited(KProcess*)), TQT_SLOT(slotExited(KProcess*)));
61 if (!KShellProcess::start(KProcess::NotifyOnExit, comm))
75 void ShellProcess::slotExited(KProcess* 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);
117 void ShellProcess::writtenStdin(KProcess* 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");