|
|
132810 |
commit 82349a5eb0e1122d5532a03367d91d5ee838722d
|
|
|
132810 |
Author: Serhei Makarov <smakarov@redhat.com>
|
|
|
132810 |
Date: Fri Mar 1 11:16:32 2019 -0500
|
|
|
132810 |
|
|
|
132810 |
Don't print to /dev/kmsg if it's unavailable
|
|
|
132810 |
|
|
|
132810 |
* stapbpf/stapbpf.cxx (kmsg): initialize to NULL.
|
|
|
132810 |
(prog_load): only print to kmsg if it's available.
|
|
|
132810 |
(main): warn if kmsg is unavailable.
|
|
|
132810 |
|
|
|
132810 |
diff --git a/stapbpf/stapbpf.cxx b/stapbpf/stapbpf.cxx
|
|
|
132810 |
index 188724b..ae97d4b 100644
|
|
|
132810 |
--- a/stapbpf/stapbpf.cxx
|
|
|
132810 |
+++ b/stapbpf/stapbpf.cxx
|
|
|
132810 |
@@ -73,7 +73,7 @@ static int warnings = 1;
|
|
|
132810 |
static int exit_phase = 0;
|
|
|
132810 |
static int interrupt_message = 0;
|
|
|
132810 |
static FILE *output_f = stdout;
|
|
|
132810 |
-static FILE *kmsg;
|
|
|
132810 |
+static FILE *kmsg = NULL;
|
|
|
132810 |
|
|
|
132810 |
static const char *module_name;
|
|
|
132810 |
static const char *module_basename;
|
|
|
132810 |
@@ -341,9 +341,12 @@ prog_load(Elf_Data *data, const char *name)
|
|
|
132810 |
if (data->d_size % sizeof(bpf_insn))
|
|
|
132810 |
fatal("program size not a multiple of %zu\n", sizeof(bpf_insn));
|
|
|
132810 |
|
|
|
132810 |
- fprintf (kmsg, "%s (%s): stapbpf: %s, name: %s, d_size: %lu\n",
|
|
|
132810 |
- module_basename, script_name, VERSION, name, (unsigned long)data->d_size);
|
|
|
132810 |
- fflush (kmsg); // Otherwise, flush will only happen after the prog runs.
|
|
|
132810 |
+ if (kmsg != NULL)
|
|
|
132810 |
+ {
|
|
|
132810 |
+ fprintf (kmsg, "%s (%s): stapbpf: %s, name: %s, d_size: %lu\n",
|
|
|
132810 |
+ module_basename, script_name, VERSION, name, (unsigned long)data->d_size);
|
|
|
132810 |
+ fflush (kmsg); // Otherwise, flush will only happen after the prog runs.
|
|
|
132810 |
+ }
|
|
|
132810 |
int fd = bpf_prog_load(prog_type, static_cast<bpf_insn *>(data->d_buf),
|
|
|
132810 |
data->d_size, module_license, kernel_version);
|
|
|
132810 |
if (fd < 0)
|
|
|
132810 |
@@ -1575,5 +1578,7 @@ main(int argc, char **argv)
|
|
|
132810 |
|
|
|
132810 |
- kmsg = fopen("/dev/kmsg", "a");
|
|
|
132810 |
+ kmsg = fopen("/dev/kmsg", "w");
|
|
|
132810 |
+ if (kmsg == NULL)
|
|
|
132810 |
+ fprintf(stderr, "WARNING: could not open /dev/kmsg for diagnostics: %s\n", strerror(errno));
|
|
|
132810 |
|
|
|
132810 |
load_bpf_file(argv[optind]);
|
|
|
132810 |
init_internal_globals();
|
|
|
132810 |
|