<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 21, 2015 at 5:30 PM, Pavel Emelyanov <span dir="ltr"><<a href="mailto:xemul@parallels.com" target="_blank">xemul@parallels.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">On 01/21/2015 07:46 PM, Paschalis Mpeis wrote:<br>
> A "return" at line 77 <<a href="https://gist.github.com/Paschalis/a96b2747ed85b8e5a796#file-crlib-c-L77" target="_blank">https://gist.github.com/Paschalis/a96b2747ed85b8e5a796#file-crlib-c-L77</a>> could do the<br>
<span>> trick. However, the restored program has standard input, output, and error closed.<br>
<br>
</span>Of course. In line 60 of crlib.c you close them before dumping.<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span>
<br>
</span>Since they are terminals there's no easy way to do it. If you could<br>
redirect stdios to files, then you could just leave them open on<br>
dump, then restore would re-create them back.<span><br></span></blockquote><div><br></div><div><span style="font-family:verdana,sans-serif">Yes, I do, but it's because otherwise CRIU won't dump the application. <div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">O</div><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">n one hand, it makes sense to have them closed, but on the other CRIU could just handle them like the rest of the files. </div></span></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span>
> I tried backing them using dup, and restoring them using dup2. But this causes CRIU dump to fail. What is the<br>
> proper way to do it? I have googled your mailing lists but I didn't found anything!<br>
<br>
</span>Well, the shell job C/R (<a href="http://criu.org/Advanced_usage#Shell_jobs_C.2FR" target="_blank">http://criu.org/Advanced_usage#Shell_jobs_C.2FR</a>)<br>
is pretty close to what you try to achieve.<br></blockquote><div class="gmail_quote"><br></div>I have tried with files, and I stucked on a segmentation fault<div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">.</div></div><div class="gmail_quote">So,<div class="gmail_default" style="font-family:verdana,sans-serif;display:inline"> </div>you are suggesting to use "--shell-job". I guess there must be a way to pass it on "criu_init_opts"?<div><br></div><div><br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5"><span style="color:rgb(34,34,34)"> *Capture:*</span><br></div></div><span class="">> Process A is my program. Then, it is forked, so we have B,<br><br></span>Which is the complete copy of A.<br><span class=""><br>> in which you do your magic, so my program is captured. B is a "capturer". Right?<br><br></span>Not exactly. The capturer in your case is criu service. And B is what is being captured.<br><span class=""><br>> So, when B continues, it does staff unrelated to my program, maybe some CRIU staff, and then it finally exits.<br><br></span>No, it does what's written in your dumpApplication() function.<br><span class=""><br>> Then, process A, waits for the dump to be finished, and when this happens, it continues execution.<br><br></span>Yes.<br></blockquote><div><br></div><div><div class="gmail_default" style="font-family:verdana,sans-serif">So we fork B, so as to have all memory pages, etc copied to the new process, and then simply write all these data to images.</div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>> Specifically, A will continue executing from line 30 here <<a href="https://gist.github.com/Paschalis/a96b2747ed85b8e5a796#file-linpack_h1_-c-L30" target="_blank">https://gist.github.com/Paschalis/a96b2747ed85b8e5a796#file-linpack_h1_-c-L30</a>>.<br>> Is that correct?<br><br>No. The A will continue execution here: <a href="https://gist.github.com/Paschalis/a96b2747ed85b8e5a796#file-crlib-c-L86" target="_blank">https://gist.github.com/Paschalis/a96b2747ed85b8e5a796#file-crlib-c-L86</a></blockquote><div><br></div><div><div class="gmail_default" style="font-family:verdana,sans-serif">Yes, I meant that A will wait for the child B (crlib.c:86), make the chk_exit, and then return where it was before the call of dumpApplication, and finally continue execution.</div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">> Also, I have a question regarding command "criu_set_leave_running(true)".<br>> It will be executed by child B, right?<br><br></span>Yes.<br><span class=""><br>> Why should I bother setting this, since B is the capturer?<br><br></span>B is what being captured. Well, I think you can avoid setting this in B, in this<br>case criu would kill B after dump, A will wake up and continue running. After restore<br>everything should look the same.<br></blockquote><div><br></div><div><div class="gmail_default" style="font-family:verdana,sans-serif">Can you provide a very simple use case scenario?<br>For example, if I set leave_running, and instead of exit I do a return, then both A and B will execute the remaining of the execution? (the code after the dump)</div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">> Is C the "restorer"? (I am bit confused about this)<br><br></span>No. C forks criu, criu forks D as C's child and restores B's state into D. So after<br>restore D is C's child and is 100% clone of B.<br></blockquote><div><br></div><div><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">Just to see whether I got this correctly.</div></div><div><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">I launch C. Then C it is forked into CRIU.</div></div><div><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">Then CRIU it is forked into D, but its parent is C.</div></div><div><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">Then the dumped state (of B), is restored to D.</div></div><div><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline"><br></div></div><div><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline"><br></div></div><div><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">Sorry for the multiple messages, and a big big thank you Pavel.</div></div><div><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">As for the function-only capturing, I might need some direction, just to point me to the right source files so I can implement such feature.</div></div><div><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline"><br></div></div><div><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">Cheers,<br>Paschalis</div></div></div></div></div></div>