install: apply install -g option 85/162985/2
authorSooyoung Ha <yoosah.ha@samsung.com>
Wed, 6 Dec 2017 16:22:36 +0000 (01:22 +0900)
committerSooyoung Ha <yoosah.ha@samsung.com>
Wed, 6 Dec 2017 16:36:25 +0000 (01:36 +0900)
Change-Id: Ib84bb299caa8c43aa5e49116b31db5b76fb9f4d6
Signed-off-by: Sooyoung Ha <yoosah.ha@samsung.com>
src/services.c

index 180ce77..20a1d57 100644 (file)
@@ -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);
     }