zzz.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. zzz - a program to imitate FreeBSD's `zzz` sleep utility for laptops, only
  3. that this one uses `loginctl` for the backend.
  4. USAGE: zzz
  5. Sleeps the system (sudo may be required depending on the user's rights)
  6. Note that in order for this program to work, you must have loginctl available
  7. in your system. If your distribution uses systemd (i.e. Debian/Ubuntu based,
  8. Fedora, Arch Linux, etc), it will include it by default. Other non-systemd
  9. distros can install the standalone elogind daemon instead.
  10. Copyright 2022- kzimmermann. All Rights reserved.
  11. This program is Free Software released under the terms and conditions of the
  12. GNU GPL v3. See https://gnu.org/licenses for more information
  13. */
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. int
  17. main(int argc, char* argv[])
  18. {
  19. char* stmt = "loginctl suspend";
  20. FILE* p;
  21. p = popen(stmt, "r");
  22. if (p == NULL) {
  23. printf("Error: `loginctl` not found.\n");
  24. printf("You must have loginctl installed (see elogind) in order to suspend your machine in a modern way\n");
  25. return 1;
  26. }
  27. pclose(p);
  28. return 0;
  29. }