0ad19a3fc3de5592e2453070a818a5a41687900edlezcano/*
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano * lxc: linux Container library
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano *
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano * (C) Copyright IBM Corp. 2007, 2008
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano *
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano * Authors:
9afe19d634946d50eab30e3b90cb5cebcde39eeaDaniel Lezcano * Daniel Lezcano <daniel.lezcano at free.fr>
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano *
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano * This library is free software; you can redistribute it and/or
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano * modify it under the terms of the GNU Lesser General Public
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano * License as published by the Free Software Foundation; either
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano * version 2.1 of the License, or (at your option) any later version.
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano *
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano * This library is distributed in the hope that it will be useful,
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano * but WITHOUT ANY WARRANTY; without even the implied warranty of
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano * Lesser General Public License for more details.
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano *
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano * You should have received a copy of the GNU Lesser General Public
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano * License along with this library; if not, write to the Free Software
250b1eec71b074acdff1c5f6b5a1f0d7d2c20b77Stéphane Graber * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano */
f1a4a029f6480db1aabdf2f9e3c30ea959937d7aS.Çağlar Onur#ifndef __LXC_MONITOR_H
f1a4a029f6480db1aabdf2f9e3c30ea959937d7aS.Çağlar Onur#define __LXC_MONITOR_H
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano
f9870943ecdba3f9a8eeff2b31e3a878368f6566Natanael Copa#include <limits.h>
80f412985ebe51a28d04dfb09aa1ca3e0a53dbbddlezcano#include <sys/param.h>
e51d4895129209cec1c15bda2322136a03ec94b2Dwight Engen#include <sys/un.h>
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn#include <poll.h>
e51d4895129209cec1c15bda2322136a03ec94b2Dwight Engen
f2363e38d07db2ad4796b5580b95e3665ed34a88S.Çağlar Onur#include "conf.h"
80f412985ebe51a28d04dfb09aa1ca3e0a53dbbddlezcano
eae6543da163348b9ff13fc65119de55b5af62bfdlezcanotypedef enum {
eae6543da163348b9ff13fc65119de55b5af62bfdlezcano lxc_msg_state,
eae6543da163348b9ff13fc65119de55b5af62bfdlezcano lxc_msg_priority,
1787abcae0f52847ab9eb93e26fccded668a93b3Jean-Tiare LE BIGOT lxc_msg_exit_code,
eae6543da163348b9ff13fc65119de55b5af62bfdlezcano} lxc_msg_type_t;
eae6543da163348b9ff13fc65119de55b5af62bfdlezcano
eae6543da163348b9ff13fc65119de55b5af62bfdlezcanostruct lxc_msg {
eae6543da163348b9ff13fc65119de55b5af62bfdlezcano lxc_msg_type_t type;
e51d4895129209cec1c15bda2322136a03ec94b2Dwight Engen char name[NAME_MAX+1];
eae6543da163348b9ff13fc65119de55b5af62bfdlezcano int value;
eae6543da163348b9ff13fc65119de55b5af62bfdlezcano};
eae6543da163348b9ff13fc65119de55b5af62bfdlezcano
e51d4895129209cec1c15bda2322136a03ec94b2Dwight Engenextern int lxc_monitor_sock_name(const char *lxcpath, struct sockaddr_un *addr);
9e60f51d0d1d295bdd77f2fa848f3046e04e6804Dwight Engenextern int lxc_monitor_fifo_name(const char *lxcpath, char *fifo_path,
9e60f51d0d1d295bdd77f2fa848f3046e04e6804Dwight Engen size_t fifo_path_sz, int do_mkdirp);
e51d4895129209cec1c15bda2322136a03ec94b2Dwight Engenextern void lxc_monitor_send_state(const char *name, lxc_state_t state,
9123e4718d0db98de2a2935cb2d0bcca1997a333Serge Hallyn const char *lxcpath);
1787abcae0f52847ab9eb93e26fccded668a93b3Jean-Tiare LE BIGOTextern void lxc_monitor_send_exit_code(const char *name, int exit_code,
1787abcae0f52847ab9eb93e26fccded668a93b3Jean-Tiare LE BIGOT const char *lxcpath);
e51d4895129209cec1c15bda2322136a03ec94b2Dwight Engenextern int lxc_monitord_spawn(const char *lxcpath);
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn/*
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * Open the monitoring mechanism for a specific container
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * The function will return an fd corresponding to the events
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * Returns a file descriptor on success, < 0 otherwise
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn */
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallynextern int lxc_monitor_open(const char *lxcpath);
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn/*
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * Blocking read for the next container state change
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * @fd : the file descriptor provided by lxc_monitor_open
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * @msg : the variable which will be filled with the state
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * Returns 0 if the monitored container has exited, > 0 if
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * data was read, < 0 otherwise
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn */
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallynextern int lxc_monitor_read(int fd, struct lxc_msg *msg);
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn/*
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * Blocking read for the next container state change with timeout
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * @fd : the file descriptor provided by lxc_monitor_open
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * @msg : the variable which will be filled with the state
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * @timeout : the timeout in seconds to wait for a state change
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * Returns 0 if the monitored container has exited, > 0 if
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * data was read, < 0 otherwise
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn */
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallynextern int lxc_monitor_read_timeout(int fd, struct lxc_msg *msg, int timeout);
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn/*
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * Blocking read from multiple monitors for the next container state
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * change with timeout
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * @fds : struct pollfd descripting the fds to use
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * @nfds : the number of entries in fds
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * @msg : the variable which will be filled with the state
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * @timeout : the timeout in seconds to wait for a state change
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * Returns 0 if the monitored container has exited, > 0 if
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn * data was read, < 0 otherwise
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn */
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallynextern int lxc_monitor_read_fdset(struct pollfd *fds, nfds_t nfds, struct lxc_msg *msg,
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn int timeout);
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn
2366b8a769b9403fda3c4780c84ad87d07b21d7eSerge Hallyn
0ad19a3fc3de5592e2453070a818a5a41687900edlezcano#endif