1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
5 * Copyright 2003 Ximian, Inc. (www.ximian.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include <sys/types.h>
32 #include "vgrulepattern.h"
34 struct _VgRulePattern
{
42 vg_rule_pattern_new (VgRule
*rule
)
47 pat
= g_new (VgRulePattern
, 1);
48 pat
->patterns
= g_ptr_array_new ();
49 pat
->type
= rule
->type
;
50 pat
->syscall
= g_strdup (rule
->syscall
);
56 regex
= g_new (regex_t
, 1);
58 if (regcomp (regex
, c
->name
, REG_EXTENDED
| REG_NOSUB
) != 0) {
63 g_ptr_array_add (pat
->patterns
, regex
);
73 vg_rule_pattern_free (VgRulePattern
*pat
)
80 for (i
= 0; i
< pat
->patterns
->len
; i
++) {
81 regex_t
*regex
= pat
->patterns
->pdata
[i
];
87 g_ptr_array_free (pat
->patterns
, TRUE
);
88 g_free (pat
->syscall
);
94 vg_rule_pattern_matches (VgRulePattern
*pat
, VgError
*err
)
96 VgErrorStack
*s
= err
->summary
->frames
;
103 if (!vg_rule_type_from_report (err
->summary
->report
, &type
, NULL
) || type
!= pat
->type
)
106 if (pat
->type
== VG_RULE_PARAM
) {
110 syscall
= err
->summary
->report
+ 14;
111 n
= strcspn (syscall
, " ");
113 if (n
!= strlen (pat
->syscall
) || strncmp (pat
->syscall
, syscall
, n
) != 0)
117 for (i
= 0; s
!= NULL
&& i
< pat
->patterns
->len
; i
++) {
118 regex_t
*regex
= pat
->patterns
->pdata
[i
];
123 } else if (s
->type
== VG_STACK_OBJECT
) {
124 str
= s
->info
.object
;
129 if (regexec (regex
, str
, 0, NULL
, 0) != 0)
135 if (i
== pat
->patterns
->len
)