added Vector_zeroEnd() function
[util-vserver.git] / util-vserver / src / vcopy-init.hc
1 // $Id$    --*- 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 static void
20 createSkeleton(char const *name)
21 {
22   char const *  app_dir;
23
24   app_dir = vc_getVserverAppDir(name, vcCFG_AUTO, "vunify");
25   if (app_dir==0 &&
26       vc_createSkeleton(name, vcCFG_AUTO, vcSKEL_FILESYSTEM|vcSKEL_PKGMGMT)==-1) {
27     perror("vc_createSkeleton()");
28     exit(1);
29   }
30
31   if (app_dir==0) {
32     app_dir = vc_getVserverAppDir(name, vcCFG_AUTO, "");
33       
34     PathInfo            path = {
35       .d = app_dir,
36       .l = strlen(app_dir),
37     };
38     PathInfo            rhs_path = {
39       .d = "vunify",
40       .l = sizeof("vunify")-1
41     };
42       
43     char                p_buf[ENSC_PI_APPSZ(path, rhs_path)];
44     PathInfo_append(&path, &rhs_path, p_buf);
45
46     Emkdir(path.d, 0755);
47   }
48
49   free(const_cast(char *)(app_dir));
50 }
51
52
53 static void
54 initModeManually(int argc, char *argv[])
55 {
56   int           count=argc/2;
57
58   if (count!=2) {
59     WRITE_MSG(2, "Bad arguments; try '--help' for more information\n");
60     exit(1);
61   }
62
63   MatchList_initManually(&global_info.dst_list, 0, strdup(argv[0]), argv[1]);
64   MatchList_initManually(&global_info.src_list, 0, strdup(argv[2]), argv[3]);
65 }
66
67
68 static void
69 initModeVserver(int argc, char *argv[])
70 {
71   int           count=argc;
72
73   if (count!=2) {
74     WRITE_MSG(2, "Bad arguments; try '--help' for more information\n");
75     exit(1);
76   }
77
78   if (!MatchList_initByVserver(&global_info.src_list, argv[1], 0)) {
79     WRITE_MSG(2, "unification not configured for source vserver\n");
80     exit(1);
81   }
82
83   if (!global_args->is_strict)
84     createSkeleton(argv[0]);
85
86   if (!MatchList_initByVserver(&global_info.dst_list, argv[0], 0)) {
87     WRITE_MSG(2, "unification not configured for destination vserver\n");
88     exit(1);
89   }
90 }