Skip to content

Commit

Permalink
Add support for shutdown hibernate mode
Browse files Browse the repository at this point in the history
For the folks, who get into trouble using the default `platform`
hibernate mode, due to various kernel / ACPI / firmware bugs.
  • Loading branch information
xdom committed Mar 16, 2024
1 parent 9fd2271 commit e782663
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 7 additions & 3 deletions zzz.8.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ zzz, ZZZ - suspend or hibernate your computer

== SYNOPSIS

*zzz* [-v] [-n|s|S|z|Z|H|R|V|h] +
*ZZZ* [-v] [-n|s|S|z|Z|H|R|V|h]
*zzz* [-v] [-n|s|S|z|Z|H|X|R|V|h] +
*ZZZ* [-v] [-n|s|S|z|Z|H|X|R|V|h]


== DESCRIPTION
Expand Down Expand Up @@ -41,6 +41,10 @@ This is the default for *ZZZ*.
Enter hibernate to disk mode and suspend.
This is also know as suspend-hybrid.

*-X*::
Enter hibernate to disk mode and shutdown.
This can be used when ACPI S4 mode causes issues.

*-R*::
Enter hibernate to disk mode and reboot.
This can be used to switch operating systems.
Expand Down Expand Up @@ -82,7 +86,7 @@ ZZZ_MODE::
The selected suspend mode; one of "`hibernate`", "`noop`", "`standby`", or "`suspend`".

ZZZ_HIBERNATE_MODE::
The selected hibernate mode: "`platform`", "`reboot`", or "`suspend`".
The selected hibernate mode: "`platform`", "`reboot`", "`shutdown`", or "`suspend`".


== EXIT CODES
Expand Down
10 changes: 8 additions & 2 deletions zzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
extern char **environ;

static const char *HELP_MSG =
"Usage: " PROGNAME " [-v] [-n|s|S|z|Z|H|R|V|h]\n"
"Usage: " PROGNAME " [-v] [-n|s|S|z|Z|H|X|R|V|h]\n"
"\n"
"Suspend or hibernate the system.\n"
"\n"
Expand All @@ -82,6 +82,7 @@ static const char *HELP_MSG =
" -z Suspend to RAM (ACPI S3). [default for zzz(8)]\n"
" -Z Hibernate to disk & power off (ACPI S4). [default for ZZZ(8)]\n"
" -H Hibernate to disk & suspend (aka suspend-hybrid).\n"
" -X Hibernate to disk & shutdown.\n"
" -R Hibernate to disk & reboot.\n"
" -v Be verbose.\n"
" -V Print program name & version and exit.\n"
Expand Down Expand Up @@ -313,7 +314,7 @@ int main (int argc, char **argv) {

int optch;
opterr = 0; // don't print implicit error message on unrecognized option
while ((optch = getopt(argc, argv, "nsSzHRZvhV")) != -1) {
while ((optch = getopt(argc, argv, "nsSzHRXZvhV")) != -1) {
switch (optch) {
case -1:
break;
Expand Down Expand Up @@ -343,6 +344,11 @@ int main (int argc, char **argv) {
sleep_state = "disk";
hibernate_mode = "reboot";
break;
case 'X':
zzz_mode = "hibernate";
sleep_state = "disk";
hibernate_mode = "shutdown";
break;
case 'Z':
zzz_mode = "hibernate";
sleep_state = "disk";
Expand Down

0 comments on commit e782663

Please sign in to comment.