restart: add switch '--self' for self-restart
PATCH 1/1 restart: add switch '--self' for self-restart
There is no reason to keep a separate program for self-restart. Get rid of self_restart.c
--- Makefile | 7 +++---- restart.c | 25 +++++++++++++++++++++++-- self_restart.c | 35 ----------------------------------- 3 files changed, 26 insertions(+), 41 deletions(-) delete mode 100644 self_restart.c
Makefile +3 -4
@@ -35,7 +35,7 @@ CFLAGS += -g $(WARNS) $(CKPT_INCLUDE) $(DEBUG) # install dir INSTALL_DIR = /bin -PROGS = self_checkpoint self_restart checkpoint restart ckptinfo +PROGS = checkpoint restart ckptinfo # other cleanup OTHER = ckptinfo_types.c
@@ -43,7 +43,6 @@ OTHER = ckptinfo_types.c LDLIBS = -lm all: $(PROGS) - echo $(SUBARCH) @make -C test # restart needs to be thread-safe
@@ -68,8 +67,8 @@ ckptinfo_types.c: $(CKPT_HEADERS) ckptinfo.py @cat $(CKPT_HEADERS) | ./ckptinfo.py > ckptinfo_types.c install: - @echo /usr/bin/install -m 755 checkpoint restart self_restart ckptinfo $(INSTALL_DIR) - @/usr/bin/install -m 755 checkpoint restart self_restart ckptinfo $(INSTALL_DIR) + @echo /usr/bin/install -m 755 checkpoint restart ckptinfo $(INSTALL_DIR) + @/usr/bin/install -m 755 checkpoint restart ckptinfo $(INSTALL_DIR) clean: @rm -f $(PROGS) $(OTHER) *~ *.o
restart.c +23 -2
@@ -63,6 +63,7 @@ static char usage_str[] =" -p,--pidns create a new pid namspace (default with --pids)\n" " -P,--no-pidns do not create a new pid namespace (default)\n" " --pids restore original pids (default with --pidns)\n" +" --self restart a single task, usually from self-checkpoint\n" " -r,--root=ROOT restart under the directory ROOT instead of current\n" " --signal=SIG send SIG to root task on SIGINT (default: SIGKILL\n" " to container root, SIGINT otherwise)\n"
@@ -335,6 +336,7 @@ struct pid_swap { };struct args { +int self;int pids;int pidns;int no_pidns;
@@ -372,6 +374,7 @@ static void parse_args(struct args *args, int argc, char *argv[]) { "pidns", no_argument, NULL, 'p' }, { "no-pidns", no_argument, NULL, 'P' }, { "pids", no_argument, NULL, 3 }, + { "self", no_argument, NULL, 6}, { "signal", required_argument, NULL, 4 }, { "inspect", no_argument, NULL, 5 }, { "input", required_argument, NULL, 'i' },
@@ -417,6 +420,9 @@ static void parse_args(struct args *args, int argc, char *argv[])case 'P' : args->no_pidns =1 ;break ; +case 6 :/* --self */ + args->self =1 ; +break ;case 4 :/* --signal */ sig =str2sig (optarg);if (sig <0 )
@@ -488,6 +494,13 @@ static void parse_args(struct args *args, int argc, char *argv[]) exit(1); }#endif + +if (args->self && + (args->pids || args->pidns || args->no_pidns || args->wait || + args->show_status || args->copy_status || args->freezer)) { +printf ("Invalid mix of --self with multiprocess options\n" ); +exit (1 ); + } }static void report_exit_status (int status,char *str,int debug)
@@ -650,14 +663,22 @@ int main(int argc, char *argv[])if (args.freezer &&freezer_prepare (&ctx) <0 )exit (1 ); -setpgrp (); -/* chroot ? */ if (args.root &&chroot (args.root) <0 ) {perror ("chroot" );exit (1 ); } +/* self-restart ends here: */ +if (args.self) { +restart (getpid (),STDIN_FILENO ,RESTART_TASKSELF ); +/* reach here if restart(2) failed ! */ +perror ("restart" ); +exit (1 ); + } + +setpgrp (); + ret =ckpt_read_header (&ctx);if (ret <0 ) {perror ("read c/r header" );
self_restart.c deleted +0 -35
@@ -1,35 +0,0 @@ -/* -* self_restart.c: restart a single process -* -* Copyright (C) 2008 Oren Laadan -* -* This file is subject to the terms and conditions of the GNU General Public -* License. See the file COPYING in the main directory of the Linux -* distribution for more details. -*/ - -#define _GNU_SOURCE/* or _BSD_SOURCE or _SVID_SOURCE */ - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <fcntl.h> -#include <unistd.h> -#include <asm/unistd.h> -#include <sys/syscall.h> - -#include <linux/checkpoint.h> - -int main (int argc,char *argv[]) -{ -pid_t pid =getpid (); -int ret; - - ret =syscall (__NR_restart, pid,STDIN_FILENO ,RESTART_TASKSELF ); -if (ret <0 ) -perror ("restart" ); - -printf ("should not reach here !\n" ); - -return 0 ; -}
Signature · 1 line
1.6.0.4
A message that is not in the archive (sent off-list or not yet received): 1253664996-3439-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org
Serge E. Hallyn
Acked-byQuoted 2 lines · Oren Laadan
There is no reason to keep a separate program for self-restart. Get rid of
self_restart.c
Hmm? But you also took self_checkpoint.c out of PROGS in Makefile...
Quoted 165 lines
Signed-off-by Oren Laadan <[email protected]>--- Makefile | 7 +++---- restart.c | 25 +++++++++++++++++++++++-- self_restart.c | 35 ----------------------------------- 3 files changed, 26 insertions(+), 41 deletions(-) delete mode 100644 self_restart.cMakefile +3
-4@@ -35,7 +35,7 @@ CFLAGS += -g $(WARNS) $(CKPT_INCLUDE) $(DEBUG) # install dir INSTALL_DIR = /bin -PROGS = self_checkpoint self_restart checkpoint restart ckptinfo +PROGS = checkpoint restart ckptinfo # other cleanup OTHER = ckptinfo_types.c@@ -43,7 +43,6 @@ OTHER = ckptinfo_types.c LDLIBS = -lm all: $(PROGS) - echo $(SUBARCH) @make -C test # restart needs to be thread-safe@@ -68,8 +67,8 @@ ckptinfo_types.c: $(CKPT_HEADERS) ckptinfo.py @cat $(CKPT_HEADERS) | ./ckptinfo.py > ckptinfo_types.c install: - @echo /usr/bin/install -m 755 checkpoint restart self_restart ckptinfo $(INSTALL_DIR) - @/usr/bin/install -m 755 checkpoint restart self_restart ckptinfo $(INSTALL_DIR) + @echo /usr/bin/install -m 755 checkpoint restart ckptinfo $(INSTALL_DIR) + @/usr/bin/install -m 755 checkpoint restart ckptinfo $(INSTALL_DIR) clean: @rm -f $(PROGS) $(OTHER) *~ *.orestart.c +23
-2@@ -63,6 +63,7 @@ static char usage_str[] =" -p,--pidns create a new pid namspace (default with --pids)\n" " -P,--no-pidns do not create a new pid namespace (default)\n" " --pids restore original pids (default with --pidns)\n" +" --self restart a single task, usually from self-checkpoint\n" " -r,--root=ROOT restart under the directory ROOT instead of current\n" " --signal=SIG send SIG to root task on SIGINT (default: SIGKILL\n" " to container root, SIGINT otherwise)\n" @@ -335,6 +336,7 @@ struct pid_swap { };struct args { +int self;int pids;int pidns;int no_pidns;@@ -372,6 +374,7 @@ static void parse_args(struct args *args, int argc, char *argv[]) { "pidns", no_argument, NULL, 'p' }, { "no-pidns", no_argument, NULL, 'P' }, { "pids", no_argument, NULL, 3 }, + { "self", no_argument, NULL, 6}, { "signal", required_argument, NULL, 4 }, { "inspect", no_argument, NULL, 5 }, { "input", required_argument, NULL, 'i' },@@ -417,6 +420,9 @@ static void parse_args(struct args *args, int argc, char *argv[])case 'P' : args->no_pidns =1 ;break ; +case 6 :/* --self */ + args->self =1 ; +break ;case 4 :/* --signal */ sig =str2sig (optarg);if (sig <0 )@@ -488,6 +494,13 @@ static void parse_args(struct args *args, int argc, char *argv[]) exit(1); }#endif + +if (args->self && + (args->pids || args->pidns || args->no_pidns || args->wait || + args->show_status || args->copy_status || args->freezer)) { +printf ("Invalid mix of --self with multiprocess options\n" ); +exit (1 ); + } }static void report_exit_status (int status,char *str,int debug)@@ -650,14 +663,22 @@ int main(int argc, char *argv[])if (args.freezer &&freezer_prepare (&ctx) <0 )exit (1 ); -setpgrp (); -/* chroot ? */ if (args.root &&chroot (args.root) <0 ) {perror ("chroot" );exit (1 ); } +/* self-restart ends here: */ +if (args.self) { +restart (getpid (),STDIN_FILENO ,RESTART_TASKSELF ); +/* reach here if restart(2) failed ! */ +perror ("restart" ); +exit (1 ); + } + +setpgrp (); + ret =ckpt_read_header (&ctx);if (ret <0 ) {perror ("read c/r header" );self_restart.c deleted +0
-35@@ -1,35 +0,0 @@ -/* -* self_restart.c: restart a single process -* -* Copyright (C) 2008 Oren Laadan -* -* This file is subject to the terms and conditions of the GNU General Public -* License. See the file COPYING in the main directory of the Linux -* distribution for more details. -*/ - -#define _GNU_SOURCE/* or _BSD_SOURCE or _SVID_SOURCE */ - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <fcntl.h> -#include <unistd.h> -#include <asm/unistd.h> -#include <sys/syscall.h> - -#include <linux/checkpoint.h> - -int main (int argc,char *argv[]) -{ -pid_t pid =getpid (); -int ret; - - ret =syscall (__NR_restart, pid,STDIN_FILENO ,RESTART_TASKSELF ); -if (ret <0 ) -perror ("restart" ); - -printf ("should not reach here !\n" ); - -return 0 ; -}Signature · 6 lines
1.6.0.4 _______________________________________________ Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org https://lists.linux-foundation.org/mailman/listinfo/containers
A message that is not in the archive (sent off-list or not yet received): 20090923042805.GC11296-r/[email protected]
Quoted 5 lines · Serge E. Hallyn
Quoted 2 lines · Oren Laadan
There is no reason to keep a separate program for self-restart. Get rid of
self_restart.cHmm? But you also took
self_checkpoint.cout of PROGS inMakefile...
self_checkpoint.c is an example of how to do self-checkpoint.
It isn't a utility, so I see no point in compiling it....
Quoted 168 lines
Quoted 165 lines
Signed-off-by Oren Laadan <[email protected]>--- Makefile | 7 +++---- restart.c | 25 +++++++++++++++++++++++-- self_restart.c | 35 ----------------------------------- 3 files changed, 26 insertions(+), 41 deletions(-) delete mode 100644 self_restart.cMakefile +3
-4@@ -35,7 +35,7 @@ CFLAGS += -g $(WARNS) $(CKPT_INCLUDE) $(DEBUG) # install dir INSTALL_DIR = /bin -PROGS = self_checkpoint self_restart checkpoint restart ckptinfo +PROGS = checkpoint restart ckptinfo # other cleanup OTHER = ckptinfo_types.c@@ -43,7 +43,6 @@ OTHER = ckptinfo_types.c LDLIBS = -lm all: $(PROGS) - echo $(SUBARCH) @make -C test # restart needs to be thread-safe@@ -68,8 +67,8 @@ ckptinfo_types.c: $(CKPT_HEADERS) ckptinfo.py @cat $(CKPT_HEADERS) | ./ckptinfo.py > ckptinfo_types.c install: - @echo /usr/bin/install -m 755 checkpoint restart self_restart ckptinfo $(INSTALL_DIR) - @/usr/bin/install -m 755 checkpoint restart self_restart ckptinfo $(INSTALL_DIR) + @echo /usr/bin/install -m 755 checkpoint restart ckptinfo $(INSTALL_DIR) + @/usr/bin/install -m 755 checkpoint restart ckptinfo $(INSTALL_DIR) clean: @rm -f $(PROGS) $(OTHER) *~ *.orestart.c +23
-2@@ -63,6 +63,7 @@ static char usage_str[] =" -p,--pidns create a new pid namspace (default with --pids)\n" " -P,--no-pidns do not create a new pid namespace (default)\n" " --pids restore original pids (default with --pidns)\n" +" --self restart a single task, usually from self-checkpoint\n" " -r,--root=ROOT restart under the directory ROOT instead of current\n" " --signal=SIG send SIG to root task on SIGINT (default: SIGKILL\n" " to container root, SIGINT otherwise)\n" @@ -335,6 +336,7 @@ struct pid_swap { };struct args { +int self;int pids;int pidns;int no_pidns;@@ -372,6 +374,7 @@ static void parse_args(struct args *args, int argc, char *argv[]) { "pidns", no_argument, NULL, 'p' }, { "no-pidns", no_argument, NULL, 'P' }, { "pids", no_argument, NULL, 3 }, + { "self", no_argument, NULL, 6}, { "signal", required_argument, NULL, 4 }, { "inspect", no_argument, NULL, 5 }, { "input", required_argument, NULL, 'i' },@@ -417,6 +420,9 @@ static void parse_args(struct args *args, int argc, char *argv[])case 'P' : args->no_pidns =1 ;break ; +case 6 :/* --self */ + args->self =1 ; +break ;case 4 :/* --signal */ sig =str2sig (optarg);if (sig <0 )@@ -488,6 +494,13 @@ static void parse_args(struct args *args, int argc, char *argv[]) exit(1); }#endif + +if (args->self && + (args->pids || args->pidns || args->no_pidns || args->wait || + args->show_status || args->copy_status || args->freezer)) { +printf ("Invalid mix of --self with multiprocess options\n" ); +exit (1 ); + } }static void report_exit_status (int status,char *str,int debug)@@ -650,14 +663,22 @@ int main(int argc, char *argv[])if (args.freezer &&freezer_prepare (&ctx) <0 )exit (1 ); -setpgrp (); -/* chroot ? */ if (args.root &&chroot (args.root) <0 ) {perror ("chroot" );exit (1 ); } +/* self-restart ends here: */ +if (args.self) { +restart (getpid (),STDIN_FILENO ,RESTART_TASKSELF ); +/* reach here if restart(2) failed ! */ +perror ("restart" ); +exit (1 ); + } + +setpgrp (); + ret =ckpt_read_header (&ctx);if (ret <0 ) {perror ("read c/r header" );self_restart.c deleted +0
-35@@ -1,35 +0,0 @@ -/* -* self_restart.c: restart a single process -* -* Copyright (C) 2008 Oren Laadan -* -* This file is subject to the terms and conditions of the GNU General Public -* License. See the file COPYING in the main directory of the Linux -* distribution for more details. -*/ - -#define _GNU_SOURCE/* or _BSD_SOURCE or _SVID_SOURCE */ - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <fcntl.h> -#include <unistd.h> -#include <asm/unistd.h> -#include <sys/syscall.h> - -#include <linux/checkpoint.h> - -int main (int argc,char *argv[]) -{ -pid_t pid =getpid (); -int ret; - - ret =syscall (__NR_restart, pid,STDIN_FILENO ,RESTART_TASKSELF ); -if (ret <0 ) -perror ("restart" ); - -printf ("should not reach here !\n" ); - -return 0 ; -}Signature · 6 lines
1.6.0.4 _______________________________________________ Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org https://lists.linux-foundation.org/mailman/listinfo/containers
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · Oren Laadan
Quoted 5 lines · Serge E. Hallyn
Quoted 2 lines · Oren Laadan
There is no reason to keep a separate program for self-restart. Get rid of
self_restart.cHmm? But you also took
self_checkpoint.cout of PROGS inMakefile...
self_checkpoint.cis an example of how to do self-checkpoint.
Sounds like something to go into an examples/ or contrib/ subdirectory. You could do the same with self_restart.c...
Cheers,
-Matt Helsley
A message that is not in the archive (sent off-list or not yet received): 20090923214142.GA6876-52DBMbEzqgQ/wnmkkaCWp/[email protected]
Quoted 10 lines · Matt Helsley
Quoted 6 lines · Oren Laadan
Quoted 4 lines · Serge E. Hallyn
Quoted 2 lines · Oren Laadan
There is no reason to keep a separate program for self-restart. Get rid of
self_restart.cHmm? But you also took
self_checkpoint.cout of PROGS inMakefile...
self_checkpoint.cis an example of how to do self-checkpoint.Sounds like something to go into an examples/ or contrib/ subdirectory. You could do the same with
self_restart.c...
Good point. Done on ckpt-v18.
Oren.