Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:26

0001 /*----------------------------------------------------------------------
0002  
0003  UnixSignalService: At present, this defines a SIGUSR2 handler and
0004  sets the shutdown flag when that signal has been raised.
0005  
0006  This service is instantiated at job startup.
0007  
0008  ----------------------------------------------------------------------*/
0009 #include <iostream>
0010 #include <cstdlib>
0011 
0012 #include "FWCore/ServiceRegistry/interface/ServiceMaker.h"
0013 
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 
0016 #include "FWCore/Utilities/interface/UnixSignalHandlers.h"
0017 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0019 
0020 namespace edm {
0021   namespace service {
0022     class UnixSignalService {
0023     public:
0024       explicit UnixSignalService(ParameterSet const& ps);
0025       ~UnixSignalService();
0026 
0027       static void fillDescriptions(ConfigurationDescriptions& descriptions);
0028 
0029     private:
0030       bool enableSigInt_;
0031     };  // class UnixSignalService
0032   }  // end of namespace service
0033 }  // end of namespace edm
0034 
0035 namespace edm {
0036 
0037   namespace service {
0038 
0039     UnixSignalService::UnixSignalService(ParameterSet const& pset)
0040         : enableSigInt_(pset.getUntrackedParameter<bool>("EnableCtrlC")) {
0041       installCustomHandler(SIGUSR2, ep_sigusr2);
0042       if (enableSigInt_)
0043         installCustomHandler(SIGINT, ep_sigusr2);
0044     }
0045 
0046     UnixSignalService::~UnixSignalService() {}
0047 
0048     void UnixSignalService::fillDescriptions(ConfigurationDescriptions& descriptions) {
0049       ParameterSetDescription desc;
0050       desc.addUntracked<bool>("EnableCtrlC", true)
0051           ->setComment(
0052               "If 'true', you can stop a cmsRun job gracefully by sending it a '<control> c' keyboard interrupt (i.e. "
0053               "SIGINT).");
0054       descriptions.add("UnixSignalService", desc);
0055       descriptions.setComment(
0056           "This service sets up unix signal handlers for the unix signal SIGUSR2 and optionally SIGINT"
0057           " so that when cmsRun is sent a signal the application will stop processing and shut down gracefully.");
0058     }
0059   }  // end of namespace service
0060 }  // end of namespace edm
0061 
0062 using edm::service::UnixSignalService;
0063 typedef edm::serviceregistry::ParameterSetMaker<UnixSignalService> UnixSignalMaker;
0064 DEFINE_FWK_SERVICE_MAKER(UnixSignalService, UnixSignalMaker);