[CRIU] [PATCH 2/3] test: app-emu -- job: Fix comparison
Andrew Vagin
avagin at parallels.com
Tue May 7 04:01:43 EDT 2013
On Mon, May 06, 2013 at 11:34:32PM +0400, Cyrill Gorcunov wrote:
> On Mon, May 06, 2013 at 11:18:57PM +0400, Andrey Wagin wrote:
> > On May 6, 2013 7:13 PM, "Cyrill Gorcunov" <gorcunov at openvz.org> wrote:
> > >
> > > Since we're migrating session leader here,
> > > test for session has not been changed instead.
> >
> > In this case the test doesn't wait c/r. I don't like when sleep is used
> > for synchronization instead of sending a signal.
>
> It does wait. Maybe in somehow weird way (ie by sleeps) but still. The main
> expect script writes pid
>
> system ../../../crtools dump -v 4 -D ./dump -o dump.log -j -t $pid
> system echo "$pid" > ./dump/pid.pid
>
> once dump complete, then restore stage initiated.
Look at the attached patch.
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
-------------- next part --------------
diff --git a/test/app-emu/job/job.c b/test/app-emu/job/job.c
index e01480a..ad6fed3 100644
--- a/test/app-emu/job/job.c
+++ b/test/app-emu/job/job.c
@@ -14,6 +14,13 @@
#include <dirent.h>
+static int stop = 0;
+
+void sighandler(int sig)
+{
+ stop = 1;
+}
+
int main(int argc, char *argv[])
{
int pid, gid, sid;
@@ -23,6 +30,12 @@ int main(int argc, char *argv[])
int c = 0;
struct dirent *de;
DIR *fd_dir;
+ sigset_t bmask, cmask;
+
+ if (signal(SIGTERM, sighandler)) {
+ printf("Unable to set a signal handler: %m\n");
+ return 1;
+ }
if (!isatty(fd)) {
printf("stdout is not tty\n");
@@ -70,21 +83,20 @@ int main(int argc, char *argv[])
}
printf("stdout gid = %d\n", tty_gid);
+ sigemptyset(&cmask);
+ sigemptyset(&bmask);
+ sigaddset(&bmask, SIGTERM);
+
+ sigprocmask(SIG_SETMASK, &bmask, NULL);
+
printf("READY\n");
c = 0;
- while (1) {
- sleep(1);
- if (c++ > 10) {
- printf("Too long for restore\n");
- exit(-1);
- }
+ while (!stop)
+ sigsuspend(&cmask);
- if (getsid(pid) != sid) {
- printf("ALIVE\n");
- break;
- }
- }
+ if (getsid(pid) == sid)
+ printf("ALIVE\n");
return 0;
}
More information about the CRIU
mailing list