]>
git.proxmox.com Git - mirror_lxc.git/blob - src/liblxc/monitor.c
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <dlezcano at fr.ibm.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/inotify.h>
32 #include <netinet/in.h>
39 int lxc_monitor(const char *name
, int output_fd
)
41 char path
[MAXPATHLEN
];
42 int err
= -1, nfd
, wfd
, state
;
46 lxc_log_syserror("failed to initialize inotify");
50 snprintf(path
, MAXPATHLEN
, LXCPATH
"/%s/state", name
);
52 wfd
= inotify_add_watch(nfd
, path
, IN_DELETE_SELF
|IN_CLOSE_WRITE
);
54 lxc_log_syserror("failed to add a watch on %s", path
);
59 struct inotify_event evt
;
61 if (read(nfd
, &evt
, sizeof(evt
)) < 0) {
62 lxc_log_syserror("failed to read inotify event");
66 if (evt
.mask
& IN_CLOSE_WRITE
) {
68 state
= lxc_getstate(name
);
70 lxc_log_error("failed to get the state for %s",
75 if (write(output_fd
, &state
, sizeof(state
)) < 0) {
76 lxc_log_syserror("failed to send state to %d",
83 if (evt
.mask
& IN_DELETE_SELF
) {
89 lxc_log_error("unknown evt for inotity (%d)", evt
.mask
);
94 inotify_rm_watch(nfd
, wfd
);