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 53
53
#include < stdio.h>
54
54
55
55
#ifndef WIN32
56
+ #include < attributes.h>
57
+ #include < cerrno>
56
58
#include < signal.h>
57
59
#include < sys/stat.h>
58
60
#endif
@@ -1192,12 +1194,29 @@ bool AppInitLockDataDirectory()
1192
1194
return true ;
1193
1195
}
1194
1196
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
+
1195
1211
bool AppInitMain (InitInterfaces& interfaces)
1196
1212
{
1197
1213
const CChainParams& chainparams = Params ();
1198
1214
// ********************************************************* Step 4a: application initialization
1199
1215
#ifndef WIN32
1200
- CreatePidFile (GetPidFile (), getpid ());
1216
+ if (!CreatePidFile ()) {
1217
+ // Detailed error printed inside CreatePidFile().
1218
+ return false ;
1219
+ }
1201
1220
#endif
1202
1221
if (g_logger->m_print_to_file ) {
1203
1222
if (gArgs .GetBoolArg (" -shrinkdebugfile" , g_logger->DefaultShrinkDebugFile ())) {
Original file line number Diff line number Diff line change @@ -963,16 +963,6 @@ fs::path GetPidFile()
963
963
{
964
964
return AbsPathForConfigVal (fs::path (gArgs .GetArg (" -pid" , BITCOIN_PID_FILENAME)));
965
965
}
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
- }
976
966
#endif
977
967
978
968
bool RenameOver (fs::path src, fs::path dest)
Original file line number Diff line number Diff line change @@ -86,7 +86,6 @@ void ClearDatadirCache();
86
86
fs::path GetConfigFile (const std::string& confPath);
87
87
#ifndef WIN32
88
88
fs::path GetPidFile ();
89
- void CreatePidFile (const fs::path &path, pid_t pid);
90
89
#endif
91
90
#ifdef WIN32
92
91
fs::path GetSpecialFolderPath (int nFolder, bool fCreate = true );
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ KNOWN_VIOLATIONS=(
8
8
" src/dbwrapper.cpp:.*vsnprintf"
9
9
" src/httprpc.cpp.*trim"
10
10
" src/init.cpp:.*atoi"
11
+ " src/init.cpp:.*fprintf"
11
12
" src/qt/rpcconsole.cpp:.*atoi"
12
13
" src/rest.cpp:.*strtol"
13
14
" src/test/dbwrapper_tests.cpp:.*snprintf"
@@ -18,7 +19,6 @@ KNOWN_VIOLATIONS=(
18
19
" src/util/strencodings.cpp:.*strtoul"
19
20
" src/util/strencodings.h:.*atoi"
20
21
" src/util/system.cpp:.*atoi"
21
- " src/util/system.cpp:.*fprintf"
22
22
)
23
23
24
24
REGEXP_IGNORE_EXTERNAL_DEPENDENCIES=" ^src/(crypto/ctaes/|leveldb/|secp256k1/|tinyformat.h|univalue/)"
You can’t perform that action at this time.
0 commit comments