generic: make use of KStandardDirs::findRootExe()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-02-16 22:43:53 +02:00
parent 9717293996
commit 02229c1726
8 changed files with 44 additions and 34 deletions

View file

@ -141,9 +141,8 @@ void Dtime::serverTimeCheck() {
void Dtime::findNTPutility()
{
const QString exePath = QLatin1String("/usr/sbin:/usr/bin:/sbin:/bin");
foreach(const QString &possible_ntputility, QStringList() << "ntpdate" << "rdate" ) {
ntpUtility = KStandardDirs::findExe(possible_ntputility, exePath);
ntpUtility = KStandardDirs::findRootExe(possible_ntputility);
if (!ntpUtility.isEmpty()) {
return;
}

View file

@ -43,14 +43,10 @@
#include <QFile>
#include <QDir>
// We cannot rely on the $PATH environment variable, because D-Bus activation
// clears it. So we have to use a reasonable default.
static const QString exePath = QLatin1String("/usr/sbin:/usr/bin:/sbin:/bin");
static QString findNtpUtility()
{
foreach(const QString &possible_ntputility, QStringList() << "ntpdate" << "rdate" ) {
const QString ntpUtility = KStandardDirs::findExe(possible_ntputility, exePath);
const QString ntpUtility = KStandardDirs::findRootExe(possible_ntputility);
if (!ntpUtility.isEmpty()) {
return ntpUtility;
}
@ -103,7 +99,7 @@ ClockHelper::CH_Error ClockHelper::date( const QString& newdate, const QString&
return DateError;
}
QString hwclock = KStandardDirs::findExe("hwclock", exePath);
QString hwclock = KStandardDirs::findRootExe("hwclock");
if (!hwclock.isEmpty()) {
QProcess::execute(hwclock, QStringList() << "--systohc");
}

View file

@ -28,8 +28,8 @@ extern "C" {
#include <QMap>
#include <QFileInfo>
#include <QTextStream>
#include <KStandardDirs>
void ProcessChildren(QString name);
@ -87,13 +87,15 @@ bool GetInfo_SCSI(QTreeWidget* tree) {
QTextStream *t;
QString s;
if (!QFileInfo(QLatin1String("/sbin/camcontrol")).exists()) {
s = i18n("SCSI subsystem could not be queried: /sbin/camcontrol could not be found");
QByteArray camExe = KStandardPaths::findRootExe("camcontrol").toLocal8Bit();
if (camExe.isEmpty()) {
s = i18n("SCSI subsystem could not be queried: camcontrol could not be found");
QStringList list;
list << s;
new QTreeWidgetItem(tree, list);
} else if ((pipe = popen("/sbin/camcontrol devlist 2>&1", "r")) == NULL) {
s = i18n("SCSI subsystem could not be queried: /sbin/camcontrol could not be executed");
} else if ((pipe = popen(QByteArray(camExe + " devlist 2>&1").constData(), "r")) == NULL) {
s = i18n("SCSI subsystem could not be queried: camcontrol could not be executed");
QStringList list;
list << s;
new QTreeWidgetItem(tree, list);
@ -125,24 +127,27 @@ bool GetInfo_SCSI(QTreeWidget* tree) {
bool GetInfo_PCI(QTreeWidget* tree) {
FILE *pipe;
QString s, cmd;
QString s;
QByteArray cmd;
QTreeWidgetItem *olditem= NULL;
const QStringList headers(i18nc("@title:column Column name for PCI information", "Information"));
tree->setHeaderLabels(headers);
if (!QFileInfo(QLatin1String("/usr/sbin/pciconf")).exists()) {
QByteArray pciExe = KStandardPaths::findRootExe("pciconf").toLocal8Bit();
if (pciExe.isEmpty()) {
QStringList list;
list << i18n("Could not find any programs with which to query your system's PCI information");
new QTreeWidgetItem(tree, list);
return true;
} else {
cmd = "/usr/sbin/pciconf -l -v 2>&1";
cmd.append(pciExe);
cmd.append(" -l -v 2>&1");
}
// TODO: GetInfo_ReadfromPipe should be improved so that we could pass the program name and its
// arguments to it and remove most of the code below.
if ((pipe = popen(cmd.toLatin1(), "r")) == NULL) {
if ((pipe = popen(cmd.constData(), "r")) == NULL) {
QStringList list;
list << i18n("PCI subsystem could not be queried: %1 could not be executed", cmd);
olditem = new QTreeWidgetItem(olditem, list);

View file

@ -37,6 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <klocale.h>
#include <kiconloader.h>
#include <kglobalsettings.h>
#include <kstandarddirs.h>
#include <kdebug.h>
#define INFO_IRQ "/proc/interrupts"
@ -139,9 +140,14 @@ bool GetInfo_PCI(QTreeWidget* tree) {
tree->setHeaderHidden(true);
tree->setSortingEnabled(false);
QByteArray lspciCmd = KStandardDirs::findRootExe("lspci").toLocal8Bit();
if (lspciCmd.isEmpty()) {
return false;
}
lspciCmd.append(" -v");
/* try to get the output of the lspci package first */
if ((num = GetInfo_ReadfromPipe(tree, "lspci -v", true)) || (num = GetInfo_ReadfromPipe(tree, "/sbin/lspci -v", true)) || (num = GetInfo_ReadfromPipe(tree, "/usr/sbin/lspci -v", true)) || (num = GetInfo_ReadfromPipe(tree, "/usr/local/sbin/lspci -v", true)) || (num = GetInfo_ReadfromPipe(tree,
"/usr/bin/lspci -v", true)))
if (num = GetInfo_ReadfromPipe(tree, lspciCmd.constData(), true))
return num;
/* if lspci failed, read the contents of /proc/pci */

View file

@ -33,6 +33,7 @@
#include <kdebug.h>
#include <kio/global.h> /* for KIO::convertSize() */
#include <kstandarddirs.h>
typedef struct {
int string;
@ -55,7 +56,10 @@ static bool GetDmesgInfo(QTreeWidget* tree, const char *filter, void func(QTreeW
t = new QTextStream(dmesg);
} else {
delete dmesg;
pipe = popen("/sbin/dmesg", "r");
QByteArray dmesgExe = KStandardPaths::findRootExe("dmesg").toLocal8Bit();
if (dmesgExe.isEmpty())
return false;
pipe = popen(dmesgExe.constData(), "r");
if (!pipe)
return false;
usepipe = true;

View file

@ -52,7 +52,10 @@ static bool GetDmesgInfo(QTreeWidget* tree, const char *filter, void func(QTreeW
t = new QTextStream(dmesg);
} else {
delete dmesg;
pipe = popen("/sbin/dmesg", "r");
QByteArray dmesgExe = KStandardPaths::findRootExe("dmesg").toLocal8Bit();
if (dmesgExe.isEmpty())
return false;
pipe = popen(dmesgExe.constData(), "r");
if (!pipe)
return false;
usepipe = true;

View file

@ -26,6 +26,7 @@
#include <klocale.h>
#include <kdialog.h>
#include <kstandarddirs.h>
#include "ksmbstatus.h"
#include "moc_ksmbstatus.cpp"
@ -164,21 +165,18 @@ void NetMon::update() {
list->clear();
/* Re-read the Contents ... */
QString path(::getenv("PATH"));
path += "/bin:/sbin:/usr/bin:/usr/sbin";
QString smbstatusExe = KStandardDirs::findRootExe("smbstatus");
rownumber=0;
readingpart=header;
nrpid=0;
process->setEnvironment(QStringList() << ("PATH=" + path));
connect(process, SIGNAL(readyRead()), SLOT(readFromProcess()));
connect(process, SIGNAL(error(QProcess::ProcessError)), SLOT(smbstatusError()));
process->start("smbstatus");
process->start(smbstatusExe);
process->waitForFinished();
if (rownumber==0) // empty result
if (rownumber==0) { // empty result
version->setText(i18n("Error: Unable to open configuration file \"smb.conf\""));
else
{
} else {
// ok -> count the number of locked files for each pid
for (int i = 0; i < list->topLevelItemCount(); ++i)
{
@ -192,18 +190,19 @@ void NetMon::update() {
delete process;
process=0;
QString showmountExe = KStandardDirs::findRootExe("showmount");
readingpart=nfs;
delete showmountProc;
showmountProc=new QProcess();
connect(showmountProc, SIGNAL(readyRead()), SLOT(readFromProcess()));
showmountProc->setEnvironment(QStringList() << ("PATH=" + path));
//without this timer showmount hangs up to 5 minutes
//if the portmapper daemon isn't running
QTimer::singleShot(5000,this,SLOT(killShowmount()));
//kDebug()<<"starting kill timer with 5 seconds";
connect(showmountProc,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(killShowmount()));
connect(showmountProc,SIGNAL(error(QProcess::ProcessError)),this,SLOT(killShowmount()));
showmountProc->start("showmount", QStringList() << "-a" << "localhost");
showmountProc->start(showmountExe, QStringList() << "-a" << "localhost");
version->adjustSize();
list->show();

View file

@ -102,11 +102,9 @@ void HWInfo::setSources()
}
// TODO: get this from soliddevice
Plasma::DataEngine* engine = dataEngine("executable");
QString path = QString::fromLocal8Bit(qgetenv("PATH"))
+ QString::fromLatin1(":/usr/sbin:/sbin/");
QString exe = KStandardDirs::findExe( "lspci", path );
QString exe = KStandardDirs::findRootExe("lspci");
if (exe.isEmpty()) {
kError() << "lspci not found in " << path << endl;
kError() << "lspci not found in " << endl;
} else {
QString tmp = exe + " | grep VGA | sed 's/.*: //g'";
engine->connectSource(tmp, this);