File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -344,6 +344,7 @@ friend TROOT *ROOT::Internal::GetROOT2();
344
344
Int_t Timer () const { return fTimer ; }
345
345
346
346
// ---- static functions
347
+ static void CleanUpROOTAtExit ();
347
348
static Int_t DecreaseDirLevel ();
348
349
static Int_t GetDirLevel ();
349
350
static const char *GetMacroPath ();
@@ -356,6 +357,7 @@ friend TROOT *ROOT::Internal::GetROOT2();
356
357
static Int_t ConvertVersionCode2Int (Int_t code);
357
358
static Int_t ConvertVersionInt2Code (Int_t v);
358
359
static Int_t RootVersionCode ();
360
+ static void WriteCloseAllFiles ();
359
361
static const std::vector<std::string> &AddExtraInterpreterArgs (const std::vector<std::string> &args);
360
362
static const char **&GetExtraInterpreterArgs ();
361
363
Original file line number Diff line number Diff line change @@ -119,6 +119,7 @@ FARPROC dlsym(void *library, const char *function_name)
119
119
#include " TClass.h"
120
120
#include " TClassEdit.h"
121
121
#include " TClassGenerator.h"
122
+ #include " TDirectory.h"
122
123
#include " TDataType.h"
123
124
#include " TStyle.h"
124
125
#include " TObjectTable.h"
@@ -226,10 +227,33 @@ static Int_t ITIMQQ(const char *time)
226
227
return 100 *hh + mm;
227
228
}
228
229
230
+ // //////////////////////////////////////////////////////////////////////////////
231
+ // / Write and Close all open writable TFiles, useful to be called when SIGTERM is caught.
232
+
233
+ void TROOT::WriteCloseAllFiles ()
234
+ {
235
+ if (gROOT ) {
236
+ R__LOCKGUARD (gROOTMutex );
237
+
238
+ if (gROOT ->GetListOfFiles ()) {
239
+ TIter next (gROOT ->GetListOfFiles ());
240
+ while (TObject *obj = next ()) {
241
+ if (obj && obj->InheritsFrom (TClass::GetClass (" TFile" , kFALSE , kTRUE ))) {
242
+ auto fobj = static_cast <TDirectory *>(obj);
243
+ if (fobj->IsWritable ()) {
244
+ fobj->Write ();
245
+ fobj->Close ();
246
+ }
247
+ }
248
+ }
249
+ }
250
+ }
251
+ }
252
+
229
253
// //////////////////////////////////////////////////////////////////////////////
230
254
// / Clean up at program termination before global objects go out of scope.
231
255
232
- static void CleanUpROOTAtExit ()
256
+ void TROOT:: CleanUpROOTAtExit ()
233
257
{
234
258
if (gROOT ) {
235
259
R__LOCKGUARD (gROOTMutex );
Original file line number Diff line number Diff line change 24
24
#include < stdio.h>
25
25
#include < cstring>
26
26
27
+ #include < TROOT.h>
28
+
27
29
using namespace textinput ;
28
30
using std::memcpy;
29
31
using std::signal;
@@ -104,6 +106,11 @@ TerminalConfigUnix::HandleSignal(int signum) {
104
106
}
105
107
}
106
108
109
+ // gentle save and close if SIGTERM
110
+ if (signum == SIGTERM) {
111
+ TROOT::WriteCloseAllFiles ();
112
+ TROOT::CleanUpROOTAtExit ();
113
+ }
107
114
// No previous handler found, re-raise to get default handling:
108
115
signal (signum, SIG_DFL); // unregister ourselves
109
116
raise (signum); // terminate through default handler
You can’t perform that action at this time.
0 commit comments