~xnox/ubuntu/saucy/lxc/dep8

« back to all changes in this revision

Viewing changes to src/lxc/lxc_monitor.c

  • Committer: Stéphane Graber
  • Date: 2013-02-18 15:20:18 UTC
  • mto: This revision was merged to the branch mainline in revision 190.
  • Revision ID: stgraber@ubuntu.com-20130218152018-ls2gi9hkqs2kuhj8
Tags: upstream-0.9.0~alpha3
Import upstream version 0.9.0~alpha3

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
        struct lxc_msg msg;
61
61
        regex_t preg;
62
62
        int fd;
 
63
        int len, rc;
63
64
 
64
65
        if (lxc_arguments_parse(&my_args, argc, argv))
65
66
                return -1;
66
67
 
67
 
        if (lxc_log_init(my_args.log_file, my_args.log_priority,
 
68
        if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
68
69
                         my_args.progname, my_args.quiet))
69
70
                return -1;
70
71
 
71
 
        regexp = malloc(strlen(my_args.name) + 3);
 
72
        len = strlen(my_args.name) + 3;
 
73
        regexp = malloc(len + 3);
72
74
        if (!regexp) {
73
75
                ERROR("failed to allocate memory");
74
76
                return -1;
75
77
        }
76
 
        sprintf(regexp, "^%s$", my_args.name);
 
78
        rc = snprintf(regexp, len, "^%s$", my_args.name);
 
79
        if (rc < 0 || rc >= len) {
 
80
                ERROR("Name too long");
 
81
                free(regexp);
 
82
                return -1;
 
83
        }
77
84
 
78
85
        if (regcomp(&preg, regexp, REG_NOSUB|REG_EXTENDED)) {
79
86
                ERROR("failed to compile the regex '%s'", my_args.name);
95
102
 
96
103
                switch (msg.type) {
97
104
                case lxc_msg_state:
98
 
                        printf("'%s' changed state to [%s]\n", 
 
105
                        printf("'%s' changed state to [%s]\n",
99
106
                               msg.name, lxc_state2str(msg.value));
100
107
                        break;
101
108
                default: