mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
string: define wrapers __setproctitle and __setproctitle_init to hide bsd headers
We see that libbsd redefines __has_include to be always true, which breaks such checks for rseq. The idea behind this patch is to put all uses of libbsd functions to separate c files and only export wrapper functions for them. Using __setproctitle and __setproctitle_init everywhere in existing code: git grep --files-with-matches "setproctitle" | xargs sed -i 's/setproctitle/__setproctitle/g' git grep --files-with-matches "setproctitle_init" | xargs sed -i 's/setproctitle_init/__setproctitle_init/g' Fixes: #2036 Suggested-by: Andrei Vagin <avagin@google.com> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This commit is contained in:
parent
0a7c5fd1bd
commit
a92dfb61ff
5 changed files with 54 additions and 23 deletions
|
|
@ -74,6 +74,7 @@ obj-y += sk-unix.o
|
|||
obj-y += sockets.o
|
||||
obj-y += stats.o
|
||||
obj-y += string.o
|
||||
obj-y += setproctitle.o
|
||||
obj-y += sysctl.o
|
||||
obj-y += sysfs_parse.o
|
||||
obj-y += timerfd.o
|
||||
|
|
|
|||
|
|
@ -752,7 +752,7 @@ 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);
|
||||
__setproctitle("dump --rpc -t %d -D %s", req->pid, images_dir);
|
||||
|
||||
if (init_pidfd_store_hash())
|
||||
goto pidfd_store_err;
|
||||
|
|
@ -795,7 +795,7 @@ 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);
|
||||
__setproctitle("restore --rpc -D %s", images_dir);
|
||||
|
||||
if (cr_restore_tasks())
|
||||
goto exit;
|
||||
|
|
@ -841,7 +841,7 @@ static int check(int sk, CriuOpts *req)
|
|||
}
|
||||
|
||||
if (pid == 0) {
|
||||
setproctitle("check --rpc");
|
||||
__setproctitle("check --rpc");
|
||||
|
||||
opts.mode = CR_CHECK;
|
||||
if (setup_opts_from_req(sk, req))
|
||||
|
|
@ -879,7 +879,7 @@ static int pre_dump_using_req(int sk, CriuOpts *req, bool single)
|
|||
if (setup_opts_from_req(sk, req))
|
||||
goto cout;
|
||||
|
||||
setproctitle("pre-dump --rpc -t %d -D %s", req->pid, images_dir);
|
||||
__setproctitle("pre-dump --rpc -t %d -D %s", req->pid, images_dir);
|
||||
|
||||
if (init_pidfd_store_hash())
|
||||
goto pidfd_store_err;
|
||||
|
|
@ -957,7 +957,7 @@ static int start_page_server_req(int sk, CriuOpts *req, bool daemon_mode)
|
|||
if (setup_opts_from_req(sk, req))
|
||||
goto out_ch;
|
||||
|
||||
setproctitle("page-server --rpc --address %s --port %hu", opts.addr, opts.port);
|
||||
__setproctitle("page-server --rpc --address %s --port %hu", opts.addr, opts.port);
|
||||
|
||||
pr_debug("Starting page server\n");
|
||||
|
||||
|
|
@ -1117,7 +1117,7 @@ static int handle_feature_check(int sk, CriuReq *msg)
|
|||
if (kerndat_init())
|
||||
exit(1);
|
||||
|
||||
setproctitle("feature-check --rpc");
|
||||
__setproctitle("feature-check --rpc");
|
||||
|
||||
if ((msg->features->has_mem_track == 1) && (msg->features->mem_track == true))
|
||||
feat.mem_track = kdat.has_dirty_track;
|
||||
|
|
@ -1204,8 +1204,8 @@ static int handle_cpuinfo(int sk, CriuReq *msg)
|
|||
if (setup_opts_from_req(sk, msg->opts))
|
||||
goto cout;
|
||||
|
||||
setproctitle("cpuinfo %s --rpc -D %s", msg->type == CRIU_REQ_TYPE__CPUINFO_DUMP ? "dump" : "check",
|
||||
images_dir);
|
||||
__setproctitle("cpuinfo %s --rpc -D %s", msg->type == CRIU_REQ_TYPE__CPUINFO_DUMP ? "dump" : "check",
|
||||
images_dir);
|
||||
|
||||
if (msg->type == CRIU_REQ_TYPE__CPUINFO_DUMP)
|
||||
ret = cpuinfo_dump();
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ int main(int argc, char *argv[], char *envp[])
|
|||
}
|
||||
|
||||
cr_pb_init();
|
||||
setproctitle_init(argc, argv, envp);
|
||||
__setproctitle_init(argc, argv, envp);
|
||||
|
||||
if (argc < 2)
|
||||
goto usage;
|
||||
|
|
|
|||
|
|
@ -1,19 +1,7 @@
|
|||
#ifndef __CR_SETPROCTITLE_H__
|
||||
#define __CR_SETPROCTITLE_H__
|
||||
|
||||
#ifdef CONFIG_HAS_LIBBSD
|
||||
#include <bsd/unistd.h>
|
||||
#else
|
||||
|
||||
/*
|
||||
* setproctitle_init is in the libbsd since v0.6.0. This macro allows to
|
||||
* compile criu with libbsd<0.6.0.
|
||||
*/
|
||||
#ifndef CONFIG_HAS_SETPROCTITLE_INIT
|
||||
#define setproctitle_init(argc, argv, envp)
|
||||
#endif
|
||||
|
||||
#define setproctitle(fmt, ...)
|
||||
#endif
|
||||
extern void __setproctitle_init(int argc, char *argv[], char *envp[]);
|
||||
extern void __setproctitle(const char *fmt, ...);
|
||||
|
||||
#endif /* __CR_SETPROCTITLE_H__ */
|
||||
|
|
|
|||
42
criu/setproctitle.c
Normal file
42
criu/setproctitle.c
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef CONFIG_HAS_LIBBSD
|
||||
#include <bsd/unistd.h>
|
||||
#else
|
||||
|
||||
#include "setproctitle.h"
|
||||
|
||||
/*
|
||||
* setproctitle_init is in the libbsd since v0.6.0. This macro allows to
|
||||
* compile criu with libbsd<0.6.0.
|
||||
*/
|
||||
#ifndef CONFIG_HAS_SETPROCTITLE_INIT
|
||||
#define setproctitle_init(argc, argv, envp)
|
||||
#endif
|
||||
|
||||
#define setproctitle(fmt, ...)
|
||||
#endif
|
||||
|
||||
void __setproctitle_init(int argc, char *argv[], char *envp[])
|
||||
{
|
||||
setproctitle_init(argc, argv, envp);
|
||||
}
|
||||
|
||||
#ifndef SPT_MAXTITLE
|
||||
#define SPT_MAXTITLE 255
|
||||
#endif
|
||||
|
||||
void __setproctitle(const char *fmt, ...)
|
||||
{
|
||||
char buf[SPT_MAXTITLE + 1];
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buf, sizeof(buf), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
setproctitle("%s", buf);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue