3 // Copyright (C) 2007 Daniel Hokka Zakrisson
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; either version 2, or (at your option)
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <lib/internal.h>
35 #define ENSC_WRAPPERS_PREFIX "vmemctrl: "
36 #define ENSC_WRAPPERS_VSERVER 1
37 #define ENSC_WRAPPERS_UNISTD 1
40 #define CMD_HELP 0x1000
41 #define CMD_VERSION 0x1001
43 #define CMD_SET 0x2000
44 #define CMD_GET 0x2001
46 #define CMD_XID 0x4000
47 #define CMD_BADNESS 0x4001
49 int wrapper_exit_code = 255;
52 static struct option const
54 { "help", no_argument, 0, CMD_HELP },
55 { "version", no_argument, 0, CMD_VERSION },
56 { "set", no_argument, 0, CMD_SET },
57 { "get", no_argument, 0, CMD_GET },
58 { "xid", required_argument, 0, CMD_XID },
59 { "badness", required_argument, 0, CMD_BADNESS },
72 hasArg(struct Arguments *args, uint32_t arg)
74 return (args->mask & arg) == arg;
78 showHelp(int fd, char const *cmd, int res)
80 WRITE_MSG(fd, "Usage:\n ");
83 " (--set|--get) [--xid <xid>] [--badness <OOM bias>]\n"
84 " [--] [<command> <args>*]\n\n"
85 "Please report bugs to " PACKAGE_BUGREPORT "\n");
94 "vmemctrl " VERSION " -- \n"
95 "This program is part of " PACKAGE_STRING "\n\n"
96 "Copyright (C) 2007 Daniel Hokka Zakrisson\n"
97 VERSION_COPYRIGHT_DISCLAIMER);
102 doset(struct Arguments *args)
104 if (hasArg(args, CMD_BADNESS) &&
105 vc_set_badness(args->xid, args->badness) == -1) {
106 perror(ENSC_WRAPPERS_PREFIX "vc_set_badness()");
107 exit(wrapper_exit_code);
112 doget(struct Arguments *args)
117 if (vc_get_badness(args->xid, &badness) == -1) {
118 perror(ENSC_WRAPPERS_PREFIX "vc_get_badness()");
119 exit(wrapper_exit_code);
121 l = utilvserver_fmt_int64(buf, badness);
127 int main (int argc, char *argv[])
129 struct Arguments args = {
138 int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0);
142 case CMD_HELP : showHelp(1, argv[0], 0);
143 case CMD_VERSION : showVersion();
144 case CMD_XID : args.xid = Evc_xidopt2xid(optarg,true); break;
145 case CMD_SET : args.do_set = true; break;
146 case CMD_GET : args.do_get = true; break;
149 args.badness = strtoll(optarg, &endptr, 0);
151 WRITE_MSG(2, ENSC_WRAPPERS_PREFIX "Badness '");
152 WRITE_STR(2, optarg);
153 WRITE_MSG(2, "' is not an integer\n");
154 exit(wrapper_exit_code);
159 WRITE_MSG(2, "Try '");
160 WRITE_STR(2, argv[0]);
161 WRITE_MSG(2, " --help' for more information.\n");
162 exit(wrapper_exit_code);
168 if (args.xid == VC_NOCTX) args.xid = Evc_get_task_xid(0);
170 if (!args.do_set && !args.do_get) {
171 WRITE_MSG(2, "No operation specified; try '--help' for more information\n");
172 exit(wrapper_exit_code);
174 else if (((args.do_set ? 1 : 0) + (args.do_get ? 1 : 0)) > 1) {
175 WRITE_MSG(2, "Multiple operations specified; try '--help' for more information\n");
176 exit(wrapper_exit_code);
181 else if (args.do_get)
185 Eexecvp (argv[optind],argv+optind);