1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef NETD_SERVER_PROCESS_H_ 18 #define NETD_SERVER_PROCESS_H_ 19 20 #include "netdutils/DumpWriter.h" 21 22 #include <string> 23 24 namespace android { 25 namespace net { 26 namespace process { 27 28 // Does what is says on the tin. 29 void blockSigPipe(); 30 31 void writePidFile(const std::string& pidFile); 32 void removePidFile(const std::string& pidFile); 33 34 class ScopedPidFile { 35 public: 36 ScopedPidFile() = delete; ScopedPidFile(const std::string & filename)37 ScopedPidFile(const std::string& filename) : pidFile(filename) { 38 removePidFile(pidFile); 39 writePidFile(pidFile); 40 } 41 ScopedPidFile(const ScopedPidFile&) = delete; 42 ScopedPidFile(ScopedPidFile&&) = delete; 43 ~ScopedPidFile()44 ~ScopedPidFile() { 45 removePidFile(pidFile); 46 } 47 48 ScopedPidFile& operator=(const ScopedPidFile&) = delete; 49 ScopedPidFile& operator=(ScopedPidFile&&) = delete; 50 51 const std::string pidFile; 52 }; 53 54 void dump(netdutils::DumpWriter& dw); 55 56 } // namespace process 57 } // namespace net 58 } // namespace android 59 60 #endif // NETD_SERVER_PROCESS_H_ 61