3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
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.
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.
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.
24 #include <lib/vserver.h>
30 #define ENSC_WRAPPERS_PREFIX "vattribute: "
31 #define ENSC_WRAPPERS_VSERVER 1
32 #define ENSC_WRAPPERS_UNISTD 1
35 #define CMD_HELP 0x1000
36 #define CMD_VERSION 0x1001
37 #define CMD_XID 0x2000
38 #define CMD_SET 0x2001
39 #define CMD_CCAP 0x2002
40 #define CMD_FLAG 0x2003
41 #define CMD_SECURE 0x2004
42 #define CMD_BCAP 0x2005
44 int wrapper_exit_code = 1;
48 { "help", no_argument, 0, CMD_HELP },
49 { "version", no_argument, 0, CMD_VERSION },
50 { "xid", required_argument, 0, CMD_XID },
51 { "set", no_argument, 0, CMD_SET },
52 { "ccap", required_argument, 0, CMD_CCAP },
53 { "bcap", required_argument, 0, CMD_BCAP },
54 { "flag", required_argument, 0, CMD_FLAG },
55 { "secure", no_argument, 0, CMD_SECURE },
61 struct vc_ctx_flags flags;
62 struct vc_ctx_caps caps;
66 showHelp(int fd, char const *cmd, int res)
68 WRITE_MSG(fd, "Usage:\n ");
71 " --set [--xid <xid>] [--bcap [~!]<cap>] [--ccap [~!]<cap>] [--flag [~!]<flag>] [--secure] -- [<program> <args>*]\n"
73 "Please report bugs to " PACKAGE_BUGREPORT "\n");
82 "vattribute " VERSION " -- sets attributes of vservers\n"
83 "This program is part of " PACKAGE_STRING "\n\n"
84 "Copyright (C) 2004 Enrico Scholz\n"
85 VERSION_COPYRIGHT_DISCLAIMER);
90 setFlags(char const *str, struct vc_ctx_flags *flags)
92 struct vc_err_listparser err;
95 rc = vc_list2flag(str,0, &err, flags);
98 WRITE_MSG(2, "Unknown flag '");
99 write(2, err.ptr, err.len);
101 exit(wrapper_exit_code);
106 setBCaps(char const *str, struct vc_ctx_caps *caps)
108 struct vc_err_listparser err;
111 rc = vc_list2bcap(str,0, &err, caps);
114 WRITE_MSG(2, "Unknown bcap '");
115 write(2, err.ptr, err.len);
117 exit(wrapper_exit_code);
122 setCCaps(char const *str, struct vc_ctx_caps *caps)
124 struct vc_err_listparser err;
127 rc = vc_list2ccap(str,0, &err, caps);
130 WRITE_MSG(2, "Unknown ccap '");
131 write(2, err.ptr, err.len);
133 exit(wrapper_exit_code);
140 setSecure(struct vc_ctx_flags UNUSED * flags,
141 struct vc_ctx_caps UNUSED * caps)
143 #warning Implement me...
148 int main(int argc, char *argv[])
150 struct Arguments args = {
152 .flags = { .flagword = 0, .mask = 0 },
153 .caps = { .bcaps = 0, .ccaps = 0, .cmask = 0 },
157 int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0);
161 case CMD_HELP : showHelp(1, argv[0], 0);
162 case CMD_VERSION : showVersion();
163 case CMD_SET : break; // default op currently
164 case CMD_XID : args.xid = atoi(optarg); break;
165 case CMD_FLAG : setFlags(optarg, &args.flags); break;
166 case CMD_CCAP : setCCaps(optarg, &args.caps); break;
167 case CMD_BCAP : setBCaps(optarg, &args.caps); break;
168 case CMD_SECURE : setSecure(&args.flags, &args.caps); break;
170 WRITE_MSG(2, "Try '");
171 WRITE_STR(2, argv[0]);
172 WRITE_MSG(2, " --help\" for more information.\n");
178 if (args.xid==VC_NOCTX) args.xid = Evc_get_task_xid(0);
180 if (vc_set_flags(args.xid, &args.flags)==-1)
181 perror("vc_set_flags()");
182 else if (vc_set_ccaps(args.xid, &args.caps)==-1)
183 perror("vc_set_ccaps()");
184 else if (optind<argc)
185 EexecvpD(argv[optind], argv+optind);