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 <string>
18 #include <unistd.h>
19 #include <vector>
20 #include "fs_manager/mount.h"
21 #include "log.h"
22 #include "updater/updater_const.h"
23 #include "update_processor.h"
24 #include "utils.h"
25 
26 using namespace Updater;
27 #ifndef UPDATER_UT
main(int argc,char ** argv)28 int main(int argc, char **argv)
29 {
30     InitLogger("UPDATER_BINARY");
31     if (argc < MINIMAL_ARGC_LIMIT || argc > MAXIMAL_ARGC_LIMIT) {
32         LOG(ERROR) << "Invalid arguments:" << argc;
33         return EXIT_INVALID_ARGS;
34     }
35     bool retry = false;
36     int pipeFd;
37     std::string packagePath;
38     if (argc == 2) { // 2: package, pipe
39         packagePath = argv[0];
40         pipeFd = static_cast<int>(std::strtol(argv[1], nullptr, DECIMAL));
41     } else if (argc == 3) { // 3 a: package, pipe, retry
42         if (strcmp(argv[2], "retry") == 0) { // 2: retry index
43             retry = true;
44         }
45         packagePath = argv[0];
46         pipeFd = static_cast<int>(std::strtol(argv[1], nullptr, DECIMAL));
47     } else { // 4 a: binary, package, pipe, retry=1/retry=0
48         packagePath = argv[1];
49         pipeFd = static_cast<int>(std::strtol(argv[2], nullptr, DECIMAL)); // 2: pipe index
50         retry = strcmp(argv[3], "retry=0") == 0 ? false : true; // 3: retry index
51     }
52 
53     // Re-load fstab to child process.
54     LoadFstab();
55     return ProcessUpdater(retry, pipeFd, packagePath, Utils::GetCertName());
56 }
57 #endif
58