* [PATCH] restart: add switch '--self' for self-restart
@ 2009-09-23 0:16 Oren Laadan
[not found] ` <1253664996-3439-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Oren Laadan @ 2009-09-23 0:16 UTC (permalink / raw)
To: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
There is no reason to keep a separate program for self-restart.
Get rid of self_restart.c
Signed-off-by: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
---
Makefile | 7 +++----
restart.c | 25 +++++++++++++++++++++++--
self_restart.c | 35 -----------------------------------
3 files changed, 26 insertions(+), 41 deletions(-)
delete mode 100644 self_restart.c
diff --git a/Makefile b/Makefile
index 830e2c8..7f5cb27 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/restart.c b/restart.c
index 600a282..c0d52a5 100644
--- a/restart.c
+++ b/restart.c
@@ -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");
diff --git a/self_restart.c b/self_restart.c
deleted file mode 100644
index b0fbaab..0000000
--- a/self_restart.c
+++ /dev/null
@@ -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;
-}
--
1.6.0.4
^ permalink raw reply related [flat|nested] 5+ messages in thread[parent not found: <1253664996-3439-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>]
* Re: [PATCH] restart: add switch '--self' for self-restart [not found] ` <1253664996-3439-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org> @ 2009-09-23 4:28 ` Serge E. Hallyn [not found] ` <20090923042805.GC11296-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Serge E. Hallyn @ 2009-09-23 4:28 UTC (permalink / raw) To: Oren Laadan; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA Quoting Oren Laadan (orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org): > 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... Acked-by: Serge Hallyn <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org> > Signed-off-by: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org> > --- > Makefile | 7 +++---- > restart.c | 25 +++++++++++++++++++++++-- > self_restart.c | 35 ----------------------------------- > 3 files changed, 26 insertions(+), 41 deletions(-) > delete mode 100644 self_restart.c > > diff --git a/Makefile b/Makefile > index 830e2c8..7f5cb27 100644 > --- a/Makefile > +++ b/Makefile > @@ -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 > diff --git a/restart.c b/restart.c > index 600a282..c0d52a5 100644 > --- a/restart.c > +++ b/restart.c > @@ -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"); > diff --git a/self_restart.c b/self_restart.c > deleted file mode 100644 > index b0fbaab..0000000 > --- a/self_restart.c > +++ /dev/null > @@ -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; > -} > -- > 1.6.0.4 > > _______________________________________________ > Containers mailing list > Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org > https://lists.linux-foundation.org/mailman/listinfo/containers ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <20090923042805.GC11296-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>]
* Re: [PATCH] restart: add switch '--self' for self-restart [not found] ` <20090923042805.GC11296-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org> @ 2009-09-23 7:12 ` Oren Laadan [not found] ` <4AB9CA48.5000402-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Oren Laadan @ 2009-09-23 7:12 UTC (permalink / raw) To: Serge E. Hallyn; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA Serge E. Hallyn wrote: > Quoting Oren Laadan (orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org): >> 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... 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.... > > Acked-by: Serge Hallyn <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org> > >> Signed-off-by: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org> >> --- >> Makefile | 7 +++---- >> restart.c | 25 +++++++++++++++++++++++-- >> self_restart.c | 35 ----------------------------------- >> 3 files changed, 26 insertions(+), 41 deletions(-) >> delete mode 100644 self_restart.c >> >> diff --git a/Makefile b/Makefile >> index 830e2c8..7f5cb27 100644 >> --- a/Makefile >> +++ b/Makefile >> @@ -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 >> diff --git a/restart.c b/restart.c >> index 600a282..c0d52a5 100644 >> --- a/restart.c >> +++ b/restart.c >> @@ -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"); >> diff --git a/self_restart.c b/self_restart.c >> deleted file mode 100644 >> index b0fbaab..0000000 >> --- a/self_restart.c >> +++ /dev/null >> @@ -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; >> -} >> -- >> 1.6.0.4 >> >> _______________________________________________ >> Containers mailing list >> Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org >> https://lists.linux-foundation.org/mailman/listinfo/containers ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <4AB9CA48.5000402-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>]
* Re: [PATCH] restart: add switch '--self' for self-restart [not found] ` <4AB9CA48.5000402-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org> @ 2009-09-23 21:41 ` Matt Helsley [not found] ` <20090923214142.GA6876-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Matt Helsley @ 2009-09-23 21:41 UTC (permalink / raw) To: Oren Laadan; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA On Wed, Sep 23, 2009 at 03:12:08AM -0400, Oren Laadan wrote: > > Serge E. Hallyn wrote: > > Quoting Oren Laadan (orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org): > >> 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... > > self_checkpoint.c is 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <20090923214142.GA6876-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>]
* Re: [PATCH] restart: add switch '--self' for self-restart [not found] ` <20090923214142.GA6876-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org> @ 2009-09-24 6:04 ` Oren Laadan 0 siblings, 0 replies; 5+ messages in thread From: Oren Laadan @ 2009-09-24 6:04 UTC (permalink / raw) To: Matt Helsley; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA Matt Helsley wrote: > On Wed, Sep 23, 2009 at 03:12:08AM -0400, Oren Laadan wrote: >> Serge E. Hallyn wrote: >>> Quoting Oren Laadan (orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org): >>>> 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... >> self_checkpoint.c is 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. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-09-24 6:04 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-23 0:16 [PATCH] restart: add switch '--self' for self-restart Oren Laadan
[not found] ` <1253664996-3439-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-09-23 4:28 ` Serge E. Hallyn
[not found] ` <20090923042805.GC11296-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-09-23 7:12 ` Oren Laadan
[not found] ` <4AB9CA48.5000402-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-09-23 21:41 ` Matt Helsley
[not found] ` <20090923214142.GA6876-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2009-09-24 6:04 ` Oren Laadan
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.