diff options
author | cjihrig <cjihrig@gmail.com> | 2019-04-08 17:09:53 -0400 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2019-04-10 20:41:39 -0400 |
commit | 547576f530afb0a5f0f98368212ee636a352d063 (patch) | |
tree | d99e5ab040fc93cbaafcfaab68ad2aa9c38f583f /src/util.cc | |
parent | 44a3acb6272accf6296be521ff2f626514874acc (diff) | |
download | node-new-547576f530afb0a5f0f98368212ee636a352d063.tar.gz |
src: always use diagnostic file sequence number
This commit attaches a sequence number to all filenames that
are automatically generated by DiagnosticFilename. This prevents
accidental overwriting of existing files.
PR-URL: https://github.com/nodejs/node/pull/27142
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'src/util.cc')
-rw-r--r-- | src/util.cc | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/util.cc b/src/util.cc index 49c8a0f46a..4091fffb6b 100644 --- a/src/util.cc +++ b/src/util.cc @@ -41,10 +41,13 @@ #include <sys/types.h> #endif +#include <atomic> #include <cstdio> #include <iomanip> #include <sstream> +static std::atomic_int seq = {0}; // Sequence number for diagnostic filenames. + namespace node { // Microseconds in a second, as a float. @@ -225,8 +228,7 @@ void DiagnosticFilename::LocalTime(TIME_TYPE* tm_struct) { std::string DiagnosticFilename::MakeFilename( uint64_t thread_id, const char* prefix, - const char* ext, - int seq) { + const char* ext) { std::ostringstream oss; TIME_TYPE tm_struct; LocalTime(&tm_struct); @@ -262,8 +264,7 @@ std::string DiagnosticFilename::MakeFilename( #endif oss << "." << uv_os_getpid(); oss << "." << thread_id; - if (seq >= 0) - oss << "." << std::setfill('0') << std::setw(3) << ++seq; + oss << "." << std::setfill('0') << std::setw(3) << ++seq; oss << "." << ext; return oss.str(); } |