]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/stop.c
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <dlezcano at fr.ibm.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <sys/param.h>
29 #include <sys/signal.h>
30 #include <sys/types.h>
32 #include <sys/socket.h>
36 #include <lxc/start.h>
41 lxc_log_define(lxc_stop
, lxc
);
43 int lxc_stop(const char *name
)
45 struct lxc_command command
= {
46 .request
= { .type
= LXC_COMMAND_STOP
},
51 ret
= lxc_command(name
, &command
,&stopped
);
52 if (ret
< 0 && stopped
) {
53 INFO("'%s' is already stopped", name
);
58 ERROR("failed to send command");
62 /* we do not expect any answer, because we wait for the connection to be
66 ERROR("failed to stop '%s': %s",
67 name
, strerror(-command
.answer
.ret
));
71 INFO("'%s' has stopped", name
);
76 /*----------------------------------------------------------------------------
77 * functions used by lxc-start mainloop
78 * to handle above command request.
79 *--------------------------------------------------------------------------*/
80 extern int lxc_stop_callback(int fd
, struct lxc_request
*request
,
81 struct lxc_handler
*handler
)
83 struct lxc_answer answer
;
86 answer
.ret
= kill(handler
->pid
, SIGKILL
);
88 ret
= lxc_unfreeze(handler
->name
);
92 ERROR("failed to unfreeze container");
96 ret
= send(fd
, &answer
, sizeof(answer
), 0);
98 WARN("failed to send answer to the peer");
102 if (ret
!= sizeof(answer
)) {
103 ERROR("partial answer sent");