-
Notifications
You must be signed in to change notification settings - Fork 8
/
kill.c
56 lines (48 loc) · 1.65 KB
/
kill.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* bubblewrap-oci
* Copyright (C) 2016, 2017 Giuseppe Scrivano
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 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, see <http://www.gnu.org/licenses/>.
*
*/
#include <config.h>
#include "util.h"
#include "kill.h"
#ifdef HAVE_ERROR_H
#include <error.h>
#endif
#include <stdlib.h>
#include <errno.h>
void
kill_container (const char *name, const char *signal)
{
cleanup_free gchar *run_directory = get_run_directory ();
cleanup_free gchar *path = NULL;
pid_t pid;
int r;
long signal_value;
char *endptr = NULL;
path = g_strdup_printf ("%s/%s/status.json", run_directory, name);
if (! file_exist_p ("", path))
error (EXIT_FAILURE, 0, "container %s doesn't exist", name);
read_container_status_file (path, &pid, NULL);
if (pid == 0)
error (EXIT_FAILURE, 0, "container %s doesn't exist", name);
errno = 0;
signal_value = strtol (signal, &endptr, 10);
if (errno != 0 || signal_value == 0 || *endptr != '\0')
error (EXIT_FAILURE, errno, "invalid signal specified");
r = kill (pid, signal_value);
if (r < 0)
error (EXIT_FAILURE, errno, "kill %lu", signal_value);
}