From b75d66e7dfe189460a45c631783ad5c384a2e93f Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 18 Jul 2012 07:23:05 +0400 Subject: [PATCH] itimers: Don't write itimer_entry from parasite Same as with previous patch -- we have to pull image-independent entry out of the victim task to be able to use protobuf library for encoding. Signed-off-by: Pavel Emelyanov --- cr-dump.c | 1 + include/parasite.h | 6 ++++++ parasite-syscall.c | 54 ++++++++++++++++++++++++---------------------- parasite.c | 50 +++++++----------------------------------- 4 files changed, 43 insertions(+), 68 deletions(-) diff --git a/cr-dump.c b/cr-dump.c index 8b59b4a24..13221afb2 100644 --- a/cr-dump.c +++ b/cr-dump.c @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/include/parasite.h b/include/parasite.h index 6c81b9fa1..0e0c87cfc 100644 --- a/include/parasite.h +++ b/include/parasite.h @@ -52,6 +52,12 @@ struct parasite_dump_sa_args { rt_sigaction_t sas[SIGMAX]; }; +struct parasite_dump_itimers_args { + struct itimerval real; + struct itimerval virt; + struct itimerval prof; +}; + /* * Misc sfuff, that is too small for separate file, but cannot * be read w/o using parasite diff --git a/parasite-syscall.c b/parasite-syscall.c index c8aa94c4f..9838f1527 100644 --- a/parasite-syscall.c +++ b/parasite-syscall.c @@ -349,30 +349,6 @@ static int parasite_prep_file(int fd, struct parasite_ctl *ctl) return 0; } -static int parasite_file_cmd(char *what, int cmd, int type, - struct parasite_ctl *ctl, - struct cr_fdset *cr_fdset) -{ - int ret = -1, fd; - - pr_info("\n"); - pr_info("Dumping %s (pid: %d)\n", what, ctl->pid); - pr_info("----------------------------------------\n"); - - fd = fdset_fd(cr_fdset, type); - ret = parasite_prep_file(fd, ctl); - if (ret < 0) - goto out; - - ret = parasite_execute(cmd, ctl, NULL, 0); - - fchmod(fd, CR_FD_PERM); -out: - pr_info("----------------------------------------\n"); - - return ret; -} - static int parasite_init(struct parasite_ctl *ctl, pid_t pid) { struct parasite_init_args args = { }; @@ -479,10 +455,36 @@ int parasite_dump_sigacts_seized(struct parasite_ctl *ctl, struct cr_fdset *cr_f return 0; } +static int dump_one_timer(struct itimerval *v, int fd) +{ + struct itimer_entry ie; + + ie.isec = v->it_interval.tv_sec; + ie.iusec = v->it_interval.tv_usec; + ie.vsec = v->it_value.tv_sec; + ie.vusec = v->it_value.tv_sec; + + return write_img(fd, &ie); +} + int parasite_dump_itimers_seized(struct parasite_ctl *ctl, struct cr_fdset *cr_fdset) { - return parasite_file_cmd("timers", PARASITE_CMD_DUMP_ITIMERS, - CR_FD_ITIMERS, ctl, cr_fdset); + struct parasite_dump_itimers_args args; + int ret, fd; + + ret = parasite_execute(PARASITE_CMD_DUMP_ITIMERS, ctl, &args, sizeof(args)); + if (ret < 0) + return ret; + + fd = fdset_fd(cr_fdset, CR_FD_ITIMERS); + + ret = dump_one_timer(&args.real, fd); + if (!ret) + ret = dump_one_timer(&args.virt, fd); + if (!ret) + ret = dump_one_timer(&args.prof, fd); + + return ret; } int parasite_dump_misc_seized(struct parasite_ctl *ctl, struct parasite_dump_misc *misc) diff --git a/parasite.c b/parasite.c index 7decc64f9..b70110af2 100644 --- a/parasite.c +++ b/parasite.c @@ -280,53 +280,19 @@ static int dump_sigact(struct parasite_dump_sa_args *da) return ret; } -static int dump_itimer(int which, int fd) +static int dump_itimers(struct parasite_dump_itimers_args *args) { - struct itimerval val; int ret; - struct itimer_entry ie; - ret = sys_getitimer(which, &val); - if (ret < 0) { - sys_write_msg("getitimer failed\n"); - return ret; - } + ret = sys_getitimer(ITIMER_REAL, &args->real); + if (!ret) + ret = sys_getitimer(ITIMER_VIRTUAL, &args->virt); + if (!ret) + ret = sys_getitimer(ITIMER_PROF, &args->prof); - ie.isec = val.it_interval.tv_sec; - ie.iusec = val.it_interval.tv_usec; - ie.vsec = val.it_value.tv_sec; - ie.vusec = val.it_value.tv_sec; - - ret = sys_write_safe(fd, &ie, sizeof(ie)); if (ret) - return ret; + sys_write_msg("getitimer failed\n"); - return 0; -} - -static int dump_itimers() -{ - int fd; - int ret = -1; - - fd = recv_fd(tsock); - if (fd < 0) - return fd; - - ret = dump_itimer(ITIMER_REAL, fd); - if (ret < 0) - goto err_close; - - ret = dump_itimer(ITIMER_VIRTUAL, fd); - if (ret < 0) - goto err_close; - - ret = dump_itimer(ITIMER_PROF, fd); - if (ret < 0) - goto err_close; - -err_close: - sys_close(fd); return ret; } @@ -453,7 +419,7 @@ int __used parasite_service(unsigned long cmd, void *args) case PARASITE_CMD_DUMP_SIGACTS: return dump_sigact((struct parasite_dump_sa_args *)args); case PARASITE_CMD_DUMP_ITIMERS: - return dump_itimers(); + return dump_itimers((struct parasite_dump_itimers_args *)args); case PARASITE_CMD_DUMP_MISC: return dump_misc((struct parasite_dump_misc *)args); case PARASITE_CMD_DUMP_TID_ADDR: