summaryrefslogtreecommitdiff
path: root/x11/kde4-baseapps/files/patch-apps-konsole-src-ProcessInfo.cpp
blob: 34dd2af1bd30e910ed2c931b73cf6a1d3d309861 (plain) (blame)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
--- apps/konsole/src/ProcessInfo.cpp.orig	2009-04-15 12:25:25.000000000 +0200
+++ apps/konsole/src/ProcessInfo.cpp	2009-08-14 03:00:37.000000000 +0200
@@ -27,6 +27,14 @@
 #include <unistd.h>
 #include <pwd.h>
 
+// FreeBSD
+#ifdef Q_OS_FREEBSD
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/user.h>
+#include <libutil.h>
+#endif
+
 // Qt
 #include <KDebug>
 #include <QtCore/QDir>
@@ -657,6 +665,120 @@
     }
 } ;
 
+#ifdef Q_OS_FREEBSD
+class FreeBSDProcessInfo : public UnixProcessInfo
+{
+public:
+    FreeBSDProcessInfo(int pid, bool readEnvironment) 
+    : UnixProcessInfo(pid,readEnvironment)
+    {
+    }
+private:
+    virtual bool readProcInfo(int pid)
+    {
+        struct kinfo_proc *kip;
+        int name[4];
+        size_t len;
+
+        name[0] = CTL_KERN;
+        name[1] = KERN_PROC;
+        name[2] = KERN_PROC_PID;
+        name[3] = pid;
+
+        len = 0;
+        if (sysctl(name, 4, NULL, &len, NULL, 0) < 0)
+            return false;
+
+        kip = static_cast<struct kinfo_proc*>(malloc(len));
+        if (kip == NULL)
+            return false;
+
+        if (sysctl(name, 4, kip, &len, NULL, 0) < 0) {
+            free(kip);
+            return false;
+        }
+
+        if (len != sizeof(*kip) || (kip->ki_structsize != sizeof(*kip)) || (kip->ki_pid != pid)) {
+            free(kip);
+            return false;
+        }
+
+        setParentPid(kip->ki_ppid);
+        setForegroundPid(kip->ki_pgid);
+        setName(kip->ki_comm);
+        setPid(pid);
+
+        setUserId(kip->ki_uid);
+        readUserName();
+
+        free(kip);
+
+        return true;
+    }
+
+    virtual bool readArguments(int pid)
+    {
+        char args[ARG_MAX];
+        int name[4];
+        size_t len;
+
+        name[0] = CTL_KERN;
+        name[1] = KERN_PROC;
+        name[2] = KERN_PROC_ARGS;
+        name[3] = pid;
+
+        len = sizeof(args);
+        if (sysctl(name, 4, args, &len, NULL, 0) < 0);
+            return false;
+
+        for (char *cp = args; cp < args + len; cp += strlen(cp) + 1)
+            addArgument(QString(cp));
+
+        return true;
+    }
+
+    virtual bool readEnvironment(int /*pid*/)
+    {
+        // Not supported in FreeBSD
+        return true;
+    }
+
+    virtual bool readCurrentDir(int pid)
+    {
+        struct kinfo_file *kif;
+        int count;
+
+        kif = kinfo_getfile(pid, &count);
+        if (kif == NULL)
+            return false;
+
+        for (int i = 0; i < count; i++) {
+            if (kif[i].kf_fd == KF_FD_TYPE_CWD) {
+                QFileInfo info(QString(kif[i].kf_path));
+                free(kif);
+
+                const bool readable = info.isReadable();
+
+                if (readable) {
+                    if(info.isSymLink())
+                        setCurrentDir(info.symLinkTarget());
+                    else
+                        setCurrentDir(info.filePath());
+                    return true;
+                } else {
+                    if (!readable)
+                        setError(PermissionsError);
+                    else
+                        setError(UnknownError);
+
+                    return false;
+                }
+            }
+        }
+    }
+};
+#endif
+
 SSHProcessInfo::SSHProcessInfo(const ProcessInfo& process)
  : _process(process)
 {
@@ -802,6 +924,8 @@
     return new LinuxProcessInfo(pid,enableEnvironmentRead);
 #elif defined(Q_OS_SOLARIS)
     return new SolarisProcessInfo(pid,enableEnvironmentRead);
+#elif defined(Q_OS_FREEBSD)
+    return new FreeBSDProcessInfo(pid,enableEnvironmentRead);
 #else
     return new NullProcessInfo(pid,enableEnvironmentRead);
 #endif