]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/arguments.h
extend the struct lxc_arguments
[mirror_lxc.git] / src / lxc / arguments.h
1 /*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <dlezcano at fr.ibm.com>
8 * Michel Normand <normand at fr.ibm.com>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 #ifndef __arguments_h
25 #define __arguments_h
26
27 #include <getopt.h>
28
29 struct lxc_arguments;
30
31 typedef int (*lxc_arguments_parser_t) (struct lxc_arguments *, int, char*);
32 typedef int (*lxc_arguments_checker_t) (const struct lxc_arguments *);
33
34 struct lxc_arguments {
35 const char *help;
36 const char *progname;
37 const struct option* options;
38 lxc_arguments_parser_t parser;
39 lxc_arguments_checker_t checker;
40
41 const char *name;
42 char *log_file;
43 char *log_priority;
44 int quiet;
45 int daemonize;
46 const char *rcfile;
47 const char *console;
48
49 /* for lxc-checkpoint/restart */
50 const char *statefile;
51 int statefd;
52 int flags;
53
54 /* for lxc-console */
55 int ttynum;
56 char escape;
57
58 /* for lxc-wait */
59 char *states;
60
61 /* remaining arguments */
62 char *const *argv;
63 int argc;
64
65 /* private arguments */
66 void *data;
67 };
68
69 #define LXC_COMMON_OPTIONS \
70 {"name", required_argument, 0, 'n'}, \
71 {"help", no_argument, 0, 'h'}, \
72 {"usage", no_argument, 0, OPT_USAGE}, \
73 {"quiet", no_argument, 0, 'q'}, \
74 {"logfile", required_argument, 0, 'o'}, \
75 {"logpriority", required_argument, 0, 'l'}, \
76 {0, 0, 0, 0}
77
78 /* option keys for long only options */
79 #define OPT_USAGE 0x1000
80
81 extern int lxc_arguments_parse(struct lxc_arguments *args,
82 int argc, char *const argv[]);
83
84 extern int lxc_arguments_str_to_int(struct lxc_arguments *args, const char *str);
85
86 extern const char *lxc_strerror(int errnum);
87
88 #define lxc_error(arg, fmt, args...) if (!(arg)->quiet) \
89 fprintf(stderr, "%s: " fmt "\n", (arg)->progname, ## args)
90
91 #endif