tdehw dbus daemon: improved response for can* functions and added

polkit support to cpugovernor and brightness interfaces.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
feat/fix-suspend-code
Michele Calgaro 6 years ago
parent b11c809588
commit 5931eecd26
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -7,6 +7,26 @@
<vendor>The Trinity Desktop Environment Project</vendor> <vendor>The Trinity Desktop Environment Project</vendor>
<vendor_url>http://www.trinitydesktop.org</vendor_url> <vendor_url>http://www.trinitydesktop.org</vendor_url>
<action id="org.trinitydesktop.hardwarecontrol.cpugovernor.setcpugovernor">
<description>Set CPU governor.</description>
<message>Authentication is required to set the CPU governor.</message>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
</action>
<action id="org.trinitydesktop.hardwarecontrol.brightness.setbrightness">
<description>Set display brightness.</description>
<message>Authentication is required to set the display brightness.</message>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
</action>
<action id="org.trinitydesktop.hardwarecontrol.power.freeze"> <action id="org.trinitydesktop.hardwarecontrol.power.freeze">
<description>Freeze the system.</description> <description>Freeze the system.</description>
<message>Authentication is required to freeze the system.</message> <message>Authentication is required to freeze the system.</message>
@ -57,4 +77,14 @@
</defaults> </defaults>
</action> </action>
<action id="org.trinitydesktop.hardwarecontrol.power.sethibernationmethod">
<description>Set method used to hibernate the system.</description>
<message>Authentication is required to set hibernation method.</message>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
</action>
</policyconfig> </policyconfig>

@ -21,8 +21,7 @@
#define BITS_PER_LONG (sizeof(long) * 8) #define BITS_PER_LONG (sizeof(long) * 8)
#define NUM_BITS(x) ((((x) - 1) / BITS_PER_LONG) + 1) #define NUM_BITS(x) ((((x) - 1) / BITS_PER_LONG) + 1)
bool checkPolKitAuthorization(DBusMessage* msg, const TQString &action_id) bool checkPolKitAuthorization(DBusMessage* msg, const TQString &action_id) {
{
if (!msg) { if (!msg) {
return false; return false;
} }
@ -64,7 +63,7 @@ bool checkPolKitAuthorization(DBusMessage* msg, const TQString &action_id)
return false; return false;
} }
void reply_Bool(DBusMessage* msg, DBusConnection* conn, int value) { void replyBool(DBusMessage* msg, DBusConnection* conn, int value) {
DBusMessage* reply; DBusMessage* reply;
DBusMessageIter args; DBusMessageIter args;
const char* member = dbus_message_get_member(msg); const char* member = dbus_message_get_member(msg);
@ -91,218 +90,141 @@ void reply_Bool(DBusMessage* msg, DBusConnection* conn, int value) {
dbus_message_unref(reply); dbus_message_unref(reply);
} }
void reply_CanSetGivenPath(DBusMessage* msg, DBusConnection* conn, const char* param) { bool setGivenPath(const char *path, const char *contents) {
DBusMessage* reply; int writable = (access(path, W_OK) == 0);
DBusMessageIter args; bool result = false;
const char* member = dbus_message_get_member(msg);
dbus_uint32_t serial = 0;
int writable = false;
// check if path is writable
int rval = access (param, W_OK);
if (rval == 0) {
writable = true;
}
// create a reply from the message
reply = dbus_message_new_method_return(msg);
// add the arguments to the reply
dbus_message_iter_init_append(reply, &args);
if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_BOOLEAN, &writable)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: dbus_message_iter_append_basic failed\n", member);
return;
}
// send the reply && flush the connection
if (!dbus_connection_send(conn, reply, &serial)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: dbus_connection_send failed\n", member);
return;
}
dbus_connection_flush(conn);
// free the reply
dbus_message_unref(reply);
}
void reply_SetGivenPath(DBusMessage* msg, DBusConnection* conn, const char* param, const char* contents) {
DBusMessage* reply;
DBusMessageIter args;
const char* member = dbus_message_get_member(msg);
dbus_uint32_t serial = 0;
int writable = false;
int written = false;
// check if path is writable
int rval = access (param, W_OK);
if (rval == 0) {
writable = true;
}
if (writable) { if (writable) {
FILE *node = fopen(param, "w"); FILE *node = fopen(path, "w");
if (node != NULL) { if (node != NULL) {
if (fputs(contents, node) != EOF) { if (fputs(contents, node) != EOF) {
written = true; result = true;
}
if (fclose(node) == EOF) {
// Error!
} }
fclose(node);
} }
} }
return result;
// create a reply from the message
reply = dbus_message_new_method_return(msg);
// add the arguments to the reply
dbus_message_iter_init_append(reply, &args);
if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_BOOLEAN, &written)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: dbus_message_iter_append_basic failed\n", member);
return;
}
// send the reply && flush the connection
if (!dbus_connection_send(conn, reply, &serial)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: dbus_connection_send failed\n", member);
return;
}
dbus_connection_flush(conn);
// free the reply
dbus_message_unref(reply);
} }
void reply_CanSetCPUGovernor(DBusMessage* msg, DBusConnection* conn) { bool canSetCPUGovernor(DBusMessage *msg, DBusConnection *conn) {
DBusMessageIter args; DBusMessageIter args;
const char* member = dbus_message_get_member(msg); const char *member = dbus_message_get_member(msg);
dbus_int32_t cpunum;
char path[256];
// read the arguments // read the arguments
if (!dbus_message_iter_init(msg, &args)) { if (!dbus_message_iter_init(msg, &args)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: no argument supplied\n", member); fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: no argument supplied\n", member);
return false;
} }
else if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) { else if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: argument not 32-bit integer\n", member); fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: argument not 32-bit integer\n", member);
return false;
} }
else { dbus_int32_t cpunum;
dbus_message_iter_get_basic(&args, &cpunum); dbus_message_iter_get_basic(&args, &cpunum);
}
char path[256];
snprintf(path, 256, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", cpunum); snprintf(path, 256, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", cpunum);
reply_CanSetGivenPath(msg, conn, path); return (access(path, W_OK) == 0);
} }
void reply_SetCPUGovernor(DBusMessage* msg, DBusConnection* conn) { bool setCPUGovernor(DBusMessage *msg, DBusConnection *conn) {
DBusMessageIter args; DBusMessageIter args;
const char* member = dbus_message_get_member(msg); const char *member = dbus_message_get_member(msg);
dbus_int32_t cpunum = -1;
char* governor = NULL;
char path[256];
// read the arguments // read the arguments
if (!dbus_message_iter_init(msg, &args)) { if (!dbus_message_iter_init(msg, &args)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: no arguments supplied\n", member); fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: no arguments supplied\n", member);
return false;
} }
else if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) { else if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: first argument not 32-bit integer\n", member); fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: first argument not 32-bit integer\n", member);
return false;
} }
else { dbus_int32_t cpunum = -1;
dbus_message_iter_get_basic(&args, &cpunum); dbus_message_iter_get_basic(&args, &cpunum);
}
if (!dbus_message_iter_next(&args)) { if (!dbus_message_iter_next(&args)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: second argument not supplied\n", member); fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: second argument not supplied\n", member);
return false;
} }
else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) { else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: second argument not string\n", member); fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: second argument not string\n", member);
return false;
} }
else { char *governor = NULL;
dbus_message_iter_get_basic(&args, &governor); dbus_message_iter_get_basic(&args, &governor);
}
bool result = false;
char path[256];
snprintf(path, 256, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", cpunum); snprintf(path, 256, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", cpunum);
if ((cpunum>-1) && governor) { if ((cpunum > -1) && governor) {
reply_SetGivenPath(msg, conn, path, governor); result = setGivenPath(path, governor);
}
else {
reply_Bool(msg, conn, false);
} }
return result;
} }
void reply_CanSetBrightness(DBusMessage* msg, DBusConnection* conn) { bool CanSetBrightness(DBusMessage* msg, DBusConnection* conn) {
DBusMessageIter args; DBusMessageIter args;
const char* member = dbus_message_get_member(msg); const char* member = dbus_message_get_member(msg);
char* rawpath;
char* safepath;
// read the arguments // read the arguments
if (!dbus_message_iter_init(msg, &args)) { if (!dbus_message_iter_init(msg, &args)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: no argument supplied\n", member); fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: no argument supplied\n", member);
return false;
} }
else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) { else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: argument not string\n", member); fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: argument not string\n", member);
return false;
} }
else { char *rawpath;
dbus_message_iter_get_basic(&args, &rawpath); dbus_message_iter_get_basic(&args, &rawpath);
}
safepath = realpath(rawpath, NULL);
if (safepath && bool result = false;
(strstr(safepath, "/sys/devices") == safepath) && char *safepath = realpath(rawpath, NULL);
(strstr(safepath, "/brightness") == (safepath+strlen(safepath)-strlen("/brightness"))) if (safepath && (strstr(safepath, "/sys/devices") == safepath) &&
) { (strstr(safepath, "/brightness") == (safepath+strlen(safepath)-strlen("/brightness")))) {
reply_CanSetGivenPath(msg, conn, safepath); result = (access(safepath, W_OK) == 0);
}
else {
reply_Bool(msg, conn, false);
} }
free(safepath); free(safepath);
return result;
} }
void reply_SetBrightness(DBusMessage* msg, DBusConnection* conn) { bool SetBrightness(DBusMessage* msg, DBusConnection* conn) {
DBusMessageIter args; DBusMessageIter args;
const char* member = dbus_message_get_member(msg); const char* member = dbus_message_get_member(msg);
char* rawpath;
char* safepath;
char* brightness;
// read the arguments // read the arguments
if (!dbus_message_iter_init(msg, &args)) { if (!dbus_message_iter_init(msg, &args)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: no arguments supplied\n", member); fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: no arguments supplied\n", member);
return false;
} }
else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) { else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: first argument not string\n", member); fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: first argument not string\n", member);
return false;
} }
else { char* rawpath;
dbus_message_iter_get_basic(&args, &rawpath); dbus_message_iter_get_basic(&args, &rawpath);
}
if (!dbus_message_iter_next(&args)) { if (!dbus_message_iter_next(&args)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: second argument not supplied\n", member); fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: second argument not supplied\n", member);
return false;
} }
else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) { else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: second argument not string\n", member); fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: second argument not string\n", member);
return false;
} }
else { char* brightness;
dbus_message_iter_get_basic(&args, &brightness); dbus_message_iter_get_basic(&args, &brightness);
}
bool result = false;
char* safepath;
safepath = realpath(rawpath, NULL); safepath = realpath(rawpath, NULL);
if (safepath && brightness && (strstr(safepath, "/sys/devices") == safepath) &&
if (safepath && brightness && (strstr(safepath, "/brightness") == (safepath+strlen(safepath)-strlen("/brightness")))) {
(strstr(safepath, "/sys/devices") == safepath) && result = setGivenPath(safepath, brightness);
(strstr(safepath, "/brightness") == (safepath+strlen(safepath)-strlen("/brightness")))
) {
reply_SetGivenPath(msg, conn, safepath, brightness);
}
else {
reply_Bool(msg, conn, false);
} }
free(safepath); free(safepath);
return result;
} }
bool CanSetPowerState(const char* state, const char* disk, const char* mem) { bool CanSetPowerState(const char* state, const char* disk, const char* mem) {
@ -424,33 +346,32 @@ bool SetPowerState(const char* state, const char* disk, const char* mem) {
return result; return result;
} }
void reply_CanSetHibernationMethod(DBusMessage* msg, DBusConnection* conn) { bool CanSetHibernationMethod(DBusMessage* msg, DBusConnection* conn) {
// check if path is writable return (access("/sys/power/disk", W_OK) == 0);
reply_CanSetGivenPath(msg, conn, "/sys/power/disk");
} }
void reply_SetHibernationMethod(DBusMessage* msg, DBusConnection* conn) { bool SetHibernationMethod(DBusMessage* msg, DBusConnection* conn) {
DBusMessageIter args; DBusMessageIter args;
const char* member = dbus_message_get_member(msg); const char* member = dbus_message_get_member(msg);
char* method = NULL;
// read the arguments // read the arguments
if (!dbus_message_iter_init(msg, &args)) { if (!dbus_message_iter_init(msg, &args)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: no arguments supplied\n", member); fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: no arguments supplied\n", member);
return false;
} }
else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) { else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) {
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: argument not string\n", member); fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: argument not string\n", member);
return false;
} }
else { char* method = NULL;
dbus_message_iter_get_basic(&args, &method); dbus_message_iter_get_basic(&args, &method);
}
// set hibernation method // set hibernation method
if (method) { if (method) {
reply_SetGivenPath(msg, conn, "/sys/power/disk", method); return setGivenPath("/sys/power/disk", method);
} }
else { else {
reply_Bool(msg, conn, false); return false;
} }
} }
@ -807,26 +728,51 @@ void listen() {
// check this is a method call for the right interface & method // check this is a method call for the right interface & method
if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.CPUGovernor", "CanSetCPUGovernor")) { if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.CPUGovernor", "CanSetCPUGovernor")) {
reply_CanSetCPUGovernor(msg, conn); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.cpugovernor.setcpugovernor");
if (result) {
result = canSetCPUGovernor(msg, conn);
}
replyBool(msg, conn, result);
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.CPUGovernor", "SetCPUGovernor")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.CPUGovernor", "SetCPUGovernor")) {
reply_SetCPUGovernor(msg, conn); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.cpugovernor.setcpugovernor");
if (!result) {
error_PolkitAccessDenied(msg, conn);
}
else {
result = false;
if (canSetCPUGovernor(msg, conn)) {
result = setCPUGovernor(msg, conn);
}
replyBool(msg, conn, result);
}
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Brightness", "CanSetBrightness")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Brightness", "CanSetBrightness")) {
reply_CanSetBrightness(msg, conn); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.brightness.setbrightness");
if (result) {
result = CanSetBrightness(msg, conn);
}
replyBool(msg, conn, result);
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Brightness", "SetBrightness")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Brightness", "SetBrightness")) {
reply_SetBrightness(msg, conn); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.brightness.setbrightness");
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanFreeze")) {
bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.freeze");
if (!result) { if (!result) {
error_PolkitAccessDenied(msg, conn); error_PolkitAccessDenied(msg, conn);
} }
else { else {
result = false;
if (CanSetBrightness(msg, conn)) {
result = SetBrightness(msg, conn);
}
replyBool(msg, conn, result);
}
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanFreeze")) {
bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.freeze");
if (result) {
result = CanSetPowerState("freeze", NULL, NULL) || CanSetPowerState("mem", NULL, "s2idle"); result = CanSetPowerState("freeze", NULL, NULL) || CanSetPowerState("mem", NULL, "s2idle");
reply_Bool(msg, conn, result);
} }
replyBool(msg, conn, result);
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Freeze")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Freeze")) {
bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.freeze"); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.freeze");
@ -841,18 +787,15 @@ void listen() {
else if (CanSetPowerState("mem", NULL, "s2idle")) { else if (CanSetPowerState("mem", NULL, "s2idle")) {
result = SetPowerState("mem", NULL, "s2idle"); result = SetPowerState("mem", NULL, "s2idle");
} }
reply_Bool(msg, conn, result); replyBool(msg, conn, result);
} }
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanStandby")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanStandby")) {
bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.standby"); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.standby");
if (!result) { if (result) {
error_PolkitAccessDenied(msg, conn);
}
else {
result = CanSetPowerState("standby", NULL, NULL) || CanSetPowerState("mem", NULL, "shallow"); result = CanSetPowerState("standby", NULL, NULL) || CanSetPowerState("mem", NULL, "shallow");
reply_Bool(msg, conn, result);
} }
replyBool(msg, conn, result);
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Standby")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Standby")) {
bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.standby"); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.standby");
@ -867,19 +810,16 @@ void listen() {
else if (CanSetPowerState("mem", NULL, "shallow")) { else if (CanSetPowerState("mem", NULL, "shallow")) {
result = SetPowerState("mem", NULL, "shallow"); result = SetPowerState("mem", NULL, "shallow");
} }
reply_Bool(msg, conn, result); replyBool(msg, conn, result);
} }
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSuspend")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSuspend")) {
bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.suspend"); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.suspend");
if (!result) { if (result) {
error_PolkitAccessDenied(msg, conn);
}
else {
result = (CanSetPowerState("mem", NULL, NULL) && access("/sys/power/mem_sleep", R_OK) != 0) || result = (CanSetPowerState("mem", NULL, NULL) && access("/sys/power/mem_sleep", R_OK) != 0) ||
CanSetPowerState("mem", NULL, "deep"); CanSetPowerState("mem", NULL, "deep");
reply_Bool(msg, conn, result);
} }
replyBool(msg, conn, result);
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Suspend")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Suspend")) {
bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.suspend"); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.suspend");
@ -894,18 +834,15 @@ void listen() {
else if (CanSetPowerState("mem", NULL, "deep")) { else if (CanSetPowerState("mem", NULL, "deep")) {
result = SetPowerState("mem", NULL, "deep"); result = SetPowerState("mem", NULL, "deep");
} }
reply_Bool(msg, conn, result); replyBool(msg, conn, result);
} }
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanHybridSuspend")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanHybridSuspend")) {
bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.hybridsuspend"); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.hybridsuspend");
if (!result) { if (result) {
error_PolkitAccessDenied(msg, conn);
}
else {
result = CanSetPowerState("disk", "suspend", NULL); result = CanSetPowerState("disk", "suspend", NULL);
reply_Bool(msg, conn, result);
} }
replyBool(msg, conn, result);
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "HybridSuspend")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "HybridSuspend")) {
bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.hybridsuspend"); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.hybridsuspend");
@ -913,19 +850,19 @@ void listen() {
error_PolkitAccessDenied(msg, conn); error_PolkitAccessDenied(msg, conn);
} }
else { else {
result = SetPowerState("disk", "suspend", NULL); result = false;
reply_Bool(msg, conn, result); if (CanSetPowerState("disk", "suspend", NULL)) {
result = SetPowerState("disk", "suspend", NULL);
}
replyBool(msg, conn, result);
} }
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanHibernate")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanHibernate")) {
bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.hibernate"); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.hibernate");
if (!result) { if (result) {
error_PolkitAccessDenied(msg, conn);
}
else {
result = CanSetPowerState("disk", "shutdown", NULL) || CanSetPowerState("disk", "platform", NULL); result = CanSetPowerState("disk", "shutdown", NULL) || CanSetPowerState("disk", "platform", NULL);
reply_Bool(msg, conn, result);
} }
replyBool(msg, conn, result);
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Hibernate")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Hibernate")) {
bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.hibernate"); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.hibernate");
@ -940,14 +877,28 @@ void listen() {
else if (CanSetPowerState("disk", "platform", NULL)) { else if (CanSetPowerState("disk", "platform", NULL)) {
result = SetPowerState("disk", "platform", NULL); result = SetPowerState("disk", "platform", NULL);
} }
reply_Bool(msg, conn, result); replyBool(msg, conn, result);
} }
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSetHibernationMethod")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSetHibernationMethod")) {
reply_CanSetHibernationMethod(msg, conn); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.sethibernationmethod");
if (result) {
result = CanSetHibernationMethod(msg, conn);
}
replyBool(msg, conn, result);
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "SetHibernationMethod")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "SetHibernationMethod")) {
reply_SetHibernationMethod(msg, conn); bool result = checkPolKitAuthorization(msg, "org.trinitydesktop.hardwarecontrol.power.sethibernationmethod");
if (!result) {
error_PolkitAccessDenied(msg, conn);
}
else {
result = false;
if (CanSetHibernationMethod(msg, conn)) {
result = SetHibernationMethod(msg, conn);
}
replyBool(msg, conn, result);
}
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.InputEvents", "GetProvidedSwitches")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.InputEvents", "GetProvidedSwitches")) {
reply_InputEventsGetSwitches(msg, conn, false); reply_InputEventsGetSwitches(msg, conn, false);

Loading…
Cancel
Save