From 06d0c3e98a744106cdc761c2ae45a93aa480585f Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Sat, 29 Oct 2005 12:06:19 +0000 Subject: [PATCH] vc_getVserverCtx(): allow vc_get_vx_info() to fail but check for errno==ESRCH; for xid!=0, this syscall will return ENOSYS always git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2210 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/lib/getvserverctx.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/util-vserver/lib/getvserverctx.c b/util-vserver/lib/getvserverctx.c index 667c3cf..59c3963 100644 --- a/util-vserver/lib/getvserverctx.c +++ b/util-vserver/lib/getvserverctx.c @@ -155,12 +155,18 @@ vc_getVserverCtx(char const *id, vcCfgStyle style, bool honor_static, bool *is_r char *cur_name; struct vc_vx_info info; - // determine the vserver which is associated with the xid - // resp. skip this step when the context does not exist - cur_name = (vc_get_vx_info(res, &info)!=-1 ? - vc_getVserverByCtx_Internal(res, &style, 0, false) : 0); + // determine the vserver which is associated with the xid resp. skip + // this step when the context does not exist. When checking whether + // the context exists, do not rely on the success of + // vc_get_vx_info() alone but check 'errno' for ESRCH also. Else, + // wrong results will be caused e.g. for xid 1 which will fail with + // ENOSYS. + cur_name = (vc_get_vx_info(res, &info)!=-1 || errno!=ESRCH ? + vc_getVserverByCtx_Internal(res, &style, 0, false) : + 0); buf[idx] = '\0'; // cut off the '/run' from the vserver name + res = ((cur_name!=0 && vc_compareVserverById(buf, vcCFG_RECENT_FULL, cur_name, vcCFG_RECENT_FULL)==0) @@ -178,7 +184,7 @@ vc_getVserverCtx(char const *id, vcCfgStyle style, bool honor_static, bool *is_r res = getCtxFromFile(buf); } - + return res; } default : return VC_NOCTX; -- 1.8.1.5