forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 1
/
event-parse.c
5612 lines (4771 loc) · 118 KB
/
event-parse.c
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <[email protected]>
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License (not later!)
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* The parts for function graph printing was taken and modified from the
* Linux Kernel that were written by
* - Copyright (C) 2009 Frederic Weisbecker,
* Frederic Weisbecker gave his permission to relicense the code to
* the Lesser General Public License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <errno.h>
#include <stdint.h>
#include <limits.h>
#include "event-parse.h"
#include "event-utils.h"
static const char *input_buf;
static unsigned long long input_buf_ptr;
static unsigned long long input_buf_siz;
static int is_flag_field;
static int is_symbolic_field;
static int show_warning = 1;
#define do_warning(fmt, ...) \
do { \
if (show_warning) \
warning(fmt, ##__VA_ARGS__); \
} while (0)
static void init_input_buf(const char *buf, unsigned long long size)
{
input_buf = buf;
input_buf_siz = size;
input_buf_ptr = 0;
}
const char *pevent_get_input_buf(void)
{
return input_buf;
}
unsigned long long pevent_get_input_buf_ptr(void)
{
return input_buf_ptr;
}
struct event_handler {
struct event_handler *next;
int id;
const char *sys_name;
const char *event_name;
pevent_event_handler_func func;
void *context;
};
struct pevent_func_params {
struct pevent_func_params *next;
enum pevent_func_arg_type type;
};
struct pevent_function_handler {
struct pevent_function_handler *next;
enum pevent_func_arg_type ret_type;
char *name;
pevent_func_handler func;
struct pevent_func_params *params;
int nr_args;
};
static unsigned long long
process_defined_func(struct trace_seq *s, void *data, int size,
struct event_format *event, struct print_arg *arg);
static void free_func_handle(struct pevent_function_handler *func);
/**
* pevent_buffer_init - init buffer for parsing
* @buf: buffer to parse
* @size: the size of the buffer
*
* For use with pevent_read_token(), this initializes the internal
* buffer that pevent_read_token() will parse.
*/
void pevent_buffer_init(const char *buf, unsigned long long size)
{
init_input_buf(buf, size);
}
void breakpoint(void)
{
static int x;
x++;
}
struct print_arg *alloc_arg(void)
{
return calloc(1, sizeof(struct print_arg));
}
struct cmdline {
char *comm;
int pid;
};
static int cmdline_cmp(const void *a, const void *b)
{
const struct cmdline *ca = a;
const struct cmdline *cb = b;
if (ca->pid < cb->pid)
return -1;
if (ca->pid > cb->pid)
return 1;
return 0;
}
struct cmdline_list {
struct cmdline_list *next;
char *comm;
int pid;
};
static int cmdline_init(struct pevent *pevent)
{
struct cmdline_list *cmdlist = pevent->cmdlist;
struct cmdline_list *item;
struct cmdline *cmdlines;
int i;
cmdlines = malloc(sizeof(*cmdlines) * pevent->cmdline_count);
if (!cmdlines)
return -1;
i = 0;
while (cmdlist) {
cmdlines[i].pid = cmdlist->pid;
cmdlines[i].comm = cmdlist->comm;
i++;
item = cmdlist;
cmdlist = cmdlist->next;
free(item);
}
qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp);
pevent->cmdlines = cmdlines;
pevent->cmdlist = NULL;
return 0;
}
static char *find_cmdline(struct pevent *pevent, int pid)
{
const struct cmdline *comm;
struct cmdline key;
if (!pid)
return "<idle>";
if (!pevent->cmdlines && cmdline_init(pevent))
return "<not enough memory for cmdlines!>";
key.pid = pid;
comm = bsearch(&key, pevent->cmdlines, pevent->cmdline_count,
sizeof(*pevent->cmdlines), cmdline_cmp);
if (comm)
return comm->comm;
return "<...>";
}
/**
* pevent_pid_is_registered - return if a pid has a cmdline registered
* @pevent: handle for the pevent
* @pid: The pid to check if it has a cmdline registered with.
*
* Returns 1 if the pid has a cmdline mapped to it
* 0 otherwise.
*/
int pevent_pid_is_registered(struct pevent *pevent, int pid)
{
const struct cmdline *comm;
struct cmdline key;
if (!pid)
return 1;
if (!pevent->cmdlines && cmdline_init(pevent))
return 0;
key.pid = pid;
comm = bsearch(&key, pevent->cmdlines, pevent->cmdline_count,
sizeof(*pevent->cmdlines), cmdline_cmp);
if (comm)
return 1;
return 0;
}
/*
* If the command lines have been converted to an array, then
* we must add this pid. This is much slower than when cmdlines
* are added before the array is initialized.
*/
static int add_new_comm(struct pevent *pevent, const char *comm, int pid)
{
struct cmdline *cmdlines = pevent->cmdlines;
const struct cmdline *cmdline;
struct cmdline key;
if (!pid)
return 0;
/* avoid duplicates */
key.pid = pid;
cmdline = bsearch(&key, pevent->cmdlines, pevent->cmdline_count,
sizeof(*pevent->cmdlines), cmdline_cmp);
if (cmdline) {
errno = EEXIST;
return -1;
}
cmdlines = realloc(cmdlines, sizeof(*cmdlines) * (pevent->cmdline_count + 1));
if (!cmdlines) {
errno = ENOMEM;
return -1;
}
cmdlines[pevent->cmdline_count].comm = strdup(comm);
if (!cmdlines[pevent->cmdline_count].comm) {
free(cmdlines);
errno = ENOMEM;
return -1;
}
cmdlines[pevent->cmdline_count].pid = pid;
if (cmdlines[pevent->cmdline_count].comm)
pevent->cmdline_count++;
qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp);
pevent->cmdlines = cmdlines;
return 0;
}
/**
* pevent_register_comm - register a pid / comm mapping
* @pevent: handle for the pevent
* @comm: the command line to register
* @pid: the pid to map the command line to
*
* This adds a mapping to search for command line names with
* a given pid. The comm is duplicated.
*/
int pevent_register_comm(struct pevent *pevent, const char *comm, int pid)
{
struct cmdline_list *item;
if (pevent->cmdlines)
return add_new_comm(pevent, comm, pid);
item = malloc(sizeof(*item));
if (!item)
return -1;
item->comm = strdup(comm);
if (!item->comm) {
free(item);
return -1;
}
item->pid = pid;
item->next = pevent->cmdlist;
pevent->cmdlist = item;
pevent->cmdline_count++;
return 0;
}
struct func_map {
unsigned long long addr;
char *func;
char *mod;
};
struct func_list {
struct func_list *next;
unsigned long long addr;
char *func;
char *mod;
};
static int func_cmp(const void *a, const void *b)
{
const struct func_map *fa = a;
const struct func_map *fb = b;
if (fa->addr < fb->addr)
return -1;
if (fa->addr > fb->addr)
return 1;
return 0;
}
/*
* We are searching for a record in between, not an exact
* match.
*/
static int func_bcmp(const void *a, const void *b)
{
const struct func_map *fa = a;
const struct func_map *fb = b;
if ((fa->addr == fb->addr) ||
(fa->addr > fb->addr &&
fa->addr < (fb+1)->addr))
return 0;
if (fa->addr < fb->addr)
return -1;
return 1;
}
static int func_map_init(struct pevent *pevent)
{
struct func_list *funclist;
struct func_list *item;
struct func_map *func_map;
int i;
func_map = malloc(sizeof(*func_map) * (pevent->func_count + 1));
if (!func_map)
return -1;
funclist = pevent->funclist;
i = 0;
while (funclist) {
func_map[i].func = funclist->func;
func_map[i].addr = funclist->addr;
func_map[i].mod = funclist->mod;
i++;
item = funclist;
funclist = funclist->next;
free(item);
}
qsort(func_map, pevent->func_count, sizeof(*func_map), func_cmp);
/*
* Add a special record at the end.
*/
func_map[pevent->func_count].func = NULL;
func_map[pevent->func_count].addr = 0;
func_map[pevent->func_count].mod = NULL;
pevent->func_map = func_map;
pevent->funclist = NULL;
return 0;
}
static struct func_map *
find_func(struct pevent *pevent, unsigned long long addr)
{
struct func_map *func;
struct func_map key;
if (!pevent->func_map)
func_map_init(pevent);
key.addr = addr;
func = bsearch(&key, pevent->func_map, pevent->func_count,
sizeof(*pevent->func_map), func_bcmp);
return func;
}
/**
* pevent_find_function - find a function by a given address
* @pevent: handle for the pevent
* @addr: the address to find the function with
*
* Returns a pointer to the function stored that has the given
* address. Note, the address does not have to be exact, it
* will select the function that would contain the address.
*/
const char *pevent_find_function(struct pevent *pevent, unsigned long long addr)
{
struct func_map *map;
map = find_func(pevent, addr);
if (!map)
return NULL;
return map->func;
}
/**
* pevent_find_function_address - find a function address by a given address
* @pevent: handle for the pevent
* @addr: the address to find the function with
*
* Returns the address the function starts at. This can be used in
* conjunction with pevent_find_function to print both the function
* name and the function offset.
*/
unsigned long long
pevent_find_function_address(struct pevent *pevent, unsigned long long addr)
{
struct func_map *map;
map = find_func(pevent, addr);
if (!map)
return 0;
return map->addr;
}
/**
* pevent_register_function - register a function with a given address
* @pevent: handle for the pevent
* @function: the function name to register
* @addr: the address the function starts at
* @mod: the kernel module the function may be in (NULL for none)
*
* This registers a function name with an address and module.
* The @func passed in is duplicated.
*/
int pevent_register_function(struct pevent *pevent, char *func,
unsigned long long addr, char *mod)
{
struct func_list *item = malloc(sizeof(*item));
if (!item)
return -1;
item->next = pevent->funclist;
item->func = strdup(func);
if (!item->func)
goto out_free;
if (mod) {
item->mod = strdup(mod);
if (!item->mod)
goto out_free_func;
} else
item->mod = NULL;
item->addr = addr;
pevent->funclist = item;
pevent->func_count++;
return 0;
out_free_func:
free(item->func);
item->func = NULL;
out_free:
free(item);
errno = ENOMEM;
return -1;
}
/**
* pevent_print_funcs - print out the stored functions
* @pevent: handle for the pevent
*
* This prints out the stored functions.
*/
void pevent_print_funcs(struct pevent *pevent)
{
int i;
if (!pevent->func_map)
func_map_init(pevent);
for (i = 0; i < (int)pevent->func_count; i++) {
printf("%016llx %s",
pevent->func_map[i].addr,
pevent->func_map[i].func);
if (pevent->func_map[i].mod)
printf(" [%s]\n", pevent->func_map[i].mod);
else
printf("\n");
}
}
struct printk_map {
unsigned long long addr;
char *printk;
};
struct printk_list {
struct printk_list *next;
unsigned long long addr;
char *printk;
};
static int printk_cmp(const void *a, const void *b)
{
const struct printk_map *pa = a;
const struct printk_map *pb = b;
if (pa->addr < pb->addr)
return -1;
if (pa->addr > pb->addr)
return 1;
return 0;
}
static int printk_map_init(struct pevent *pevent)
{
struct printk_list *printklist;
struct printk_list *item;
struct printk_map *printk_map;
int i;
printk_map = malloc(sizeof(*printk_map) * (pevent->printk_count + 1));
if (!printk_map)
return -1;
printklist = pevent->printklist;
i = 0;
while (printklist) {
printk_map[i].printk = printklist->printk;
printk_map[i].addr = printklist->addr;
i++;
item = printklist;
printklist = printklist->next;
free(item);
}
qsort(printk_map, pevent->printk_count, sizeof(*printk_map), printk_cmp);
pevent->printk_map = printk_map;
pevent->printklist = NULL;
return 0;
}
static struct printk_map *
find_printk(struct pevent *pevent, unsigned long long addr)
{
struct printk_map *printk;
struct printk_map key;
if (!pevent->printk_map && printk_map_init(pevent))
return NULL;
key.addr = addr;
printk = bsearch(&key, pevent->printk_map, pevent->printk_count,
sizeof(*pevent->printk_map), printk_cmp);
return printk;
}
/**
* pevent_register_print_string - register a string by its address
* @pevent: handle for the pevent
* @fmt: the string format to register
* @addr: the address the string was located at
*
* This registers a string by the address it was stored in the kernel.
* The @fmt passed in is duplicated.
*/
int pevent_register_print_string(struct pevent *pevent, char *fmt,
unsigned long long addr)
{
struct printk_list *item = malloc(sizeof(*item));
if (!item)
return -1;
item->next = pevent->printklist;
item->addr = addr;
item->printk = strdup(fmt);
if (!item->printk)
goto out_free;
pevent->printklist = item;
pevent->printk_count++;
return 0;
out_free:
free(item);
errno = ENOMEM;
return -1;
}
/**
* pevent_print_printk - print out the stored strings
* @pevent: handle for the pevent
*
* This prints the string formats that were stored.
*/
void pevent_print_printk(struct pevent *pevent)
{
int i;
if (!pevent->printk_map)
printk_map_init(pevent);
for (i = 0; i < (int)pevent->printk_count; i++) {
printf("%016llx %s\n",
pevent->printk_map[i].addr,
pevent->printk_map[i].printk);
}
}
static struct event_format *alloc_event(void)
{
return calloc(1, sizeof(struct event_format));
}
static int add_event(struct pevent *pevent, struct event_format *event)
{
int i;
struct event_format **events = realloc(pevent->events, sizeof(event) *
(pevent->nr_events + 1));
if (!events)
return -1;
pevent->events = events;
for (i = 0; i < pevent->nr_events; i++) {
if (pevent->events[i]->id > event->id)
break;
}
if (i < pevent->nr_events)
memmove(&pevent->events[i + 1],
&pevent->events[i],
sizeof(event) * (pevent->nr_events - i));
pevent->events[i] = event;
pevent->nr_events++;
event->pevent = pevent;
return 0;
}
static int event_item_type(enum event_type type)
{
switch (type) {
case EVENT_ITEM ... EVENT_SQUOTE:
return 1;
case EVENT_ERROR ... EVENT_DELIM:
default:
return 0;
}
}
static void free_flag_sym(struct print_flag_sym *fsym)
{
struct print_flag_sym *next;
while (fsym) {
next = fsym->next;
free(fsym->value);
free(fsym->str);
free(fsym);
fsym = next;
}
}
static void free_arg(struct print_arg *arg)
{
struct print_arg *farg;
if (!arg)
return;
switch (arg->type) {
case PRINT_ATOM:
free(arg->atom.atom);
break;
case PRINT_FIELD:
free(arg->field.name);
break;
case PRINT_FLAGS:
free_arg(arg->flags.field);
free(arg->flags.delim);
free_flag_sym(arg->flags.flags);
break;
case PRINT_SYMBOL:
free_arg(arg->symbol.field);
free_flag_sym(arg->symbol.symbols);
break;
case PRINT_HEX:
free_arg(arg->hex.field);
free_arg(arg->hex.size);
break;
case PRINT_TYPE:
free(arg->typecast.type);
free_arg(arg->typecast.item);
break;
case PRINT_STRING:
case PRINT_BSTRING:
free(arg->string.string);
break;
case PRINT_DYNAMIC_ARRAY:
free(arg->dynarray.index);
break;
case PRINT_OP:
free(arg->op.op);
free_arg(arg->op.left);
free_arg(arg->op.right);
break;
case PRINT_FUNC:
while (arg->func.args) {
farg = arg->func.args;
arg->func.args = farg->next;
free_arg(farg);
}
break;
case PRINT_NULL:
default:
break;
}
free(arg);
}
static enum event_type get_type(int ch)
{
if (ch == '\n')
return EVENT_NEWLINE;
if (isspace(ch))
return EVENT_SPACE;
if (isalnum(ch) || ch == '_')
return EVENT_ITEM;
if (ch == '\'')
return EVENT_SQUOTE;
if (ch == '"')
return EVENT_DQUOTE;
if (!isprint(ch))
return EVENT_NONE;
if (ch == '(' || ch == ')' || ch == ',')
return EVENT_DELIM;
return EVENT_OP;
}
static int __read_char(void)
{
if (input_buf_ptr >= input_buf_siz)
return -1;
return input_buf[input_buf_ptr++];
}
static int __peek_char(void)
{
if (input_buf_ptr >= input_buf_siz)
return -1;
return input_buf[input_buf_ptr];
}
/**
* pevent_peek_char - peek at the next character that will be read
*
* Returns the next character read, or -1 if end of buffer.
*/
int pevent_peek_char(void)
{
return __peek_char();
}
static int extend_token(char **tok, char *buf, int size)
{
char *newtok = realloc(*tok, size);
if (!newtok) {
free(*tok);
*tok = NULL;
return -1;
}
if (!*tok)
strcpy(newtok, buf);
else
strcat(newtok, buf);
*tok = newtok;
return 0;
}
static enum event_type force_token(const char *str, char **tok);
static enum event_type __read_token(char **tok)
{
char buf[BUFSIZ];
int ch, last_ch, quote_ch, next_ch;
int i = 0;
int tok_size = 0;
enum event_type type;
*tok = NULL;
ch = __read_char();
if (ch < 0)
return EVENT_NONE;
type = get_type(ch);
if (type == EVENT_NONE)
return type;
buf[i++] = ch;
switch (type) {
case EVENT_NEWLINE:
case EVENT_DELIM:
if (asprintf(tok, "%c", ch) < 0)
return EVENT_ERROR;
return type;
case EVENT_OP:
switch (ch) {
case '-':
next_ch = __peek_char();
if (next_ch == '>') {
buf[i++] = __read_char();
break;
}
/* fall through */
case '+':
case '|':
case '&':
case '>':
case '<':
last_ch = ch;
ch = __peek_char();
if (ch != last_ch)
goto test_equal;
buf[i++] = __read_char();
switch (last_ch) {
case '>':
case '<':
goto test_equal;
default:
break;
}
break;
case '!':
case '=':
goto test_equal;
default: /* what should we do instead? */
break;
}
buf[i] = 0;
*tok = strdup(buf);
return type;
test_equal:
ch = __peek_char();
if (ch == '=')
buf[i++] = __read_char();
goto out;
case EVENT_DQUOTE:
case EVENT_SQUOTE:
/* don't keep quotes */
i--;
quote_ch = ch;
last_ch = 0;
concat:
do {
if (i == (BUFSIZ - 1)) {
buf[i] = 0;
tok_size += BUFSIZ;
if (extend_token(tok, buf, tok_size) < 0)
return EVENT_NONE;
i = 0;
}
last_ch = ch;
ch = __read_char();
buf[i++] = ch;
/* the '\' '\' will cancel itself */
if (ch == '\\' && last_ch == '\\')
last_ch = 0;
} while (ch != quote_ch || last_ch == '\\');
/* remove the last quote */
i--;
/*
* For strings (double quotes) check the next token.
* If it is another string, concatinate the two.
*/
if (type == EVENT_DQUOTE) {
unsigned long long save_input_buf_ptr = input_buf_ptr;
do {
ch = __read_char();
} while (isspace(ch));
if (ch == '"')
goto concat;
input_buf_ptr = save_input_buf_ptr;
}
goto out;
case EVENT_ERROR ... EVENT_SPACE:
case EVENT_ITEM:
default:
break;
}
while (get_type(__peek_char()) == type) {
if (i == (BUFSIZ - 1)) {
buf[i] = 0;
tok_size += BUFSIZ;
if (extend_token(tok, buf, tok_size) < 0)
return EVENT_NONE;
i = 0;
}
ch = __read_char();
buf[i++] = ch;
}
out:
buf[i] = 0;
if (extend_token(tok, buf, tok_size + i + 1) < 0)
return EVENT_NONE;
if (type == EVENT_ITEM) {
/*
* Older versions of the kernel has a bug that
* creates invalid symbols and will break the mac80211
* parsing. This is a work around to that bug.
*
* See Linux kernel commit:
* 811cb50baf63461ce0bdb234927046131fc7fa8b
*/
if (strcmp(*tok, "LOCAL_PR_FMT") == 0) {
free(*tok);
*tok = NULL;
return force_token("\"\%s\" ", tok);
} else if (strcmp(*tok, "STA_PR_FMT") == 0) {
free(*tok);
*tok = NULL;
return force_token("\" sta:%pM\" ", tok);
} else if (strcmp(*tok, "VIF_PR_FMT") == 0) {
free(*tok);
*tok = NULL;
return force_token("\" vif:%p(%d)\" ", tok);
}
}
return type;
}
static enum event_type force_token(const char *str, char **tok)
{
const char *save_input_buf;
unsigned long long save_input_buf_ptr;