blob: 9adfc0e8124200fe27a9d2524c1d6bdaff0f139a [file] [log] [blame]
Victor Hsiehc9821f12020-08-07 11:32:29 -07001/*
2 * Copyright (C) 2020 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 ANDROID_INSTALLD_EXECV_HELPER_H
18#define ANDROID_INSTALLD_EXECV_HELPER_H
19
20#include <string>
21#include <vector>
22
23namespace android {
24namespace installd {
25
26// ExecVHelper prepares and holds pointers to parsed command line arguments so that no allocations
27// need to be performed between the fork and exec.
28class ExecVHelper {
29 public:
30 ExecVHelper();
31 virtual ~ExecVHelper();
32
33 [[ noreturn ]]
34 virtual void Exec(int exit_code);
35
36 void PrepareArgs(const std::string& bin);
37
38 // Add an arg if it's not empty.
39 void AddArg(const std::string& arg);
40
41 // Add a runtime arg if it's not empty.
42 void AddRuntimeArg(const std::string& arg);
43
44 protected:
45 // Holder arrays for backing arg storage.
46 std::vector<std::string> args_;
47
48 // Argument poiners.
49 std::vector<const char*> argv_;
50};
51
52} // namespace installd
53} // namespace android
54
55#endif // ANDROID_INSTALLD_EXECV_HELPER_H