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
|
--- sysdeps/freebsd/glibtop_private.c.orig 2007-06-26 18:07:59.000000000 -0400
+++ sysdeps/freebsd/glibtop_private.c 2007-06-27 00:07:50.000000000 -0400
@@ -0,0 +1,54 @@
+#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
+
+#include "glibtop_private.h"
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#include <glib.h>
+#include <errno.h>
+
+char *
+execute_lsof(pid_t pid) {
+ char *output = NULL;
+ char *lsof;
+ char *command;
+ int exit_status;
+
+ lsof = g_find_program_in_path("lsof");
+ if (lsof == NULL)
+ return NULL;
+
+ command = g_strdup_printf("%s -n -P -Fftn -p %d", lsof, pid);
+ g_free(lsof);
+
+ if (g_spawn_command_line_sync (command, &output, NULL, &exit_status, NULL)) {
+ if (exit_status != 0) {
+ g_warning("Could not execute \"%s\" (%i)", command,
+ exit_status);
+ output = NULL;
+ }
+ }
+
+ g_free(command);
+ return output;
+}
+
+/* Ported from linux/glibtop_private.c */
+gboolean
+safe_readlink(const char *path, char *buf, int bufsiz)
+{
+ int ret;
+
+ ret = readlink(path, buf, bufsiz - 1);
+
+ if (ret == -1) {
+ g_warning("Could not read link %s : %s", path, strerror(errno));
+ return FALSE;
+ }
+
+ buf[ret] = '\0';
+ return TRUE;
+}
|