From 2773479202890fe53a9be956fcc12930d193e792 Mon Sep 17 00:00:00 2001 From: Sooyoung Ha Date: Thu, 7 Dec 2017 01:22:36 +0900 Subject: [PATCH] install: apply install -g option Change-Id: Ib84bb299caa8c43aa5e49116b31db5b76fb9f4d6 Signed-off-by: Sooyoung Ha --- src/services.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/services.c b/src/services.c index 180ce77..20a1d57 100644 --- a/src/services.c +++ b/src/services.c @@ -1152,6 +1152,63 @@ void get_boot(int fd, void *cookie) { sdb_close(fd); } +#define GRANT_FILE "/opt/share/askuser_disable" +int grantfile_exist = 0; +// TODO remove debug codes (snprintf buf) +void handle_grantfile(int fd, void *cookie) { + char buf[2] = { 0, }; + int opcode = atoi((char*)cookie); + char* tmppath = NULL; + + if (opcode == 1) { // create + tmppath = realpath(GRANT_FILE, NULL); + if (tmppath == NULL && errno == ENOENT) { + grantfile_exist = 0; + FILE *f = fopen(GRANT_FILE, "w"); + + if (f != NULL) { + fclose(f); + snprintf(buf, sizeof(buf), "%s", " "); + } else { + D("sdbd: cannot create %s file, errno %d.\n", GRANT_FILE, errno); + snprintf(buf, sizeof(buf), "%s", "5"); + } + } else { + grantfile_exist = 1; + D("sdbd: %s file is already existed.\n", GRANT_FILE); + snprintf(buf, sizeof(buf), "%s", "3"); + free(tmppath); + } + } else if (opcode == 2) { // remove + if (grantfile_exist != 0) { + D("sdbd: %s file is already existed.\n", GRANT_FILE); + snprintf(buf, sizeof(buf), "%s", "4"); + } else { + tmppath = realpath(GRANT_FILE, NULL); + if (tmppath == NULL && errno == ENOENT) { + D("sdbd: cannot find %s file.\n", GRANT_FILE); + snprintf(buf, sizeof(buf), "%s", "6"); + } else if (tmppath != NULL && !strncmp(GRANT_FILE, tmppath, strlen(GRANT_FILE)+1)) { + sdb_unlink(GRANT_FILE); + snprintf(buf, sizeof(buf), "%s", " "); + free(tmppath); + } else { + D("sdbd: unknown error has occured.\n"); + snprintf(buf, sizeof(buf), "%s", "8"); + if (tmppath != NULL) { + free(tmppath); + } + } + } + } else { + // abnormal operation + D("sdbd: abnormal operation.\n"); + snprintf(buf, sizeof(buf), "%s", "9"); + } + writex(fd, buf, strlen(buf)); + sdb_close(fd); +} + int service_to_fd(const char *name) { int ret = -1; @@ -1254,6 +1311,8 @@ int service_to_fd(const char *name) char* env_variable = NULL; env_variable = strdup(name+14); ret = create_service_thread(get_tzplatform_env, (void *)(env_variable)); + } else if(!strncmp(name, "grantfile:", 10)){ + ret = create_service_thread(handle_grantfile, (void*)name+10); } else if(!strncmp(name, "appcmd:", 7)){ ret = request_appcmd_to_plugin(name+7); } -- 2.7.4