29
29
#include <sys/signal.h>
30
30
#include <sys/types.h>
31
31
#include <sys/stat.h>
32
#include <sys/socket.h>
35
35
#include <lxc/log.h>
36
#include <lxc/start.h>
37
40
lxc_log_define(lxc_stop, lxc);
41
42
int lxc_stop(const char *name)
43
char init[MAXPATHLEN];
48
if (lxc_check_lock(name) < 0)
51
snprintf(init, MAXPATHLEN, LXCPATH "/%s/init", name);
52
fd = open(init, O_RDONLY);
54
SYSERROR("failed to open init file for %s", name);
58
if (read(fd, val, sizeof(val)) < 0) {
59
SYSERROR("failed to read %s", init);
65
if (kill(pid, SIGKILL)) {
66
SYSERROR("failed to kill %zd", pid);
44
struct lxc_command command = {
45
.request = { .type = LXC_COMMAND_STOP },
50
ret = lxc_command(name, &command,&stopped);
51
if (ret < 0 && stopped) {
52
INFO("'%s' is already stopped", name);
57
ERROR("failed to send command");
61
/* we do not expect any answer, because we wait for the connection to be
65
ERROR("failed to stop '%s': %s",
66
name, strerror(-command.answer.ret));
70
INFO("'%s' has stopped", name);
75
/*----------------------------------------------------------------------------
76
* functions used by lxc-start mainloop
77
* to handle above command request.
78
*--------------------------------------------------------------------------*/
79
extern int lxc_stop_callback(int fd, struct lxc_request *request,
80
struct lxc_handler *handler)
82
struct lxc_answer answer;
85
answer.ret = kill(handler->pid, SIGKILL);
89
ret = send(fd, &answer, sizeof(answer), 0);
91
WARN("failed to send answer to the peer");
95
if (ret != sizeof(answer)) {
96
ERROR("partial answer sent");