initial checkin
[util-vserver.git] / util-vserver / src / vattribute.c
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 #ifdef HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include "util.h"
24 #include <lib/vserver.h>
25
26 #include <getopt.h>
27 #include <stdint.h>
28
29 #define ENSC_WRAPPERS_VSERVER   1
30 #include <wrappers.h>
31
32 #define CMD_HELP                0x1000
33 #define CMD_VERSION             0x1001
34 #define CMD_XID                 0x2000
35 #define CMD_SET                 0x2001
36 #define CMD_CAP                 0x2002
37 #define CMD_FLAG                0x2003
38 #define CMD_SECURE              0x2004
39
40 int                     wrapper_exit_code = 1;
41
42 struct option const
43 CMDLINE_OPTIONS[] = {
44   { "help",       no_argument,       0, CMD_HELP },
45   { "version",    no_argument,       0, CMD_VERSION },
46   { "xid",        required_argument, 0, CMD_XID },
47   { "set",        no_argument,       0, CMD_SET },
48   { "cap",        required_argument, 0, CMD_CAP },
49   { "flag",       required_argument, 0, CMD_FLAG },
50   { "secure",     no_argument,       0, CMD_SECURE },
51   {0,0,0,0}
52 };
53
54 struct Arguments {
55     xid_t               xid;
56     struct vc_ctx_flags flags;
57     struct vc_ctx_flags caps;
58 };
59
60 static void
61 showHelp(int fd, char const *cmd, int res)
62 {
63   WRITE_MSG(fd, "Usage:\n    ");
64   WRITE_STR(fd, cmd);
65   WRITE_MSG(fd,
66             " --set [--xid <xid>] [--cap [~!]<cap>] [--flag [~!]<flag>] [--secure] -- [<program> <args>*]\n"
67             "\n"
68             "Please report bugs to " PACKAGE_BUGREPORT "\n");
69
70   exit(res);
71 }
72
73 static void
74 showVersion()
75 {
76   WRITE_MSG(1,
77             "vattribute " VERSION " -- sets attributes of vservers\n"
78             "This program is part of " PACKAGE_STRING "\n\n"
79             "Copyright (C) 2004 Enrico Scholz\n"
80             VERSION_COPYRIGHT_DISCLAIMER);
81   exit(0);
82 }
83
84 static void
85 setFlags(char const UNUSED *str, struct vc_ctx_flags UNUSED * flags)
86 {
87   abort();
88 }
89
90 static void
91 setCaps(char const UNUSED *str, struct vc_ctx_flags UNUSED * caps)
92 {
93   abort();
94 }
95
96 static void
97 setSecure(struct vc_ctx_flags UNUSED * flags,
98           struct vc_ctx_flags UNUSED * caps)
99 {
100   abort();
101 }
102
103
104 int main(int argc, char *argv[])
105 {
106   struct Arguments              args = {
107     .xid   = VC_NOCTX,
108     .flags = { .flagword = 0, .mask = 0 },
109     .caps  = { .flagword = 0, .mask = 0 },
110   };
111   
112   while (1) {
113     int         c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0);
114     if (c==-1) break;
115
116     switch (c) {
117       case CMD_HELP     :  showHelp(1, argv[0], 0);
118       case CMD_VERSION  :  showVersion();
119       case CMD_SET      :  break; // default op currently
120       case CMD_XID      :  args.xid = atoi(optarg); break;
121       case CMD_FLAG     :  setFlags(optarg, &args.flags);      break;
122       case CMD_CAP      :  setCaps(optarg,  &args.caps);       break;
123       case CMD_SECURE   :  setSecure(&args.flags, &args.caps); break;
124       default           :
125         WRITE_MSG(2, "Try '");
126         WRITE_STR(2, argv[0]);
127         WRITE_MSG(2, " --help\" for more information.\n");
128         return 255;
129         break;
130     }
131   }
132
133   if (args.xid==VC_NOCTX) args.xid = Evc_get_task_xid(0);
134
135   if (vc_set_flags(args.xid,&args.flags)==-1)
136     perror("vc_set_flags()");
137 //  else if (vc_set_caps(xid, &args.caps)==-1)
138 //    perror("vc_set_caps()");
139   else
140     return EXIT_SUCCESS;
141
142   return EXIT_FAILURE;
143 }