Revert "Revert "Add the appcmd protocol for product extended routine.""
[sdk/target/sdbd.git] / src / services.c
index 22b9dda..5d40ce9 100644 (file)
@@ -310,6 +310,7 @@ void inoti_service(int fd, void *arg)
 
     if ( ifd < 0 ) {
         D( "inotify_init failed\n");
+        sdb_close(fd);
         return;
     }
 
@@ -437,7 +438,7 @@ static void redirect_and_exec(int pts, const char *cmd, char * const argv[], cha
     execve(cmd, argv, envp);
 }
 
-static int create_subprocess(const char *cmd, pid_t *pid, char * const argv[], char * const envp[])
+int create_subprocess(const char *cmd, pid_t *pid, char * const argv[], char * const envp[])
 {
     char devname[64];
     int ptm;
@@ -518,7 +519,6 @@ static int create_subprocess(const char *cmd, pid_t *pid, char * const argv[], c
 }
 #endif  /* !SDB_HOST */
 
-#define SHELL_COMMAND "/bin/sh"
 #define LOGIN_COMMAND "/bin/login"
 #define SUPER_USER    "root"
 #define LOGIN_CONFIG  "/etc/login.defs"
@@ -555,7 +555,7 @@ static void subproc_waiter_service(int fd, void *cookie)
     }
 }
 
-static void get_env(char *key, char **env)
+void get_env(char *key, char **env)
 {
     FILE *fp;
     char buf[1024];
@@ -842,7 +842,6 @@ static int create_syncproc_thread()
 
     return ret_fd;
 }
-
 #endif
 
 static void get_platforminfo(int fd, void *cookie) {
@@ -995,12 +994,16 @@ static void get_capability(int fd, void *cookie) {
                                 "sdbd_cap_version", g_capabilities.sdbd_cap_version);
 
     // Sdbd log enable
-   offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
-                               "log_enable", g_capabilities.log_enable);
+    offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
+            "log_enable", g_capabilities.log_enable);
 
     // Sdbd log path
-   offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
-                               "log_path", g_capabilities.log_path);
+    offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
+            "log_path", g_capabilities.log_path);
+
+    // Application command support
+    offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
+            "appcmd_support", g_capabilities.appcmd_support);
 
     offset++; // for '\0' character
 
@@ -1165,6 +1168,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, "appcmd:", 7)){
+        ret = request_appcmd_to_plugin(name+7);
     }
 
     if (ret >= 0) {