[CRIU] [PATCH] criu: make criu static library

Pavel Emelyanov xemul at parallels.com
Thu Aug 15 05:27:13 EDT 2013


On 08/15/2013 03:33 AM, Yicheng Qin wrote:
> Generate criu static library 'libcriu.a'

Well, a library is something that we've been asked for several times already, so
thank you for looking at this.

But I see several problems with the proposed approach:

1. I think, that it should rather be dynamically linked lib, rather than static.
2. We have the lib/* stuff where the beginnings of it are and $src/lib/libcriu.so
   plus and $src/libcriu.a looks confusing.
3. I'm not an expert in writing libraries, but I've never met any library
   calls (except for execve() and derived), that accept raw command line arguments.
   I think we should rather have separate criu_dump() and criu_restore() calls.
4. The major one -- criu uses kernel APIs, that are CAP_SYS_ADMIN protected, i.e.
   only root can use it. With this, this library only makes sense for programs 
   launched from root, which narrows down its usage.

   We have an in-progress work to implement criu_dump_me() library call, that will
   dump the calling program whatever user it's launched from. The same problem with
   cap-s is true there, and we overcome this by using a criu service, as described
   here -- http://criu.org/Self_dump

   I think, that in order to have the criu_dump()/criu_resume()/criu_whatever()
   functionality available as library calls, we should implement them in the same
   manner.

Thanks,
Pavel

> The public function in criu can be called by using this library.
> 
> Function is recommended to be used by now:
> *	int criu_main(int argc, char *argv[]);
> 	It has the same logic as main function of criu binary.
> 
> Signed-off-by: Yicheng Qin <yichengq at google.com>
> ---
>  Makefile | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index 8e34770..4a98b56 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -32,6 +32,8 @@ NM		:= $(CROSS_COMPILE)nm
>  SH		:= bash
>  MAKE		:= make
>  OBJCOPY		:= $(CROSS_COMPILE)objcopy
> +AR		:= $(CROSS_COMPILE)ar
> +CP		:= cp
>  
>  #
>  # Fetch ARCH from the uname if not yet set
> @@ -102,6 +104,7 @@ CFLAGS		+= $(WARNINGS) $(DEFINES)
>  SYSCALL-LIB	:= arch/$(ARCH)/syscalls.built-in.o
>  ARCH-LIB	:= arch/$(ARCH)/crtools.built-in.o
>  CRIU-LIB	:= lib/libcriu.so
> +CRIU-STATIC-LIB	:= libcriu.a
>  
>  export CC MAKE CFLAGS LIBS ARCH DEFINES MAKEFLAGS
>  export SRC_DIR SYSCALL-LIB SH RM ARCH_DIR OBJCOPY LDARCH LD
> @@ -127,7 +130,7 @@ ifeq ($(GCOV),1)
>  endif
>  
>  all: config pie $(VERSION_HEADER) lib
> -	$(Q) $(MAKE) $(PROGRAM)
> +	$(Q) $(MAKE) $(PROGRAM) $(CRIU-STATIC-LIB)
>  
>  lib: $(VERSION_HEADER)
>  	$(Q) $(MAKE) -C lib all
> @@ -171,6 +174,14 @@ $(PROGRAM): $(SYSCALL-LIB) $(ARCH-LIB) $(PROGRAM-BUILTINS) $(MAIN-BUILTINS)
>  	$(E) "  LINK    " $@
>  	$(Q) $(CC) $(CFLAGS) $^ $(LIBS) $(LDFLAGS) -o $@
>  
> +libcriu.o: $(SYSCALL-LIB) $(ARCH-LIB) $(PROGRAM-BUILTINS)
> +	$(E) "  LINK    " $@
> +	$(Q) $(LD) $(LDFLAGS) -r $^ -o $@
> +
> +$(CRIU-STATIC-LIB): libcriu.o
> +	$(E) "  GEN    " $@
> +	$(Q) $(AR) crs $@ $^
> +
>  zdtm: all
>  	$(Q) $(MAKE) -C test/zdtm all
>  
> 




More information about the CRIU mailing list