46
47
#define UNIX_PATH_MAX 108
49
int lxc_monitor(const char *name, int output_fd)
51
char path[MAXPATHLEN];
52
int err = -1, nfd, wfd, state;
56
SYSERROR("failed to initialize inotify");
60
snprintf(path, MAXPATHLEN, LXCPATH "/%s/state", name);
62
wfd = inotify_add_watch(nfd, path, IN_DELETE_SELF|IN_CLOSE_WRITE);
64
SYSERROR("failed to add a watch on %s", path);
69
struct inotify_event evt;
71
if (read(nfd, &evt, sizeof(evt)) < 0) {
72
SYSERROR("failed to read inotify event");
76
if (evt.mask & IN_CLOSE_WRITE) {
78
state = lxc_getstate(name);
80
ERROR("failed to get the state for %s",
85
if (write(output_fd, &state, sizeof(state)) < 0) {
86
SYSERROR("failed to send state to %d",
93
if (evt.mask & IN_DELETE_SELF) {
99
ERROR("unknown evt for inotity (%d)", evt.mask);
104
inotify_rm_watch(nfd, wfd);
109
50
static void lxc_monitor_send(struct lxc_msg *msg)
162
103
socklen_t len = sizeof(from);
165
ret = recvfrom(fd, msg, sizeof(*msg), 0,
106
ret = recvfrom(fd, msg, sizeof(*msg), 0,
166
107
(struct sockaddr *)&from, &len);
168
109
SYSERROR("failed to receive state");