File tree Expand file tree Collapse file tree 4 files changed +21
-13
lines changed Expand file tree Collapse file tree 4 files changed +21
-13
lines changed Original file line number Diff line number Diff line change 5353#include < stdio.h>
5454
5555#ifndef WIN32
56+ #include < attributes.h>
57+ #include < cerrno>
5658#include < signal.h>
5759#include < sys/stat.h>
5860#endif
@@ -1192,12 +1194,29 @@ bool AppInitLockDataDirectory()
11921194 return true ;
11931195}
11941196
1197+ #ifndef WIN32
1198+ NODISCARD static bool CreatePidFile ()
1199+ {
1200+ FILE* file = fsbridge::fopen (GetPidFile (), " w" );
1201+ if (file) {
1202+ fprintf (file, " %d\n " , getpid ());
1203+ fclose (file);
1204+ return true ;
1205+ } else {
1206+ return InitError (strprintf (_ (" Unable to create the PID file '%s': %s" ), GetPidFile ().string (), std::strerror (errno)));
1207+ }
1208+ }
1209+ #endif
1210+
11951211bool AppInitMain (InitInterfaces& interfaces)
11961212{
11971213 const CChainParams& chainparams = Params ();
11981214 // ********************************************************* Step 4a: application initialization
11991215#ifndef WIN32
1200- CreatePidFile (GetPidFile (), getpid ());
1216+ if (!CreatePidFile ()) {
1217+ // Detailed error printed inside CreatePidFile().
1218+ return false ;
1219+ }
12011220#endif
12021221 if (g_logger->m_print_to_file ) {
12031222 if (gArgs .GetBoolArg (" -shrinkdebugfile" , g_logger->DefaultShrinkDebugFile ())) {
Original file line number Diff line number Diff line change @@ -963,16 +963,6 @@ fs::path GetPidFile()
963963{
964964 return AbsPathForConfigVal (fs::path (gArgs .GetArg (" -pid" , BITCOIN_PID_FILENAME)));
965965}
966-
967- void CreatePidFile (const fs::path &path, pid_t pid)
968- {
969- FILE* file = fsbridge::fopen (path, " w" );
970- if (file)
971- {
972- fprintf (file, " %d\n " , pid);
973- fclose (file);
974- }
975- }
976966#endif
977967
978968bool RenameOver (fs::path src, fs::path dest)
Original file line number Diff line number Diff line change @@ -86,7 +86,6 @@ void ClearDatadirCache();
8686fs::path GetConfigFile (const std::string& confPath);
8787#ifndef WIN32
8888fs::path GetPidFile ();
89- void CreatePidFile (const fs::path &path, pid_t pid);
9089#endif
9190#ifdef WIN32
9291fs::path GetSpecialFolderPath (int nFolder, bool fCreate = true );
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ KNOWN_VIOLATIONS=(
88 " src/dbwrapper.cpp:.*vsnprintf"
99 " src/httprpc.cpp.*trim"
1010 " src/init.cpp:.*atoi"
11+ " src/init.cpp:.*fprintf"
1112 " src/qt/rpcconsole.cpp:.*atoi"
1213 " src/rest.cpp:.*strtol"
1314 " src/test/dbwrapper_tests.cpp:.*snprintf"
@@ -18,7 +19,6 @@ KNOWN_VIOLATIONS=(
1819 " src/util/strencodings.cpp:.*strtoul"
1920 " src/util/strencodings.h:.*atoi"
2021 " src/util/system.cpp:.*atoi"
21- " src/util/system.cpp:.*fprintf"
2222)
2323
2424REGEXP_IGNORE_EXTERNAL_DEPENDENCIES=" ^src/(crypto/ctaes/|leveldb/|secp256k1/|tinyformat.h|univalue/)"
You can’t perform that action at this time.
0 commit comments