2525DECLARE_EARLY_CONSTRUCT (std::unordered_set<std::string>, target_sources);
2626DECLARE_EARLY_CONSTRUCT (taintdag::PolyTracker, polytracker_tdag);
2727DECLARE_EARLY_CONSTRUCT (std::string, polytracker_db_name);
28+ DECLARE_EARLY_CONSTRUCT (std::string, polytracker_stderr_sink);
29+ DECLARE_EARLY_CONSTRUCT (std::string, polytracker_stdout_sink);
2830
2931uint64_t byte_start = 0 ;
3032uint64_t byte_end = 0 ;
@@ -55,6 +57,9 @@ void polytracker_parse_env() {
5557 if (auto pdb = getenv (" POLYDB" )) {
5658 get_polytracker_db_name () = pdb;
5759 }
60+
61+ get_polytracker_stdout_sink () = getenv (" POLYTRACKER_STDOUT_SINK" );
62+ get_polytracker_stderr_sink () = getenv (" POLYTRACKER_STDERR_SINK" );
5863}
5964
6065/*
@@ -71,12 +76,22 @@ void polytracker_get_settings() {
7176}
7277
7378void polytracker_end () {
79+ if (int f = fileno (stdout); f >= 0 ) {
80+ get_polytracker_tdag ().close_file (f);
81+ }
82+ if (int f = fileno (stderr); f >= 0 ) {
83+ get_polytracker_tdag ().close_file (f);
84+ }
7485 // Explicitly destroy the PolyTracker instance to flush mapping to disk
7586 get_polytracker_tdag ().~PolyTracker ();
7687}
7788
7889void polytracker_print_settings () {
79- printf (" POLYDB: %s\n " , get_polytracker_db_name ().c_str ());
90+ printf (" POLYDB: %s\n " , get_polytracker_db_name ().c_str ());
91+ printf (" POLYTRACKER_STDOUT_SINK: %s\n " ,
92+ get_polytracker_stdout_sink ().c_str ());
93+ printf (" POLYTRACKER_STDERR_SINK: %s\n " ,
94+ get_polytracker_stderr_sink ().c_str ());
8095}
8196
8297void polytracker_start (func_mapping const *globals, uint64_t globals_count,
@@ -96,6 +111,14 @@ void polytracker_start(func_mapping const *globals, uint64_t globals_count,
96111 " instrumentation.\n " );
97112 }
98113
114+ if (int f = fileno (stdout); f >= 0 && get_polytracker_stdout_sink () == " 1" ) {
115+ get_polytracker_tdag ().open_file (f, " /dev/stdout" );
116+ }
117+
118+ if (int f = fileno (stderr); f >= 0 && get_polytracker_stderr_sink () == " 1" ) {
119+ get_polytracker_tdag ().open_file (f, " /dev/stderr" );
120+ }
121+
99122 // Set up the atexit call
100123 atexit (polytracker_end);
101124}
0 commit comments