summaryrefslogtreecommitdiff
path: root/sysutils/open-vm-tools/patches/patch-bf
blob: 9d604f1bacd3f758bd2af10bd7df90c45eafb514 (plain)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
$NetBSD: patch-bf,v 1.3 2016/10/12 13:57:13 ryoon Exp $

--- lib/procMgr/procMgrPosix.c.orig	2016-02-16 20:06:46.000000000 +0000
+++ lib/procMgr/procMgrPosix.c
@@ -27,7 +27,7 @@
 // pull in setresuid()/setresgid() if possible
 #define  _GNU_SOURCE
 #include <unistd.h>
-#if !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__)
+#if !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__) && !defined(__NetBSD__)
 #include <asm/param.h>
 #endif
 #if !defined(sun) && !defined(__APPLE__)
@@ -47,13 +47,13 @@
 #include <time.h>
 #include <grp.h>
 #include <sys/syscall.h>
-#if defined(linux) || defined(__FreeBSD__) || defined(HAVE_SYS_USER_H)
+#if defined(linux) || defined(__FreeBSD__) || defined(HAVE_SYS_USER_H) || defined(__NetBSD__)
 // sys/param.h is required on FreeBSD before sys/user.h
 #   include <sys/param.h>
 // Pull in PAGE_SIZE/PAGE_SHIFT defines ahead of vm_basic_defs.h
 #   include <sys/user.h>
 #endif
-#if defined (__FreeBSD__)
+#if defined (__FreeBSD__) || defined(__NetBSD__)
 #include <kvm.h>
 #include <limits.h>
 #include <paths.h>
@@ -633,7 +633,7 @@ abort:
  *----------------------------------------------------------------------
  */
 
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__NetBSD__)
 ProcMgrProcInfoArray *
 ProcMgr_ListProcesses(void)
 {
@@ -641,7 +641,11 @@ ProcMgr_ListProcesses(void)
    ProcMgrProcInfo procInfo;
    Bool failed = TRUE;
    static kvm_t *kd;
+#if defined(__NetBSD__)
+   struct kinfo_proc2 *kp;
+#else
    struct kinfo_proc *kp;
+#endif
    char errbuf[_POSIX2_LINE_MAX];
    int i;
    int nentries=-1;
@@ -664,7 +668,12 @@ ProcMgr_ListProcesses(void)
    /*
     * Get the list of process info structs
     */
+#if defined(__NetBSD__)
+   int elemsize = INT_MAX;
+   kp = kvm_getproc2(kd, KERN_PROC_ALL, flag, elemsize, &nentries);
+#else
    kp = kvm_getprocs(kd, KERN_PROC_PROC, flag, &nentries);
+#endif
    if (kp == NULL || nentries <= 0) {
       Warning("%s: failed to get proc infos with error: %s\n",
               __FUNCTION__, kvm_geterr(kd));
@@ -692,14 +701,26 @@ ProcMgr_ListProcesses(void)
       /*
        * Store the pid of the process.
        */
+#if defined(__NetBSD__)
+      procInfo.procId = kp->p_pid;
+#else
       procInfo.procId = kp->ki_pid;
+#endif
 
       /*
        * Store the owner of the process.
        */
+#if defined(__NetBSD__)
+      pwd = getpwuid(kp->p_uid);
+#else
       pwd = getpwuid(kp->ki_uid);
+#endif
       procInfo.procOwner = (NULL == pwd)
+#if defined(__NetBSD__)
+                           ? Str_SafeAsprintf(NULL, "%d", (int) kp->p_uid)
+#else
                            ? Str_SafeAsprintf(NULL, "%d", (int) kp->ki_uid)
+#endif
                            : Unicode_Alloc(pwd->pw_name, STRING_ENCODING_DEFAULT);
 
       /*
@@ -707,15 +728,24 @@ ProcMgr_ListProcesses(void)
        * maximum allowed size, then we can save it right now. Else we shall
        * need to try and parse it from the entire command line.
        */
+#if defined(__NetBSD__)
+      if (strlen(kp->p_comm) + 1 < sizeof kp->p_comm) {
+         procInfo.procCmdName = Unicode_Alloc(kp->p_comm, STRING_ENCODING_DEFAULT);
+#else
       if (strlen(kp->ki_comm) + 1 < sizeof kp->ki_comm) {
          procInfo.procCmdName = Unicode_Alloc(kp->ki_comm, STRING_ENCODING_DEFAULT);
+#endif
          cmdNameLookup = FALSE;
       }
 
       /*
        * Store the command line string of the process.
        */
+#if defined(__NetBSD__)
+      cmdLineTemp = kvm_getargv2(kd, kp, 0);
+#else
       cmdLineTemp = kvm_getargv(kd, kp, 0);
+#endif
       if (cmdLineTemp != NULL) {
          /*
           * Flatten the argument list to get cmd & all params.
@@ -771,9 +801,15 @@ ProcMgr_ListProcesses(void)
          procInfo.procCmdLine = DynBuf_Detach(&dbuf);
          DynBuf_Destroy(&dbuf);
       } else {
+#if defined(__NetBSD__)
+         procInfo.procCmdLine = Unicode_Alloc(kp->p_comm, STRING_ENCODING_DEFAULT);
+         if (cmdNameLookup) {
+            procInfo.procCmdName = Unicode_Alloc(kp->p_comm, STRING_ENCODING_DEFAULT);
+#else
          procInfo.procCmdLine = Unicode_Alloc(kp->ki_comm, STRING_ENCODING_DEFAULT);
          if (cmdNameLookup) {
             procInfo.procCmdName = Unicode_Alloc(kp->ki_comm, STRING_ENCODING_DEFAULT);
+#endif
             cmdNameLookup = FALSE;
          }
       }
@@ -781,7 +817,11 @@ ProcMgr_ListProcesses(void)
       /*
        * Store the start time of the process
        */
+#if defined(__NetBSD__)
+      procInfo.procStartTime = kp->p_rtime_sec;
+#else
       procInfo.procStartTime = kp->ki_start.tv_sec;
+#endif
 
       /*
        * Store the process info pointer into a list buffer.
@@ -811,7 +851,7 @@ abort:
 
    return procList;
 }
-#endif // defined(__FreeBSD__)
+#endif // defined(__NetBSD__)
 
 
 #if defined(__APPLE__)
@@ -2033,7 +2073,7 @@ ProcMgr_Free(ProcMgr_AsyncProc *asyncPro
    free(asyncProc);
 }
 
-#if defined(linux) || defined(__FreeBSD__) || defined(__APPLE__)
+#if defined(linux) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__)
 
 /*
  *----------------------------------------------------------------------
@@ -2106,7 +2146,7 @@ ProcMgr_ImpersonateUserStart(const char 
    // first change group
 #if defined(USERWORLD)
    ret = Id_SetREGid(ppw->pw_gid, ppw->pw_gid);
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) || defined(__NetBSD__)
    ret = setregid(ppw->pw_gid, ppw->pw_gid);
 #else
    ret = setresgid(ppw->pw_gid, ppw->pw_gid, root_gid);
@@ -2125,7 +2165,7 @@ ProcMgr_ImpersonateUserStart(const char 
    // now user
 #if defined(USERWORLD)
    ret = Id_SetREUid(ppw->pw_uid, ppw->pw_uid);
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) || defined(__NetBSD__)
    ret = setreuid(ppw->pw_uid, ppw->pw_uid);
 #else
    ret = setresuid(ppw->pw_uid, ppw->pw_uid, 0);
@@ -2187,7 +2227,7 @@ ProcMgr_ImpersonateUserStop(void)
    // first change back user
 #if defined(USERWORLD)
    ret = Id_SetREUid(ppw->pw_uid, ppw->pw_uid);
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) || defined(__NetBSD__)
    ret = setreuid(ppw->pw_uid, ppw->pw_uid);
 #else
    ret = setresuid(ppw->pw_uid, ppw->pw_uid, 0);
@@ -2200,7 +2240,7 @@ ProcMgr_ImpersonateUserStop(void)
    // now group
 #if defined(USERWORLD)
    ret = Id_SetREGid(ppw->pw_gid, ppw->pw_gid);
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) || defined(__NetBSD__)
    ret = setregid(ppw->pw_gid, ppw->pw_gid);
 #else
    ret = setresgid(ppw->pw_gid, ppw->pw_gid, ppw->pw_gid);