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