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_CAP 0x2002
40 #define CMD_FLAG 0x2003
41 #define CMD_SECURE 0x2004
43 int wrapper_exit_code = 1;
47 { "help", no_argument, 0, CMD_HELP },
48 { "version", no_argument, 0, CMD_VERSION },
49 { "xid", required_argument, 0, CMD_XID },
50 { "set", no_argument, 0, CMD_SET },
51 { "cap", required_argument, 0, CMD_CAP },
52 { "flag", required_argument, 0, CMD_FLAG },
53 { "secure", no_argument, 0, CMD_SECURE },
59 struct vc_ctx_flags flags;
60 struct vc_ctx_flags caps;
64 showHelp(int fd, char const *cmd, int res)
66 WRITE_MSG(fd, "Usage:\n ");
69 " --set [--xid <xid>] [--cap [~!]<cap>] [--flag [~!]<flag>] [--secure] -- [<program> <args>*]\n"
71 "Please report bugs to " PACKAGE_BUGREPORT "\n");
80 "vattribute " VERSION " -- sets attributes of vservers\n"
81 "This program is part of " PACKAGE_STRING "\n\n"
82 "Copyright (C) 2004 Enrico Scholz\n"
83 VERSION_COPYRIGHT_DISCLAIMER);
88 setFlags(char const UNUSED *str, struct vc_ctx_flags UNUSED * flags)
94 rc = vc_list2flag(str,0, &err_ptr,&err_len, &flags->flagword, &flags->mask);
97 WRITE_MSG(2, "Unknown flag '");
98 write(2, err_ptr, err_len);
100 exit(wrapper_exit_code);
105 setCaps(char const UNUSED *str, struct vc_ctx_flags UNUSED * caps)
107 #warning Implement me...
112 setSecure(struct vc_ctx_flags UNUSED * flags,
113 struct vc_ctx_flags UNUSED * caps)
115 #warning Implement me...
120 int main(int argc, char *argv[])
122 struct Arguments args = {
124 .flags = { .flagword = 0, .mask = 0 },
125 .caps = { .flagword = 0, .mask = 0 },
129 int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0);
133 case CMD_HELP : showHelp(1, argv[0], 0);
134 case CMD_VERSION : showVersion();
135 case CMD_SET : break; // default op currently
136 case CMD_XID : args.xid = atoi(optarg); break;
137 case CMD_FLAG : setFlags(optarg, &args.flags); break;
138 case CMD_CAP : setCaps(optarg, &args.caps); break;
139 case CMD_SECURE : setSecure(&args.flags, &args.caps); break;
141 WRITE_MSG(2, "Try '");
142 WRITE_STR(2, argv[0]);
143 WRITE_MSG(2, " --help\" for more information.\n");
149 if (args.xid==VC_NOCTX) args.xid = Evc_get_task_xid(0);
151 if (vc_set_flags(args.xid,&args.flags)==-1)
152 perror("vc_set_flags()");
153 // else if (vc_set_caps(xid, &args.caps)==-1)
154 // perror("vc_set_caps()");
155 else if (optind<argc)
156 EexecvpD(argv[optind], argv+optind);