-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlist.c
86 lines (78 loc) · 2.3 KB
/
list.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* 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 <unistd.h>
#include <stdlib.h>
#ifdef HAVE_ERROR_H
#include <error.h>
#endif
#include <stdio.h>
#include <glib.h>
#include <glib-object.h>
#include <json-glib/json-glib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <seccomp.h>
#include <errno.h>
#include <glib/gprintf.h>
#include <string.h>
#include <sys/socket.h>
#include <gio/gunixinputstream.h>
#include <libgen.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <dirent.h>
#include "safe-read-write.h"
#include "subugidmap.h"
#include "util.h"
void
list_containers ()
{
cleanup_free gchar *run_directory = get_run_directory ();
DIR *dir = opendir (run_directory);
struct dirent *dp;
if (dir == NULL)
{
if (errno == ENOENT)
{
g_free (run_directory);
return;
}
error (EXIT_FAILURE, errno, "error opening %s", run_directory);
}
printf ("%-30s%-10s%-10s%s\n", "NAME", "PID", "STATUS", "BUNDLE");
do
{
cleanup_free gchar *path = NULL;
cleanup_free gchar *bundlePath = NULL;
const char *process_status;
pid_t pid;
if ((dp = readdir(dir)) != NULL)
{
if (dp->d_name[0] == '.')
continue;
path = g_strdup_printf ("%s/%s/status.json", run_directory, dp->d_name);
read_container_status_file (path, &pid, &bundlePath);
process_status = pid_running_p (pid) ? "running" : "stopped";
printf ("%-30s%-10d%-10s%s\n", dp->d_name, pid, process_status, bundlePath ? : "(none)");
}
}
while (dp != NULL);
closedir (dir);
}