summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2015-01-26 23:19:03 +0100
committerAndreas Schneider <asn@cryptomilk.org>2015-01-27 09:01:47 +0100
commit2dccb183e7309e2b64b7b615bfd6629b32120626 (patch)
treeda69db77322226a4d0663e5a489763be7e700e87
parent0be084139d4000537bfeace6de3ae371812d3117 (diff)
downloadandroid_hardware_samsung-2dccb183e7309e2b64b7b615bfd6629b32120626.tar.gz
android_hardware_samsung-2dccb183e7309e2b64b7b615bfd6629b32120626.tar.bz2
android_hardware_samsung-2dccb183e7309e2b64b7b615bfd6629b32120626.zip
macloader: Use fchmod() to change permissions.
Change-Id: I18bca9b022dba24403867b022af9d858aad72bc4 Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--macloader/macloader.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/macloader/macloader.c b/macloader/macloader.c
index e182588..03ecc3d 100644
--- a/macloader/macloader.c
+++ b/macloader/macloader.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <unistd.h>
#include <cutils/log.h>
@@ -147,12 +148,19 @@ int main() {
ALOGE("Can't write to %s\n", CID_PATH);
return -1;
}
- fclose(cidfile);
- /* set permissions on cid file */
- ALOGD("Setting permissions on %s\n", CID_PATH);
+ /* Change permissions of cid file */
+ ALOGD("Change permissions of %s\n", CID_PATH);
+
+ fd = fileno(cidfile);
amode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
- ret = chmod(CID_PATH, amode);
+ ret = fchmod(fd, amode);
+ fclose(cidfile);
+ if (ret != 0) {
+ ALOGE("Can't set permissions on %s - %s\n",
+ CID_PATH, strerror(errno));
+ return 1;
+ }
char* chown_cmd = (char*) malloc(strlen("chown system ") + strlen(CID_PATH) + 1);
char* chgrp_cmd = (char*) malloc(strlen("chgrp system ") + strlen(CID_PATH) + 1);
@@ -161,12 +169,6 @@ int main() {
system(chown_cmd);
system(chgrp_cmd);
- if (ret != 0) {
- fprintf(stderr, "chmod() on file %s failed\n", CID_PATH);
- ALOGE("Can't set permissions on %s\n", CID_PATH);
- return ret;
- }
-
} else {
/* delete cid file if no specific type */
ALOGD("Deleting file %s\n", CID_PATH);