[CRIU] [PATCH 3/3] service: use setproctitle
Ruslan Kuprieiev
kupruser at gmail.com
Wed Aug 6 12:56:24 PDT 2014
Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
cr-service.c | 20 ++++++++++++++++++++
crtools.c | 6 +++++-
2 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/cr-service.c b/cr-service.c
index 9504c14..79201e0 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -25,6 +25,8 @@
#include "net.h"
#include "mount.h"
+#include "setproctitle.h"
+
unsigned int service_sk_ino = -1;
static int recv_criu_msg(int socket_fd, CriuReq **msg)
@@ -164,6 +166,8 @@ int send_criu_rpc_script(char *script, int fd)
return 0;
}
+static char images_dir[PATH_MAX];
+
static int setup_opts_from_req(int sk, CriuOpts *req)
{
struct ucred ids;
@@ -200,6 +204,12 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
return -1;
}
+ /* get full path to images_dir to use in process title */
+ if (readlink(images_dir_path, images_dir, PATH_MAX) == -1) {
+ pr_perror("Can't readlink %s", images_dir_path);
+ return -1;
+ }
+
/* chdir to work dir */
if (req->has_work_dir_fd)
sprintf(work_dir_path, "/proc/%d/fd/%d", ids.pid, req->work_dir_fd);
@@ -315,6 +325,8 @@ static int dump_using_req(int sk, CriuOpts *req)
if (setup_opts_from_req(sk, req))
goto exit;
+ setproctitle("dump --rpc -t %d -D %s", req->pid, images_dir);
+
/*
* FIXME -- cr_dump_tasks() may return code from custom
* scripts, that can be positive. However, right now we
@@ -351,6 +363,8 @@ static int restore_using_req(int sk, CriuOpts *req)
if (setup_opts_from_req(sk, req))
goto exit;
+ setproctitle("restore --rpc -D %s", images_dir);
+
if (cr_restore_tasks())
goto exit;
@@ -388,6 +402,8 @@ static int check(int sk)
resp.type = CRIU_REQ_TYPE__CHECK;
+ setproctitle("check --rpc");
+
/* Check only minimal kernel support */
opts.check_ms_kernel = true;
@@ -414,6 +430,8 @@ static int pre_dump_using_req(int sk, CriuOpts *req)
if (setup_opts_from_req(sk, req))
goto cout;
+ setproctitle("pre-dump --rpc -t %d -D %s", req->pid, images_dir);
+
if (cr_pre_dump_tasks(req->pid))
goto cout;
@@ -477,6 +495,8 @@ static int start_page_server_req(int sk, CriuOpts *req)
if (setup_opts_from_req(sk, req))
goto out;
+ setproctitle("page-server --rpc --address %s --port %hu", opts.addr, opts.ps_port);
+
pr_debug("Starting page server\n");
ret = cr_page_server(true);
diff --git a/crtools.c b/crtools.c
index 28d343e..e0ca36d 100644
--- a/crtools.c
+++ b/crtools.c
@@ -36,6 +36,8 @@
#include "plugin.h"
#include "mount.h"
+#include "setproctitle.h"
+
struct cr_options opts;
void init_opts(void)
@@ -116,7 +118,7 @@ Esyntax:
return -1;
}
-int main(int argc, char *argv[])
+int main(int argc, char *argv[], char *envp[])
{
pid_t pid = 0, tree_id = 0;
int ret = -1;
@@ -176,6 +178,8 @@ int main(int argc, char *argv[])
if (restrict_uid(getuid(), getgid()))
return 1;
+ setproctitle_init(argc, argv, envp);
+
if (argc < 2)
goto usage;
--
1.9.1
More information about the CRIU
mailing list