mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-10-16 15:41:13 +02:00
2023-06-29 Fred Gleason <fredg@paravelsystems.com>
* Added a 'RDCoreApplication::isUniqueProcess()' static method. * Added processuniqueness checks to caed(8), rdairplay(1), rdrepld(8), rdrssd(8), rdservice(8), rdvairplayd(8), ripcd(8) and rdalsaconfig(8). Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// rdapplication.cpp
|
||||
// rdcoreapplication.cpp
|
||||
//
|
||||
// Base Application Class
|
||||
//
|
||||
@@ -22,6 +22,9 @@
|
||||
#include <syslog.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QIODevice>
|
||||
#include <QProcess>
|
||||
#include <QStyleFactory>
|
||||
#include <QTranslator>
|
||||
@@ -132,8 +135,8 @@ RDCoreApplication::~RDCoreApplication()
|
||||
}
|
||||
|
||||
|
||||
bool RDCoreApplication::open(QString *err_msg,RDCoreApplication::ErrorType *err_type,
|
||||
bool check_svc)
|
||||
bool RDCoreApplication::open(QString *err_msg,ErrorType *err_type,
|
||||
bool check_svc,bool check_unique)
|
||||
{
|
||||
int schema=0;
|
||||
QString db_err;
|
||||
@@ -177,6 +180,17 @@ bool RDCoreApplication::open(QString *err_msg,RDCoreApplication::ErrorType *err_
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Process Uniqueness Check
|
||||
//
|
||||
if(check_unique) {
|
||||
if(!isUniqueProcess(app_command_name)) {
|
||||
fprintf(stderr,"%s: prior instance found\n",
|
||||
app_command_name.toUtf8().constData());
|
||||
exit(RDApplication::ExitPriorInstance);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Open rd.conf(5)
|
||||
//
|
||||
@@ -638,6 +652,32 @@ QString RDCoreApplication::exitCodeText(RDCoreApplication::ExitCode code)
|
||||
}
|
||||
|
||||
|
||||
bool RDCoreApplication::isUniqueProcess(const QString &cmdname)
|
||||
{
|
||||
bool ok=false;
|
||||
QStringList dirs=
|
||||
QDir("/proc").entryList(QDir::Dirs|QDir::NoDotAndDotDot);
|
||||
|
||||
for(int i=0;i<dirs.size();i++) {
|
||||
pid_t pid=dirs.at(i).toUInt(&ok);
|
||||
if(ok&&(pid!=getpid())) {
|
||||
QFile *file=new QFile("/proc/"+dirs.at(i)+"/cmdline");
|
||||
if(file->open(QIODevice::ReadOnly)) {
|
||||
QString cmdline(QString::fromUtf8(file->readAll()));
|
||||
QStringList f0=cmdline.trimmed().split("/",QString::SkipEmptyParts);
|
||||
if((f0.size()>0)&&(f0.last().trimmed()==cmdname)) {
|
||||
delete file;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
delete file;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void RDCoreApplication::userChangedData()
|
||||
{
|
||||
QString sql;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// Base Application Class
|
||||
//
|
||||
// (C) Copyright 2018-2022 Fred Gleason <fredg@paravelsystems.com>
|
||||
// (C) Copyright 2018-2023 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@@ -58,7 +58,8 @@ class RDCoreApplication : public QObject
|
||||
RDCoreApplication(const QString &module_name,const QString &cmdname,
|
||||
const QString &usage,bool use_translations,QObject *parent);
|
||||
~RDCoreApplication();
|
||||
bool open(QString *err_msg,ErrorType *err_type,bool check_svc);
|
||||
bool open(QString *err_msg,ErrorType *err_type,
|
||||
bool check_svc,bool check_unique);
|
||||
RDAirPlayConf *airplayConf();
|
||||
RDCae *cae();
|
||||
RDCmdSwitch *cmdSwitch();
|
||||
@@ -89,6 +90,7 @@ class RDCoreApplication : public QObject
|
||||
const QString &login_name=QString());
|
||||
static void syslog(RDConfig *config,int priority,const char *fmt,...);
|
||||
static QString exitCodeText(ExitCode code);
|
||||
static bool isUniqueProcess(const QString &cmdname);
|
||||
|
||||
private slots:
|
||||
void userChangedData();
|
||||
|
Reference in New Issue
Block a user