1 // Copyright (C) 2020 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <poll.h> 18 19 #include <string> 20 #include <vector> 21 22 #include "snapuserd_server.h" 23 24 namespace android { 25 namespace snapshot { 26 27 class Daemon { 28 // The Daemon class is a singleton to avoid 29 // instantiating more than once 30 public: Daemon()31 Daemon() {} 32 Instance()33 static Daemon& Instance() { 34 static Daemon instance; 35 return instance; 36 } 37 38 bool StartServer(int argc, char** argv); 39 void Run(); 40 void Interrupt(); 41 42 private: 43 // Signal mask used with ppoll() 44 sigset_t signal_mask_; 45 46 Daemon(Daemon const&) = delete; 47 void operator=(Daemon const&) = delete; 48 49 SnapuserdServer server_; 50 void MaskAllSignalsExceptIntAndTerm(); 51 void MaskAllSignals(); 52 static void SignalHandler(int signal); 53 }; 54 55 } // namespace snapshot 56 } // namespace android 57