chiark / gitweb /
loginctl: don't show [UACCESS] info in device tree
[elogind.git] / src / login / logind-action.c
index bd5664e90539bab48983fed5d8977690c3297da2..a796ebe9eca24ab2842f4c564eebac8d0dffd517 100644 (file)
@@ -19,6 +19,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <unistd.h>
+
 #include "conf-parser.h"
 #include "special.h"
 #include "dbus-common.h"
@@ -54,15 +56,37 @@ int manager_handle_action(
         DBusError error;
         int r;
         InhibitWhat inhibit_operation;
+        bool supported;
 
         assert(m);
 
+        if (m->action_job || m->delayed_unit) {
+                log_debug("Action already in progress, ignoring.");
+                return -EALREADY;
+        }
+
         /* If the key handling is turned off, don't do anything */
         if (handle == HANDLE_IGNORE) {
                 log_debug("Refusing operation, as it is turned off.");
                 return 0;
         }
 
+        if (handle == HANDLE_SUSPEND)
+                supported = can_sleep("mem") > 0;
+        else if (handle == HANDLE_HIBERNATE)
+                supported = can_sleep("disk") > 0;
+        else if (handle == HANDLE_HYBRID_SLEEP)
+                supported = can_sleep("disk") > 0 && can_sleep_disk("suspend") > 0;
+        else if (handle == HANDLE_KEXEC)
+                supported = access("/sbin/kexec", X_OK) >= 0;
+        else
+                supported = true;
+
+        if (!supported) {
+                log_warning("Requested operation not supported, ignoring.");
+                return -ENOTSUP;
+        }
+
         /* If the key handling is inhibited, don't do anything */
         if (inhibit_key > 0) {
                 if (manager_is_inhibited(m, inhibit_key, INHIBIT_BLOCK, NULL, true, false, 0)) {