• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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 
16 #include <cstdio>
17 #include <cstdlib>
18 #include <iostream>
19 #include <string>
20 #include <unistd.h>
21 #include <vector>
22 
23 enum EXIT_CODES {
24     EXIT_INVALID_ARGS = EXIT_SUCCESS + 1,
25     EXIT_READ_PACKAGE_ERROR = 2,
26     EXIT_FOUND_SCRIPT_ERROR = 3,
27     EXIT_PARSE_SCRIPT_ERROR = 4,
28     EXIT_EXEC_SCRIPT_ERROR = 5,
29 };
30 
main(int argc,char ** argv)31 int main(int argc, char **argv)
32 {
33     constexpr int lessArgIndex = 2;
34     constexpr int withRetry = 3;
35     constexpr int decimal = 10;
36     if (argc < lessArgIndex) {
37         std::cout << "Invalid arguments\n";
38         return EXIT_INVALID_ARGS;
39     }
40 
41     bool retry = false;
42     int pipeFd = static_cast<int>(std::strtol(argv[1], nullptr, decimal));
43     if (argc >= withRetry && strcmp(argv[withRetry - 1], "retry") == 0) {
44         retry = true;
45     }
46     FILE *pipeWrite = fdopen(pipeFd, "w");
47     if (pipeWrite == nullptr) {
48         std::cout << "Failed to fdopen\n";
49         return EXIT_INVALID_ARGS;
50     }
51 
52     setlinebuf(pipeWrite);
53     fclose(pipeWrite);
54     // Return failure directly.
55     return EXIT_PARSE_SCRIPT_ERROR;
56 }
57 
58