[systemd-devel] [RFC] [PATCHv3 3/3] resume-generator: add a generator for instantiating the resume unit.

Lennart Poettering lennart at poettering.net
Mon Aug 25 10:58:52 PDT 2014


On Mon, 25.08.14 02:16, Ivan Shapovalov (intelfx100 at gmail.com) wrote:

> +
> +static const char *arg_dest = "/tmp";
> +static char *arg_resume_dev = NULL;
> +
> +static int parse_proc_cmdline_item(const char *key, const char *value) {
> +        if (streq(key, "resume") && value) {
> +                free(arg_resume_dev);
> +                arg_resume_dev = strdup(value);
> +                if (!arg_resume_dev)
> +                        return log_oom();
> +                }
> +
> +        return 0;

There's something wrong with the indentation here...

> +}
> +
> +static int process_resume(void) {
> +        _cleanup_free_ char *name = NULL, *lnk = NULL;
> +
> +        name = unit_name_from_path_instance("systemd-resume", arg_resume_dev, ".service");
> +        if (!name)
> +                return log_oom();
> +
> +        lnk = strjoin(arg_dest, "/" SPECIAL_SYSINIT_TARGET ".wants/", name, NULL);
> +        if (!lnk)
> +                return log_oom();
> +
> +        mkdir_parents_label(lnk, 0755);
> +        if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-resume at .service", lnk) < 0) {
> +                log_error("Failed to create symlink %s: %m", lnk);
> +                return -errno;
> +        }
> +
> +        return 0;
> +}
> +
> +int main(int argc, char *argv[]) {
> +        int r = 0;
> +
> +        if (argc > 1 && argc != 4) {
> +                log_error("This program takes three or no arguments.");
> +                return EXIT_FAILURE;
> +        }
> +
> +        if (argc > 1)
> +                arg_dest = argv[1];
> +
> +        log_set_target(LOG_TARGET_SAFE);
> +        log_parse_environment();
> +        log_open();
> +
> +        umask(0022);
> +
> +        /* Don't even consider resuming outside of initramfs. */
> +        if (!in_initrd())
> +                return EXIT_SUCCESS;
> +
> +        if (parse_proc_cmdline(parse_proc_cmdline_item) < 0)
> +                return EXIT_FAILURE;
> +
> +        if (arg_resume_dev != NULL)
> +                r = process_resume();
> +
> +        free(arg_resume_dev);
> +
> +        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
> +}

Looks good otherwise!

One more question though, regarding the terminology. So far we used the
following terms:

    "suspend" → means suspend-to-ram
    "hibernate" → means suspend-to-disk
    "hybrid-sleep" → means both STR + STD combined
    "sleep" → a generic term for all of the above.

Now, I do wonder how we should call the operation when we come back from
the sleep states.

To me "resume" would probably most clearly be the reverse of "suspend",
but you actually are looking for the reverse of "hibernate" here. 

The reverse of "sleep" would be "wake" I figure...

On the kernel side the terminology for all of this is completely
random. Especially given that the input layer names some keys with the
precise opposite of what the PM layer calls the operations... But we
really should try to clean this up a bit when exposing this in
userspace...

So, dunno, what's the antonym of "hibernate"? SOmething like "thaw"
maybe? Any native english speakers with ideas?

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list