minor code cleanups
[util-vserver.git] / util-vserver / lib / getctx-legacy.hc
1 // $Id$    --*- c++ -*--
2
3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 //  
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
8 //  
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //  
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18
19 #ifndef H_UTIL_VSERVER_LIB_GETCTX_LEGACY_H
20 #define H_UTIL_VSERVER_LIB_GETCTX_LEGACY_H
21
22 #ifdef HAVE_CONFIG_H
23 #  include <config.h>
24 #endif
25 #include "compat.h"
26
27 #include "vserver.h"
28 #include "utils-legacy.h"
29
30 #include <errno.h>
31 #include <sys/types.h>
32
33 static xid_t
34 vc_X_getctx_legacy_internal(pid_t pid)
35 {
36   size_t                        bufsize = utilvserver_getProcEntryBufsize();
37   char                          buf[bufsize];
38   char                          *pos = 0;
39
40   pos = utilvserver_getProcEntry(pid, "\ns_context: ", buf, bufsize);
41
42   if (pos!=0) return atoi(pos);
43   else        return VC_NOCTX;
44 }
45
46 static xid_t
47 vc_X_getctx_legacy(pid_t pid)
48 {
49   xid_t         res;
50   do {
51     res = vc_X_getctx_legacy_internal(pid);
52   } while (res==VC_NOCTX && errno==EAGAIN);
53
54   return res;
55 }
56
57
58 #endif  //  H_UTIL_VSERVER_LIB_GETCTX_LEGACY_H