~akhil011/ubuntu/wily/monit/crypto_fix

« back to all changes in this revision

Viewing changes to src/process/sysdep_LINUX.c

  • Committer: Package Import Robot
  • Author(s): Sergey B Kirpichev
  • Date: 2014-05-19 13:33:44 UTC
  • mfrom: (1.1.22)
  • Revision ID: package-import@ubuntu.com-20140519133344-xucbhs18wvojnsu4
Tags: 1:5.8.1-1
* Imported Upstream version 5.8.1
* Refresh patches
* Fix HURD build, broken by upstream
* Install CONTRIBUTORS file

Show diffs side-by-side

added added

removed removed

Lines of Context:
147
147
  long  page_size;
148
148
  int   page_shift;
149
149
 
150
 
  if (! read_proc_file(buf, sizeof(buf), "meminfo", -1, NULL))
 
150
  if (! read_proc_file(buf, sizeof(buf), "meminfo", -1, NULL)) {
 
151
    DEBUG("system statistic error -- cannot read /proc/meminfo\n");
151
152
    return FALSE;
 
153
  }
152
154
  if (! (ptr = strstr(buf, MEMTOTAL))) {
153
155
    DEBUG("system statistic error -- cannot get real memory amount\n");
154
156
    return FALSE;
171
173
    return FALSE;
172
174
  }
173
175
 
174
 
  for (page_shift = 0; page_size != 1; page_size >>= 1, page_shift++);
 
176
  for (page_shift = 0; page_size != 1; page_size >>= 1, page_shift++)
 
177
        ;
175
178
  page_shift_to_kb = page_shift - 10;
176
179
 
177
180
  return TRUE;
189
192
  int                 i = 0, j;
190
193
  int                 rv, bytes = 0;
191
194
  int                 treesize = 0;
 
195
  int                 stat_pid = 0;
192
196
  int                 stat_ppid = 0;
 
197
  int                 stat_uid = 0;
 
198
  int                 stat_euid = 0;
 
199
  int                 stat_gid = 0;
193
200
  char               *tmp = NULL;
194
201
  char                procname[STRLEN];
195
202
  char                buf[1024];
217
224
 
218
225
  /* Insert data from /proc directory */
219
226
  for (i = 0; i < treesize; i++) {
220
 
 
221
 
    pt[i].pid = atoi(globbuf.gl_pathv[i] + strlen("/proc/"));
222
 
 
223
 
    if (!read_proc_file(buf, sizeof(buf), "stat", pt[i].pid, NULL)) {
224
 
      DEBUG("system statistic error -- cannot read /proc/%d/stat\n", pt[i].pid);
 
227
    stat_pid = atoi(globbuf.gl_pathv[i] + strlen("/proc/"));
 
228
 
 
229
    /********** /proc/PID/stat **********/
 
230
    if (!read_proc_file(buf, sizeof(buf), "stat", stat_pid, NULL)) {
 
231
      DEBUG("system statistic error -- cannot read /proc/%d/stat\n", stat_pid);
225
232
      continue;
226
233
    }
227
 
 
228
 
    pt[i].time = get_float_time();
229
 
 
230
234
    if (!(tmp = strrchr(buf, ')'))) {
231
 
      DEBUG("system statistic error -- file /proc/%d/stat parse error\n", pt[i].pid);
 
235
      DEBUG("system statistic error -- file /proc/%d/stat parse error\n", stat_pid);
232
236
      continue;
233
237
    }
234
238
    *tmp = 0;
235
239
    if (sscanf(buf, "%*d (%256s", procname) != 1) {
236
 
      DEBUG("system statistic error -- file /proc/%d/stat process name parse error\n", pt[i].pid);
 
240
      DEBUG("system statistic error -- file /proc/%d/stat process name parse error\n", stat_pid);
237
241
      continue;
238
242
    }
239
 
 
240
243
    tmp += 2;
241
 
 
242
 
    /* This implementation is done by using fs/procfs/array.c as a basis
243
 
     * it is also worth looking into the source of the procps utils */
244
244
    if (sscanf(tmp,
245
245
         "%c %d %*d %*d %*d %*d %*u %*u"
246
246
         "%*u %*u %*u %lu %lu %ld %ld %*d %*d %*d "
254
254
         &stat_item_cstime,
255
255
         &stat_item_starttime,
256
256
         &stat_item_rss) != 8) {
257
 
      DEBUG("system statistic error -- file /proc/%d/stat parse error\n", pt[i].pid);
258
 
      continue;
259
 
    }
260
 
 
261
 
    pt[i].ppid      = stat_ppid;
262
 
    pt[i].starttime = get_starttime() + (time_t)(stat_item_starttime / HZ);
263
 
 
264
 
    /* jiffies -> seconds = 1 / HZ
265
 
     * HZ is defined in "asm/param.h"  and it is usually 1/100s but on
266
 
     * alpha system it is 1/1024s */
267
 
    pt[i].cputime     = ((float)(stat_item_utime + stat_item_stime) * 10.0) / HZ;
268
 
    pt[i].cpu_percent = 0;
269
 
 
270
 
    /* State is Zombie -> then we are a Zombie ... clear or? (-: */
271
 
    if (stat_item_state == 'Z')
272
 
      pt[i].status_flag |= PROCESS_ZOMBIE;
273
 
 
274
 
    if (page_shift_to_kb < 0)
275
 
      pt[i].mem_kbyte = (stat_item_rss >> abs(page_shift_to_kb));
276
 
    else
277
 
      pt[i].mem_kbyte = (stat_item_rss << abs(page_shift_to_kb));
278
 
 
279
 
    if (! read_proc_file(buf, sizeof(buf), "status", pt[i].pid, NULL))
280
 
      return FALSE;
281
 
 
 
257
      DEBUG("system statistic error -- file /proc/%d/stat parse error\n", stat_pid);
 
258
      continue;
 
259
    }
 
260
 
 
261
    /********** /proc/PID/status **********/
 
262
    if (! read_proc_file(buf, sizeof(buf), "status", stat_pid, NULL)) {
 
263
      DEBUG("system statistic error -- cannot read /proc/%d/status\n", stat_pid);
 
264
      continue;
 
265
    }
282
266
    if (! (tmp = strstr(buf, UID))) {
283
267
      DEBUG("system statistic error -- cannot find process uid\n");
284
 
      return FALSE;
 
268
      continue;
285
269
    }
286
 
    if (sscanf(tmp+strlen(UID), "\t%d\t%d", &(pt[i].uid), &(pt[i].euid)) != 2) {
 
270
    if (sscanf(tmp+strlen(UID), "\t%d\t%d", &stat_uid, &stat_euid) != 2) {
287
271
      DEBUG("system statistic error -- cannot read process uid\n");
288
 
      return FALSE;
 
272
      continue;
289
273
    }
290
 
 
291
274
    if (! (tmp = strstr(buf, GID))) {
292
275
      DEBUG("system statistic error -- cannot find process gid\n");
293
 
      return FALSE;
 
276
      continue;
294
277
    }
295
 
    if (sscanf(tmp+strlen(GID), "\t%d", &(pt[i].gid)) != 1) {
 
278
    if (sscanf(tmp+strlen(GID), "\t%d", &stat_gid) != 1) {
296
279
      DEBUG("system statistic error -- cannot read process gid\n");
297
 
      return FALSE;
 
280
      continue;
298
281
    }
299
282
 
300
 
    if (! read_proc_file(buf, sizeof(buf), "cmdline", pt[i].pid, &bytes)) {
301
 
      DEBUG("system statistic error -- cannot read /proc/%d/cmdline\n", pt[i].pid);
 
283
    /********** /proc/PID/cmdline **********/
 
284
    if (! read_proc_file(buf, sizeof(buf), "cmdline", stat_pid, &bytes)) {
 
285
      DEBUG("system statistic error -- cannot read /proc/%d/cmdline\n", stat_pid);
302
286
      continue;
303
287
    }
304
 
    /* The cmdline file contains argv elements/strings terminated separated by '\0' => join the string: */
305
 
    for (j = 0; j < (bytes - 1); j++)
 
288
    for (j = 0; j < (bytes - 1); j++) // The cmdline file contains argv elements/strings terminated separated by '\0' => join the string
306
289
      if (buf[j] == 0)
307
290
        buf[j] = ' ';
308
 
    pt[i].cmdline = *buf ? Str_dup(buf) : Str_dup(procname);
 
291
 
 
292
    /* Set the data in ptree only if all process related reads succeeded (prevent partial data in the case that continue was called during data gathering) */
 
293
    pt[i].time = get_float_time();
 
294
    pt[i].pid = stat_pid;
 
295
    pt[i].ppid = stat_ppid;
 
296
    pt[i].uid = stat_uid;
 
297
    pt[i].euid = stat_euid;
 
298
    pt[i].gid = stat_gid;
 
299
    pt[i].starttime = get_starttime() + (time_t)(stat_item_starttime / HZ);
 
300
    pt[i].cmdline = Str_dup(*buf ? buf : procname);
 
301
    pt[i].cputime = ((float)(stat_item_utime + stat_item_stime) * 10.0) / HZ; // jiffies -> seconds = 1 / HZ. HZ is defined in "asm/param.h"  and it is usually 1/100s but on alpha system it is 1/1024s
 
302
    pt[i].cpu_percent = 0;
 
303
    pt[i].mem_kbyte = (page_shift_to_kb < 0) ? (stat_item_rss >> abs(page_shift_to_kb)) : (stat_item_rss << abs(page_shift_to_kb));
 
304
    if (stat_item_state == 'Z') // State is Zombie -> then we are a Zombie ... clear or? (-:
 
305
      pt[i].status_flag |= PROCESS_ZOMBIE;
309
306
  }
310
307
 
311
308
  *reference = pt;