added new management functions + doc
[util-vserver.git] / util-vserver / lib / getinitpid-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_GETINITPID_LEGACY_H
20 #define H_UTIL_VSERVER_LIB_GETINITPID_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 <string.h>
31 #include <errno.h>
32 #include <sys/types.h>
33
34 static pid_t
35 vc_X_getinitpid_legacy_internal(pid_t pid)
36 {
37   size_t                        bufsize = utilvserver_getProcEntryBufsize();
38   char                          buf[bufsize];
39   char                          *pos = 0;
40
41   pos = utilvserver_getProcEntry(pid, "\ninitpid: ", buf, bufsize);
42
43   if (pos!=0) {
44     if (memcmp(pos,"none",4)==0) return 1;
45     else                         return atoi(pos);
46   }
47   else        return -1;
48 }
49
50 static pid_t
51 vc_X_getinitpid_legacy(pid_t pid)
52 {
53   pid_t         res;
54   do {
55     res = vc_X_getinitpid_legacy_internal(pid);
56   } while (res==-1 && errno==EAGAIN);
57
58   return res;
59 }
60
61 #endif  //  H_UTIL_VSERVER_LIB_GETINITPID_LEGACY_H