Skip to content

Commit a361809

Browse files
krutonAndroid (Google) Code Review
authored andcommitted
Merge "Remove "unlinklib" command from installd" into jb-mr1-dev
2 parents 8015f03 + 9bbd70a commit a361809

File tree

5 files changed

+36
-139
lines changed

5 files changed

+36
-139
lines changed

cmds/installd/commands.c

Lines changed: 22 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ dir_rec_t android_data_dir;
2727
dir_rec_t android_asec_dir;
2828
dir_rec_t android_app_dir;
2929
dir_rec_t android_app_private_dir;
30+
dir_rec_t android_app_lib_dir;
3031
dir_rec_t android_media_dir;
3132
dir_rec_array_t android_system_dirs;
3233

3334
int install(const char *pkgname, uid_t uid, gid_t gid)
3435
{
3536
char pkgdir[PKG_PATH_MAX];
36-
char libdir[PKG_PATH_MAX];
37+
char libsymlink[PKG_PATH_MAX];
38+
char applibdir[PKG_PATH_MAX];
3739

3840
if ((uid < AID_SYSTEM) || (gid < AID_SYSTEM)) {
3941
ALOGE("invalid uid/gid: %d %d\n", uid, gid);
@@ -45,63 +47,48 @@ int install(const char *pkgname, uid_t uid, gid_t gid)
4547
return -1;
4648
}
4749

48-
if (create_pkg_path(libdir, pkgname, PKG_LIB_POSTFIX, 0)) {
49-
ALOGE("cannot create package lib path\n");
50+
if (create_pkg_path(libsymlink, pkgname, PKG_LIB_POSTFIX, 0)) {
51+
ALOGE("cannot create package lib symlink origin path\n");
52+
return -1;
53+
}
54+
55+
if (create_pkg_path_in_dir(applibdir, &android_app_lib_dir, pkgname, PKG_DIR_POSTFIX)) {
56+
ALOGE("cannot create package lib symlink dest path\n");
5057
return -1;
5158
}
5259

5360
if (mkdir(pkgdir, 0751) < 0) {
5461
ALOGE("cannot create dir '%s': %s\n", pkgdir, strerror(errno));
55-
return -errno;
62+
return -1;
5663
}
5764
if (chmod(pkgdir, 0751) < 0) {
5865
ALOGE("cannot chmod dir '%s': %s\n", pkgdir, strerror(errno));
5966
unlink(pkgdir);
60-
return -errno;
67+
return -1;
6168
}
6269

63-
if (mkdir(libdir, 0755) < 0) {
64-
ALOGE("cannot create dir '%s': %s\n", libdir, strerror(errno));
70+
if (symlink(applibdir, libsymlink) < 0) {
71+
ALOGE("couldn't symlink directory '%s' -> '%s': %s\n", libsymlink, applibdir,
72+
strerror(errno));
6573
unlink(pkgdir);
66-
return -errno;
67-
}
68-
if (chmod(libdir, 0755) < 0) {
69-
ALOGE("cannot chmod dir '%s': %s\n", libdir, strerror(errno));
70-
unlink(libdir);
71-
unlink(pkgdir);
72-
return -errno;
73-
}
74-
if (chown(libdir, AID_SYSTEM, AID_SYSTEM) < 0) {
75-
ALOGE("cannot chown dir '%s': %s\n", libdir, strerror(errno));
76-
unlink(libdir);
77-
unlink(pkgdir);
78-
return -errno;
74+
return -1;
7975
}
8076

8177
#ifdef HAVE_SELINUX
82-
if (selinux_android_setfilecon(libdir, pkgname, AID_SYSTEM) < 0) {
83-
ALOGE("cannot setfilecon dir '%s': %s\n", libdir, strerror(errno));
84-
unlink(libdir);
78+
if (selinux_android_setfilecon(pkgdir, pkgname, uid) < 0) {
79+
ALOGE("cannot setfilecon dir '%s': %s\n", pkgdir, strerror(errno));
80+
unlink(libsymlink);
8581
unlink(pkgdir);
86-
return -errno;
82+
return -1;
8783
}
8884
#endif
8985

9086
if (chown(pkgdir, uid, gid) < 0) {
9187
ALOGE("cannot chown dir '%s': %s\n", pkgdir, strerror(errno));
92-
unlink(libdir);
93-
unlink(pkgdir);
94-
return -errno;
95-
}
96-
97-
#ifdef HAVE_SELINUX
98-
if (selinux_android_setfilecon(pkgdir, pkgname, uid) < 0) {
99-
ALOGE("cannot setfilecon dir '%s': %s\n", pkgdir, strerror(errno));
100-
unlink(libdir);
88+
unlink(libsymlink);
10189
unlink(pkgdir);
102-
return -errno;
90+
return -1;
10391
}
104-
#endif
10592

10693
return 0;
10794
}
@@ -185,7 +172,6 @@ int delete_user_data(const char *pkgname, uid_t persona)
185172
int make_user_data(const char *pkgname, uid_t uid, uid_t persona)
186173
{
187174
char pkgdir[PKG_PATH_MAX];
188-
char real_libdir[PKG_PATH_MAX];
189175

190176
// Create the data dir for the package
191177
if (create_pkg_path(pkgdir, pkgname, PKG_DIR_POSTFIX, persona)) {
@@ -1038,85 +1024,3 @@ int linklib(const char* dataDir, const char* asecLibDir)
10381024

10391025
return rc;
10401026
}
1041-
1042-
int unlinklib(const char* dataDir)
1043-
{
1044-
char libdir[PKG_PATH_MAX];
1045-
struct stat s, libStat;
1046-
int rc = 0;
1047-
1048-
const size_t libdirLen = strlen(dataDir) + strlen(PKG_LIB_POSTFIX);
1049-
if (libdirLen >= PKG_PATH_MAX) {
1050-
return -1;
1051-
}
1052-
1053-
if (snprintf(libdir, sizeof(libdir), "%s%s", dataDir, PKG_LIB_POSTFIX) != (ssize_t)libdirLen) {
1054-
ALOGE("library dir not written successfully: %s\n", strerror(errno));
1055-
return -1;
1056-
}
1057-
1058-
if (stat(dataDir, &s) < 0) {
1059-
ALOGE("couldn't state data dir");
1060-
return -1;
1061-
}
1062-
1063-
if (chown(dataDir, AID_INSTALL, AID_INSTALL) < 0) {
1064-
ALOGE("failed to chown '%s': %s\n", dataDir, strerror(errno));
1065-
return -1;
1066-
}
1067-
1068-
if (chmod(dataDir, 0700) < 0) {
1069-
ALOGE("unlinklib() 1: failed to chmod '%s': %s\n", dataDir, strerror(errno));
1070-
rc = -1;
1071-
goto out;
1072-
}
1073-
1074-
if (lstat(libdir, &libStat) < 0) {
1075-
ALOGE("couldn't stat lib dir: %s\n", strerror(errno));
1076-
rc = -1;
1077-
goto out;
1078-
}
1079-
1080-
if (S_ISDIR(libStat.st_mode)) {
1081-
if (delete_dir_contents(libdir, 1, 0) < 0) {
1082-
rc = -1;
1083-
goto out;
1084-
}
1085-
} else if (S_ISLNK(libStat.st_mode)) {
1086-
if (unlink(libdir) < 0) {
1087-
rc = -1;
1088-
goto out;
1089-
}
1090-
}
1091-
1092-
if (mkdir(libdir, 0755) < 0) {
1093-
ALOGE("cannot create dir '%s': %s\n", libdir, strerror(errno));
1094-
rc = -errno;
1095-
goto out;
1096-
}
1097-
if (chmod(libdir, 0755) < 0) {
1098-
ALOGE("cannot chmod dir '%s': %s\n", libdir, strerror(errno));
1099-
unlink(libdir);
1100-
rc = -errno;
1101-
goto out;
1102-
}
1103-
if (chown(libdir, AID_SYSTEM, AID_SYSTEM) < 0) {
1104-
ALOGE("cannot chown dir '%s': %s\n", libdir, strerror(errno));
1105-
unlink(libdir);
1106-
rc = -errno;
1107-
goto out;
1108-
}
1109-
1110-
out:
1111-
if (chmod(dataDir, s.st_mode) < 0) {
1112-
ALOGE("unlinklib() 2: failed to chmod '%s': %s\n", dataDir, strerror(errno));
1113-
rc = -1;
1114-
}
1115-
1116-
if (chown(dataDir, s.st_uid, s.st_gid) < 0) {
1117-
ALOGE("failed to chown '%s' : %s\n", dataDir, strerror(errno));
1118-
return -1;
1119-
}
1120-
1121-
return rc;
1122-
}

cmds/installd/installd.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ static int do_linklib(char **arg, char reply[REPLY_MAX])
126126
return linklib(arg[0], arg[1]);
127127
}
128128

129-
static int do_unlinklib(char **arg, char reply[REPLY_MAX])
130-
{
131-
return unlinklib(arg[0]);
132-
}
133-
134129
struct cmdinfo {
135130
const char *name;
136131
unsigned numargs;
@@ -152,7 +147,6 @@ struct cmdinfo cmds[] = {
152147
{ "rmuserdata", 2, do_rm_user_data },
153148
{ "movefiles", 0, do_movefiles },
154149
{ "linklib", 2, do_linklib },
155-
{ "unlinklib", 1, do_unlinklib },
156150
{ "mkuserdata", 3, do_mk_user_data },
157151
{ "rmuser", 1, do_rm_user },
158152
{ "cloneuserdata", 3, do_clone_user_data },
@@ -290,6 +284,11 @@ int initialize_globals() {
290284
return -1;
291285
}
292286

287+
// Get the android app native library directory.
288+
if (copy_and_append(&android_app_lib_dir, &android_data_dir, APP_LIB_SUBDIR) < 0) {
289+
return -1;
290+
}
291+
293292
// Get the sd-card ASEC mount point.
294293
if (get_path_from_env(&android_asec_dir, "ASEC_MOUNTPOINT") < 0) {
295294
return -1;

cmds/installd/installd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262

6363
#define APP_SUBDIR "app/" // sub-directory under ANDROID_DATA
6464

65+
#define APP_LIB_SUBDIR "app-lib/" // sub-directory under ANDROID_DATA
66+
6567
#define MEDIA_SUBDIR "media/" // sub-directory under ANDROID_DATA
6668

6769
/* other handy constants */
@@ -93,6 +95,7 @@ typedef struct {
9395

9496
extern dir_rec_t android_app_dir;
9597
extern dir_rec_t android_app_private_dir;
98+
extern dir_rec_t android_app_lib_dir;
9699
extern dir_rec_t android_data_dir;
97100
extern dir_rec_t android_asec_dir;
98101
extern dir_rec_t android_media_dir;
@@ -207,4 +210,3 @@ int free_cache(int64_t free_size);
207210
int dexopt(const char *apk_path, uid_t uid, int is_public);
208211
int movefiles();
209212
int linklib(const char* target, const char* source);
210-
int unlinklib(const char* libPath);

services/java/com/android/server/pm/Installer.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,10 @@ public int moveFiles() {
369369
*/
370370
public int linkNativeLibraryDirectory(String dataPath, String nativeLibPath) {
371371
if (dataPath == null) {
372-
Slog.e(TAG, "unlinkNativeLibraryDirectory dataPath is null");
372+
Slog.e(TAG, "linkNativeLibraryDirectory dataPath is null");
373373
return -1;
374374
} else if (nativeLibPath == null) {
375-
Slog.e(TAG, "unlinkNativeLibraryDirectory nativeLibPath is null");
375+
Slog.e(TAG, "linkNativeLibraryDirectory nativeLibPath is null");
376376
return -1;
377377
}
378378

@@ -383,16 +383,4 @@ public int linkNativeLibraryDirectory(String dataPath, String nativeLibPath) {
383383

384384
return execute(builder.toString());
385385
}
386-
387-
public int unlinkNativeLibraryDirectory(String dataPath) {
388-
if (dataPath == null) {
389-
Slog.e(TAG, "unlinkNativeLibraryDirectory dataPath is null");
390-
return -1;
391-
}
392-
393-
StringBuilder builder = new StringBuilder("unlinklib ");
394-
builder.append(dataPath);
395-
396-
return execute(builder.toString());
397-
}
398386
}

services/java/com/android/server/pm/PackageManagerService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4468,16 +4468,20 @@ private static int copyNativeLibrariesForInternalApp(File scanFile, final File n
44684468
throws IOException {
44694469
if (!nativeLibraryDir.isDirectory()) {
44704470
nativeLibraryDir.delete();
4471+
44714472
if (!nativeLibraryDir.mkdir()) {
44724473
throw new IOException("Cannot create " + nativeLibraryDir.getPath());
44734474
}
4475+
44744476
try {
44754477
Libcore.os.chmod(nativeLibraryDir.getPath(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH
44764478
| S_IXOTH);
44774479
} catch (ErrnoException e) {
44784480
throw new IOException("Cannot chmod native library directory "
44794481
+ nativeLibraryDir.getPath(), e);
44804482
}
4483+
} else if (!SELinux.restorecon(nativeLibraryDir)) {
4484+
throw new IOException("Cannot set SELinux context for " + nativeLibraryDir.getPath());
44814485
}
44824486

44834487
/*

0 commit comments

Comments
 (0)