Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for shutdown hibernate mode #7

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading