2010-04-14 11:35:46 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INIT_UTIL_H_
|
|
|
|
#define _INIT_UTIL_H_
|
|
|
|
|
2010-04-22 03:04:20 +08:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2016-11-11 09:43:47 +08:00
|
|
|
#include <chrono>
|
2015-04-26 08:42:52 +08:00
|
|
|
#include <functional>
|
2016-11-30 03:20:58 +08:00
|
|
|
#include <ostream>
|
|
|
|
#include <string>
|
2015-02-07 04:19:48 +08:00
|
|
|
|
2017-03-25 02:43:02 +08:00
|
|
|
#include <android-base/chrono_utils.h>
|
2017-05-02 08:10:09 +08:00
|
|
|
#include <selinux/label.h>
|
2017-03-25 02:43:02 +08:00
|
|
|
|
2014-11-25 11:52:41 +08:00
|
|
|
#define COLDBOOT_DONE "/dev/.coldboot_done"
|
2010-04-22 03:04:20 +08:00
|
|
|
|
2017-04-17 22:17:09 +08:00
|
|
|
const std::string kAndroidDtDir("/proc/device-tree/firmware/android/");
|
|
|
|
|
2017-03-25 02:43:02 +08:00
|
|
|
using android::base::boot_clock;
|
2016-11-11 09:43:47 +08:00
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
2017-06-23 03:53:17 +08:00
|
|
|
namespace android {
|
|
|
|
namespace init {
|
|
|
|
|
2017-05-06 05:44:35 +08:00
|
|
|
int CreateSocket(const char* name, int type, bool passcred, mode_t perm, uid_t uid, gid_t gid,
|
|
|
|
const char* socketcon, selabel_handle* sehandle);
|
2015-02-07 04:19:48 +08:00
|
|
|
|
2017-05-05 09:17:33 +08:00
|
|
|
bool ReadFile(const std::string& path, std::string* content, std::string* err);
|
|
|
|
bool WriteFile(const std::string& path, const std::string& content, std::string* err);
|
2015-02-07 04:19:48 +08:00
|
|
|
|
2017-05-05 08:40:33 +08:00
|
|
|
bool DecodeUid(const std::string& name, uid_t* uid, std::string* err);
|
2010-04-14 11:35:46 +08:00
|
|
|
|
2017-05-02 08:10:09 +08:00
|
|
|
int mkdir_recursive(const std::string& pathname, mode_t mode, selabel_handle* sehandle);
|
2016-11-11 09:43:47 +08:00
|
|
|
int wait_for_file(const char *filename, std::chrono::nanoseconds timeout);
|
2015-05-07 10:19:24 +08:00
|
|
|
void import_kernel_cmdline(bool in_qemu,
|
2016-07-28 07:25:51 +08:00
|
|
|
const std::function<void(const std::string&, const std::string&, bool)>&);
|
2017-05-02 08:10:09 +08:00
|
|
|
int make_dir(const char* path, mode_t mode, selabel_handle* sehandle);
|
2015-05-08 23:30:33 +08:00
|
|
|
std::string bytes_to_hex(const uint8_t *bytes, size_t bytes_len);
|
2015-07-25 07:57:14 +08:00
|
|
|
bool is_dir(const char* pathname);
|
2015-08-27 02:43:36 +08:00
|
|
|
bool expand_props(const std::string& src, std::string* dst);
|
2016-11-30 03:20:58 +08:00
|
|
|
|
|
|
|
void panic() __attribute__((__noreturn__));
|
|
|
|
|
2017-04-17 22:17:09 +08:00
|
|
|
// Reads or compares the content of device tree file under kAndroidDtDir directory.
|
|
|
|
bool read_android_dt_file(const std::string& sub_path, std::string* dt_content);
|
|
|
|
bool is_android_dt_value_expected(const std::string& sub_path, const std::string& expected_content);
|
|
|
|
|
2017-06-23 03:53:17 +08:00
|
|
|
} // namespace init
|
|
|
|
} // namespace android
|
|
|
|
|
2010-04-14 11:35:46 +08:00
|
|
|
#endif
|