Blame SOURCES/stapbpf-kmsg.patch

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