merge with 0.30.213
[util-vserver.git] / lib_internal / switchtowatchxid.c
1 // $Id: switchtowatchxid.c 2501 2007-02-20 17:33:35Z dhozac $    --*- c -*--
2
3 // Copyright (C) 2004 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 #ifdef HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include <vserver.h>
24 #include <errno.h>
25 #include <unistd.h>
26
27   // try to switch into context 1
28 bool
29 switchToWatchXid(char const **errptr)
30 {
31 #if 0
32 #  warning Compiling in debug-code
33   return;
34 #endif
35   if (vc_get_task_xid(0)==1) return true;
36
37   if (vc_isSupported(vcFEATURE_MIGRATE)) {
38     if (vc_ctx_migrate(1, 0)==-1) {
39       if (errptr) *errptr = "vc_migrate_context()";
40       return false;
41     }
42   }
43   else {
44 #if VC_ENABLE_API_COMPAT
45     if (vc_new_s_context(1,0,0)==VC_NOCTX) {
46       if (errptr) *errptr = "vc_new_s_context()";
47       return false;
48     }
49 #else
50     if (errptr) *errptr = "can not change context: migrate kernel feature missing and 'compat' API disabled";
51     errno = ENOSYS;
52     return false;
53 #endif
54   }
55
56   return true;
57 }
58