monitor.c revision 250b1eec71b074acdff1c5f6b5a1f0d7d2c20b77
/*
* 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 <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include "error.h"
#include "af_unix.h"
/* routines used by monitor publishers (containers) */
{
ERROR("lxcpath too long to open monitor fifo");
return;
}
if (fd < 0) {
/* it is normal for this open to fail when there is no monitor
* running, so we don't log it
*/
return;
}
return;
}
}
{
}
/* routines used by monitor subscribers (lxc-monitor) */
int lxc_monitor_close(int fd)
{
}
int ret;
/* addr.sun_path is only 108 bytes.
* should we take a hash of lxcpath? a subset of it? ftok()? we need
* to make sure it is unique.
*/
ERROR("lxcpath too long for unix socket");
return -1;
}
return 0;
}
int lxc_monitor_open(const char *lxcpath)
{
struct sockaddr_un addr;
return -1;
if (fd < 0) {
return -1;
}
break;
}
if (ret < 0) {
goto err1;
}
return fd;
err1:
return ret;
}
int timeout)
{
int ret,i;
if (timeout != -1) {
}
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) {
SYSERROR("client failed to recv (monitord died?) %s",
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 pipefd[2];
char pipefd_str[11];
char * const args[] = {
"lxc-monitord",
(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.
*/
}
umask(0);
if (setsid() < 0) {
SYSERROR("failed to setsid");
}
close(0);
close(1);
close(2);
}