-
Notifications
You must be signed in to change notification settings - Fork 4
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
Enabling hibernation-setup-tool, hibernate and resume services #7
base: main
Are you sure you want to change the base?
Conversation
|
||
static bool ensure_systemd_service_enabled(char *dest_dir){ | ||
const char *execfn = (const char *)getauxval(AT_EXECFN); | ||
const char *usr_sbin_default = "/usr/sbin", *systemd_dir_default = "/lib/systemd/system"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also usr/lib/systemd/system based on the distro?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Ubuntu /usr/lib and /lib and different directories. On Ubuntu, /usr/lib is a user-based directory to store things that require access to libraries. The /lib folder is the actual place for essential standard libraries. We need to put our services in this directory in order to access the targets we need (hibernate.target) and for systemd to recognize us as a legitimate service.
After testing on Debian, Rhel and CentOS, the /usr/lib and /lib directories are identical for each of them. On each of them lib is a symbolic link pointing to /usr/lib. In other words, /lib and /usr/lib go to the same place.
/lib is preferred because it includes ubuntu and so works on all distros.
Additional testing: On Debian tool executes without any issues.
However, Rhel has the additional challenges of not having enough space on root "/" partition no matter how much space it's created with. This causes the free space check to prevent tool from running, and if that check is removed, it causes insufficient space error upon allocating hibfile.
…d created. Cold boot bug resolved.
…-tool into dev/t-isehgal/link-bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found no obvious issue, so this looks good to me.
@pavanrachapudy: please take a closer look. :-)
log_info("This is fine, but couldn't remove %s: %s", real_path, strerror(errno)); | ||
} | ||
cold_booted = true; | ||
notify_vm_host(HOST_VM_NOTIFY_FAILED_RESUME_FROM_HIBERNATION); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for my understanding - are we coming to conclusion that it is cold boot scenario even if there is some issue in creating the link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use the symbolic link (/etc/hibernation-setup-tool.last_hibernation) to find the temporary file. If, after resuming from hibernate, we cannot read from that symbolic link we assume a cold boot. Keep in mind this symbolic link gets created just before hibernating (in the pre hook). So it should exist in the post hook, no room for user intervention.
hibernation-setup-tool.c
Outdated
return true; | ||
} | ||
|
||
static bool enable_systemd_service(const char *dir_parent, char *service_file_name, char *systemd_dir) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename the method since it is doing much more than just enabling a service?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to link_and_enable_systemd_service. I think that should be a bit more descriptive. This function is essentially hard linking the service file into /lib/systemd/system and then running enable on it.
@@ -0,0 +1,10 @@ | |||
[Unit] | |||
Description=User resume actions | |||
After=hibernate.target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean it gets triggered only after resume or after cold boot as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This service only gets triggered after resume. I have tested this very thoroughly.
Currently systemd service hibernation-setup-tool relies on a make file instructions to create folders to store the service and executable.
Lines from Makefile:
These make instructions currently do not get executed by the extension. This should get executed by the tool for:
In addition hibernation-setup-tool service is not enabled. It is simply ran once by extension. If we are to enable this service to run on reboot, we must set systemctl enable on the service, which is done here.
Finally, if a user wants to set a custom destination directory we support that here with optional arguments. Currently arguments passed are not parsed but grabbed arbitrarily from argv, this isn't good for tool security, readability, robustness and extensibility (as new arguments are to be added). So to add this new argument (destination directory) and for future arguments I added argument parsing. PR for argument parsing: #13
In addition to the above, the code has now implemented sleep hook service files: hibernate.service and resume.service. And enabled these services. These services now run pre and post hooks, before hibernate and after resume. The pre and post hooks tool code these services rely on have been fixed. One so that they run without failure, and two so that they log whether hibernate/resume was successful or not to syslog. PR for fixing hooks: #11