monitor.c revision 8b79a8fec4127c754509d65faae1fe7f09515365
/*
* lxc: linux Container library
*
* (C) Copyright IBM Corp. 2007, 2008
*
* Authors:
* Daniel Lezcano <daniel.lezcano at free.fr>
* Dwight Engen <dwight.engen@oracle.com>
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <poll.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "config.h"
#include "af_unix.h"
#include "error.h"
#include "log.h"
#include "lxclock.h"
#include "monitor.h"
#include "state.h"
#include "utils.h"
/* routines used by monitor publishers (containers) */
int do_mkdirp)
{
int ret;
char *rundir;
rundir = get_rundir();
if (!rundir)
return -1;
if (do_mkdirp) {
return -1;
}
if (ret < 0) {
return ret;
}
}
return -1;
}
return 0;
}
{
if (ret < 0)
return;
/* Open the fifo nonblock in case the monitor is dead, we don't want the
* open to wait for a reader since it may never come.
*/
if (fd < 0) {
/* It is normal for this open() to fail with ENXIO when there is
* no monitor running, so we don't log it.
*/
return;
return;
}
return;
}
return;
}
}
const char *lxcpath)
{
}
const char *lxcpath)
{
}
/* routines used by monitor subscribers (lxc-monitor) */
int lxc_monitor_close(int fd)
{
}
int ret;
char *sockname;
char *path;
/* addr.sun_path is only 108 bytes, so we hash the full name and
* then append as much of the name as we can fit.
*/
ERROR("Failed to create path for monitor.");
return -1;
}
if (ret < 0)
return -1;
return 0;
}
int lxc_monitor_open(const char *lxcpath)
{
struct sockaddr_un addr;
int fd;
return -1;
if (fd < 0) {
return -1;
}
ret = -1;
goto on_error;
}
break;
}
if (ret < 0) {
goto on_error;
}
return fd;
return ret;
}
int timeout)
{
long i;
int ret;
if (ret == -1)
return -1;
else if (ret == 0)
return -2; // timed out
/* Only read from the first ready fd, the others will remain ready for
* when this routine is called again.
*/
for (i = 0; i < nfds; i++) {
if (ret <= 0) {
return -1;
}
return ret;
}
}
SYSERROR("No ready fd found.");
return -1;
}
{
}
{
}
/* Used to spawn a monitord either on startup of a daemon container, or when
* lxc-monitor starts.
*/
int lxc_monitord_spawn(const char *lxcpath)
{
int ret;
int pipefd[2];
char pipefd_str[LXC_NUMSTRLEN64];
char *const args[] = {
(char *)lxcpath,
NULL,
};
/* double fork to avoid zombies when monitord exits */
if (pid1 < 0) {
SYSERROR("Failed to fork().");
return -1;
}
if (pid1) {
return -1;
return 0;
}
SYSERROR("Failed to create pipe.");
}
if (pid2 < 0) {
SYSERROR("Failed to fork().");
}
if (pid2) {
char c;
/* Wait for daemon to create socket. */
/* Sync with child, we're ignoring the return from read
* because regardless if it works or not, either way we've
* synced with the child process. the if-empty-statement
* construct is to quiet the warn-unused-result warning.
*/
;
}
if (setsid() < 0) {
SYSERROR("Failed to setsid().");
}
if (null_stdfds() < 0) {
}
ERROR("Failed to create pid argument to pass to monitord.");
}
ERROR("Failed to exec lxc-monitord.");
}