@@ -17,7 +17,7 @@ static const char *__doc__ = " XDP RX-queue info extract example\n\n"
17
17
#include <getopt.h>
18
18
#include <net/if.h>
19
19
#include <time.h>
20
-
20
+ #include <limits.h>
21
21
#include <arpa/inet.h>
22
22
#include <linux/if_link.h>
23
23
@@ -43,6 +43,9 @@ static struct bpf_map *rx_queue_index_map;
43
43
#define EXIT_FAIL_BPF 4
44
44
#define EXIT_FAIL_MEM 5
45
45
46
+ #define FAIL_MEM_SIG INT_MAX
47
+ #define FAIL_STAT_SIG (INT_MAX - 1)
48
+
46
49
static const struct option long_options [] = {
47
50
{"help" , no_argument , NULL , 'h' },
48
51
{"dev" , required_argument , NULL , 'd' },
@@ -76,6 +79,12 @@ static void int_exit(int sig)
76
79
printf ("program on interface changed, not removing\n" );
77
80
}
78
81
}
82
+
83
+ if (sig == FAIL_MEM_SIG )
84
+ exit (EXIT_FAIL_MEM );
85
+ else if (sig == FAIL_STAT_SIG )
86
+ exit (EXIT_FAIL );
87
+
79
88
exit (EXIT_OK );
80
89
}
81
90
@@ -140,7 +149,8 @@ static char* options2str(enum cfg_options_flags flag)
140
149
if (flag & READ_MEM )
141
150
return "read" ;
142
151
fprintf (stderr , "ERR: Unknown config option flags" );
143
- exit (EXIT_FAIL );
152
+ int_exit (FAIL_STAT_SIG );
153
+ return "unknown" ;
144
154
}
145
155
146
156
static void usage (char * argv [])
@@ -173,7 +183,7 @@ static __u64 gettime(void)
173
183
res = clock_gettime (CLOCK_MONOTONIC , & t );
174
184
if (res < 0 ) {
175
185
fprintf (stderr , "Error with gettimeofday! (%i)\n" , res );
176
- exit ( EXIT_FAIL );
186
+ int_exit ( FAIL_STAT_SIG );
177
187
}
178
188
return (__u64 ) t .tv_sec * NANOSEC_PER_SEC + t .tv_nsec ;
179
189
}
@@ -201,7 +211,7 @@ static struct datarec *alloc_record_per_cpu(void)
201
211
array = calloc (nr_cpus , sizeof (struct datarec ));
202
212
if (!array ) {
203
213
fprintf (stderr , "Mem alloc error (nr_cpus:%u)\n" , nr_cpus );
204
- exit ( EXIT_FAIL_MEM );
214
+ int_exit ( FAIL_MEM_SIG );
205
215
}
206
216
return array ;
207
217
}
@@ -214,7 +224,7 @@ static struct record *alloc_record_per_rxq(void)
214
224
array = calloc (nr_rxqs , sizeof (struct record ));
215
225
if (!array ) {
216
226
fprintf (stderr , "Mem alloc error (nr_rxqs:%u)\n" , nr_rxqs );
217
- exit ( EXIT_FAIL_MEM );
227
+ int_exit ( FAIL_MEM_SIG );
218
228
}
219
229
return array ;
220
230
}
@@ -228,7 +238,7 @@ static struct stats_record *alloc_stats_record(void)
228
238
rec = calloc (1 , sizeof (struct stats_record ));
229
239
if (!rec ) {
230
240
fprintf (stderr , "Mem alloc error\n" );
231
- exit ( EXIT_FAIL_MEM );
241
+ int_exit ( FAIL_MEM_SIG );
232
242
}
233
243
rec -> rxq = alloc_record_per_rxq ();
234
244
for (i = 0 ; i < nr_rxqs ; i ++ )
0 commit comments