----- Original Message -----
> From: "zenglg.jy" <[email protected]>
> To: "Jan Stancek" <[email protected]>
> Cc: "chrubis" <[email protected]>, "ltp-list" <[email protected]>
> Sent: Monday, 25 November, 2013 10:11:22 AM
> Subject: Re: [LTP] [PATCH v2] clone/clone08.c: Add new flags
> 
> On Wed, 2013-11-20 at 04:11 -0500, Jan Stancek wrote:
> > > +static int child_clone_parent()
> > > +{
> > > + usleep(500000);
> > > + if (parent_ppid == getppid())
> > > +         kill(tgid, SIG_PASS);
> > > + else
> > > +         kill(tgid, SIG_FAIL);
> > > + exit(PASS);
> > > +}
> > 
> > Hi,
> > 
> > why not just exit with either PASS or FAIL and parent can check the status?
> > You wouldn't need sleep or signals.
> > 
> > If you need parent/child synchronization, then consider "checkpoints"
> > (lib/tst_checkpoint.c)
> > 
> 
> There is a little different with CLONE_PARENT. The exit value can't be
> easily gained by the calling process(after CLONE_PARENT, they are not
> really parent and child, maybe brothers precise).
> wait(&status);          /* It will faile because of no child. */
> if (WIFEXITED(status) && WEXITSTATUS(status) == PASS)
>         ...
> 
> > > +#ifdef CLONE_STOPPED
> > > +static void test_clone_stopped(int tid)
> > > +{
> > > + int i;
> > > +
> > > + /* give the kernel scheduler chance to run the child */
> > > + for (i = 0; i < 100; i++) {
> > > +         sched_yield();
> > > +         usleep(1000);
> > > + }
> > > + if (thread_state == 0)
> > 
> > Does the child have even chance to change this value in parent without
> > CLONE_VM?
> > 
> 
> Yes, we should add CLONE_VM.
> 
> > > +         tst_resm(TPASS, "test CLONE_STOPPED success");
> > > + else
> > > +         tst_resm(TFAIL, "test CLONE_STOPPED fail");
> > > +
> > > + if (kill(tid, SIGCONT) != 0)
> > > +         tst_brkm(TBROK | TERRNO, cleanup, "kill SIGCONT failed");
> > > +}
> > > +
> > > +static int child_clone_stopped()
> > > +{
> > > + thread_state = 1;
> > 
> > thread_state should be reset to 0 before this test, in case you run it in
> > loop (-i parameter).
> > 
> 
> Yes,  thread_state should be reset to 0 at the begin of the loop.
> 
> > > + exit(PASS);
> > > +}
> > > +#endif
> > > +
> > > +static int child_clone_thread(void)
> > > +{
> > > + pid_t child_tgid;
> > > +
> > > + child_tgid = getpid();
> > > +
> > > + if (tgid == child_tgid)
> > > +         kill(tgid, SIG_PASS);
> > > + else
> > > +         kill(tgid, SIG_FAIL);
> > > + usleep(500000);
> > > + exit(PASS);
> > > +}
> > 
> > Same as above, why not just return PASS or FAIL and check status in parent?
> > 
> 
> When a CLONE_THREAD thread terminates, the thread  that  created it  using
> clone() is not sent a SIGCHLD (or other termination) signal; nor can the
> status of such a thread be obtained using wait(2).  (The thread is said to
> be detached.)

I see. But still I'd like to find a way to do it without those sleeps.

If we use checkpoints and signal parent only in good case, then
failed run will get aborted with TBROK, as there is built-in timeout.

Or other idea: Make one more fork so we have a pid to wait for and
call clone(CLONE_THREAD) inside.

from man 2 clone:
"After all of the threads in a thread group terminate the parent process
of the thread group is sent a SIGCHLD (or  other  termination) signal."

Any thoughts?

Regards,
Jan

> 
> best regards,
> Zeng
> 
> > Regards,
> > Jan
> 
> 
> 

------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing 
conversations that shape the rapidly evolving mobile landscape. Sign up now. 
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to