28
29
#include <sys/types.h>
30
31
#include <lxc/lxc.h>
34
fprintf(stderr, "%s <command>\n", basename(cmd));
35
fprintf(stderr, "\t -n <name> : name of the container or regular expression\n");
32
#include "arguments.h"
34
lxc_log_define(monitor, lxc);
36
static const struct option my_longopts[] = {
40
static struct lxc_arguments my_args = {
41
.progname = "lxc-monitor",
45
lxc-monitor monitors the state of the NAME container\n\
48
-n, --name=NAME NAME for name of the container\n\
49
NAME may be a regular expression",
50
.options = my_longopts,
39
55
int main(int argc, char *argv[])
43
58
struct lxc_msg msg;
47
while ((opt = getopt(argc, argv, "n:")) != -1) {
58
regexp = malloc(strlen(name) + 3);
59
sprintf(regexp, "^%s$", name);
62
if (lxc_arguments_parse(&my_args, argc, argv))
65
if (lxc_log_init(my_args.log_file, my_args.log_priority,
66
my_args.progname, my_args.quiet))
69
regexp = malloc(strlen(my_args.name) + 3);
70
sprintf(regexp, "^%s$", my_args.name);
61
72
if (regcomp(&preg, regexp, REG_NOSUB|REG_EXTENDED)) {
62
fprintf(stderr, "failed to compile the regex '%s'\n",
73
ERROR("failed to compile the regex '%s'", my_args.name);
67
77
fd = lxc_monitor_open();
69
fprintf(stderr, "failed to open monitor for '%s'\n", name);
74
if (lxc_monitor_read(fd, &msg) < 0) {
76
"failed to read monitor's message for '%s'\n",
82
if (lxc_monitor_read(fd, &msg) < 0)
81
85
if (regexec(&preg, msg.name, 0, NULL, 0))