~n-muench/ubuntu/precise/open-vm-tools/open-vm-tools.raring-precise.backport

« back to all changes in this revision

Viewing changes to lib/procMgr/procMgrSolaris.c

  • Committer: Package Import Robot
  • Author(s): Nate Muench
  • Date: 2012-01-23 16:09:45 UTC
  • mfrom: (1.4.6) (2.4.26 sid)
  • Revision ID: package-import@ubuntu.com-20120123160945-b6s0r1vkcovucpf3
Tags: 2011.12.20-562307-0ubuntu1
* Merge latest upstream git tag. Fixes building on Precise
  (LP: #898289, LP: #905612)

* Items merged from Debian unstable:
  - debian/control:
    + open-vm-tools recommends open-vm-dkms. (LP: #598933)
    + open-vm-tools now suggests open-vm-toolbox. (LP: #604998)
  (From 2011.08.21-471295-1 release)
  - Updating maintainer and uploaders fields.
  - Removing vcs fields.
  - Removing references to Daniel's old email address.
  - Updating years in copyright file.
  - Updating to standards version 3.9.2.
  - Updating to debhelper version 8.
  - Switching to source format 3.0 (quilt).
  - Removing manual chrpath setting.
  - Removing exclusion from plugins from debhelper shlibs.
  - Rediffing kvers.patch.
  (From 2011.09.23-491607-1 release)
  - Marking binary architecture-dependend packages as linux and kfreebsd
  only.
  - Removing liburiparser-dev from build-depends as upstream dropped
  unity support.
  - Building with libproc-dev on amd64 again.
  - Dropping disabling of dnet support.
  (From 2011.09.23-491607-2 release)
  - Adding doxygen to build-depends for api documentation.
  - Adding libcunit1-dev to build-depends for test suites.
  - Minimizing rules file.
  - Adding open-vm-tools-dev package, containing only the api
    documentation for now.
  (From 2011.09.23-491607-3 release)
  - Sorting overrides in rules alphabetically.
  - Compacting copyright file.
  - Adding udev rule to set timeout for vmware scsi devices
  (From 2011.12.20-562307-1 release)
  - Adding patch to correct typo in upstreams dkms configuration

* Remaining Changes:
  - Remove Stable part of version numbering.
  - debian folder:
    + Re-added open-vm-dkms.postinst & open-vm-dkms.prerm.
      * Allows dkms modules to compile upon installation.
  - debian/control:
    + Re-add open-vm-source and make into a transitional package
      for open-vm-toolbox.
    + Return dependancies that were moved to open-vm-tools back to
      open-vm-toolbox.
  - debian/rules and debian/open-vm-toolbox.lintian-overrides:
    + Make vmware-user-suid-wrapper suid-root
  - debian/rules:
    + Added CFLAGS field with -Wno-deprecated-declarations
      * Will suppress issues with glib 2.31 or later.
    + Add line to copy vmware-xdg-detect-de into place.
    + Install vmware-user.desktop through toolbox package.
  - debian/open-vm-tools.init:
    + Re-add 'modprobe [-r] vmblock'.
    + Add 'modprobe [-r] vmxnet'.
      * Incase it's not loaded during boot.
    + Remove and re-add pcnet32 module
      * Will be done before (remove) and after (readd) vmxnet module
        is added.
      * If vmxnet doesn't exist (aka modules fail to build), pcnet32 can be
        still used for network connectivity.
      * Workaround until a better fix can be done.
  - Re-add gnome-session to debian/local/xautostart.conf
  - Manpages removed (from debian/manpages):
    + vmmemctl.9
    + vmxnet3.9
    + Remove references to manpages that have been removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
 *----------------------------------------------------------------------------
86
86
 */
87
87
 
88
 
ProcMgr_ProcList *
 
88
ProcMgrProcInfoArray *
89
89
ProcMgr_ListProcesses(void)
90
90
{
91
 
   ProcMgr_ProcList *procList = NULL;
92
 
 
93
 
   Bool failed = FALSE;
94
 
   DynBuf dbProcId;
95
 
   DynBuf dbProcCmd;
96
 
   DynBuf dbProcStartTime;
97
 
   DynBuf dbProcOwner;
 
91
   ProcMgrProcInfoArray *procList = NULL;
 
92
   ProcMgrProcInfo processInfo;
 
93
   Bool failed = TRUE;
98
94
   DIR *dir;
99
95
   struct dirent *ent;
100
96
 
101
 
   DynBuf_Init(&dbProcId);
102
 
   DynBuf_Init(&dbProcCmd);
103
 
   DynBuf_Init(&dbProcStartTime);
104
 
   DynBuf_Init(&dbProcOwner);
 
97
   procList = Util_SafeCalloc(1, sizeof *procList);
 
98
   ProcMgrProcInfoArray_Init(procList, 0);
 
99
   processInfo.procOwner = NULL;
 
100
   processInfo.procCmd = NULL;
105
101
 
106
102
   dir = opendir("/proc");
107
103
   if (NULL == dir) {
108
104
      Warning("ProcMgr_ListProcesses unable to open /proc\n");
109
 
      failed = TRUE;
110
105
      goto exit;
111
106
   }
112
107
 
113
108
   while (TRUE) {
114
 
      pid_t pid;
115
109
      struct passwd *pwd;
116
 
      char *cmdLineTemp;
117
 
      char *userName = NULL;
118
110
      char tempPath[MAXPATHLEN];
119
 
      time_t processStartTime;
120
111
      psinfo_t procInfo;
121
112
      size_t strLen = 0;
122
113
      size_t numRead = 0;
131
122
         if (errno == 0) {
132
123
            break;
133
124
         } else {
134
 
            failed = TRUE;
135
125
            goto exit;
136
126
         }
137
127
      }
152
142
             (res == FILEIO_NO_PERMISSION)) {
153
143
            continue;
154
144
         } else {
155
 
            failed = TRUE;
156
145
            goto exit;
157
146
         }
158
147
      }
160
149
      res = FileIO_Read(&psInfoFd, &procInfo, sizeof procInfo, &numRead);
161
150
      FileIO_Close(&psInfoFd);
162
151
      if (res != FILEIO_SUCCESS) {
163
 
         failed = TRUE;
164
152
         goto exit;
165
153
      }
166
154
 
167
 
      processStartTime = procInfo.pr_start.tv_sec;
 
155
      processInfo.procStartTime = procInfo.pr_start.tv_sec;
168
156
 
169
157
      /*
170
158
       * Command line strings in procInfo.pr_psargs are truncated to PRARGZ
178
166
 
179
167
         tmp = ExtractCommandLineFromAddressSpaceFile(&procInfo);
180
168
         if (tmp != NULL) {
181
 
            cmdLineTemp = Unicode_Alloc(tmp, STRING_ENCODING_DEFAULT);
 
169
            processInfo.procCmd = Unicode_Alloc(tmp, STRING_ENCODING_DEFAULT);
182
170
            free(tmp);
183
171
         } else {
184
 
            cmdLineTemp = Unicode_Alloc(procInfo.pr_psargs,
185
 
                                        STRING_ENCODING_DEFAULT);
 
172
            processInfo.procCmd = Unicode_Alloc(procInfo.pr_psargs,
 
173
                                                STRING_ENCODING_DEFAULT);
186
174
         }
187
175
      } else {
188
 
         cmdLineTemp = Unicode_Alloc(procInfo.pr_psargs,
189
 
                                     STRING_ENCODING_DEFAULT);
 
176
         processInfo.procCmd = Unicode_Alloc(procInfo.pr_psargs,
 
177
                                             STRING_ENCODING_DEFAULT);
190
178
      }
191
179
 
192
180
      /*
193
 
       * Store the command line string pointer in dynbuf.
194
 
       */
195
 
      DynBuf_Append(&dbProcCmd, &cmdLineTemp, sizeof cmdLineTemp);
196
 
 
197
 
      /*
198
181
       * Store the pid in dynbuf.
199
182
       */
200
 
      pid = procInfo.pr_pid;
201
 
      DynBuf_Append(&dbProcId, &pid, sizeof pid);
 
183
      processInfo.procId = procInfo.pr_pid;
202
184
 
203
185
      /*
204
186
       * Store the owner of the process.
205
187
       */
206
188
      pwd = getpwuid(procInfo.pr_uid);
207
 
      userName = (NULL == pwd)
208
 
                 ? Str_Asprintf(&strLen, "%d", (int) procInfo.pr_uid)
209
 
                 : Unicode_Alloc(pwd->pw_name, STRING_ENCODING_DEFAULT);
210
 
      DynBuf_Append(&dbProcOwner, &userName, sizeof userName);
 
189
      processInfo.procOwner = (NULL == pwd)
 
190
                              ? Str_SafeAsprintf(&strLen, "%d", (int) procInfo.pr_uid)
 
191
                              : Unicode_Alloc(pwd->pw_name, STRING_ENCODING_DEFAULT);
211
192
 
212
193
      /*
213
 
       * Store the time that the process started.
 
194
       * Store the process info into a list buffer.
214
195
       */
215
 
      DynBuf_Append(&dbProcStartTime,
216
 
                    &processStartTime,
217
 
                    sizeof processStartTime);
 
196
      if (!ProcMgrProcInfoArray_Push(procList, processInfo)) {
 
197
         Warning("%s: failed to expand DynArray - out of memory\n",
 
198
                 __FUNCTION__);
 
199
         goto exit;
 
200
      }
 
201
      processInfo.procCmd = NULL;
 
202
      processInfo.procOwner = NULL;
218
203
   } // while (TRUE)
219
204
 
 
205
   if (0 < ProcMgrProcInfoArray_Count(procList)) {
 
206
      failed = FALSE;
 
207
   }
 
208
 
 
209
exit:
220
210
   closedir(dir);
221
211
 
222
 
   if (0 == DynBuf_GetSize(&dbProcId)) {
223
 
      failed = TRUE;
224
 
      goto exit;
225
 
   }
226
 
 
227
 
   /*
228
 
    * We're done adding to DynBuf.  Trim off any unused allocated space.
229
 
    * DynBuf_Trim() followed by DynBuf_Detach() avoids a memcpy().
230
 
    */
231
 
   DynBuf_Trim(&dbProcId);
232
 
   DynBuf_Trim(&dbProcCmd);
233
 
   DynBuf_Trim(&dbProcStartTime);
234
 
   DynBuf_Trim(&dbProcOwner);
235
 
 
236
 
   /*
237
 
    * Create a ProcMgr_ProcList and populate its fields.
238
 
    */
239
 
   procList = (ProcMgr_ProcList *) Util_SafeCalloc(1, sizeof(ProcMgr_ProcList));
240
 
   ASSERT_MEM_ALLOC(procList);
241
 
 
242
 
   procList->procCount = DynBuf_GetSize(&dbProcId) / sizeof(pid_t);
243
 
 
244
 
   procList->procIdList = (pid_t *) DynBuf_Detach(&dbProcId);
245
 
   ASSERT_MEM_ALLOC(procList->procIdList);
246
 
   procList->procCmdList = (char **) DynBuf_Detach(&dbProcCmd);
247
 
   ASSERT_MEM_ALLOC(procList->procCmdList);
248
 
   procList->startTime = (time_t *) DynBuf_Detach(&dbProcStartTime);
249
 
   ASSERT_MEM_ALLOC(procList->startTime);
250
 
   procList->procOwnerList = (char **) DynBuf_Detach(&dbProcOwner);
251
 
   ASSERT_MEM_ALLOC(procList->procOwnerList);
252
 
 
253
 
exit:
254
 
   DynBuf_Destroy(&dbProcId);
255
 
   DynBuf_Destroy(&dbProcCmd);
256
 
   DynBuf_Destroy(&dbProcStartTime);
257
 
   DynBuf_Destroy(&dbProcOwner);
 
212
   free(processInfo.procOwner);
 
213
   free(processInfo.procCmd);
258
214
 
259
215
   if (failed) {
260
216
      ProcMgr_FreeProcList(procList);
608
564
   struct passwd *ppw;
609
565
   gid_t root_gid;
610
566
   int ret;
 
567
   char *userLocal;
611
568
 
612
569
   ppw = &pw;
613
570
   if ((ppw = getpwuid_r(0, &pw, buffer, sizeof buffer)) == NULL) {
616
573
 
617
574
   root_gid = ppw->pw_gid;
618
575
 
619
 
   if ((ppw = getpwnam_r(user, &pw, buffer, sizeof buffer)) == NULL) {
 
576
   /* convert user name to local character set */
 
577
   userLocal = (char *)Unicode_GetAllocBytes(user, Unicode_GetCurrentEncoding());
 
578
   if (!userLocal) {
 
579
       Warning("Failed to convert user name %s to local character set.\n", user);
 
580
       return FALSE;
 
581
   }
 
582
 
 
583
   ppw = getpwnam_r(userLocal, &pw, buffer, sizeof buffer);
 
584
 
 
585
   free(userLocal);
 
586
 
 
587
   if (ppw == NULL) {
620
588
      return FALSE;
621
589
   }
622
590