kill.c revision 5e97c3fcce787a5bc0f8ceef43aa3e05195b480a
2ronwalf/*
2ronwalf * lxc: linux Container library
2ronwalf *
2ronwalf * (C) Copyright IBM Corp. 2007, 2008
2ronwalf *
2ronwalf * Authors:
2ronwalf * Daniel Lezcano <dlezcano at fr.ibm.com>
2ronwalf *
2ronwalf * This library is free software; you can redistribute it and/or
2ronwalf * modify it under the terms of the GNU Lesser General Public
2ronwalf * License as published by the Free Software Foundation; either
2ronwalf * version 2.1 of the License, or (at your option) any later version.
2ronwalf *
2ronwalf * This library is distributed in the hope that it will be useful,
2ronwalf * but WITHOUT ANY WARRANTY; without even the implied warranty of
2ronwalf * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2ronwalf * Lesser General Public License for more details.
2ronwalf *
2ronwalf * You should have received a copy of the GNU Lesser General Public
2ronwalf * License along with this library; if not, write to the Free Software
2ronwalf * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2ronwalf */
2ronwalf#define _GNU_SOURCE
2ronwalf#include <stdio.h>
2ronwalf#undef _GNU_SOURCE
2ronwalf#include <stdlib.h>
2ronwalf#include <errno.h>
2ronwalf#include <unistd.h>
2ronwalf#include <string.h>
2ronwalf#include <signal.h>
2ronwalf#include <fcntl.h>
2ronwalf#include <sys/types.h>
2ronwalf#include <sys/stat.h>
2ronwalf#include <sys/param.h>
2ronwalf#include <netinet/in.h>
2ronwalf#include <net/if.h>
2ronwalf
2ronwalf#include <lxc.h>
2ronwalf#include <state.h>
2ronwalf#include <list.h>
2ronwalf#include <conf.h>
2ronwalf#include <log.h>
2ronwalf
2ronwalfint lxc_kill(const char *name, int signum)
2ronwalf{
2ronwalf char *freezer = NULL, *signal = NULL;
2ronwalf int fd = -1, ret = -1;
2ronwalf
2ronwalf if (signum < SIGHUP || signum > SIGRTMAX) {
2ronwalf lxc_log_error("bad signal value %d", signum);
2ronwalf goto out;
2ronwalf }
2ronwalf
2ronwalf asprintf(&freezer, LXCPATH "/%s/nsgroup/freezer.kill", name);
2ronwalf asprintf(&signal, "%d", signum);
2ronwalf
2ronwalf fd = open(freezer, O_WRONLY);
2ronwalf if (fd < 0) {
2ronwalf lxc_log_syserror("failed to open %s for %s", freezer, name);
2ronwalf goto out;
2ronwalf }
2ronwalf
2ronwalf if (write(fd, &signal, strlen(signal)) < 0) {
2ronwalf lxc_log_syserror("failed to write to %s", freezer);
2ronwalf goto out;
2ronwalf }
2ronwalf
2ronwalf ret = 0;
2ronwalfout:
2ronwalf close(fd);
2ronwalf free(freezer);
2ronwalf free(signal);
2ronwalf return ret;
2ronwalf}
2ronwalf