[CRIU] [PATCH] service: use setproctitle(), v2

Ruslan Kuprieiev kupruser at gmail.com
Thu Feb 20 01:51:21 PST 2014


Enhance ps output.

Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 cr-service.c | 22 ++++++++++++++++++++++
 crtools.c    |  5 +++++
 2 files changed, 27 insertions(+)

diff --git a/cr-service.c b/cr-service.c
index 9688b76..bf4f653 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -23,6 +23,7 @@
 #include "sd-daemon.h"
 #include "page-xfer.h"
 #include "net.h"
+#include "setproctitle.h"
 
 unsigned int service_sk_ino = -1;
 
@@ -153,6 +154,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;
@@ -188,6 +191,12 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
 		return -1;
 	}
 
+	/* get full path to images_dir to use it 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);
@@ -283,6 +292,8 @@ static int dump_using_req(int sk, CriuOpts *req)
 	if (setup_opts_from_req(sk, req))
 		goto exit;
 
+	setproctitle("dump --rpc --pid %d --images-dir %s", req->pid, images_dir);
+
 	/*
 	 * FIXME -- cr_dump_tasks() may return code from custom
 	 * scripts, that can be positive. However, right now we
@@ -319,6 +330,8 @@ static int restore_using_req(int sk, CriuOpts *req)
 	if (setup_opts_from_req(sk, req))
 		goto exit;
 
+	setproctitle("restore --rpc --images-dir %s", images_dir);
+
 	if (cr_restore_tasks())
 		goto exit;
 
@@ -339,6 +352,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;
 
@@ -365,6 +380,9 @@ static int pre_dump_using_req(int sk, CriuOpts *opts)
 		if (setup_opts_from_req(sk, opts))
 			goto cout;
 
+		setproctitle("pre-dump --rpc --pid %d --images-dir %s",
+				opts->pid, images_dir);
+
 		if (cr_pre_dump_tasks(opts->pid))
 			goto cout;
 
@@ -428,6 +446,8 @@ static int start_page_server_req(int sk, CriuOpts *opts)
 	if (setup_opts_from_req(sk, opts))
 		goto out;
 
+	setproctitle("page-server --rpc");
+
 	pr_debug("Starting page server\n");
 
 	ret = cr_page_server(true);
@@ -548,6 +568,8 @@ int cr_service(bool daemon_mode)
 	struct sockaddr_un client_addr;
 	socklen_t client_addr_len;
 
+	setproctitle("service");
+
 	n = sd_listen_fds(0);
 	if (n > 1) {
 		pr_err("Too many file descriptors (%d) recieved", n);
diff --git a/crtools.c b/crtools.c
index b35d752..20478c1 100644
--- a/crtools.c
+++ b/crtools.c
@@ -34,6 +34,7 @@
 #include "file-lock.h"
 #include "cr-service.h"
 #include "plugin.h"
+#include "setproctitle.h"
 
 struct cr_options opts;
 
@@ -129,6 +130,10 @@ int main(int argc, char *argv[])
 	cr_pb_init();
 	restrict_uid(getuid(), getgid());
 
+	argv = setproctitle_init(argc, argv);
+	if (!argv)
+		return 1;
+
 	if (argc < 2)
 		goto usage;
 
-- 
1.8.3.2



More information about the CRIU mailing list