monitor.c revision 025ed0f3911836b71f498d8368725c77a7e1932a
/*
* 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 <inttypes.h>
#include <stdint.h>
#include "error.h"
#include "af_unix.h"
/* routines used by monitor publishers (containers) */
int do_mkdirp)
{
int ret;
const char *rundir;
rundir = get_rundir();
if (do_mkdirp) {
return -1;
}
process_lock();
if (ret < 0) {
return ret;
}
}
return -1;
}
return 0;
}
{
if (ret < 0)
return;
process_lock();
if (fd < 0) {
/* it is normal for this open to fail when there is no monitor
* running, so we don't log it
*/
return;
}
process_lock();
return;
}
process_lock();
}
{
}
/* routines used by monitor subscribers (lxc-monitor) */
int lxc_monitor_close(int fd)
{
int ret;
process_lock();
return ret;
}
/* Note we don't use SHA-1 here as we don't want to depend on HAVE_GNUTLS.
* FNV has good anti collision properties and we're not worried
* about pre-image resistance or one-way-ness, we're just trying to make
* the name unique in the 108 bytes of space we have.
*/
{
unsigned char *bp;
{
/* xor the bottom with the current octet */
/* gcc optimised:
* multiply by the 64 bit FNV magic prime mod 2^64
*/
}
return hval;
}
int ret;
/* 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.
*/
return -1;
}
if (ret < 0)
return -1;
return 0;
}
int lxc_monitor_open(const char *lxcpath)
{
struct sockaddr_un addr;
return -1;
process_lock();
if (fd < 0) {
return -1;
}
break;
}
if (ret < 0) {
goto err1;
}
return fd;
err1:
process_lock();
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;
}
process_unlock(); // we're no longer sharing
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);
}