~poelzi/ulatencyd/master

« back to all changes in this revision

Viewing changes to modules/simplerules.c

  • Committer: Daniel Poelzleithner
  • Date: 2016-07-01 19:03:45 UTC
  • mfrom: (454.1.77)
  • Revision ID: git-v1:cc1f176396cbdabeb1f4fa1e33936b2f2f94265d
Merge branch 'master' of github.com:poelzi/ulatencyd

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <string.h>
33
33
#include <errno.h>
34
34
#include <glib.h>
 
35
#include <gmodule.h>
35
36
#include <sys/stat.h>
36
37
#include <fnmatch.h>
37
38
 
38
 
int simplerules_id;
39
 
int simplerules_debug;
 
39
int       simplerules_id;
 
40
int       simplerules_debug;
 
41
GModule  *simplerules_module;
40
42
 
41
43
struct simple_rule {
42
44
  gid_t         gid;
309
311
//    printf("add proc %d to %s\n", proc->pid, proc->exe);
310
312
    gboolean match = FALSE;
311
313
    if(rule->glob_cmd) {
312
 
        if(u_proc_ensure(proc, CMDLINE, NOUPDATE) && proc->cmdline_match) {
 
314
        if(u_proc_ensure(proc, CMDLINE, UPDATE_DEFAULT)
 
315
            && *proc->cmdline_match != '\0')
 
316
        {
313
317
           match = g_pattern_match_string(rule->glob_cmd, proc->cmdline_match);
314
318
           simple_debug("match pid:%d cmdline glob:'%s' cmdline:'%s' = %d", proc->pid, rule->pattern, proc->cmdline_match, match)
315
319
           if(match)
317
321
        }
318
322
    }
319
323
    if(rule->glob_basename) {
320
 
        if(u_proc_ensure(proc, CMDLINE, NOUPDATE) && proc->cmdfile) {
 
324
        if(u_proc_ensure(proc, CMDLINE, UPDATE_DEFAULT)
 
325
            && *proc->cmdfile != '\0')
 
326
        {
321
327
           match = g_pattern_match_string(rule->glob_basename, proc->cmdfile);
322
328
           simple_debug("match pid:%d basename glob:'%s' basename:'%s' = %d", proc->pid, rule->pattern, proc->cmdfile, match)
323
329
           if(match)
325
331
        }
326
332
    }
327
333
    if(rule->glob_exe) {
328
 
        if(u_proc_ensure(proc, EXE, NOUPDATE) && proc->exe) {
 
334
        if(u_proc_ensure(proc, EXE, UPDATE_DEFAULT) && *proc->exe != '\0') {
329
335
           match = g_pattern_match_string(rule->glob_exe, proc->exe);
330
336
           simple_debug("match pid:%d exe glob:'%s' exe:'%s' = %d", proc->pid, rule->pattern, proc->exe, match)
331
337
           if(match)
333
339
        }
334
340
    }
335
341
    if(rule->re_exe) {
336
 
        if(u_proc_ensure(proc, EXE, NOUPDATE) && proc->exe) {
 
342
        if(u_proc_ensure(proc, EXE, UPDATE_DEFAULT) && *proc->exe != '\0') {
337
343
           match = g_regex_match(rule->re_exe, proc->exe, 0, NULL);
338
 
           simple_debug("match pid:%d cmdline re:'%s' exe:'%s' = %d", proc->pid, rule->pattern, proc->cmdline_match, match)
 
344
           simple_debug("match pid:%d exe re:'%s' exe:'%s' = %d", proc->pid, rule->pattern, proc->exe, match)
339
345
           if(match)
340
346
              return TRUE;
341
347
        }
342
348
    }
343
349
    if(rule->re_cmd) {
344
 
        if(u_proc_ensure(proc, CMDLINE, NOUPDATE) && proc->cmdline) {
 
350
        if(u_proc_ensure(proc, CMDLINE, UPDATE_DEFAULT)
 
351
            && *proc->cmdline_match != '\0')
 
352
        {
345
353
           match = g_regex_match(rule->re_cmd, proc->cmdline_match, 0, NULL);
346
354
           simple_debug("match pid:%d cmdline re:'%s' cmdline:'%s' = %d", proc->pid, rule->pattern, proc->cmdline_match, match)
347
355
           if(match)
349
357
        }
350
358
    }
351
359
    if(rule->re_basename) {
352
 
        if(u_proc_ensure(proc, CMDLINE, NOUPDATE) && proc->cmdfile) {
 
360
        if(u_proc_ensure(proc, CMDLINE, UPDATE_DEFAULT)
 
361
            && *proc->cmdfile != '\0')
 
362
        {
353
363
           match = g_regex_match(rule->re_basename, proc->cmdfile, 0, NULL);
354
 
           simple_debug("match pid:%d cmdline re:'%s' basename:'%s' = %d", proc->pid, rule->pattern, proc->cmdline_match, match)
 
364
           simple_debug("match pid:%d cmdfile re:'%s' basename:'%s' = %d", proc->pid, rule->pattern, proc->cmdfile, match)
355
365
           if(match)
356
366
              return TRUE;
357
367
        }
371
381
    nf->value       = t->value;
372
382
    nf->threshold   = t->threshold;
373
383
    nf->inherit     = t->inherit;
 
384
    if(t->urgent)
 
385
        nf->urgent = t->urgent;
374
386
 
375
387
    u_trace("add flag %s to %d", nf->name, proc->pid); 
376
388
 
377
 
    u_flag_add(proc, nf);
 
389
    u_flag_add(proc, nf, -1);
378
390
    DEC_REF(nf);
379
391
}
380
392
 
393
405
    return FILTER_MIX(FILTER_RERUN_EXEC | FILTER_STOP, 0);
394
406
}
395
407
 
396
 
 
397
 
int simplerules_init() {
 
408
G_MODULE_EXPORT const gchar*
 
409
g_module_check_init (GModule *module)
 
410
{
398
411
    int i = 0;
399
412
    simplerules_id = get_plugin_id();
 
413
    simplerules_module = module;
400
414
    u_filter *filter;
401
415
    simplerules_debug = g_key_file_get_boolean(config_data, "simplerules", "debug", NULL);
402
416
//    target_rules = NULL;
413
427
        }
414
428
    }
415
429
//    }
416
 
    return 0;
 
430
    return NULL;
417
431
}
418
432