tty: Make sure the controlling terminal is restored by session leader
tty: Make sure the controlling terminal is restored by session leader

The controling terminal should be sestored by a session leader,
thus we need to test if the SID we've found in process tree
is a leader.

Otherwise we might have pretty interesting situation: the user
passed -j on dump, ie telling us to inherit shell jobs and on
restore procedure the SID get inherited from the crtools but
session leader for this sid doesn't belong to our peocess tree
and thus we should not try to restore controlling terminal
but inherit it as well.

Reported-by: Andrey Vagin <74c05afa918858348d6db8037d82fa8124870113@openvz.org>
Signed-off-by: Cyrill Gorcunov <7a1ea01eee6961eb1e372e3508c2670446d086f4@openvz.org>
Acked-by: Andrey Vagin <74c05afa918858348d6db8037d82fa8124870113@openvz.org>
Signed-off-by: Pavel Emelyanov <c9a32589e048e044184536f7ac71ef92fe82df3e@parallels.com>

KKoukiou/criu-remote,kawamuray/criu,tych0/criu,tych0/criu,tych0/criu,fbocharov/criu,ldu4/criu,gonkulator/criu,AuthenticEshkinKot/criu,gonkulator/criu,marcosnils/criu,KKoukiou/criu-remote,wtf42/criu,tych0/criu,fbocharov/criu,biddyweb/criu,AuthenticEshkinKot/criu,efiop/criu,wtf42/criu,sdgdsffdsfff/criu,wtf42/criu,ldu4/criu,rentzsch/criu,eabatalov/criu,sdgdsffdsfff/criu,marcosnils/criu,LK4D4/criu,svloyso/criu,svloyso/criu,marcosnils/criu,tych0/criu,AuthenticEshkinKot/criu,fbocharov/criu,gablg1/criu,efiop/criu,svloyso/criu,rentzsch/criu,biddyweb/criu,LK4D4/criu,gonkulator/criu,eabatalov/criu,tych0/criu,gablg1/criu,sdgdsffdsfff/criu,KKoukiou/criu-remote,kawamuray/criu,biddyweb/criu,rentzsch/criu,wtf42/criu,sdgdsffdsfff/criu,biddyweb/criu,eabatalov/criu,gablg1/criu,biddyweb/criu,kawamuray/criu,AuthenticEshkinKot/criu,KKoukiou/criu-remote,biddyweb/criu,marcosnils/criu,rentzsch/criu,fbocharov/criu,sdgdsffdsfff/criu,wtf42/criu,eabatalov/criu,svloyso/criu,gablg1/criu,LK4D4/criu,LK4D4/criu,eabatalov/criu,KKoukiou/criu-remote,svloyso/criu,AuthenticEshkinKot/criu,KKoukiou/criu-remote,rentzsch/criu,LK4D4/criu,kawamuray/criu,svloyso/criu,AuthenticEshkinKot/criu,efiop/criu,gablg1/criu,gablg1/criu,marcosnils/criu,wtf42/criu,ldu4/criu,LK4D4/criu,fbocharov/criu,gonkulator/criu,ldu4/criu,sdgdsffdsfff/criu,eabatalov/criu,kawamuray/criu,kawamuray/criu,gonkulator/criu,fbocharov/criu,ldu4/criu,marcosnils/criu,efiop/criu,efiop/criu,ldu4/criu,rentzsch/criu,efiop/criu,gonkulator/criu