2009-03-04 11:32:55 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 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.
|
|
|
|
*/
|
|
|
|
|
2016-10-27 22:45:34 +08:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <ftw.h>
|
|
|
|
#include <pwd.h>
|
2009-03-04 11:32:55 +08:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2010-04-14 10:35:09 +08:00
|
|
|
#include <time.h>
|
2016-10-27 22:45:34 +08:00
|
|
|
#include <unistd.h>
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2014-01-28 23:34:09 +08:00
|
|
|
#include <selinux/android.h>
|
2016-10-27 22:45:34 +08:00
|
|
|
#include <selinux/label.h>
|
2012-01-13 21:48:47 +08:00
|
|
|
|
2016-10-27 22:45:34 +08:00
|
|
|
#include <sys/socket.h>
|
2009-03-04 11:32:55 +08:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
|
2016-11-15 09:08:47 +08:00
|
|
|
#include <thread>
|
|
|
|
|
2015-12-05 14:00:26 +08:00
|
|
|
#include <android-base/file.h>
|
2016-06-25 06:12:21 +08:00
|
|
|
#include <android-base/logging.h>
|
2017-03-29 07:40:41 +08:00
|
|
|
#include <android-base/properties.h>
|
2016-10-27 22:45:34 +08:00
|
|
|
#include <android-base/stringprintf.h>
|
2015-12-05 14:00:26 +08:00
|
|
|
#include <android-base/strings.h>
|
2016-11-08 02:16:53 +08:00
|
|
|
#include <android-base/unique_fd.h>
|
2016-11-30 03:20:58 +08:00
|
|
|
|
|
|
|
#include <cutils/android_reboot.h>
|
2009-03-04 11:32:55 +08:00
|
|
|
/* for ANDROID_SOCKET_* */
|
|
|
|
#include <cutils/sockets.h>
|
|
|
|
|
2012-01-13 21:48:47 +08:00
|
|
|
#include "init.h"
|
2010-04-20 08:05:34 +08:00
|
|
|
#include "log.h"
|
2017-03-14 02:54:47 +08:00
|
|
|
#include "reboot.h"
|
2010-04-22 03:04:20 +08:00
|
|
|
#include "util.h"
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2015-06-19 08:46:54 +08:00
|
|
|
static unsigned int do_decode_uid(const char *s)
|
2009-03-04 11:32:55 +08:00
|
|
|
{
|
|
|
|
unsigned int v;
|
|
|
|
|
|
|
|
if (!s || *s == '\0')
|
2015-06-19 08:46:54 +08:00
|
|
|
return UINT_MAX;
|
2016-04-07 10:18:50 +08:00
|
|
|
|
|
|
|
if (isalpha(s[0])) {
|
|
|
|
struct passwd* pwd = getpwnam(s);
|
|
|
|
if (!pwd)
|
|
|
|
return UINT_MAX;
|
|
|
|
return pwd->pw_uid;
|
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
v = (unsigned int) strtoul(s, 0, 0);
|
|
|
|
if (errno)
|
2015-06-19 08:46:54 +08:00
|
|
|
return UINT_MAX;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* decode_uid - decodes and returns the given string, which can be either the
|
|
|
|
* numeric or name representation, into the integer uid or gid. Returns
|
|
|
|
* UINT_MAX on error.
|
|
|
|
*/
|
|
|
|
unsigned int decode_uid(const char *s) {
|
|
|
|
unsigned int v = do_decode_uid(s);
|
|
|
|
if (v == UINT_MAX) {
|
2016-06-25 06:12:21 +08:00
|
|
|
LOG(ERROR) << "decode_uid: Unable to find UID for '" << s << "'; returning UINT_MAX";
|
2015-06-19 08:46:54 +08:00
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create_socket - creates a Unix domain socket in ANDROID_SOCKET_DIR
|
|
|
|
* ("/dev/socket") as dictated in init.rc. This socket is inherited by the
|
|
|
|
* daemon. We communicate the file descriptor's value via the environment
|
|
|
|
* variable ANDROID_SOCKET_ENV_PREFIX<name> ("ANDROID_SOCKET_foo").
|
|
|
|
*/
|
2013-05-14 00:37:04 +08:00
|
|
|
int create_socket(const char *name, int type, mode_t perm, uid_t uid,
|
|
|
|
gid_t gid, const char *socketcon)
|
2009-03-04 11:32:55 +08:00
|
|
|
{
|
2015-11-24 08:26:42 +08:00
|
|
|
if (socketcon) {
|
|
|
|
if (setsockcreatecon(socketcon) == -1) {
|
2016-06-25 06:12:21 +08:00
|
|
|
PLOG(ERROR) << "setsockcreatecon(\"" << socketcon << "\") failed";
|
2015-11-24 08:26:42 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2016-11-08 02:16:53 +08:00
|
|
|
android::base::unique_fd fd(socket(PF_UNIX, type, 0));
|
2009-03-04 11:32:55 +08:00
|
|
|
if (fd < 0) {
|
2016-06-25 06:12:21 +08:00
|
|
|
PLOG(ERROR) << "Failed to open socket '" << name << "'";
|
2009-03-04 11:32:55 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-11-08 02:16:53 +08:00
|
|
|
if (socketcon) setsockcreatecon(NULL);
|
2013-05-14 00:37:04 +08:00
|
|
|
|
2016-11-08 02:16:53 +08:00
|
|
|
struct sockaddr_un addr;
|
2009-03-04 11:32:55 +08:00
|
|
|
memset(&addr, 0 , sizeof(addr));
|
|
|
|
addr.sun_family = AF_UNIX;
|
|
|
|
snprintf(addr.sun_path, sizeof(addr.sun_path), ANDROID_SOCKET_DIR"/%s",
|
|
|
|
name);
|
|
|
|
|
2016-11-08 02:16:53 +08:00
|
|
|
if ((unlink(addr.sun_path) != 0) && (errno != ENOENT)) {
|
2016-06-25 06:12:21 +08:00
|
|
|
PLOG(ERROR) << "Failed to unlink old socket '" << name << "'";
|
2016-11-08 02:16:53 +08:00
|
|
|
return -1;
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 02:16:53 +08:00
|
|
|
char *filecon = NULL;
|
2012-01-13 21:48:47 +08:00
|
|
|
if (sehandle) {
|
2016-11-08 02:16:53 +08:00
|
|
|
if (selabel_lookup(sehandle, &filecon, addr.sun_path, S_IFSOCK) == 0) {
|
2013-05-14 00:37:04 +08:00
|
|
|
setfscreatecon(filecon);
|
2016-11-08 02:16:53 +08:00
|
|
|
}
|
2012-01-13 21:48:47 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 02:16:53 +08:00
|
|
|
int ret = bind(fd, (struct sockaddr *) &addr, sizeof (addr));
|
|
|
|
int savederrno = errno;
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2012-01-13 21:48:47 +08:00
|
|
|
setfscreatecon(NULL);
|
2013-05-14 00:37:04 +08:00
|
|
|
freecon(filecon);
|
2012-01-13 21:48:47 +08:00
|
|
|
|
2016-02-25 07:50:52 +08:00
|
|
|
if (ret) {
|
2016-11-08 02:16:53 +08:00
|
|
|
errno = savederrno;
|
2016-06-25 06:12:21 +08:00
|
|
|
PLOG(ERROR) << "Failed to bind socket '" << name << "'";
|
2016-02-25 07:50:52 +08:00
|
|
|
goto out_unlink;
|
|
|
|
}
|
|
|
|
|
2016-11-08 02:16:53 +08:00
|
|
|
if (lchown(addr.sun_path, uid, gid)) {
|
2016-06-25 06:12:21 +08:00
|
|
|
PLOG(ERROR) << "Failed to lchown socket '" << addr.sun_path << "'";
|
2016-02-25 07:50:52 +08:00
|
|
|
goto out_unlink;
|
|
|
|
}
|
2016-11-08 02:16:53 +08:00
|
|
|
if (fchmodat(AT_FDCWD, addr.sun_path, perm, AT_SYMLINK_NOFOLLOW)) {
|
2016-06-25 06:12:21 +08:00
|
|
|
PLOG(ERROR) << "Failed to fchmodat socket '" << addr.sun_path << "'";
|
2016-02-25 07:50:52 +08:00
|
|
|
goto out_unlink;
|
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2016-06-25 06:12:21 +08:00
|
|
|
LOG(INFO) << "Created socket '" << addr.sun_path << "'"
|
|
|
|
<< ", mode " << std::oct << perm << std::dec
|
|
|
|
<< ", user " << uid
|
|
|
|
<< ", group " << gid;
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2016-11-08 02:16:53 +08:00
|
|
|
return fd.release();
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
out_unlink:
|
|
|
|
unlink(addr.sun_path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-07 04:19:48 +08:00
|
|
|
bool read_file(const char* path, std::string* content) {
|
|
|
|
content->clear();
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2017-03-21 05:24:25 +08:00
|
|
|
android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_NOFOLLOW | O_CLOEXEC)));
|
2015-02-07 04:19:48 +08:00
|
|
|
if (fd == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2015-02-07 04:19:48 +08:00
|
|
|
// For security reasons, disallow world-writable
|
|
|
|
// or group-writable files.
|
|
|
|
struct stat sb;
|
|
|
|
if (fstat(fd, &sb) == -1) {
|
2016-06-25 06:12:21 +08:00
|
|
|
PLOG(ERROR) << "fstat failed for '" << path << "'";
|
2015-02-07 04:19:48 +08:00
|
|
|
return false;
|
2012-01-19 02:39:01 +08:00
|
|
|
}
|
|
|
|
if ((sb.st_mode & (S_IWGRP | S_IWOTH)) != 0) {
|
2017-03-21 05:24:25 +08:00
|
|
|
LOG(ERROR) << "skipping insecure file '" << path << "'";
|
2015-02-07 04:19:48 +08:00
|
|
|
return false;
|
2012-01-19 02:39:01 +08:00
|
|
|
}
|
|
|
|
|
2017-03-21 05:24:25 +08:00
|
|
|
return android::base::ReadFdToString(fd, content);
|
2015-02-07 04:19:48 +08:00
|
|
|
}
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2016-12-29 03:07:02 +08:00
|
|
|
bool write_file(const char* path, const char* content) {
|
2016-12-28 16:06:19 +08:00
|
|
|
android::base::unique_fd fd(TEMP_FAILURE_RETRY(
|
|
|
|
open(path, O_WRONLY | O_CREAT | O_NOFOLLOW | O_TRUNC | O_CLOEXEC, 0600)));
|
2015-02-07 04:19:48 +08:00
|
|
|
if (fd == -1) {
|
2016-06-25 06:12:21 +08:00
|
|
|
PLOG(ERROR) << "write_file: Unable to open '" << path << "'";
|
2016-12-29 03:07:02 +08:00
|
|
|
return false;
|
2015-04-26 05:10:03 +08:00
|
|
|
}
|
2016-12-29 03:07:02 +08:00
|
|
|
bool success = android::base::WriteStringToFd(content, fd);
|
|
|
|
if (!success) {
|
2016-06-25 06:12:21 +08:00
|
|
|
PLOG(ERROR) << "write_file: Unable to write to '" << path << "'";
|
2015-02-07 04:19:48 +08:00
|
|
|
}
|
2016-12-29 03:07:02 +08:00
|
|
|
return success;
|
2009-03-04 11:32:55 +08:00
|
|
|
}
|
|
|
|
|
2017-02-15 03:20:20 +08:00
|
|
|
boot_clock::time_point boot_clock::now() {
|
|
|
|
timespec ts;
|
|
|
|
clock_gettime(CLOCK_BOOTTIME, &ts);
|
|
|
|
return boot_clock::time_point(std::chrono::seconds(ts.tv_sec) +
|
|
|
|
std::chrono::nanoseconds(ts.tv_nsec));
|
2010-04-14 10:35:09 +08:00
|
|
|
}
|
2010-04-09 07:16:20 +08:00
|
|
|
|
|
|
|
int mkdir_recursive(const char *pathname, mode_t mode)
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
const char *slash;
|
|
|
|
const char *p = pathname;
|
|
|
|
int width;
|
|
|
|
int ret;
|
|
|
|
struct stat info;
|
|
|
|
|
|
|
|
while ((slash = strchr(p, '/')) != NULL) {
|
|
|
|
width = slash - pathname;
|
|
|
|
p = slash + 1;
|
|
|
|
if (width < 0)
|
|
|
|
break;
|
|
|
|
if (width == 0)
|
|
|
|
continue;
|
|
|
|
if ((unsigned int)width > sizeof(buf) - 1) {
|
2016-06-25 06:12:21 +08:00
|
|
|
LOG(ERROR) << "path too long for mkdir_recursive";
|
2010-04-09 07:16:20 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy(buf, pathname, width);
|
|
|
|
buf[width] = 0;
|
|
|
|
if (stat(buf, &info) != 0) {
|
2012-06-12 01:37:39 +08:00
|
|
|
ret = make_dir(buf, mode);
|
2010-04-09 07:16:20 +08:00
|
|
|
if (ret && errno != EEXIST)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2012-06-12 01:37:39 +08:00
|
|
|
ret = make_dir(pathname, mode);
|
2010-04-09 07:16:20 +08:00
|
|
|
if (ret && errno != EEXIST)
|
|
|
|
return ret;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-18 22:41:19 +08:00
|
|
|
/*
|
|
|
|
* replaces any unacceptable characters with '_', the
|
|
|
|
* length of the resulting string is equal to the input string
|
|
|
|
*/
|
2010-04-09 07:16:20 +08:00
|
|
|
void sanitize(char *s)
|
|
|
|
{
|
2012-04-18 22:41:19 +08:00
|
|
|
const char* accept =
|
|
|
|
"abcdefghijklmnopqrstuvwxyz"
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
"0123456789"
|
|
|
|
"_-.";
|
|
|
|
|
2010-04-09 07:16:20 +08:00
|
|
|
if (!s)
|
|
|
|
return;
|
2012-04-18 22:41:19 +08:00
|
|
|
|
2014-09-23 02:35:54 +08:00
|
|
|
while (*s) {
|
2012-04-18 22:41:19 +08:00
|
|
|
s += strspn(s, accept);
|
2014-09-23 02:35:54 +08:00
|
|
|
if (*s) *s++ = '_';
|
2012-04-18 22:41:19 +08:00
|
|
|
}
|
2010-04-09 07:16:20 +08:00
|
|
|
}
|
2012-04-18 22:41:19 +08:00
|
|
|
|
2016-11-11 09:43:47 +08:00
|
|
|
int wait_for_file(const char* filename, std::chrono::nanoseconds timeout) {
|
|
|
|
boot_clock::time_point timeout_time = boot_clock::now() + timeout;
|
|
|
|
while (boot_clock::now() < timeout_time) {
|
|
|
|
struct stat sb;
|
|
|
|
if (stat(filename, &sb) != -1) return 0;
|
2010-04-20 08:10:24 +08:00
|
|
|
|
2016-11-15 09:08:47 +08:00
|
|
|
std::this_thread::sleep_for(10ms);
|
2016-11-11 09:43:47 +08:00
|
|
|
}
|
|
|
|
return -1;
|
2010-04-20 08:10:24 +08:00
|
|
|
}
|
2010-04-22 03:04:20 +08:00
|
|
|
|
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)>& fn) {
|
2015-05-07 10:19:24 +08:00
|
|
|
std::string cmdline;
|
|
|
|
android::base::ReadFileToString("/proc/cmdline", &cmdline);
|
2011-09-29 00:55:31 +08:00
|
|
|
|
2015-05-07 10:19:24 +08:00
|
|
|
for (const auto& entry : android::base::Split(android::base::Trim(cmdline), " ")) {
|
|
|
|
std::vector<std::string> pieces = android::base::Split(entry, "=");
|
|
|
|
if (pieces.size() == 2) {
|
|
|
|
fn(pieces[0], pieces[1], in_qemu);
|
|
|
|
}
|
2011-09-29 00:55:31 +08:00
|
|
|
}
|
|
|
|
}
|
2012-06-12 01:37:39 +08:00
|
|
|
|
|
|
|
int make_dir(const char *path, mode_t mode)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
char *secontext = NULL;
|
|
|
|
|
|
|
|
if (sehandle) {
|
|
|
|
selabel_lookup(sehandle, &secontext, path, mode);
|
|
|
|
setfscreatecon(secontext);
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = mkdir(path, mode);
|
|
|
|
|
|
|
|
if (secontext) {
|
|
|
|
int save_errno = errno;
|
|
|
|
freecon(secontext);
|
|
|
|
setfscreatecon(NULL);
|
|
|
|
errno = save_errno;
|
|
|
|
}
|
2012-10-17 14:07:05 +08:00
|
|
|
|
2012-06-12 01:37:39 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-11-15 07:40:18 +08:00
|
|
|
int restorecon(const char* pathname, int flags)
|
2012-06-12 01:37:39 +08:00
|
|
|
{
|
2016-11-15 07:40:18 +08:00
|
|
|
return selinux_android_restorecon(pathname, flags);
|
2016-07-16 06:21:34 +08:00
|
|
|
}
|
|
|
|
|
2015-05-08 23:30:33 +08:00
|
|
|
/*
|
|
|
|
* Writes hex_len hex characters (1/2 byte) to hex from bytes.
|
|
|
|
*/
|
|
|
|
std::string bytes_to_hex(const uint8_t* bytes, size_t bytes_len) {
|
|
|
|
std::string hex("0x");
|
|
|
|
for (size_t i = 0; i < bytes_len; i++)
|
|
|
|
android::base::StringAppendF(&hex, "%02x", bytes[i]);
|
|
|
|
return hex;
|
|
|
|
}
|
2015-07-25 07:57:14 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns true is pathname is a directory
|
|
|
|
*/
|
|
|
|
bool is_dir(const char* pathname) {
|
|
|
|
struct stat info;
|
|
|
|
if (stat(pathname, &info) == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return S_ISDIR(info.st_mode);
|
|
|
|
}
|
2015-08-27 02:43:36 +08:00
|
|
|
|
|
|
|
bool expand_props(const std::string& src, std::string* dst) {
|
|
|
|
const char* src_ptr = src.c_str();
|
|
|
|
|
|
|
|
if (!dst) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* - variables can either be $x.y or ${x.y}, in case they are only part
|
|
|
|
* of the string.
|
|
|
|
* - will accept $$ as a literal $.
|
|
|
|
* - no nested property expansion, i.e. ${foo.${bar}} is not supported,
|
|
|
|
* bad things will happen
|
2016-06-07 23:49:01 +08:00
|
|
|
* - ${x.y:-default} will return default value if property empty.
|
2015-08-27 02:43:36 +08:00
|
|
|
*/
|
|
|
|
while (*src_ptr) {
|
|
|
|
const char* c;
|
|
|
|
|
|
|
|
c = strchr(src_ptr, '$');
|
|
|
|
if (!c) {
|
|
|
|
dst->append(src_ptr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst->append(src_ptr, c);
|
|
|
|
c++;
|
|
|
|
|
|
|
|
if (*c == '$') {
|
|
|
|
dst->push_back(*(c++));
|
|
|
|
src_ptr = c;
|
|
|
|
continue;
|
|
|
|
} else if (*c == '\0') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string prop_name;
|
2016-06-07 23:49:01 +08:00
|
|
|
std::string def_val;
|
2015-08-27 02:43:36 +08:00
|
|
|
if (*c == '{') {
|
|
|
|
c++;
|
|
|
|
const char* end = strchr(c, '}');
|
|
|
|
if (!end) {
|
|
|
|
// failed to find closing brace, abort.
|
2016-06-25 06:12:21 +08:00
|
|
|
LOG(ERROR) << "unexpected end of string in '" << src << "', looking for }";
|
2015-08-27 02:43:36 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
prop_name = std::string(c, end);
|
|
|
|
c = end + 1;
|
2016-06-07 23:49:01 +08:00
|
|
|
size_t def = prop_name.find(":-");
|
|
|
|
if (def < prop_name.size()) {
|
|
|
|
def_val = prop_name.substr(def + 2);
|
|
|
|
prop_name = prop_name.substr(0, def);
|
|
|
|
}
|
2015-08-27 02:43:36 +08:00
|
|
|
} else {
|
|
|
|
prop_name = c;
|
2016-06-25 06:12:21 +08:00
|
|
|
LOG(ERROR) << "using deprecated syntax for specifying property '" << c << "', use ${name} instead";
|
2015-08-27 02:43:36 +08:00
|
|
|
c += prop_name.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prop_name.empty()) {
|
2016-06-25 06:12:21 +08:00
|
|
|
LOG(ERROR) << "invalid zero-length property name in '" << src << "'";
|
2015-08-27 02:43:36 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-29 07:40:41 +08:00
|
|
|
std::string prop_val = android::base::GetProperty(prop_name, "");
|
2015-08-27 02:43:36 +08:00
|
|
|
if (prop_val.empty()) {
|
2016-06-07 23:49:01 +08:00
|
|
|
if (def_val.empty()) {
|
2016-06-25 06:12:21 +08:00
|
|
|
LOG(ERROR) << "property '" << prop_name << "' doesn't exist while expanding '" << src << "'";
|
2016-06-07 23:49:01 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
prop_val = def_val;
|
2015-08-27 02:43:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dst->append(prop_val);
|
|
|
|
src_ptr = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-11-30 03:20:58 +08:00
|
|
|
|
|
|
|
void panic() {
|
|
|
|
LOG(ERROR) << "panic: rebooting to bootloader";
|
2017-03-14 02:54:47 +08:00
|
|
|
DoReboot(ANDROID_RB_RESTART2, "reboot", "bootloader", false);
|
2016-11-30 03:20:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& os, const Timer& t) {
|
|
|
|
os << t.duration_s() << " seconds";
|
|
|
|
return os;
|
|
|
|
}
|