2012-10-24 17:45:23 +00:00
|
|
|
/*
|
|
|
|
** Copyright 2008, The Android Open Source Project
|
|
|
|
**
|
2015-04-07 19:44:51 +00:00
|
|
|
** 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
|
2012-10-24 17:45:23 +00:00
|
|
|
**
|
2015-04-07 19:44:51 +00:00
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
2012-10-24 17:45:23 +00:00
|
|
|
**
|
2015-04-07 19:44:51 +00:00
|
|
|
** 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
|
2012-10-24 17:45:23 +00:00
|
|
|
** limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-04-09 03:56:42 +00:00
|
|
|
#include "installd.h"
|
|
|
|
|
|
|
|
#include <base/logging.h>
|
|
|
|
|
2013-03-01 00:59:13 +00:00
|
|
|
#include <sys/capability.h>
|
2014-07-19 00:29:15 +00:00
|
|
|
#include <sys/prctl.h>
|
2013-04-16 16:16:50 +00:00
|
|
|
#include <selinux/android.h>
|
|
|
|
#include <selinux/avc.h>
|
2012-10-24 17:45:23 +00:00
|
|
|
|
|
|
|
#define BUFFER_MAX 1024 /* input buffer for commands */
|
2015-03-03 20:25:29 +00:00
|
|
|
#define TOKEN_MAX 16 /* max number of arguments in buffer */
|
2012-10-24 17:45:23 +00:00
|
|
|
#define REPLY_MAX 256 /* largest reply allowed */
|
|
|
|
|
2015-04-09 20:10:03 +00:00
|
|
|
static char* parse_null(char* arg) {
|
|
|
|
if (strcmp(arg, "!") == 0) {
|
|
|
|
return nullptr;
|
|
|
|
} else {
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_ping(char **arg __unused, char reply[REPLY_MAX] __unused)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_install(char **arg, char reply[REPLY_MAX] __unused)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2015-04-09 20:10:03 +00:00
|
|
|
return install(parse_null(arg[0]), arg[1], atoi(arg[2]), atoi(arg[3]), arg[4]); /* uuid, pkgname, uid, gid, seinfo */
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_dexopt(char **arg, char reply[REPLY_MAX] __unused)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2015-03-26 22:47:38 +00:00
|
|
|
/* apk_path, uid, is_public, pkgname, instruction_set,
|
2015-09-21 20:21:30 +00:00
|
|
|
* dexopt_needed, vm_safe_mode, debuggable, oat_dir, boot_complete */
|
2015-03-26 22:47:38 +00:00
|
|
|
return dexopt(arg[0], atoi(arg[1]), atoi(arg[2]), arg[3], arg[4], atoi(arg[5]),
|
2015-09-21 20:21:30 +00:00
|
|
|
atoi(arg[6]), atoi(arg[7]), arg[8], atoi(arg[9]));
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2014-11-23 21:28:26 +00:00
|
|
|
static int do_mark_boot_complete(char **arg, char reply[REPLY_MAX] __unused)
|
2014-11-10 15:03:46 +00:00
|
|
|
{
|
|
|
|
return mark_boot_complete(arg[0] /* instruction set */);
|
|
|
|
}
|
|
|
|
|
2014-11-23 21:28:26 +00:00
|
|
|
static int do_move_dex(char **arg, char reply[REPLY_MAX] __unused)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2014-04-11 12:17:00 +00:00
|
|
|
return move_dex(arg[0], arg[1], arg[2]); /* src, dst, instruction_set */
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_rm_dex(char **arg, char reply[REPLY_MAX] __unused)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2014-04-11 12:17:00 +00:00
|
|
|
return rm_dex(arg[0], arg[1]); /* pkgname, instruction_set */
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_remove(char **arg, char reply[REPLY_MAX] __unused)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2015-04-09 20:10:03 +00:00
|
|
|
return uninstall(parse_null(arg[0]), arg[1], atoi(arg[2])); /* uuid, pkgname, userid */
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_rename(char **arg, char reply[REPLY_MAX] __unused)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
|
|
|
return renamepkg(arg[0], arg[1]); /* oldpkgname, newpkgname */
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_fixuid(char **arg, char reply[REPLY_MAX] __unused)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2015-04-09 20:10:03 +00:00
|
|
|
return fix_uid(parse_null(arg[0]), arg[1], atoi(arg[2]), atoi(arg[3])); /* uuid, pkgname, uid, gid */
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_free_cache(char **arg, char reply[REPLY_MAX] __unused) /* TODO int:free_size */
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2015-04-09 20:10:03 +00:00
|
|
|
return free_cache(parse_null(arg[0]), (int64_t)atoll(arg[1])); /* uuid, free_size */
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_rm_cache(char **arg, char reply[REPLY_MAX] __unused)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2015-04-09 20:10:03 +00:00
|
|
|
return delete_cache(parse_null(arg[0]), arg[1], atoi(arg[2])); /* uuid, pkgname, userid */
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-12 16:00:50 +00:00
|
|
|
static int do_rm_code_cache(char **arg, char reply[REPLY_MAX] __unused)
|
2014-07-16 04:49:51 +00:00
|
|
|
{
|
2015-04-09 20:10:03 +00:00
|
|
|
return delete_code_cache(parse_null(arg[0]), arg[1], atoi(arg[2])); /* uuid, pkgname, userid */
|
2014-07-16 04:49:51 +00:00
|
|
|
}
|
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
static int do_get_size(char **arg, char reply[REPLY_MAX])
|
|
|
|
{
|
|
|
|
int64_t codesize = 0;
|
|
|
|
int64_t datasize = 0;
|
|
|
|
int64_t cachesize = 0;
|
|
|
|
int64_t asecsize = 0;
|
|
|
|
int res = 0;
|
|
|
|
|
2015-04-09 20:10:03 +00:00
|
|
|
/* uuid, pkgdir, userid, apkpath */
|
|
|
|
res = get_size(parse_null(arg[0]), arg[1], atoi(arg[2]), arg[3], arg[4], arg[5], arg[6],
|
|
|
|
arg[7], &codesize, &datasize, &cachesize, &asecsize);
|
2012-10-24 17:45:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Each int64_t can take up 22 characters printed out. Make sure it
|
|
|
|
* doesn't go over REPLY_MAX in the future.
|
|
|
|
*/
|
|
|
|
snprintf(reply, REPLY_MAX, "%" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
|
|
|
|
codesize, datasize, cachesize, asecsize);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_rm_user_data(char **arg, char reply[REPLY_MAX] __unused)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2015-04-09 20:10:03 +00:00
|
|
|
return delete_user_data(parse_null(arg[0]), arg[1], atoi(arg[2])); /* uuid, pkgname, userid */
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 20:31:37 +00:00
|
|
|
static int do_cp_complete_app(char **arg, char reply[REPLY_MAX] __unused)
|
2015-04-09 03:56:42 +00:00
|
|
|
{
|
2015-04-30 22:58:19 +00:00
|
|
|
// from_uuid, to_uuid, package_name, data_app_name, appid, seinfo
|
2015-07-07 20:31:37 +00:00
|
|
|
return copy_complete_app(parse_null(arg[0]), parse_null(arg[1]), arg[2], arg[3], atoi(arg[4]), arg[5]);
|
2015-04-09 03:56:42 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_mk_user_data(char **arg, char reply[REPLY_MAX] __unused)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2015-04-09 20:10:03 +00:00
|
|
|
return make_user_data(parse_null(arg[0]), arg[1], atoi(arg[2]), atoi(arg[3]), arg[4]);
|
|
|
|
/* uuid, pkgname, uid, userid, seinfo */
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_mk_user_config(char **arg, char reply[REPLY_MAX] __unused)
|
2014-04-25 14:05:19 +00:00
|
|
|
{
|
2014-06-10 17:46:26 +00:00
|
|
|
return make_user_config(atoi(arg[0])); /* userid */
|
2014-04-25 14:05:19 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_rm_user(char **arg, char reply[REPLY_MAX] __unused)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2015-04-09 20:10:03 +00:00
|
|
|
return delete_user(parse_null(arg[0]), atoi(arg[1])); /* uuid, userid */
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_movefiles(char **arg __unused, char reply[REPLY_MAX] __unused)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
|
|
|
return movefiles();
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_linklib(char **arg, char reply[REPLY_MAX] __unused)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2015-04-09 20:10:03 +00:00
|
|
|
return linklib(parse_null(arg[0]), arg[1], arg[2], atoi(arg[3]));
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:46 +00:00
|
|
|
static int do_idmap(char **arg, char reply[REPLY_MAX] __unused)
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
{
|
|
|
|
return idmap(arg[0], arg[1], atoi(arg[2]));
|
|
|
|
}
|
|
|
|
|
2014-03-27 14:21:12 +00:00
|
|
|
static int do_restorecon_data(char **arg, char reply[REPLY_MAX] __attribute__((unused)))
|
2014-02-20 15:25:56 +00:00
|
|
|
{
|
2015-04-09 20:10:03 +00:00
|
|
|
return restorecon_data(parse_null(arg[0]), arg[1], arg[2], atoi(arg[3]));
|
|
|
|
/* uuid, pkgName, seinfo, uid*/
|
2014-02-20 15:25:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 20:25:29 +00:00
|
|
|
static int do_create_oat_dir(char **arg, char reply[REPLY_MAX] __unused)
|
|
|
|
{
|
|
|
|
/* oat_dir, instruction_set */
|
|
|
|
return create_oat_dir(arg[0], arg[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_rm_package_dir(char **arg, char reply[REPLY_MAX] __unused)
|
|
|
|
{
|
|
|
|
/* oat_dir */
|
|
|
|
return rm_package_dir(arg[0]);
|
2014-07-21 19:23:48 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 12:20:27 +00:00
|
|
|
static int do_link_file(char **arg, char reply[REPLY_MAX] __unused)
|
|
|
|
{
|
|
|
|
/* relative_path, from_base, to_base */
|
|
|
|
return link_file(arg[0], arg[1], arg[2]);
|
|
|
|
}
|
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
struct cmdinfo {
|
|
|
|
const char *name;
|
|
|
|
unsigned numargs;
|
|
|
|
int (*func)(char **arg, char reply[REPLY_MAX]);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cmdinfo cmds[] = {
|
|
|
|
{ "ping", 0, do_ping },
|
2015-04-09 20:10:03 +00:00
|
|
|
{ "install", 5, do_install },
|
2015-09-21 20:21:30 +00:00
|
|
|
{ "dexopt", 10, do_dexopt },
|
2014-11-10 15:03:46 +00:00
|
|
|
{ "markbootcomplete", 1, do_mark_boot_complete },
|
2014-04-11 12:17:00 +00:00
|
|
|
{ "movedex", 3, do_move_dex },
|
|
|
|
{ "rmdex", 2, do_rm_dex },
|
2015-04-09 20:10:03 +00:00
|
|
|
{ "remove", 3, do_remove },
|
2012-10-24 17:45:23 +00:00
|
|
|
{ "rename", 2, do_rename },
|
2015-04-09 20:10:03 +00:00
|
|
|
{ "fixuid", 4, do_fixuid },
|
|
|
|
{ "freecache", 2, do_free_cache },
|
|
|
|
{ "rmcache", 3, do_rm_cache },
|
|
|
|
{ "rmcodecache", 3, do_rm_code_cache },
|
|
|
|
{ "getsize", 8, do_get_size },
|
|
|
|
{ "rmuserdata", 3, do_rm_user_data },
|
2015-07-07 20:31:37 +00:00
|
|
|
{ "cpcompleteapp", 6, do_cp_complete_app },
|
2012-10-24 17:45:23 +00:00
|
|
|
{ "movefiles", 0, do_movefiles },
|
2015-04-09 20:10:03 +00:00
|
|
|
{ "linklib", 4, do_linklib },
|
|
|
|
{ "mkuserdata", 5, do_mk_user_data },
|
2014-06-10 17:46:26 +00:00
|
|
|
{ "mkuserconfig", 1, do_mk_user_config },
|
2015-04-09 20:10:03 +00:00
|
|
|
{ "rmuser", 2, do_rm_user },
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
{ "idmap", 3, do_idmap },
|
2015-04-09 20:10:03 +00:00
|
|
|
{ "restorecondata", 4, do_restorecon_data },
|
2015-03-03 20:25:29 +00:00
|
|
|
{ "createoatdir", 2, do_create_oat_dir },
|
2015-06-04 12:20:27 +00:00
|
|
|
{ "rmpackagedir", 1, do_rm_package_dir },
|
|
|
|
{ "linkfile", 3, do_link_file }
|
2012-10-24 17:45:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int readx(int s, void *_buf, int count)
|
|
|
|
{
|
2015-04-07 19:44:51 +00:00
|
|
|
char *buf = (char *) _buf;
|
2012-10-24 17:45:23 +00:00
|
|
|
int n = 0, r;
|
|
|
|
if (count < 0) return -1;
|
|
|
|
while (n < count) {
|
|
|
|
r = read(s, buf + n, count - n);
|
|
|
|
if (r < 0) {
|
|
|
|
if (errno == EINTR) continue;
|
|
|
|
ALOGE("read error: %s\n", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (r == 0) {
|
|
|
|
ALOGE("eof\n");
|
|
|
|
return -1; /* EOF */
|
|
|
|
}
|
|
|
|
n += r;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int writex(int s, const void *_buf, int count)
|
|
|
|
{
|
2015-04-07 19:44:51 +00:00
|
|
|
const char *buf = (const char *) _buf;
|
2012-10-24 17:45:23 +00:00
|
|
|
int n = 0, r;
|
|
|
|
if (count < 0) return -1;
|
|
|
|
while (n < count) {
|
|
|
|
r = write(s, buf + n, count - n);
|
|
|
|
if (r < 0) {
|
|
|
|
if (errno == EINTR) continue;
|
|
|
|
ALOGE("write error: %s\n", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
n += r;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Tokenize the command buffer, locate a matching command,
|
|
|
|
* ensure that the required number of arguments are provided,
|
|
|
|
* call the function(), return the result.
|
|
|
|
*/
|
|
|
|
static int execute(int s, char cmd[BUFFER_MAX])
|
|
|
|
{
|
|
|
|
char reply[REPLY_MAX];
|
|
|
|
char *arg[TOKEN_MAX+1];
|
|
|
|
unsigned i;
|
|
|
|
unsigned n = 0;
|
|
|
|
unsigned short count;
|
|
|
|
int ret = -1;
|
|
|
|
|
2013-03-22 01:20:22 +00:00
|
|
|
// ALOGI("execute('%s')\n", cmd);
|
2012-10-24 17:45:23 +00:00
|
|
|
|
|
|
|
/* default reply is "" */
|
|
|
|
reply[0] = 0;
|
|
|
|
|
|
|
|
/* n is number of args (not counting arg[0]) */
|
|
|
|
arg[0] = cmd;
|
|
|
|
while (*cmd) {
|
|
|
|
if (isspace(*cmd)) {
|
|
|
|
*cmd++ = 0;
|
|
|
|
n++;
|
|
|
|
arg[n] = cmd;
|
|
|
|
if (n == TOKEN_MAX) {
|
|
|
|
ALOGE("too many arguments\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2014-10-29 13:38:01 +00:00
|
|
|
if (*cmd) {
|
|
|
|
cmd++;
|
|
|
|
}
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(cmds) / sizeof(cmds[0]); i++) {
|
|
|
|
if (!strcmp(cmds[i].name,arg[0])) {
|
|
|
|
if (n != cmds[i].numargs) {
|
|
|
|
ALOGE("%s requires %d arguments (%d given)\n",
|
|
|
|
cmds[i].name, cmds[i].numargs, n);
|
|
|
|
} else {
|
|
|
|
ret = cmds[i].func(arg + 1, reply);
|
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ALOGE("unsupported command '%s'\n", arg[0]);
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (reply[0]) {
|
|
|
|
n = snprintf(cmd, BUFFER_MAX, "%d %s", ret, reply);
|
|
|
|
} else {
|
|
|
|
n = snprintf(cmd, BUFFER_MAX, "%d", ret);
|
|
|
|
}
|
|
|
|
if (n > BUFFER_MAX) n = BUFFER_MAX;
|
|
|
|
count = n;
|
|
|
|
|
2013-03-22 01:20:22 +00:00
|
|
|
// ALOGI("reply: '%s'\n", cmd);
|
2012-10-24 17:45:23 +00:00
|
|
|
if (writex(s, &count, sizeof(count))) return -1;
|
|
|
|
if (writex(s, cmd, count)) return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize all the global variables that are used elsewhere. Returns 0 upon
|
|
|
|
* success and -1 on error.
|
|
|
|
*/
|
|
|
|
void free_globals() {
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < android_system_dirs.count; i++) {
|
|
|
|
if (android_system_dirs.dirs[i].path != NULL) {
|
|
|
|
free(android_system_dirs.dirs[i].path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(android_system_dirs.dirs);
|
|
|
|
}
|
|
|
|
|
|
|
|
int initialize_globals() {
|
|
|
|
// Get the android data directory.
|
|
|
|
if (get_path_from_env(&android_data_dir, "ANDROID_DATA") < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the android app directory.
|
|
|
|
if (copy_and_append(&android_app_dir, &android_data_dir, APP_SUBDIR) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the android protected app directory.
|
|
|
|
if (copy_and_append(&android_app_private_dir, &android_data_dir, PRIVATE_APP_SUBDIR) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the android app native library directory.
|
|
|
|
if (copy_and_append(&android_app_lib_dir, &android_data_dir, APP_LIB_SUBDIR) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the sd-card ASEC mount point.
|
|
|
|
if (get_path_from_env(&android_asec_dir, "ASEC_MOUNTPOINT") < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the android media directory.
|
|
|
|
if (copy_and_append(&android_media_dir, &android_data_dir, MEDIA_SUBDIR) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-04-06 23:19:39 +00:00
|
|
|
// Get the android external app directory.
|
2015-04-07 19:44:51 +00:00
|
|
|
if (get_path_from_string(&android_mnt_expand_dir, "/mnt/expand/") < 0) {
|
2015-04-06 23:19:39 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
// Take note of the system and vendor directories.
|
2014-09-09 00:14:26 +00:00
|
|
|
android_system_dirs.count = 4;
|
2012-10-24 17:45:23 +00:00
|
|
|
|
2015-04-07 19:44:51 +00:00
|
|
|
android_system_dirs.dirs = (dir_rec_t*) calloc(android_system_dirs.count, sizeof(dir_rec_t));
|
2012-10-24 17:45:23 +00:00
|
|
|
if (android_system_dirs.dirs == NULL) {
|
|
|
|
ALOGE("Couldn't allocate array for dirs; aborting\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-09-09 00:14:26 +00:00
|
|
|
dir_rec_t android_root_dir;
|
|
|
|
if (get_path_from_env(&android_root_dir, "ANDROID_ROOT") < 0) {
|
|
|
|
ALOGE("Missing ANDROID_ROOT; aborting\n");
|
2012-10-24 17:45:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-09-09 00:14:26 +00:00
|
|
|
android_system_dirs.dirs[0].path = build_string2(android_root_dir.path, APP_SUBDIR);
|
|
|
|
android_system_dirs.dirs[0].len = strlen(android_system_dirs.dirs[0].path);
|
2012-10-24 17:45:23 +00:00
|
|
|
|
2014-09-09 00:14:26 +00:00
|
|
|
android_system_dirs.dirs[1].path = build_string2(android_root_dir.path, PRIV_APP_SUBDIR);
|
2012-10-24 17:45:23 +00:00
|
|
|
android_system_dirs.dirs[1].len = strlen(android_system_dirs.dirs[1].path);
|
|
|
|
|
2015-04-07 19:44:51 +00:00
|
|
|
android_system_dirs.dirs[2].path = strdup("/vendor/app/");
|
2014-09-09 00:14:26 +00:00
|
|
|
android_system_dirs.dirs[2].len = strlen(android_system_dirs.dirs[2].path);
|
|
|
|
|
2015-04-07 19:44:51 +00:00
|
|
|
android_system_dirs.dirs[3].path = strdup("/oem/app/");
|
2014-09-09 00:14:26 +00:00
|
|
|
android_system_dirs.dirs[3].len = strlen(android_system_dirs.dirs[3].path);
|
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int initialize_directories() {
|
|
|
|
int res = -1;
|
|
|
|
|
|
|
|
// Read current filesystem layout version to handle upgrade paths
|
|
|
|
char version_path[PATH_MAX];
|
|
|
|
snprintf(version_path, PATH_MAX, "%s.layout_version", android_data_dir.path);
|
|
|
|
|
|
|
|
int oldVersion;
|
|
|
|
if (fs_read_atomic_int(version_path, &oldVersion) == -1) {
|
|
|
|
oldVersion = 0;
|
|
|
|
}
|
|
|
|
int version = oldVersion;
|
|
|
|
|
|
|
|
// /data/user
|
|
|
|
char *user_data_dir = build_string2(android_data_dir.path, SECONDARY_USER_PREFIX);
|
|
|
|
// /data/data
|
|
|
|
char *legacy_data_dir = build_string2(android_data_dir.path, PRIMARY_USER_PREFIX);
|
|
|
|
// /data/user/0
|
|
|
|
char *primary_data_dir = build_string3(android_data_dir.path, SECONDARY_USER_PREFIX, "0");
|
|
|
|
if (!user_data_dir || !legacy_data_dir || !primary_data_dir) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make the /data/user directory if necessary
|
|
|
|
if (access(user_data_dir, R_OK) < 0) {
|
|
|
|
if (mkdir(user_data_dir, 0711) < 0) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (chown(user_data_dir, AID_SYSTEM, AID_SYSTEM) < 0) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (chmod(user_data_dir, 0711) < 0) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Make the /data/user/0 symlink to /data/data if necessary
|
|
|
|
if (access(primary_data_dir, R_OK) < 0) {
|
|
|
|
if (symlink(legacy_data_dir, primary_data_dir)) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (version == 0) {
|
|
|
|
// Introducing multi-user, so migrate /data/media contents into /data/media/0
|
|
|
|
ALOGD("Upgrading /data/media for multi-user");
|
|
|
|
|
|
|
|
// Ensure /data/media
|
|
|
|
if (fs_prepare_dir(android_media_dir.path, 0770, AID_MEDIA_RW, AID_MEDIA_RW) == -1) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
// /data/media.tmp
|
|
|
|
char media_tmp_dir[PATH_MAX];
|
|
|
|
snprintf(media_tmp_dir, PATH_MAX, "%smedia.tmp", android_data_dir.path);
|
|
|
|
|
|
|
|
// Only copy when upgrade not already in progress
|
|
|
|
if (access(media_tmp_dir, F_OK) == -1) {
|
|
|
|
if (rename(android_media_dir.path, media_tmp_dir) == -1) {
|
|
|
|
ALOGE("Failed to move legacy media path: %s", strerror(errno));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create /data/media again
|
|
|
|
if (fs_prepare_dir(android_media_dir.path, 0770, AID_MEDIA_RW, AID_MEDIA_RW) == -1) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2014-02-07 14:16:46 +00:00
|
|
|
if (selinux_android_restorecon(android_media_dir.path, 0)) {
|
2013-12-17 21:04:20 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
// /data/media/0
|
|
|
|
char owner_media_dir[PATH_MAX];
|
|
|
|
snprintf(owner_media_dir, PATH_MAX, "%s0", android_media_dir.path);
|
|
|
|
|
|
|
|
// Move any owner data into place
|
|
|
|
if (access(media_tmp_dir, F_OK) == 0) {
|
|
|
|
if (rename(media_tmp_dir, owner_media_dir) == -1) {
|
|
|
|
ALOGE("Failed to move owner media path: %s", strerror(errno));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure media directories for any existing users
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *dirent;
|
|
|
|
char user_media_dir[PATH_MAX];
|
|
|
|
|
|
|
|
dir = opendir(user_data_dir);
|
|
|
|
if (dir != NULL) {
|
|
|
|
while ((dirent = readdir(dir))) {
|
|
|
|
if (dirent->d_type == DT_DIR) {
|
|
|
|
const char *name = dirent->d_name;
|
|
|
|
|
|
|
|
// skip "." and ".."
|
|
|
|
if (name[0] == '.') {
|
|
|
|
if (name[1] == 0) continue;
|
|
|
|
if ((name[1] == '.') && (name[2] == 0)) continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// /data/media/<user_id>
|
|
|
|
snprintf(user_media_dir, PATH_MAX, "%s%s", android_media_dir.path, name);
|
|
|
|
if (fs_prepare_dir(user_media_dir, 0770, AID_MEDIA_RW, AID_MEDIA_RW) == -1) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
version = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// /data/media/obb
|
|
|
|
char media_obb_dir[PATH_MAX];
|
|
|
|
snprintf(media_obb_dir, PATH_MAX, "%sobb", android_media_dir.path);
|
|
|
|
|
|
|
|
if (version == 1) {
|
|
|
|
// Introducing /data/media/obb for sharing OBB across users; migrate
|
|
|
|
// any existing OBB files from owner.
|
|
|
|
ALOGD("Upgrading to shared /data/media/obb");
|
|
|
|
|
|
|
|
// /data/media/0/Android/obb
|
|
|
|
char owner_obb_path[PATH_MAX];
|
|
|
|
snprintf(owner_obb_path, PATH_MAX, "%s0/Android/obb", android_media_dir.path);
|
|
|
|
|
|
|
|
// Only move if target doesn't already exist
|
|
|
|
if (access(media_obb_dir, F_OK) != 0 && access(owner_obb_path, F_OK) == 0) {
|
|
|
|
if (rename(owner_obb_path, media_obb_dir) == -1) {
|
|
|
|
ALOGE("Failed to move OBB from owner: %s", strerror(errno));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
version = 2;
|
|
|
|
}
|
|
|
|
|
2015-04-09 18:34:03 +00:00
|
|
|
if (ensure_media_user_dirs(nullptr, 0) == -1) {
|
2012-10-24 17:45:23 +00:00
|
|
|
ALOGE("Failed to setup media for user 0");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (fs_prepare_dir(media_obb_dir, 0770, AID_MEDIA_RW, AID_MEDIA_RW) == -1) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2014-04-29 18:42:01 +00:00
|
|
|
if (ensure_config_user_dirs(0) == -1) {
|
|
|
|
ALOGE("Failed to setup misc for user 0");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2014-04-25 14:05:19 +00:00
|
|
|
if (version == 2) {
|
|
|
|
ALOGD("Upgrading to /data/misc/user directories");
|
|
|
|
|
2014-10-07 15:55:02 +00:00
|
|
|
char misc_dir[PATH_MAX];
|
|
|
|
snprintf(misc_dir, PATH_MAX, "%smisc", android_data_dir.path);
|
|
|
|
|
|
|
|
char keychain_added_dir[PATH_MAX];
|
|
|
|
snprintf(keychain_added_dir, PATH_MAX, "%s/keychain/cacerts-added", misc_dir);
|
|
|
|
|
|
|
|
char keychain_removed_dir[PATH_MAX];
|
|
|
|
snprintf(keychain_removed_dir, PATH_MAX, "%s/keychain/cacerts-removed", misc_dir);
|
|
|
|
|
2014-04-25 14:05:19 +00:00
|
|
|
DIR *dir;
|
|
|
|
struct dirent *dirent;
|
|
|
|
dir = opendir(user_data_dir);
|
|
|
|
if (dir != NULL) {
|
|
|
|
while ((dirent = readdir(dir))) {
|
2014-10-07 15:55:02 +00:00
|
|
|
const char *name = dirent->d_name;
|
2014-04-25 14:05:19 +00:00
|
|
|
|
2014-10-07 15:55:02 +00:00
|
|
|
// skip "." and ".."
|
|
|
|
if (name[0] == '.') {
|
|
|
|
if (name[1] == 0) continue;
|
|
|
|
if ((name[1] == '.') && (name[2] == 0)) continue;
|
|
|
|
}
|
2014-04-25 14:05:19 +00:00
|
|
|
|
2014-10-07 15:55:02 +00:00
|
|
|
uint32_t user_id = atoi(name);
|
|
|
|
|
|
|
|
// /data/misc/user/<user_id>
|
|
|
|
if (ensure_config_user_dirs(user_id) == -1) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
char misc_added_dir[PATH_MAX];
|
|
|
|
snprintf(misc_added_dir, PATH_MAX, "%s/user/%s/cacerts-added", misc_dir, name);
|
|
|
|
|
|
|
|
char misc_removed_dir[PATH_MAX];
|
|
|
|
snprintf(misc_removed_dir, PATH_MAX, "%s/user/%s/cacerts-removed", misc_dir, name);
|
|
|
|
|
|
|
|
uid_t uid = multiuser_get_uid(user_id, AID_SYSTEM);
|
|
|
|
gid_t gid = uid;
|
|
|
|
if (access(keychain_added_dir, F_OK) == 0) {
|
|
|
|
if (copy_dir_files(keychain_added_dir, misc_added_dir, uid, gid) != 0) {
|
|
|
|
ALOGE("Some files failed to copy");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (access(keychain_removed_dir, F_OK) == 0) {
|
|
|
|
if (copy_dir_files(keychain_removed_dir, misc_removed_dir, uid, gid) != 0) {
|
|
|
|
ALOGE("Some files failed to copy");
|
2014-04-25 14:05:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
2014-04-29 18:42:01 +00:00
|
|
|
|
2014-10-07 15:55:02 +00:00
|
|
|
if (access(keychain_added_dir, F_OK) == 0) {
|
|
|
|
delete_dir_contents(keychain_added_dir, 1, 0);
|
2014-04-29 18:42:01 +00:00
|
|
|
}
|
2014-10-07 15:55:02 +00:00
|
|
|
if (access(keychain_removed_dir, F_OK) == 0) {
|
|
|
|
delete_dir_contents(keychain_removed_dir, 1, 0);
|
2014-04-29 18:42:01 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-25 14:05:19 +00:00
|
|
|
|
2014-04-29 18:42:01 +00:00
|
|
|
version = 3;
|
2014-04-25 14:05:19 +00:00
|
|
|
}
|
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
// Persist layout version if changed
|
|
|
|
if (version != oldVersion) {
|
|
|
|
if (fs_write_atomic_int(version_path, version) == -1) {
|
|
|
|
ALOGE("Failed to save version to %s: %s", version_path, strerror(errno));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Success!
|
|
|
|
res = 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
free(user_data_dir);
|
|
|
|
free(legacy_data_dir);
|
|
|
|
free(primary_data_dir);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-03-26 13:30:37 +00:00
|
|
|
static int log_callback(int type, const char *fmt, ...) {
|
|
|
|
va_list ap;
|
|
|
|
int priority;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case SELINUX_WARNING:
|
|
|
|
priority = ANDROID_LOG_WARN;
|
|
|
|
break;
|
|
|
|
case SELINUX_INFO:
|
|
|
|
priority = ANDROID_LOG_INFO;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
priority = ANDROID_LOG_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
va_start(ap, fmt);
|
|
|
|
LOG_PRI_VA(priority, "SELinux", fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-09 03:56:42 +00:00
|
|
|
int main(const int argc __unused, char *argv[]) {
|
2012-10-24 17:45:23 +00:00
|
|
|
char buf[BUFFER_MAX];
|
|
|
|
struct sockaddr addr;
|
|
|
|
socklen_t alen;
|
2014-09-11 21:44:46 +00:00
|
|
|
int lsocket, s;
|
2013-04-16 16:16:50 +00:00
|
|
|
int selinux_enabled = (is_selinux_enabled() > 0);
|
2012-10-24 17:45:23 +00:00
|
|
|
|
2015-04-09 03:56:42 +00:00
|
|
|
setenv("ANDROID_LOG_TAGS", "*:v", 1);
|
|
|
|
android::base::InitLogging(argv);
|
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
ALOGI("installd firing up\n");
|
|
|
|
|
2014-03-26 13:30:37 +00:00
|
|
|
union selinux_callback cb;
|
|
|
|
cb.func_log = log_callback;
|
|
|
|
selinux_set_callback(SELINUX_CB_LOG, cb);
|
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
if (initialize_globals() < 0) {
|
|
|
|
ALOGE("Could not initialize globals; exiting.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initialize_directories() < 0) {
|
|
|
|
ALOGE("Could not create directories; exiting.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2013-04-16 16:16:50 +00:00
|
|
|
if (selinux_enabled && selinux_status_open(true) < 0) {
|
|
|
|
ALOGE("Could not open selinux status; exiting.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
lsocket = android_get_control_socket(SOCKET_PATH);
|
|
|
|
if (lsocket < 0) {
|
|
|
|
ALOGE("Failed to get socket from environment: %s\n", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (listen(lsocket, 5)) {
|
|
|
|
ALOGE("Listen on socket failed: %s\n", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fcntl(lsocket, F_SETFD, FD_CLOEXEC);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
alen = sizeof(addr);
|
|
|
|
s = accept(lsocket, &addr, &alen);
|
|
|
|
if (s < 0) {
|
|
|
|
ALOGE("Accept failed: %s\n", strerror(errno));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fcntl(s, F_SETFD, FD_CLOEXEC);
|
|
|
|
|
|
|
|
ALOGI("new connection\n");
|
|
|
|
for (;;) {
|
|
|
|
unsigned short count;
|
|
|
|
if (readx(s, &count, sizeof(count))) {
|
|
|
|
ALOGE("failed to read size\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((count < 1) || (count >= BUFFER_MAX)) {
|
|
|
|
ALOGE("invalid size %d\n", count);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (readx(s, buf, count)) {
|
|
|
|
ALOGE("failed to read command\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf[count] = 0;
|
2013-04-16 16:16:50 +00:00
|
|
|
if (selinux_enabled && selinux_status_updated() > 0) {
|
|
|
|
selinux_android_seapp_context_reload();
|
|
|
|
}
|
2012-10-24 17:45:23 +00:00
|
|
|
if (execute(s, buf)) break;
|
|
|
|
}
|
|
|
|
ALOGI("closing connection\n");
|
|
|
|
close(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|