Factor out resume in a subdirectory - no functional changes. mv resume.c resume/resumelib.c Add an standalone minimal resume.c, which calls resume() from resumelib. resulting resume bin is small: ls -l /usr/lib/klibc/bin/resume -rwxr-xr-x 1 root root 2904 2006-07-11 09:18 /usr/lib/klibc/bin/resume tested with several resume/suspend cycles. as a bonus alphabetically sort the include and the clean dir Signed-off-by: maximilian attems <maks at sternwelten.at> --- applies after the whitespace the kinit/resume.c split patches. b/usr/kinit/Kbuild | 13 +++--- b/usr/kinit/resume/Kbuild | 28 +++++++++++++ b/usr/kinit/resume/resume.c | 27 +++++++++++++ b/usr/kinit/resume/resume.h | 7 +++ b/usr/kinit/resume/resumelib.c | 84 +++++++++++++++++++++++++++++++++++++++++ usr/kinit/resume.c | 84 ----------------------------------------- usr/kinit/resume.h | 7 --- 7 files changed, 154 insertions(+), 96 deletions(-) diff --git a/usr/kinit/Kbuild b/usr/kinit/Kbuild index 0000e89..b366ecb 100644 --- a/usr/kinit/Kbuild +++ b/usr/kinit/Kbuild @@ -6,25 +6,28 @@ static-y := kinit kinit-y := kinit.o do_mounts.o ramdisk_load.o initrd.o kinit-y += name_to_dev.o devname.o kinit-y += getarg.o getintfile.o open.o readfile.o xpio.o -kinit-y += do_mounts_md.o do_mounts_mtd.o nfsroot.o resume.o +kinit-y += do_mounts_md.o do_mounts_mtd.o nfsroot.o kinit-y += ipconfig/ kinit-y += nfsmount/ kinit-y += run-init/ kinit-y += fstype/ +kinit-y += resume/ shared-y := kinit.shared kinit.shared-y := $(kinit-y) # Additional include paths files -KLIBCCFLAGS += -I$(srctree)/$(src)/ipconfig \ +KLIBCCFLAGS += -I$(srctree)/$(src)/fstype \ + -I$(srctree)/$(src)/ipconfig \ -I$(srctree)/$(src)/nfsmount \ - -I$(srctree)/$(src)/run-init \ - -I$(srctree)/$(src)/fstype + -I$(srctree)/$(src)/resume \ + -I$(srctree)/$(src)/run-init + # Cleaning targets := kinit kinit.g kinit.shared kinit.shared.g -subdir- := ipconfig nfsmount run-init fstype +subdir- := fstype ipconfig nfsmount resume run-init # install binary diff --git a/usr/kinit/resume.c b/usr/kinit/resume.c deleted file mode 100644 index 952af96..0000000 --- a/usr/kinit/resume.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * resume.c - * - * Handle resume from suspend-to-disk - */ - -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <limits.h> -#include <sys/stat.h> -#include <sys/sysmacros.h> -#include <linux/config.h> /* For CONFIG_PM_STD_PARTITION */ - -#include "kinit.h" -#include "do_mounts.h" -#include "resume.h" - -#ifndef CONFIG_PM_STD_PARTITION -# define CONFIG_PM_STD_PARTITION "" -#endif - -int do_resume(int argc, char *argv[]) -{ - const char *resume_file = CONFIG_PM_STD_PARTITION; - const char *resume_arg; - - resume_arg = get_arg(argc, argv, "resume="); - resume_file = resume_arg ? resume_arg : resume_file; - /* No resume device specified */ - if (!resume_file[0]) - return 0; - - /* Fix: we either should consider reverting the device back to - ordinary swap, or (better) put that code into swapon */ - /* Noresume requested */ - if (get_flag(argc, argv, "noresume")) - return 0; - return resume(resume_file); -} - -int resume(const char *resume_file) -{ - char device_string[64]; - int powerfd = -1; - dev_t resume_device; - int len; - - resume_device = name_to_dev_t(resume_file); - - if (major(resume_device) == 0) { - fprintf(stderr, "Invalid resume device: %s\n", resume_file); - goto failure; - } - - if ((powerfd = open("/sys/power/resume", O_WRONLY)) < 0) - goto fail_r; - - len = snprintf(device_string, sizeof device_string, "%u:%u", - major(resume_device), minor(resume_device)); - - /* This should never happen */ - if (len >= sizeof device_string) - goto fail_r; - - DEBUG(("kinit: trying to resume from %s\n", resume_file)); - - if (write(powerfd, device_string, len) != len) - goto fail_r; - - /* Okay, what are we still doing alive... */ -failure: - if (powerfd >= 0) - close(powerfd); - fprintf(stderr, "Resume failed, doing normal boot...\n"); - return -1; - -fail_r: - fprintf(stderr, "Cannot write /sys/power/resume " - "(no software suspend kernel support?)\n"); - goto failure; -} diff --git a/usr/kinit/resume.h b/usr/kinit/resume.h deleted file mode 100644 index 04b8df8..0000000 --- a/usr/kinit/resume.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef RESUME_H -#define RESUME_H - -int do_resume(int argc, char *argv[]); -int resume(const char *resume_file); - -#endif /* RESUME_H */ diff --git a/usr/kinit/resume/Kbuild b/usr/kinit/resume/Kbuild new file mode 100644 index 0000000..cd0da12 --- /dev/null +++ b/usr/kinit/resume/Kbuild @@ -0,0 +1,28 @@ +# +# Kbuild file for resume +# + +static-y := static/resume +shared-y := shared/resume + +# common .o files +objs := resume.o resumelib.o ../getarg.o ../name_to_dev.o ../devname.o + +# TODO - do we want a stripped version +# TODO - do we want the static.g + shared.g directories? + +# Create built-in.o with all object files (used by kinit) +lib-y := $(objs) + +# Additional include paths files +KLIBCCFLAGS += -I$(srctree)/$(src)/.. + +# .o files used to built executables +static/resume-y := $(objs) +shared/resume-y := $(objs) + +# Cleaning +clean-dirs := static shared + +# install binary +install-y := $(shared-y) diff --git a/usr/kinit/resume/resume.c b/usr/kinit/resume/resume.c new file mode 100644 index 0000000..00e5405 --- /dev/null +++ b/usr/kinit/resume/resume.c @@ -0,0 +1,27 @@ +/* + * resume.c + * + * Handle resume from suspend-to-disk + */ + +#include <stdio.h> +#include <stdlib.h> + +#include "resume.h" + +char *progname; + +static __noreturn usage(void) +{ + fprintf(stderr, "Usage: %s /dev/<resumedevice>\n", progname); + exit(1); +} + +int main(int argc, char *argv[], char *envp[]) +{ + progname = argv[0]; + if (argc != 2) + usage(); + + return resume(argv[1]); +} diff --git a/usr/kinit/resume/resume.h b/usr/kinit/resume/resume.h new file mode 100644 index 0000000..04b8df8 --- /dev/null +++ b/usr/kinit/resume/resume.h @@ -0,0 +1,7 @@ +#ifndef RESUME_H +#define RESUME_H + +int do_resume(int argc, char *argv[]); +int resume(const char *resume_file); + +#endif /* RESUME_H */ diff --git a/usr/kinit/resume/resumelib.c b/usr/kinit/resume/resumelib.c new file mode 100644 index 0000000..2683a5d --- /dev/null +++ b/usr/kinit/resume/resumelib.c @@ -0,0 +1,84 @@ +/* + * resumelib.c + * + * Handle resume from suspend-to-disk + */ + +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <limits.h> +#include <sys/stat.h> +#include <sys/sysmacros.h> +#include <linux/config.h> /* For CONFIG_PM_STD_PARTITION */ + +#include "kinit.h" +#include "do_mounts.h" +#include "resume.h" + +#ifndef CONFIG_PM_STD_PARTITION +# define CONFIG_PM_STD_PARTITION "" +#endif + +int do_resume(int argc, char *argv[]) +{ + const char *resume_file = CONFIG_PM_STD_PARTITION; + const char *resume_arg; + + resume_arg = get_arg(argc, argv, "resume="); + resume_file = resume_arg ? resume_arg : resume_file; + /* No resume device specified */ + if (!resume_file[0]) + return 0; + + /* Fix: we either should consider reverting the device back to + ordinary swap, or (better) put that code into swapon */ + /* Noresume requested */ + if (get_flag(argc, argv, "noresume")) + return 0; + return resume(resume_file); +} + +int resume(const char *resume_file) +{ + char device_string[64]; + int powerfd = -1; + dev_t resume_device; + int len; + + resume_device = name_to_dev_t(resume_file); + + if (major(resume_device) == 0) { + fprintf(stderr, "Invalid resume device: %s\n", resume_file); + goto failure; + } + + if ((powerfd = open("/sys/power/resume", O_WRONLY)) < 0) + goto fail_r; + + len = snprintf(device_string, sizeof device_string, "%u:%u", + major(resume_device), minor(resume_device)); + + /* This should never happen */ + if (len >= sizeof device_string) + goto fail_r; + + DEBUG(("kinit: trying to resume from %s\n", resume_file)); + + if (write(powerfd, device_string, len) != len) + goto fail_r; + + /* Okay, what are we still doing alive... */ +failure: + if (powerfd >= 0) + close(powerfd); + fprintf(stderr, "Resume failed, doing normal boot...\n"); + return -1; + +fail_r: + fprintf(stderr, "Cannot write /sys/power/resume " + "(no software suspend kernel support?)\n"); + goto failure; +} -- maks