blob: f299ddf29967d6ce32fc41899a442d7bf0484652 [file] [log] [blame]
Tom Zanussi454c4072010-05-01 01:41:20 -05001/*
2 * builtin-inject.c
3 *
4 * Builtin inject command: Examine the live mode (stdin) event stream
5 * and repipe it to stdout while optionally injecting additional
6 * events into it.
7 */
8#include "builtin.h"
9
10#include "perf.h"
Andrew Vagin26a031e2012-08-07 16:56:04 +040011#include "util/color.h"
12#include "util/evlist.h"
13#include "util/evsel.h"
Tom Zanussi454c4072010-05-01 01:41:20 -050014#include "util/session.h"
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020015#include "util/tool.h"
Tom Zanussi454c4072010-05-01 01:41:20 -050016#include "util/debug.h"
Andrew Vagin54a3cf52012-08-07 16:56:05 +040017#include "util/build-id.h"
Tom Zanussi454c4072010-05-01 01:41:20 -050018
19#include "util/parse-options.h"
20
Andrew Vagin26a031e2012-08-07 16:56:04 +040021#include <linux/list.h>
22
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -030023struct perf_inject {
24 struct perf_tool tool;
25 bool build_ids;
Andrew Vagin26a031e2012-08-07 16:56:04 +040026 bool sched_stat;
Andrew Vagine558a5b2012-08-07 16:56:02 +040027 const char *input_name;
28 int pipe_output,
29 output;
30 u64 bytes_written;
Andrew Vagin26a031e2012-08-07 16:56:04 +040031 struct list_head samples;
32};
33
34struct event_entry {
35 struct list_head node;
36 u32 tid;
37 union perf_event event[0];
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -030038};
Tom Zanussi454c4072010-05-01 01:41:20 -050039
Andrew Vagine558a5b2012-08-07 16:56:02 +040040static int perf_event__repipe_synth(struct perf_tool *tool,
Adrian Hunter63c2c9f2013-07-04 16:20:20 +030041 union perf_event *event)
Tom Zanussi454c4072010-05-01 01:41:20 -050042{
Andrew Vagine558a5b2012-08-07 16:56:02 +040043 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
Tom Zanussi454c4072010-05-01 01:41:20 -050044 uint32_t size;
45 void *buf = event;
46
47 size = event->header.size;
48
49 while (size) {
Andrew Vagine558a5b2012-08-07 16:56:02 +040050 int ret = write(inject->output, buf, size);
Tom Zanussi454c4072010-05-01 01:41:20 -050051 if (ret < 0)
52 return -errno;
53
54 size -= ret;
55 buf += ret;
Andrew Vagine558a5b2012-08-07 16:56:02 +040056 inject->bytes_written += ret;
Tom Zanussi454c4072010-05-01 01:41:20 -050057 }
58
59 return 0;
60}
61
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020062static int perf_event__repipe_op2_synth(struct perf_tool *tool,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020063 union perf_event *event,
Irina Tirdea1d037ca2012-09-11 01:15:03 +030064 struct perf_session *session
65 __maybe_unused)
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020066{
Adrian Hunter63c2c9f2013-07-04 16:20:20 +030067 return perf_event__repipe_synth(tool, event);
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020068}
69
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020070static int perf_event__repipe_event_type_synth(struct perf_tool *tool,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020071 union perf_event *event)
72{
Adrian Hunter63c2c9f2013-07-04 16:20:20 +030073 return perf_event__repipe_synth(tool, event);
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020074}
75
76static int perf_event__repipe_tracing_data_synth(union perf_event *event,
Irina Tirdea1d037ca2012-09-11 01:15:03 +030077 struct perf_session *session
78 __maybe_unused)
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020079{
Adrian Hunter63c2c9f2013-07-04 16:20:20 +030080 return perf_event__repipe_synth(NULL, event);
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020081}
82
Arnaldo Carvalho de Melo10d0f082011-11-11 22:45:41 -020083static int perf_event__repipe_attr(union perf_event *event,
Irina Tirdea1d037ca2012-09-11 01:15:03 +030084 struct perf_evlist **pevlist __maybe_unused)
Arnaldo Carvalho de Melo10d0f082011-11-11 22:45:41 -020085{
Stephane Eranian1a1ed1b2012-05-15 13:28:11 +020086 int ret;
87 ret = perf_event__process_attr(event, pevlist);
88 if (ret)
89 return ret;
90
Adrian Hunter63c2c9f2013-07-04 16:20:20 +030091 return perf_event__repipe_synth(NULL, event);
Arnaldo Carvalho de Melo10d0f082011-11-11 22:45:41 -020092}
93
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020094static int perf_event__repipe(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020095 union perf_event *event,
Irina Tirdea1d037ca2012-09-11 01:15:03 +030096 struct perf_sample *sample __maybe_unused,
Adrian Hunter63c2c9f2013-07-04 16:20:20 +030097 struct machine *machine __maybe_unused)
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -020098{
Adrian Hunter63c2c9f2013-07-04 16:20:20 +030099 return perf_event__repipe_synth(tool, event);
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200100}
101
Andrew Vagin26a031e2012-08-07 16:56:04 +0400102typedef int (*inject_handler)(struct perf_tool *tool,
103 union perf_event *event,
104 struct perf_sample *sample,
105 struct perf_evsel *evsel,
106 struct machine *machine);
107
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200108static int perf_event__repipe_sample(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200109 union perf_event *event,
Andrew Vagin26a031e2012-08-07 16:56:04 +0400110 struct perf_sample *sample,
111 struct perf_evsel *evsel,
112 struct machine *machine)
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300113{
Andrew Vagin26a031e2012-08-07 16:56:04 +0400114 if (evsel->handler.func) {
115 inject_handler f = evsel->handler.func;
116 return f(tool, event, sample, evsel, machine);
117 }
118
Andrew Vagin54a3cf52012-08-07 16:56:05 +0400119 build_id__mark_dso_hit(tool, event, sample, evsel, machine);
120
Adrian Hunter63c2c9f2013-07-04 16:20:20 +0300121 return perf_event__repipe_synth(tool, event);
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300122}
123
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200124static int perf_event__repipe_mmap(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200125 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200126 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200127 struct machine *machine)
Tom Zanussi454c4072010-05-01 01:41:20 -0500128{
129 int err;
130
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200131 err = perf_event__process_mmap(tool, event, sample, machine);
132 perf_event__repipe(tool, event, sample, machine);
Tom Zanussi454c4072010-05-01 01:41:20 -0500133
134 return err;
135}
136
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300137static int perf_event__repipe_fork(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200138 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200139 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200140 struct machine *machine)
Tom Zanussi454c4072010-05-01 01:41:20 -0500141{
142 int err;
143
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300144 err = perf_event__process_fork(tool, event, sample, machine);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200145 perf_event__repipe(tool, event, sample, machine);
Tom Zanussi454c4072010-05-01 01:41:20 -0500146
147 return err;
148}
149
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200150static int perf_event__repipe_tracing_data(union perf_event *event,
151 struct perf_session *session)
Tom Zanussi454c4072010-05-01 01:41:20 -0500152{
153 int err;
154
Adrian Hunter63c2c9f2013-07-04 16:20:20 +0300155 perf_event__repipe_synth(NULL, event);
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200156 err = perf_event__process_tracing_data(event, session);
Tom Zanussi454c4072010-05-01 01:41:20 -0500157
158 return err;
159}
160
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300161static int dso__read_build_id(struct dso *self)
Tom Zanussi454c4072010-05-01 01:41:20 -0500162{
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300163 if (self->has_build_id)
164 return 0;
Tom Zanussi454c4072010-05-01 01:41:20 -0500165
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300166 if (filename__read_build_id(self->long_name, self->build_id,
167 sizeof(self->build_id)) > 0) {
168 self->has_build_id = true;
169 return 0;
Tom Zanussi454c4072010-05-01 01:41:20 -0500170 }
171
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300172 return -1;
173}
Tom Zanussi454c4072010-05-01 01:41:20 -0500174
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200175static int dso__inject_build_id(struct dso *self, struct perf_tool *tool,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200176 struct machine *machine)
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300177{
178 u16 misc = PERF_RECORD_MISC_USER;
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300179 int err;
Tom Zanussi454c4072010-05-01 01:41:20 -0500180
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300181 if (dso__read_build_id(self) < 0) {
182 pr_debug("no build_id found for %s\n", self->long_name);
183 return -1;
184 }
Tom Zanussi454c4072010-05-01 01:41:20 -0500185
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300186 if (self->kernel)
187 misc = PERF_RECORD_MISC_KERNEL;
188
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200189 err = perf_event__synthesize_build_id(tool, self, misc, perf_event__repipe,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200190 machine);
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300191 if (err) {
192 pr_err("Can't synthesize build_id event for %s\n", self->long_name);
Tom Zanussi454c4072010-05-01 01:41:20 -0500193 return -1;
194 }
195
196 return 0;
197}
198
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200199static int perf_event__inject_buildid(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200200 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200201 struct perf_sample *sample,
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300202 struct perf_evsel *evsel __maybe_unused,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200203 struct machine *machine)
Tom Zanussi454c4072010-05-01 01:41:20 -0500204{
205 struct addr_location al;
206 struct thread *thread;
207 u8 cpumode;
Tom Zanussi454c4072010-05-01 01:41:20 -0500208
209 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
210
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200211 thread = machine__findnew_thread(machine, event->ip.pid);
Tom Zanussi454c4072010-05-01 01:41:20 -0500212 if (thread == NULL) {
213 pr_err("problem processing %d event, skipping it.\n",
214 event->header.type);
Tom Zanussi454c4072010-05-01 01:41:20 -0500215 goto repipe;
216 }
217
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200218 thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
219 event->ip.ip, &al);
Tom Zanussi454c4072010-05-01 01:41:20 -0500220
221 if (al.map != NULL) {
222 if (!al.map->dso->hit) {
223 al.map->dso->hit = 1;
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300224 if (map__load(al.map, NULL) >= 0) {
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200225 dso__inject_build_id(al.map->dso, tool, machine);
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300226 /*
227 * If this fails, too bad, let the other side
228 * account this as unresolved.
229 */
Namhyung Kim393be2e2012-08-06 13:41:21 +0900230 } else {
Namhyung Kim29a0fc92012-09-28 18:31:59 +0900231#ifdef LIBELF_SUPPORT
Tom Zanussi454c4072010-05-01 01:41:20 -0500232 pr_warning("no symbols found in %s, maybe "
233 "install a debug package?\n",
234 al.map->dso->long_name);
Namhyung Kim393be2e2012-08-06 13:41:21 +0900235#endif
236 }
Tom Zanussi454c4072010-05-01 01:41:20 -0500237 }
238 }
239
240repipe:
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200241 perf_event__repipe(tool, event, sample, machine);
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300242 return 0;
Tom Zanussi454c4072010-05-01 01:41:20 -0500243}
244
Andrew Vagin26a031e2012-08-07 16:56:04 +0400245static int perf_inject__sched_process_exit(struct perf_tool *tool,
246 union perf_event *event __maybe_unused,
247 struct perf_sample *sample,
248 struct perf_evsel *evsel __maybe_unused,
249 struct machine *machine __maybe_unused)
250{
251 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
252 struct event_entry *ent;
253
254 list_for_each_entry(ent, &inject->samples, node) {
255 if (sample->tid == ent->tid) {
256 list_del_init(&ent->node);
257 free(ent);
258 break;
259 }
260 }
261
262 return 0;
263}
264
265static int perf_inject__sched_switch(struct perf_tool *tool,
266 union perf_event *event,
267 struct perf_sample *sample,
268 struct perf_evsel *evsel,
269 struct machine *machine)
270{
271 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
272 struct event_entry *ent;
273
274 perf_inject__sched_process_exit(tool, event, sample, evsel, machine);
275
276 ent = malloc(event->header.size + sizeof(struct event_entry));
277 if (ent == NULL) {
278 color_fprintf(stderr, PERF_COLOR_RED,
279 "Not enough memory to process sched switch event!");
280 return -1;
281 }
282
283 ent->tid = sample->tid;
284 memcpy(&ent->event, event, event->header.size);
285 list_add(&ent->node, &inject->samples);
286 return 0;
287}
288
289static int perf_inject__sched_stat(struct perf_tool *tool,
290 union perf_event *event __maybe_unused,
291 struct perf_sample *sample,
292 struct perf_evsel *evsel,
293 struct machine *machine)
294{
295 struct event_entry *ent;
296 union perf_event *event_sw;
297 struct perf_sample sample_sw;
298 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
299 u32 pid = perf_evsel__intval(evsel, sample, "pid");
300
301 list_for_each_entry(ent, &inject->samples, node) {
302 if (pid == ent->tid)
303 goto found;
304 }
305
306 return 0;
307found:
308 event_sw = &ent->event[0];
309 perf_evsel__parse_sample(evsel, event_sw, &sample_sw);
310
311 sample_sw.period = sample->period;
312 sample_sw.time = sample->time;
313 perf_event__synthesize_sample(event_sw, evsel->attr.sample_type,
314 &sample_sw, false);
Andrew Vagin54a3cf52012-08-07 16:56:05 +0400315 build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine);
Andrew Vagin26a031e2012-08-07 16:56:04 +0400316 return perf_event__repipe(tool, event_sw, &sample_sw, machine);
317}
318
Tom Zanussi454c4072010-05-01 01:41:20 -0500319extern volatile int session_done;
320
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300321static void sig_handler(int sig __maybe_unused)
Tom Zanussi454c4072010-05-01 01:41:20 -0500322{
323 session_done = 1;
324}
325
Andrew Vagin26a031e2012-08-07 16:56:04 +0400326static int perf_evsel__check_stype(struct perf_evsel *evsel,
327 u64 sample_type, const char *sample_msg)
328{
329 struct perf_event_attr *attr = &evsel->attr;
330 const char *name = perf_evsel__name(evsel);
331
332 if (!(attr->sample_type & sample_type)) {
333 pr_err("Samples for %s event do not have %s attribute set.",
334 name, sample_msg);
335 return -EINVAL;
336 }
337
338 return 0;
339}
340
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300341static int __cmd_inject(struct perf_inject *inject)
Tom Zanussi454c4072010-05-01 01:41:20 -0500342{
343 struct perf_session *session;
344 int ret = -EINVAL;
345
346 signal(SIGINT, sig_handler);
347
Andrew Vagin54a3cf52012-08-07 16:56:05 +0400348 if (inject->build_ids || inject->sched_stat) {
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300349 inject->tool.mmap = perf_event__repipe_mmap;
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300350 inject->tool.fork = perf_event__repipe_fork;
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300351 inject->tool.tracing_data = perf_event__repipe_tracing_data;
Tom Zanussi454c4072010-05-01 01:41:20 -0500352 }
353
Andrew Vagine558a5b2012-08-07 16:56:02 +0400354 session = perf_session__new(inject->input_name, O_RDONLY, false, true, &inject->tool);
Tom Zanussi454c4072010-05-01 01:41:20 -0500355 if (session == NULL)
356 return -ENOMEM;
357
Andrew Vagin54a3cf52012-08-07 16:56:05 +0400358 if (inject->build_ids) {
359 inject->tool.sample = perf_event__inject_buildid;
360 } else if (inject->sched_stat) {
Andrew Vagin26a031e2012-08-07 16:56:04 +0400361 struct perf_evsel *evsel;
362
363 inject->tool.ordered_samples = true;
364
365 list_for_each_entry(evsel, &session->evlist->entries, node) {
366 const char *name = perf_evsel__name(evsel);
367
368 if (!strcmp(name, "sched:sched_switch")) {
369 if (perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID"))
370 return -EINVAL;
371
372 evsel->handler.func = perf_inject__sched_switch;
373 } else if (!strcmp(name, "sched:sched_process_exit"))
374 evsel->handler.func = perf_inject__sched_process_exit;
375 else if (!strncmp(name, "sched:sched_stat_", 17))
376 evsel->handler.func = perf_inject__sched_stat;
377 }
378 }
379
Andrew Vagine558a5b2012-08-07 16:56:02 +0400380 if (!inject->pipe_output)
381 lseek(inject->output, session->header.data_offset, SEEK_SET);
382
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300383 ret = perf_session__process_events(session, &inject->tool);
Tom Zanussi454c4072010-05-01 01:41:20 -0500384
Andrew Vagine558a5b2012-08-07 16:56:02 +0400385 if (!inject->pipe_output) {
386 session->header.data_size = inject->bytes_written;
387 perf_session__write_header(session, session->evlist, inject->output, true);
388 }
389
Tom Zanussi454c4072010-05-01 01:41:20 -0500390 perf_session__delete(session);
391
392 return ret;
393}
394
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300395int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
Tom Zanussi454c4072010-05-01 01:41:20 -0500396{
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300397 struct perf_inject inject = {
398 .tool = {
399 .sample = perf_event__repipe_sample,
400 .mmap = perf_event__repipe,
401 .comm = perf_event__repipe,
402 .fork = perf_event__repipe,
403 .exit = perf_event__repipe,
404 .lost = perf_event__repipe,
405 .read = perf_event__repipe_sample,
406 .throttle = perf_event__repipe,
407 .unthrottle = perf_event__repipe,
408 .attr = perf_event__repipe_attr,
409 .event_type = perf_event__repipe_event_type_synth,
410 .tracing_data = perf_event__repipe_tracing_data_synth,
411 .build_id = perf_event__repipe_op2_synth,
412 },
Andrew Vagine558a5b2012-08-07 16:56:02 +0400413 .input_name = "-",
Andrew Vagin26a031e2012-08-07 16:56:04 +0400414 .samples = LIST_HEAD_INIT(inject.samples),
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300415 };
Andrew Vagine558a5b2012-08-07 16:56:02 +0400416 const char *output_name = "-";
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300417 const struct option options[] = {
418 OPT_BOOLEAN('b', "build-ids", &inject.build_ids,
419 "Inject build-ids into the output stream"),
Andrew Vagine558a5b2012-08-07 16:56:02 +0400420 OPT_STRING('i', "input", &inject.input_name, "file",
421 "input file name"),
422 OPT_STRING('o', "output", &output_name, "file",
423 "output file name"),
Andrew Vagin26a031e2012-08-07 16:56:04 +0400424 OPT_BOOLEAN('s', "sched-stat", &inject.sched_stat,
425 "Merge sched-stat and sched-switch for getting events "
426 "where and how long tasks slept"),
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300427 OPT_INCR('v', "verbose", &verbose,
428 "be more verbose (show build ids, etc)"),
429 OPT_END()
430 };
Arnaldo Carvalho de Melo002439e2012-10-01 15:20:58 -0300431 const char * const inject_usage[] = {
432 "perf inject [<options>]",
433 NULL
434 };
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300435
Arnaldo Carvalho de Melo002439e2012-10-01 15:20:58 -0300436 argc = parse_options(argc, argv, options, inject_usage, 0);
Tom Zanussi454c4072010-05-01 01:41:20 -0500437
438 /*
439 * Any (unrecognized) arguments left?
440 */
441 if (argc)
Arnaldo Carvalho de Melo002439e2012-10-01 15:20:58 -0300442 usage_with_options(inject_usage, options);
Tom Zanussi454c4072010-05-01 01:41:20 -0500443
Andrew Vagine558a5b2012-08-07 16:56:02 +0400444 if (!strcmp(output_name, "-")) {
445 inject.pipe_output = 1;
446 inject.output = STDOUT_FILENO;
447 } else {
448 inject.output = open(output_name, O_CREAT | O_WRONLY | O_TRUNC,
449 S_IRUSR | S_IWUSR);
450 if (inject.output < 0) {
451 perror("failed to create output file");
452 return -1;
453 }
454 }
455
Tom Zanussi454c4072010-05-01 01:41:20 -0500456 if (symbol__init() < 0)
457 return -1;
458
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300459 return __cmd_inject(&inject);
Tom Zanussi454c4072010-05-01 01:41:20 -0500460}