xref: /aosp_15_r20/external/sandboxed-api/sandboxed_api/sandbox2/forkingclient.h (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1 // Copyright 2019 Google LLC
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 //     https://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 #ifndef SANDBOXED_API_SANDBOX2_FORKINGCLIENT_H_
16 #define SANDBOXED_API_SANDBOX2_FORKINGCLIENT_H_
17 
18 #include <sys/types.h>
19 #include <memory>
20 
21 #include "sandboxed_api/sandbox2/client.h"
22 #include "sandboxed_api/sandbox2/comms.h"
23 #include "sandboxed_api/sandbox2/forkserver.h"
24 
25 namespace sandbox2 {
26 
27 class ForkingClient : public Client {
28  public:
ForkingClient(Comms * comms)29   explicit ForkingClient(Comms* comms) : Client(comms) {}
30 
31   // Forks the current process (if asked by the Executor in the parent process),
32   // and returns the newly created PID to this Executor. This is used if the
33   // current Client objects acts as a wrapper of ForkServer (and this process
34   // was created to act as a ForkServer).
35   // Return values specified as with 'fork' (incl. -1).
36   pid_t WaitAndFork();
37 
38  private:
39   // ForkServer object, which is used only if the current process is meant
40   // to behave like a Fork-Server, i.e. to create a new process which will be
41   // later sandboxed (with SandboxMeHere()).
42   std::unique_ptr<ForkServer> fork_server_worker_;
43 };
44 
45 }  // namespace sandbox2
46 
47 #endif  // SANDBOXED_API_SANDBOX2_FORKINGCLIENT_H_
48