Commit 069bdd96 authored by Pavel Emelyanov's avatar Pavel Emelyanov

scripts: Move scripts code into separate sources

Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 5c265707
......@@ -15,6 +15,7 @@ obj-y += cr-show.o
obj-y += cr-check.o
obj-y += cr-dedup.o
obj-y += util.o
obj-y += action-scripts.o
obj-y += sysctl.o
obj-y += ptrace.o
obj-y += kcmp-ids.o
......
#include <unistd.h>
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include "cr_options.h"
#include "list.h"
#include "xmalloc.h"
#include "log.h"
#include "servicefd.h"
#include "cr-service.h"
#include "action-scripts.h"
int run_scripts(char *action)
{
struct script *script;
int ret = 0;
char image_dir[PATH_MAX];
pr_debug("Running %s scripts\n", action);
if (setenv("CRTOOLS_SCRIPT_ACTION", action, 1)) {
pr_perror("Can't set CRTOOLS_SCRIPT_ACTION=%s", action);
return -1;
}
sprintf(image_dir, "/proc/%ld/fd/%d", (long) getpid(), get_service_fd(IMG_FD_OFF));
if (setenv("CRTOOLS_IMAGE_DIR", image_dir, 1)) {
pr_perror("Can't set CRTOOLS_IMAGE_DIR=%s", image_dir);
return -1;
}
list_for_each_entry(script, &opts.scripts, node) {
if (script->path == SCRIPT_RPC_NOTIFY) {
pr_debug("\tRPC\n");
ret |= send_criu_rpc_script(action, script->arg);
} else {
pr_debug("\t[%s]\n", script->path);
ret |= system(script->path);
}
}
unsetenv("CRTOOLS_SCRIPT_ACTION");
return ret;
}
int add_script(char *path, int arg)
{
struct script *script;
script = xmalloc(sizeof(struct script));
if (script == NULL)
return 1;
script->path = optarg;
script->arg = arg;
list_add(&script->node, &opts.scripts);
return 0;
}
......@@ -72,6 +72,7 @@
#include "plugin.h"
#include "irmap.h"
#include "sysfs_parse.h"
#include "action-scripts.h"
#include "asm/dump.h"
......
......@@ -71,6 +71,7 @@
#include "cgroup.h"
#include "timerfd.h"
#include "file-lock.h"
#include "action-scripts.h"
#include "parasite-syscall.h"
......
......@@ -25,6 +25,7 @@
#include "net.h"
#include "mount.h"
#include "cgroup.h"
#include "action-scripts.h"
#include "setproctitle.h"
......@@ -297,17 +298,9 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
}
}
if (req->notify_scripts) {
struct script *script;
script = xmalloc(sizeof(struct script));
if (script == NULL)
return -1;
script->path = SCRIPT_RPC_NOTIFY;
script->arg = sk;
list_add(&script->node, &opts.scripts);
}
if (req->notify_scripts &&
add_script(SCRIPT_RPC_NOTIFY, sk))
return -1;
for (i = 0; i < req->n_veths; i++) {
if (veth_pair_add(req->veths[i]->if_in, req->veths[i]->if_out))
......
......@@ -36,6 +36,7 @@
#include "plugin.h"
#include "mount.h"
#include "cgroup.h"
#include "action-scripts.h"
#include "setproctitle.h"
......@@ -310,16 +311,9 @@ int main(int argc, char *argv[], char *envp[])
}
break;
case 1049:
{
struct script *script;
script = xmalloc(sizeof(struct script));
if (script == NULL)
return 1;
if (add_script(optarg, 0))
return 1;
script->path = optarg;
list_add(&script->node, &opts.scripts);
}
break;
case 1050:
opts.use_page_server = true;
......
#ifndef __CR_ACTION_SCRIPTS_H__
#define __CR_ACTION_SCRIPTS_H__
struct script {
struct list_head node;
char *path;
int arg;
};
#define SCRIPT_RPC_NOTIFY (char *)0x1
extern int add_script(char *path, int arg);
extern int run_scripts(char *action);
#endif /* __CR_ACTION_SCRIPTS_H__ */
......@@ -5,14 +5,6 @@
#include "list.h"
struct script {
struct list_head node;
char *path;
int arg;
};
#define SCRIPT_RPC_NOTIFY (char *)0x1
/*
* CPU capability options.
*/
......
......@@ -261,7 +261,6 @@ static inline int read_img_str(int fd, char **pstr, int size)
extern void *shmalloc(size_t bytes);
extern void shfree_last(void *ptr);
extern int run_scripts(char *action);
extern int cr_system(int in, int out, int err, char *cmd, char *const argv[]);
extern int cr_daemon(int nochdir, int noclose);
......
......@@ -18,6 +18,7 @@
#include "tun.h"
#include "util-pie.h"
#include "plugin.h"
#include "action-scripts.h"
#include "protobuf.h"
#include "protobuf/netdev.pb-c.h"
......
#define _XOPEN_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdbool.h>
#include <limits.h>
#include <signal.h>
#include <limits.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
......@@ -457,39 +454,6 @@ void shfree_last(void *ptr)
rst_mem_free_last(RM_SHARED);
}
int run_scripts(char *action)
{
struct script *script;
int ret = 0;
char image_dir[PATH_MAX];
pr_debug("Running %s scripts\n", action);
if (setenv("CRTOOLS_SCRIPT_ACTION", action, 1)) {
pr_perror("Can't set CRTOOLS_SCRIPT_ACTION=%s", action);
return -1;
}
sprintf(image_dir, "/proc/%ld/fd/%d", (long) getpid(), get_service_fd(IMG_FD_OFF));
if (setenv("CRTOOLS_IMAGE_DIR", image_dir, 1)) {
pr_perror("Can't set CRTOOLS_IMAGE_DIR=%s", image_dir);
return -1;
}
list_for_each_entry(script, &opts.scripts, node) {
if (script->path == SCRIPT_RPC_NOTIFY) {
pr_debug("\tRPC\n");
ret |= send_criu_rpc_script(action, script->arg);
} else {
pr_debug("\t[%s]\n", script->path);
ret |= system(script->path);
}
}
unsetenv("CRTOOLS_SCRIPT_ACTION");
return ret;
}
#define DUP_SAFE(fd, out) \
({ \
int ret__; \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment