View previous topic :: View next topic |
Author |
Message |
whitt Tux's lil' helper
Joined: 28 Dec 2020 Posts: 131
|
Posted: Sun Nov 07, 2021 10:42 pm Post subject: s2ram as user doesn't work |
|
|
i've been su'ing to root to suspend, but thought i may as well ask how i should do this as a user. when i try as user, this is what happens:
Code: | [user@machine ~ %] s2ram
KMS graphics driver is in use, skipping quirks.
/sys/power/state does not exist; what kind of ninja mutant machine is this? |
as root, the machine instantly suspends and comes right back when i hit the power button. i get the same KMS message, but everything is great...
as user, i get a snarky question that albeit entertaining, doesn't do what i want...
what now? |
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21607
|
Posted: Sun Nov 07, 2021 11:52 pm Post subject: |
|
|
As a user, what is the output of namei -l /sys/power/state ; ls -l /sys/power/? This may just be a confusing error message from a path that is reacting to the file being writable only to the root user. As far as I know, on modern systems, s2ram is usually little more than a wrapper to write to a sysfs file to tell the kernel to trigger suspend. |
|
Back to top |
|
|
whitt Tux's lil' helper
Joined: 28 Dec 2020 Posts: 131
|
Posted: Mon Nov 08, 2021 12:43 am Post subject: |
|
|
Code: | [user@machine ~ %] namei -l /sys/power/state ; ls -l /sys/power/
f: /sys/power/state
drwxr-xr-x root root /
dr-xr-xr-x root root sys
drwxr-xr-x root root power
-rw-r--r-- root root state
total 0
-rw-r--r-- 1 root root 4096 Nov 7 19:43 disk
-rw-r--r-- 1 root root 4096 Nov 7 19:43 image_size
-rw-r--r-- 1 root root 4096 Nov 7 19:43 mem_sleep
-rw-r--r-- 1 root root 4096 Nov 7 19:43 pm_async
-rw-r--r-- 1 root root 4096 Nov 7 19:43 pm_debug_messages
-rw-r--r-- 1 root root 4096 Nov 7 19:43 pm_freeze_timeout
-rw-r--r-- 1 root root 4096 Nov 7 19:43 pm_print_times
-rw-r--r-- 1 root root 4096 Nov 7 19:43 pm_test
-rw-r--r-- 1 root root 4096 Nov 7 19:43 pm_trace
-r--r--r-- 1 root root 4096 Nov 7 19:43 pm_trace_dev_match
-r--r--r-- 1 root root 4096 Nov 7 19:43 pm_wakeup_irq
-rw-r--r-- 1 root root 4096 Nov 7 19:43 reserved_size
-rw-r--r-- 1 root root 4096 Nov 7 19:43 resume
-rw-r--r-- 1 root root 4096 Nov 7 19:43 resume_offset
-rw-r--r-- 1 root root 4096 Nov 7 08:25 state
drwxr-xr-x 2 root root 0 Nov 7 19:43 suspend_stats
-rw-r--r-- 1 root root 4096 Nov 7 19:43 sync_on_suspend
-rw-r--r-- 1 root root 4096 Nov 7 19:43 wakeup_count |
|
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21607
|
Posted: Mon Nov 08, 2021 12:53 am Post subject: |
|
|
Those permissions look normal. Looking at the source, I see that my speculation above was correct: s2ram.c: | FILE *f = fopen("/sys/power/state", "w");
if (!f) {
printf("/sys/power/state does not exist; what kind of ninja mutant machine is this?\n");
return ENODEV;
}
| If opening the file fails, you get that error. The error wrongly states it is because the file does not exist, when in fact it can be any error at all. Perhaps the author never expected anyone would run s2ram without the permission to do its job.
Looping back to your initial question - what now? You cannot use s2ram to suspend the system as a regular user. The kernel does not permit unprivileged users to open the control file for writing. |
|
Back to top |
|
|
whitt Tux's lil' helper
Joined: 28 Dec 2020 Posts: 131
|
Posted: Thu Nov 25, 2021 1:29 am Post subject: |
|
|
alright - sorry for late response, but now i've got to ask, how is a normal user is supposed to suspend?
right now i just `su` and s2ram... just seems like there should be a way to script something around it.
sorry if it's a dumb question, it just seems like a user should be able to suspend w/out su'ing. i su all the time for other stuff, but assumed this was one where i was breaking the rules and should learn "the right way to do it" instead.
is there really no right way to do this? |
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21607
|
Posted: Thu Nov 25, 2021 1:59 am Post subject: |
|
|
Normal users should not be able to suspend, because if they can, any program run by any user could suspend the system at any time, including while a administrator was trying to use the system. On systems where an administrator wants unprivileged users to be able to suspend the system, that administrator, exercising the privileges of root, can grant specific users the ability to suspend the system, by directing some privileged component to allow it when requested by the user. This could be password-less sudo s2ram, a dedicated setuid program that runs s2ram, or something through (e)logind. I know loginctl suspend purports to let ordinary users suspend the system. This always seemed like a terrible idea to me, so I've never looked into whether it can be implemented securely. I would hope that it only allows console users to suspend, but even there, I don't want my browser suspending the system just because I happen to be running it on the console. |
|
Back to top |
|
|
|