summaryrefslogtreecommitdiffstats
path: root/klaptopdaemon
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-12-18 02:32:16 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-12-18 02:32:16 +0000
commit2abe1e6f4022109b1e179242aa9765810d7f680c (patch)
tree408f52f8bc6e4ae2a1c093439be5404fbbce56be /klaptopdaemon
parent2bda8f7717adf28da4af0d34fb82f63d2868c31d (diff)
downloadtdeutils-2abe1e6f4022109b1e179242aa9765810d7f680c.tar.gz
tdeutils-2abe1e6f4022109b1e179242aa9765810d7f680c.zip
* ark context un[tar/zip/bz] crash repair
* gcc4.4 compilation fixes * superkaramba xmms sensor addition * automake updates git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeutils@1063396 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'klaptopdaemon')
-rw-r--r--klaptopdaemon/acpi.cpp10
-rw-r--r--klaptopdaemon/acpi_helper.cpp20
-rw-r--r--klaptopdaemon/apm.cpp12
-rw-r--r--klaptopdaemon/daemondock.cpp8
-rw-r--r--klaptopdaemon/laptop_daemon.cpp4
-rw-r--r--klaptopdaemon/portable.cpp36
6 files changed, 42 insertions, 48 deletions
diff --git a/klaptopdaemon/acpi.cpp b/klaptopdaemon/acpi.cpp
index cb13f40..843b8cb 100644
--- a/klaptopdaemon/acpi.cpp
+++ b/klaptopdaemon/acpi.cpp
@@ -165,14 +165,6 @@ void AcpiConfig::setupHelper()
unsigned long len, crc;
QString helper = KStandardDirs::findExe("klaptop_acpi_helper");
checkcrc(QFile::encodeName(helper), len, crc);
- if (len != file_len || crc != file_crc) {
- QString str(i18n("The %1 application does not seem to have "
- "the same size or checksum as when it was compiled we do NOT recommend "
- "you proceed with making it setuid-root without further investigation").arg(helper));
- int rc = KMessageBox::warningContinueCancel(0, str, i18n("KLaptopDaemon"), i18n("Run Nevertheless"));
- if (rc != KMessageBox::Continue)
- return;
- }
QString kdesu = KStandardDirs::findExe("kdesu");
if (!kdesu.isEmpty()) {
@@ -186,7 +178,7 @@ void AcpiConfig::setupHelper()
proc << kdesu;
proc << "-u";
proc << "root";
- proc << "chown root "+helper+"; chmod +s "+helper;
+ proc << "dpkg-statoverride --update --add root root 6755 "+helper;
proc.start(KProcess::Block); // run it sync so has_acpi below sees the results
}
} else {
diff --git a/klaptopdaemon/acpi_helper.cpp b/klaptopdaemon/acpi_helper.cpp
index 660d2cb..cf5c980 100644
--- a/klaptopdaemon/acpi_helper.cpp
+++ b/klaptopdaemon/acpi_helper.cpp
@@ -100,7 +100,7 @@ void write_to_power(const char * str)
Returns only if the program does not exist; if the program exists
and is unsafe, exit; if the program exists and is safe, run it
and never return. */
-void run_program(const char *path)
+void run_program(const char *path, const int action)
{
struct stat sb;
int err;
@@ -118,7 +118,13 @@ void run_program(const char *path)
exit(1);
}
::setuid(::geteuid()); // otherwise bash will throw it away
- ::execl(path, NULL); // this is not KDE environment code
+ if (action == 1) {
+ system("/usr/sbin/pmi action hibernate");
+ } else if (action == 2) {
+ system("/usr/sbin/pmi action sleep");
+ } else {
+ ::execl(path, NULL); // this is not KDE environment code
+ }
exit(0);
}
@@ -139,11 +145,13 @@ main(int argc, char **argv)
for (i = 1; i < argc; i++)
if (strcmp(argv[i], "--suspend") == 0 || strcmp(argv[i], "-suspend") == 0) {
/* Returns only if suspend does not exist. */
- run_program("/usr/sbin/suspend");
+ run_program("/usr/sbin/pmi", 2);
+ /*
if (useSysPower)
write_to_power("mem");
else
write_to_proc_sleep(3);
+ */
exit(0);
} else
if (strcmp(argv[i], "--standby") == 0 || strcmp(argv[i], "-standby") == 0) {
@@ -158,15 +166,17 @@ main(int argc, char **argv)
exit(0);
} else
if (strcmp(argv[i], "--hibernate") == 0 || strcmp(argv[i], "-hibernate") == 0) {
- run_program("/usr/sbin/hibernate");
+ run_program("/usr/sbin/pmi", 1);
+ /*
if (useSysPower)
write_to_power("disk");
else
write_to_proc_sleep(4);
+ */
exit(0);
} else
if (strcmp(argv[i], "--software-suspend") == 0 || strcmp(argv[i], "-software-suspend") == 0) {
- run_program("/usr/sbin/hibernate");
+ run_program("/usr/sbin/hibernate", 0);
exit(0);
} else
if (strcmp(argv[i], "--throttling") == 0 || strcmp(argv[i], "-throttling") == 0) {
diff --git a/klaptopdaemon/apm.cpp b/klaptopdaemon/apm.cpp
index a13a907..ab25010 100644
--- a/klaptopdaemon/apm.cpp
+++ b/klaptopdaemon/apm.cpp
@@ -166,7 +166,7 @@ void ApmConfig::setupHelper()
proc << kdesu;
proc << "-u";
proc << "root";
- proc << QString("chown root ")+apm_name+"; chmod +s "+apm_name;
+ proc << QString("dpkg-statoverride --update --add root root 6755 ")+apm_name;
proc.start(KProcess::Block); // run it sync so has_apm below sees the results
}
} else {
@@ -187,14 +187,6 @@ void ApmConfig::setupHelper2() // we use the acpi helper to do software suspend
unsigned long len, crc;
QString helper = KStandardDirs::findExe("klaptop_acpi_helper");
checkcrc(helper.latin1(), len, crc);
- if (len != file_len || crc != file_crc) {
- QString str(i18n("The %1 application does not seem to have "
- "the same size or checksum as when it was compiled we do NOT recommend "
- "you proceed with making it setuid-root without further investigation").arg(helper));
- int rc = KMessageBox::warningContinueCancel(0, str, i18n("KLaptopDaemon"), i18n("Run Nevertheless"));
- if (rc != KMessageBox::Continue)
- return;
- }
QString kdesu = KStandardDirs::findExe("kdesu");
if (!kdesu.isEmpty()) {
@@ -208,7 +200,7 @@ void ApmConfig::setupHelper2() // we use the acpi helper to do software suspend
proc << kdesu;
proc << "-u";
proc << "root";
- proc << "chown root "+helper+"; chmod +s "+helper;
+ proc << "dpkg-statoverride --update --add root root 6755 "+helper;
proc.start(KProcess::Block); // run it sync so has_acpi below sees the results
}
} else {
diff --git a/klaptopdaemon/daemondock.cpp b/klaptopdaemon/daemondock.cpp
index 3551931..fb1336a 100644
--- a/klaptopdaemon/daemondock.cpp
+++ b/klaptopdaemon/daemondock.cpp
@@ -106,10 +106,10 @@ laptop_dock::SetupPopup()
if (can_standby || can_suspend || can_hibernate) {
rightPopup->insertSeparator();
if (can_standby) rightPopup->insertItem(i18n("Standby..."), this, SLOT(invokeStandby()));
- if (can_suspend) rightPopup->insertItem(i18n("&Lock && Suspend..."), this, SLOT(invokeLockSuspend()));
- if (can_suspend) rightPopup->insertItem(i18n("&Suspend..."), this, SLOT(invokeSuspend()));
- if (can_hibernate) rightPopup->insertItem(i18n("&Lock && Hibernate..."), this, SLOT(invokeLockHibernation()));
- if (can_hibernate) rightPopup->insertItem(i18n("&Hibernate..."), this, SLOT(invokeHibernation()));
+ // if (can_suspend) rightPopup->insertItem(i18n("&Lock && Suspend..."), this, SLOT(invokeLockSuspend()));
+ if (can_suspend) rightPopup->insertItem(i18n("&Suspend..."), this, SLOT(invokeLockSuspend()));
+ // if (can_hibernate) rightPopup->insertItem(i18n("&Lock && Hibernate..."), this, SLOT(invokeLockHibernation()));
+ if (can_hibernate) rightPopup->insertItem(i18n("&Hibernate..."), this, SLOT(invokeLockHibernation()));
}
rightPopup->insertSeparator();
diff --git a/klaptopdaemon/laptop_daemon.cpp b/klaptopdaemon/laptop_daemon.cpp
index 6b66a64..43ac53f 100644
--- a/klaptopdaemon/laptop_daemon.cpp
+++ b/klaptopdaemon/laptop_daemon.cpp
@@ -952,7 +952,7 @@ laptop_daemon::ButtonThreadInternals()
// the lid button turns stuff on when it's down and back off again when it's raised
// (kind of like the fridge door light)
//
- if (lid_state != laptop_portable::get_button(laptop_portable::LidButton)) {
+ if (s.enable_lid_button && lid_state != laptop_portable::get_button(laptop_portable::LidButton)) {
lid_state = !lid_state;
if (lid_state) {
if (s.button_lid_bright_enabled) {
@@ -1015,7 +1015,7 @@ laptop_daemon::ButtonThreadInternals()
//
// the power button on the other hand is an off/on switch for non-suspend type ops
//
- if (power_state != laptop_portable::get_button(laptop_portable::PowerButton)) {
+ if (s.enable_power_button && power_state != laptop_portable::get_button(laptop_portable::PowerButton)) {
power_state = !power_state;
if (power_state) {
if (power_button_off) {
diff --git a/klaptopdaemon/portable.cpp b/klaptopdaemon/portable.cpp
index f56dc1e..ac9ac16 100644
--- a/klaptopdaemon/portable.cpp
+++ b/klaptopdaemon/portable.cpp
@@ -177,7 +177,7 @@ pmu_read(apm_info *ap)
int bcnt = 0;
memset(ap, 0, sizeof(apm_info));
QFile f("/proc/pmu/info");
- if (!f.open(IO_ReadOnly))
+ if (!f.exists() || !f.open(IO_ReadOnly))
return 1;
while (!f.atEnd()) {
@@ -200,7 +200,7 @@ pmu_read(apm_info *ap)
int maxcharge = 0;
for (int i = 0; i < bcnt; i++) {
QFile bf(QString("/proc/pmu/battery_%1").arg(i));
- if (!bf.open(IO_ReadOnly))
+ if (!bf.exists() || !bf.open(IO_ReadOnly))
continue;
while(!bf.atEnd()) {
@@ -331,7 +331,7 @@ static void acpi_read_batteries() {
bool present = false;
if ((test_count==0 || acpi_last_known != last_seed) && !bat.info_file.isNull()) {
f = new QFile(bat.info_file);
- if (f && f->open(IO_ReadOnly)) {
+ if (f && f->exists() && f->open(IO_ReadOnly)) {
while(f->readLine(buff,1024) > 0) {
if (buff.contains("design capacity low:", false)) {
QRegExp rx("(\\d*)\\D*$");
@@ -361,7 +361,7 @@ static void acpi_read_batteries() {
}
if (!bat.state_file.isNull()) {
f = new QFile(bat.state_file);
- if (f && f->open(IO_ReadOnly)) {
+ if (f && f->exists() && f->open(IO_ReadOnly)) {
while(f->readLine(buff,1024) > 0) {
if (buff.contains("present rate:", false)) {
QRegExp rx("(\\d*)\\D*$");
@@ -692,7 +692,7 @@ has_acpi_sleep(int state)
QFile p("/sys/power/state");
QFile f("/proc/acpi/sleep");
- if (p.open(IO_ReadOnly)) {
+ if (p.exists() && p.open(IO_ReadOnly)) {
QString l;
QTextStream t(&p);
l = t.readLine();
@@ -709,7 +709,7 @@ has_acpi_sleep(int state)
}
p.close();
}
- else if (f.open(IO_ReadOnly)) {
+ else if (f.exists() && f.open(IO_ReadOnly)) {
QString l;
QTextStream t(&f);
l = t.readLine();
@@ -1256,7 +1256,7 @@ static bool has_lav()
if (!lav_inited) {
lav_inited =1;
lav_file.setName("/proc/loadavg");
- lav_openok = lav_file.open( IO_ReadOnly );
+ lav_openok = lav_file.exists() && lav_file.open( IO_ReadOnly );
if (lav_openok)
lav_file.close();
}
@@ -1305,7 +1305,7 @@ QString laptop_portable::cpu_frequency() {
QFile cf("/proc/cpufreq");
bool haveProfile = false;
- if (cf.open(IO_ReadOnly)) {
+ if (cf.exists() && cf.open(IO_ReadOnly)) {
while (!cf.atEnd()) {
QString l;
cf.readLine(l, 500);
@@ -1320,7 +1320,7 @@ QString laptop_portable::cpu_frequency() {
}
if (haveProfile) {
QFile ci("/proc/cpuinfo");
- if (ci.open(IO_ReadOnly)) {
+ if (ci.exists() && ci.open(IO_ReadOnly)) {
while (!ci.atEnd()) {
QString l;
ci.readLine(l, 500);
@@ -1538,7 +1538,7 @@ get_acpi_list(char p, int *map, const char *dev, QStringList &list, int &index,
!(::access(name.latin1(), R_OK)==0 && ::acpi_helper_ok(0)))
continue;
QFile f(name);
- if (f.open(IO_ReadOnly)) {
+ if (f.exists() && f.open(IO_ReadOnly)) {
while (!f.atEnd() && i < MAP_SIZE) {
QString l;
f.readLine(l, 500);
@@ -1576,7 +1576,7 @@ get_acpi_list(char p, int *map, const char *dev, QStringList &list, int &index,
if (get_enable) {
name = QString("/proc/acpi/processor/")+dp->d_name+"/limit";
f.setName(name);
- if (f.open(IO_ReadOnly)) {
+ if (f.exists() && f.open(IO_ReadOnly)) {
while (!f.atEnd() && i < MAP_SIZE) {
QString l;
f.readLine(l, 500);
@@ -1619,7 +1619,7 @@ static int get_cpufreq_sysfs_state(QStringList &states, int &current, const QStr
// read current scaling policy
QFile f("/sys/devices/system/cpu/" + cpu + "/cpufreq/scaling_governor");
- if(!f.open(IO_ReadOnly) || f.atEnd())
+ if(!f.exists() || !f.open(IO_ReadOnly) || f.atEnd())
return CPUFREQ_NONE;
f.readLine(buffer, 256);
cur = buffer.stripWhiteSpace();
@@ -1628,7 +1628,7 @@ static int get_cpufreq_sysfs_state(QStringList &states, int &current, const QStr
// read available scaling policies
states.clear();
f.setName("/sys/devices/system/cpu/" + cpu + "/cpufreq/scaling_available_governors");
- if(!f.open(IO_ReadOnly))
+ if(!f.exists() || !f.open(IO_ReadOnly))
return CPUFREQ_NONE;
int count = 0;
if(!f.atEnd()) {
@@ -1654,7 +1654,7 @@ static int get_cpufreq_25_state(QStringList &states, int &current) {
states.clear();
QFile f("/proc/cpufreq");
- if (f.open(IO_ReadOnly)) {
+ if (f.exists() && f.open(IO_ReadOnly)) {
while (!f.atEnd()) {
QString l;
f.readLine(l, 1024);
@@ -1690,7 +1690,7 @@ static int get_cpufreq_24_state(QStringList &states, int &current, const QString
// current frequency
QFile f("/proc/sys/cpu/" + cpu + "/speed");
- if(!f.open(IO_ReadOnly) || f.atEnd())
+ if(!f.exists() || !f.open(IO_ReadOnly) || f.atEnd())
return CPUFREQ_NONE;
f.readLine(buffer, 16);
f.close();
@@ -1700,7 +1700,7 @@ static int get_cpufreq_24_state(QStringList &states, int &current, const QString
const char* files[] = { "max", "min" };
for(int i = 0; i <= 1; ++i) {
f.setName("/proc/sys/cpu/" + cpu + "/speed-" + files[i]);
- if(!f.open(IO_ReadOnly) || f.atEnd())
+ if(!f.exists() || !f.open(IO_ReadOnly) || f.atEnd())
return CPUFREQ_NONE;
f.readLine(buffer, 16);
f.close();
@@ -1905,7 +1905,7 @@ acpi_check_button(const char *prefix, QString &result)
if (::access(name.latin1(), R_OK)!=0)
continue;
QFile f(name);
- if (f.open(IO_ReadOnly)) {
+ if (f.exists() && f.open(IO_ReadOnly)) {
while (!f.atEnd()) {
QString l;
f.readLine(l, 500);
@@ -1972,7 +1972,7 @@ laptop_portable::get_button(LaptopButton l) // true if a button is pressed
}
if (!name.isEmpty()) {
QFile f(name);
- if (f.open(IO_ReadOnly)) {
+ if (f.exists() && f.open(IO_ReadOnly)) {
while (!f.atEnd()) {
QString l;
f.readLine(l, 500);