4bc158ebf24d3dd506547d04eb241be64f13bf9f
[sdk/target/sdbd.git] / src / default_plugin_appcmd.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdlib.h>
18 #include <stdio.h>
19 #include <unistd.h>
20 #include <string.h>
21 #include <errno.h>
22
23 #define TRACE_TAG  TRACE_APPCMD
24
25 #include "sysdeps.h"
26 #include "sdb.h"
27 #include "strutils.h"
28 #include "utils.h"
29 #include "log.h"
30
31 #include "parameter.h"
32 #include "sdbd_plugin.h"
33
34 #if APPCMD_USING_PKGMGR
35 #include <pkgmgr-info.h>
36 #include <package-manager.h>
37 #endif
38
39 #include <tzplatform_config.h>
40
41 #define APPCMD_RESULT_BUFSIZE   (4096)
42
43 typedef struct appcmd_info appcmd_info;
44 typedef int (*appcmd_gen_shellcmd)(appcmd_info*);
45 typedef void (*appcmd_receiver)(int, int);
46 struct appcmd_info {
47     int fd;
48
49     char* args[MAX_TOKENS];
50     size_t args_cnt;
51     char* raw_command;
52
53     appcmd_gen_shellcmd gen_cmd_func;
54     appcmd_receiver receiver_func;
55
56     char shell_cmd[SDBD_SHELL_CMD_MAX];
57
58     int exitcode;
59 };
60
61 static int appcmd_install_gen_shellcmd(appcmd_info* p_info) {
62     char *type = NULL;
63     char *pkgpath = NULL;
64     char *pkgid = NULL;
65     char *teppath = NULL;
66     char *buf = p_info->shell_cmd;
67     int len = sizeof(p_info->shell_cmd);
68
69     if (p_info->args_cnt != 5) {
70         D("failed to parse appcmd.(cnt=%d)\n", p_info->args_cnt);
71         return -1;
72     }
73
74     type = p_info->args[1];
75     pkgpath = p_info->args[2];
76     pkgid = p_info->args[3];
77     teppath = p_info->args[4];
78
79     D("args: type=%s, pkgpath=%s, pkgid=%s, teppath=%s\n", type, pkgpath, pkgid, teppath);
80
81     if (strncmp(pkgid, "null", 4) == 0) {
82         if (strncmp(teppath, "null", 4) == 0) {
83             /* Normal install case */
84             snprintf(buf, len, "pkgcmd -i -q -t %s -p %s -G", type, pkgpath);
85         } else {
86             /* TEP install case */
87             snprintf(buf, len, "pkgcmd -i -q -p %s -e %s -G", pkgpath, teppath);
88         }
89     } else {
90         /* Re-install case */
91         snprintf(buf, len, "pkgcmd -r -q -t %s -n %s", type, pkgid);
92     }
93
94     return 0;
95 }
96
97 static int appcmd_uninstall_gen_shellcmd(appcmd_info* p_info) {
98     char *pkgid = NULL;
99     char *buf = p_info->shell_cmd;
100     int len = sizeof(p_info->shell_cmd);
101
102     if (p_info->args_cnt != 2) {
103         D("failed to parse appcmd.(cnt=%d)\n", p_info->args_cnt);
104         return -1;
105     }
106
107     pkgid = p_info->args[1];
108
109     D("args: pkgid=%s\n", pkgid);
110
111     snprintf(buf, len, "pkgcmd -u -q -n %s", pkgid);
112
113     return 0;
114 }
115
116 static int appcmd_runapp_gen_shellcmd(appcmd_info* p_info) {
117     char *appid = NULL;
118     char *buf = p_info->shell_cmd;
119     int len = sizeof(p_info->shell_cmd);
120
121     if (p_info->args_cnt != 2) {
122         D("failed to parse appcmd.(cnt=%d)\n", p_info->args_cnt);
123         return -1;
124     }
125
126     appid = p_info->args[1];
127
128     D("args: appid=%s\n", appid);
129
130     snprintf(buf, len, "/usr/bin/app_launcher --start %s", appid);
131
132     return 0;
133 }
134
135 static int appcmd_rununittestapp_gen_shellcmd(appcmd_info* p_info) {
136     char *appid = NULL;
137     char *usr_args = NULL;
138     char *buf = p_info->shell_cmd;
139     int len = sizeof(p_info->shell_cmd);
140     char *ptr = NULL;
141     char *p_service = NULL;
142     char *p_appid = NULL;
143
144     free_strings(p_info->args, p_info->args_cnt);
145
146     p_service = strtok_r(p_info->raw_command, ":", &ptr);
147     p_appid = strtok_r(NULL, ":", &ptr);
148     if (p_service == NULL || p_appid == NULL) {
149         D("failed to parse appcmd.(cnt=%d)\n", p_info->args_cnt);
150         return -1;
151     }
152
153     p_info->args_cnt = 3;
154     p_info->args[0] = strdup(p_service);
155     p_info->args[1] = strdup(p_appid);
156     p_info->args[2] = strdup(ptr);
157
158     appid = p_info->args[1];
159     usr_args = p_info->args[2];
160
161     D("args: appid=%s, usr_args=%s\n", appid, usr_args);
162
163     snprintf(buf, len, "/usr/bin/app_launcher -s %s __AUL_SDK__ UNIT_TEST __LAUNCH_APP_MODE__ SYNC __DLP_UNIT_TEST_ARG__ \'%s\'", appid, usr_args);
164
165     return 0;
166 }
167
168 static int appcmd_killapp_gen_shellcmd(appcmd_info* p_info) {
169     char *appid = NULL;
170     char *buf = p_info->shell_cmd;
171     int len = sizeof(p_info->shell_cmd);
172
173     if (p_info->args_cnt != 2) {
174         D("failed to parse appcmd.(cnt=%d)\n", p_info->args_cnt);
175         return -1;
176     }
177
178     appid = p_info->args[1];
179
180     D("args: appid=%s\n", appid);
181
182     snprintf(buf, len, "/usr/bin/app_launcher --kill %s", appid);
183
184     return 0;
185 }
186
187 static int appcmd_packagelist_gen_shellcmd(appcmd_info* p_info) {
188     char *type = NULL;
189     char *buf = p_info->shell_cmd;
190     int len = sizeof(p_info->shell_cmd);
191
192     if (p_info->args_cnt != 2) {
193         D("failed to parse appcmd.(cnt=%d)\n", p_info->args_cnt);
194         return -1;
195     }
196
197     type = p_info->args[1];
198
199     D("args: type=%s\n", type);
200
201     snprintf(buf, len, "/usr/bin/pkgcmd -l -t %s", type);
202
203     return 0;
204 }
205
206 static int appcmd_debugwebapp_gen_shellcmd(appcmd_info* p_info) {
207     char *appid = NULL;
208     char *buf = p_info->shell_cmd;
209     int len = sizeof(p_info->shell_cmd);
210
211     if (p_info->args_cnt != 2) {
212         D("failed to parse appcmd.(cnt=%d)\n", p_info->args_cnt);
213         return -1;
214     }
215
216     appid = p_info->args[1];
217
218     D("args: appid=%s\n", appid);
219
220     snprintf(buf, len, "/usr/bin/app_launcher --start %s -w", appid);
221
222     return 0;
223 }
224
225 static int appcmd_debugnativeapp_gen_shellcmd(appcmd_info* p_info) {
226     char *debug_port = NULL;
227     char *appid= NULL;
228     char *pid_str = NULL;
229     char *gdbserver_path = NULL;
230     char *buf = p_info->shell_cmd;
231     int pid = -1;
232     int len = sizeof(p_info->shell_cmd);
233
234     if (p_info->args_cnt != 5) {
235         D("failed to parse appcmd.(cnt=%d)\n", p_info->args_cnt);
236         return -1;
237     }
238
239     debug_port = p_info->args[1];
240     appid= p_info->args[2];
241     pid_str = p_info->args[3];
242     gdbserver_path = p_info->args[4]; // not used. for 3.0 platform.
243
244     pid = atoi(pid_str);
245     D("args: debug_port=%s, appid=%s, pid=%d, gdbserver_path=%s\n", debug_port, appid, pid, gdbserver_path);
246
247     if (pid == -1) {
248         snprintf(buf, len, "/usr/bin/app_launcher --start %s __AUL_SDK__ DEBUG __DLP_DEBUG_ARG__ :%s __DLP_GDBSERVER_PATH__ %s", appid, debug_port, gdbserver_path);
249     } else {
250         /* attach mode */
251         snprintf(buf, len, "/usr/bin/launch_debug %s __AUL_SDK__ ATTACH __DLP_GDBSERVER_PATH__ %s __DLP_ATTACH_ARG__ --attach,:%s,%d", appid, gdbserver_path, debug_port, pid);
252     }
253
254     return 0;
255 }
256
257 static int appcmd_appinfo_gen_shellcmd(appcmd_info* p_info) {
258     char *pkgid = NULL;
259     char *buf = p_info->shell_cmd;
260     int len = sizeof(p_info->shell_cmd);
261
262     if (p_info->args_cnt != 2) {
263         D("failed to parse appcmd.(cnt=%d)\n", p_info->args_cnt);
264         return -1;
265     }
266
267     pkgid = p_info->args[1];
268
269     D("args: pkgid=%s\n", pkgid);
270
271     snprintf(buf, len, "/usr/bin/pkginfo --list %s", pkgid);
272
273     return 0;
274 }
275
276 static void appcmd_receiver_debugwebapp(int fd_in, int fd_out)
277 {
278     char buf[4096] = {0,};
279     char port_str[32] = {0,};
280     char out_buf[128] = {0,};
281     char* sub_str = NULL;
282     int r;
283
284     for(;;) {
285         memset(buf, 0, sizeof(buf));
286         r = read_line(fd_in, buf, sizeof(buf));
287         if (r == 0) {
288             break;
289         } else if(r < 0) {
290             if (errno == EINTR) {
291                 continue;
292             } else {
293                 break;
294             }
295         }
296
297         D("debug webapp output : %s\n", buf);
298         sub_str = strstr(buf, "port: ");
299         if (sub_str != NULL && sscanf(sub_str, "port: %s", port_str) == 1) {
300             snprintf(out_buf, sizeof(out_buf), "\n%s:%s\n", MESSAGE_PREFIX_APPCMD_RETURN, port_str);
301             writex(fd_out, out_buf, strlen(out_buf)+1);
302             break;
303         }
304     }
305 }
306
307 static void appcmd_receiver_default(int fd_in, int fd_out)
308 {
309     char buf[4096] = {0,};
310     int r;
311
312     for(;;) {
313         memset(buf, 0, sizeof(buf));
314         r = sdb_read(fd_in, buf, sizeof(buf));
315         if (r == 0) {
316             break;
317         } else if(r < 0) {
318             if (errno == EINTR) {
319                 continue;
320             } else {
321                 break;
322             }
323         }
324
325         writex(fd_out, buf, strlen(buf)+1);
326     }
327 }
328
329 static void appcmd_receiver_packagelist(int fd_in, int fd_out)
330 {
331     char buf[4096] = {0,};
332     char out_buf[4096] = {0,};
333     int out_ptr = 0;
334     int r;
335
336     snprintf(out_buf, sizeof(out_buf), "\n%s", MESSAGE_PREFIX_APPCMD_RETURN);
337     out_ptr = strlen(out_buf);
338
339     for(;;) {
340         memset(buf, 0, sizeof(buf));
341         r = read_line(fd_in, buf, sizeof(buf));
342         if (r == 0) {
343             break;
344         } else if(r < 0) {
345             if (errno == EINTR) {
346                 continue;
347             } else {
348                 break;
349             }
350         }
351
352         D("pkgcmd output : %s\n", buf);
353         char* sub1 = NULL;
354         char* sub2 = NULL;
355         sub1 = strstr(buf, "pkgid [");
356         if (sub1 != NULL) {
357             sub1 = strstr(sub1, "[")+1;
358             sub2 = strstr(sub1, "]");
359             sub2[0] = '\0';
360
361             snprintf(out_buf+out_ptr, sizeof(out_buf)-out_ptr, ":%s", sub1);
362             out_ptr += strlen(sub1)+1;
363         }
364     }
365
366     snprintf(out_buf+out_ptr, sizeof(out_buf)-out_ptr, "\n");
367
368     D("package list: %s\n", out_buf);
369     writex(fd_out, out_buf, strlen(out_buf)+1);
370 }
371
372 static void appcmd_receiver_appinfo(int fd_in, int fd_out)
373 {
374     char buf[4096] = {0,};
375     char out_buf[4096] = {0,};
376     char appid[128] = {0,};
377     char apptype[128] = {0,};
378     int out_ptr = 0;
379     int r;
380
381     snprintf(out_buf, sizeof(out_buf), "\n%s", MESSAGE_PREFIX_APPCMD_RETURN);
382     out_ptr = strlen(out_buf);
383
384     for(;;) {
385         memset(buf, 0, sizeof(buf));
386         r = read_line(fd_in, buf, sizeof(buf));
387         if (r == 0) {
388             break;
389         } else if(r < 0) {
390             if (errno == EINTR) {
391                 continue;
392             } else {
393                 break;
394             }
395         }
396
397         D("pkginfo output : %s\n", buf);
398
399         if (!strncmp(buf, "Appid: ", 7)) {
400             memset(appid, 0, sizeof(appid));
401             sscanf(buf, "Appid: %s", appid);
402
403             snprintf(out_buf+out_ptr, sizeof(out_buf)-out_ptr, ":%s", appid);
404             out_ptr += strlen(appid)+1;
405         } else if (!strncmp(buf, "Apptype: ", 9)) {
406             memset(apptype, 0, sizeof(apptype));
407             sscanf(buf, "Apptype: %s", apptype);
408
409             snprintf(out_buf+out_ptr, sizeof(out_buf)-out_ptr, ":%s", apptype);
410             out_ptr += strlen(apptype)+1;
411         }
412     }
413
414     snprintf(out_buf+out_ptr, sizeof(out_buf)-out_ptr, "\n");
415
416     D("app info: %s\n", out_buf);
417     writex(fd_out, out_buf, strlen(out_buf)+1);
418 }
419
420 static int exec_appcmd_shell_process(appcmd_info* p_info) {
421     int ptm_fd = -1;
422     pid_t pid;
423     char *value = NULL;
424     char *trim_value = NULL;
425     char path[PATH_MAX];
426     memset(path, 0, sizeof(path));
427
428     char *envp[] = {
429         "TERM=linux", /* without this, some programs based on screen can't work, e.g. top */
430         "DISPLAY=:0", /* without this, some programs based on without launchpad can't work */
431         NULL,
432         NULL,
433         NULL,
434         NULL,
435         NULL
436     };
437
438     // For the SDK user privilege.
439     envp[2] = "HOME=/home/developer";
440     get_env("ENV_PATH", &value);
441     if (value != NULL) {
442         trim_value = str_trim(value);
443         if (trim_value != NULL) {
444             // if string is not including 'PATH=', append it.
445             if (strncmp(trim_value, "PATH", 4)) {
446                 snprintf(path, sizeof(path), "PATH=%s", trim_value);
447             } else {
448                 snprintf(path, sizeof(path), "%s", trim_value);
449             }
450             envp[3] = path;
451             free(trim_value);
452         } else {
453             envp[3] = value;
454         }
455     }
456
457     D("path env:%s,%s,%s,%s\n", envp[0], envp[1], envp[2], envp[3]);
458
459     char *args[] = {
460         SHELL_COMMAND,
461         "-c",
462         NULL,
463         NULL,
464     };
465     args[2] = p_info->shell_cmd;
466
467     ptm_fd = create_subprocess(SHELL_COMMAND, &pid, (char * const*)args, (char * const*)envp);
468     D("create_subprocess() ptm_fd=%d pid=%d\n", ptm_fd, pid);
469     if (ptm_fd < 0) {
470         D("cannot create service thread\n");
471         return -1;
472     }
473
474     if (p_info->receiver_func != NULL) {
475         p_info->receiver_func(ptm_fd, p_info->fd);
476     }
477
478     // wait for shell process
479     for (;;) {
480         int status;
481         pid_t p = waitpid(pid, &status, 0);
482         if (p == pid) {
483             D("fd=%d, post waitpid(pid=%d) status=%04x\n", p_info->fd, p, status);
484
485             if (WIFEXITED(status)) {
486                 p_info->exitcode = WEXITSTATUS(status);
487                 D("*** Exit code %d\n", p_info->exitcode);
488                 break;
489             }
490         }
491     }
492     D("shell exited fd=%d of pid=%d err=%d\n", p_info->fd, pid, errno);
493
494     return 0;
495 }
496
497 #if APPCMD_USING_PKGMGR
498 static int get_pkg_info(char* pkgid, char* pkginfo_buf, int buf_size) {
499     pkgmgrinfo_pkginfo_h handle;
500     pkgmgr_client* pc = NULL;
501     char* pkgname = NULL;
502     char* type = NULL;
503     bool is_removable = 0;
504     int is_running = 0;
505     int ret = -1;
506     int pid = -1;
507
508     ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
509     if (ret < 0) {
510         D("failed to get pkginfo handle.\n");
511         return -1;
512     }
513
514     ret = pkgmgrinfo_pkginfo_get_mainappid(handle, &pkgname);
515     if (ret < 0) {
516         D("failed to get pkg name\n");
517         return -1;
518     }
519
520     ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
521     if (ret < 0) {
522         D("failed to get pkg type.\n");
523         return -1;
524     }
525
526     ret = pkgmgrinfo_pkginfo_is_removable(handle, &is_removable);
527     if (ret < 0) {
528         D("failed to get removable info.\n");
529         return -1;
530     }
531
532     pc = pkgmgr_client_new(PC_REQUEST);
533     if (pc == NULL) {
534         D("failed to create pkgmgr client.\n");
535         return -1;
536     }
537
538     ret = pkgmgr_client_request_service(PM_REQUEST_CHECK_APP, 0, pc, NULL, pkgid, NULL, NULL, &pid);
539     if (ret < 0) {
540         D("failed to get running state.\n");
541         return -1;
542     }
543     is_running = ((pid > 0) ? 1:0);
544
545     D("pkginfo: pkgname=%s, type=%s, is_removagle=%d, is_running=%d, pid=%d\n", pkgname, type, is_removable, is_running, pid);
546     snprintf(pkginfo_buf, buf_size, "%s:%s:%d:%d", pkgname, type, is_removable, is_running);
547     return 0;
548 }
549
550 static void run_appcmd_packageinfo(appcmd_info* p_info) {
551     char result_buf[APPCMD_RESULT_BUFSIZE] = {0,};
552     char pkginfo_buf[256] = {0,};
553     char *type = NULL;
554     char *pkgid = NULL;
555
556     p_info->exitcode = -1;
557
558     if (p_info->args_cnt != 3) {
559         D("failed to parse appcmd.(cnt=%d)\n", p_info->args_cnt);
560         return;
561     }
562
563     type = p_info->args[1];
564     pkgid= p_info->args[2];
565
566     D("args: type=%s, pkgid=%s\n", type, pkgid);
567
568     if (get_pkg_info(pkgid, pkginfo_buf, sizeof(pkginfo_buf)) == 0) {
569         D("success to get pkginfo. (%s)\n", pkginfo_buf);
570         p_info->exitcode = 0;
571         snprintf(result_buf, sizeof(result_buf), "\n%s:%s\n", MESSAGE_PREFIX_APPCMD_RETURN, pkginfo_buf);
572         writex(p_info->fd, result_buf, strlen(result_buf));
573     } else {
574         D("failed to get pkginfo.\n");
575     }
576 }
577 #else
578 static int appcmd_packageinfo_gen_shellcmd(appcmd_info* p_info) {
579     char *pkgid = NULL;
580     char *buf = p_info->shell_cmd;
581     int len = sizeof(p_info->shell_cmd);
582
583     if (p_info->args_cnt != 2) {
584         D("failed to parse appcmd.(cnt=%d)\n", p_info->args_cnt);
585         return -1;
586     }
587
588     pkgid = p_info->args[1];
589
590     D("args: pkgid=%s\n", pkgid);
591
592     snprintf(buf, len, "/usr/bin/pkginfo --pkg %s;/usr/bin/pkgcmd -C -n %s", pkgid, pkgid);
593
594     return 0;
595 }
596
597 static void appcmd_receiver_packageinfo(int fd_in, int fd_out)
598 {
599     char buf[4096] = {0,};
600     char mainapp_id[128] = {0,};
601     char type[128] = {0,};
602     int is_removable = 0;
603     int is_running = 0;
604     int r;
605
606     for(;;) {
607         memset(buf, 0, sizeof(buf));
608         r = read_line(fd_in, buf, sizeof(buf));
609         if (r == 0) {
610             break;
611         } else if(r < 0) {
612             if (errno == EINTR) {
613                 continue;
614             } else {
615                 break;
616             }
617         }
618
619         if (!strncmp(buf, "mainappid : ", 12)) {
620             sscanf(buf, "mainappid : %s", mainapp_id);
621         } else if (!strncmp(buf, "Type: ", 6)) {
622             sscanf(buf, "Type: %s", type);
623         } else if (!strncmp(buf, "Removable: ", 11)) {
624             sscanf(buf, "Removable: %d", &is_removable);
625         } else if (strstr(buf, " is Running") != NULL) {
626             is_running = 1;
627         }
628     }
629
630     memset(buf, 0, sizeof(buf));
631     snprintf(buf, sizeof(buf), "\n%s:%s:%s:%d:%d\n",
632                 MESSAGE_PREFIX_APPCMD_RETURN, mainapp_id, type, is_removable, is_running);
633
634     D("package info: %s\n", buf);
635     writex(fd_out, buf, strlen(buf)+1);
636 }
637 #endif
638
639 static void run_appcmd_appinstallpath(appcmd_info* p_info) {
640     char result_buf[APPCMD_RESULT_BUFSIZE] = {0,};
641
642     p_info->exitcode = -1;
643
644     const char* path = tzplatform_getenv(TZ_SDK_HOME);
645     if (path != NULL) {
646         p_info->exitcode = 0;
647         snprintf(result_buf, sizeof(result_buf), "\n%s:%s/apps_rw/\n", MESSAGE_PREFIX_APPCMD_RETURN, path);
648         writex(p_info->fd, result_buf, strlen(result_buf));
649     } else {
650         D("failed to get application install path from tzplatform_getenv.");
651     }
652 }
653
654 static void run_appcmd_with_shell_process(appcmd_info* p_info) {
655     int ret = -1;
656
657     if (p_info == NULL) {
658         D("Invalid arguments. p_info is null\n");
659         return;
660     }
661
662     if (p_info->gen_cmd_func == NULL) {
663         D("Invalid arguments.\n");
664         p_info->exitcode = -1;
665         return;
666     }
667
668     ret = p_info->gen_cmd_func(p_info);
669     if (ret < 0) {
670         D("failed to generate install shell command.\n");
671         p_info->exitcode = -1;
672     } else {
673         ret = exec_appcmd_shell_process(p_info);
674         D("exec_appcmd_shell_process: ret=%d, exitcode=%d\n", ret, p_info->exitcode);
675         if (ret < 0) {
676             D("failed to run shell process\n");
677             p_info->exitcode = -1;
678         }
679     }
680 }
681
682 int appcmd_service( parameters* in, int out_fd ) {
683     appcmd_info info;
684     char result_buf[APPCMD_RESULT_BUFSIZE] = {0,};
685     char* service_name = NULL;
686     char* command = NULL;
687
688     if (in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
689             || in->array_of_parameter[0].type != type_string) {
690         D ( "Invalid argument\n" );
691         return PLUGIN_CMD_FAIL;
692     }
693
694     command = in->array_of_parameter[0].v_string.data;
695     D("command=%s(FD:%d)\n", command, out_fd);
696
697     memset(&info, 0, sizeof(info));
698
699     /* appcmd parameter data map
700      * "service name:arg1:arg2:...:argN" */
701     info.args_cnt = tokenize(command, ":", info.args, MAX_TOKENS);
702     D("args_cnt=%d\n", info.args_cnt);
703     if (info.args_cnt < 1) {
704         D("failed to parse appcmd for install. (%s)\n", command);
705         info.exitcode = -1;
706         goto appcmd_done;
707     }
708
709     info.fd = out_fd;
710     info.exitcode = -1;
711     info.raw_command = command;
712
713     service_name = info.args[0];
714     D("service name=%s\n", service_name);
715
716     if (strncmp(service_name, "install", 7) == 0) {
717         info.receiver_func = appcmd_receiver_default;
718         info.gen_cmd_func = appcmd_install_gen_shellcmd;
719         run_appcmd_with_shell_process(&info);
720         // remove pkg files
721         if (info.args[2] != NULL) {
722             sdb_unlink(info.args[2]);
723         }
724     } else if (strncmp(service_name, "uninstall", 9) == 0) {
725         info.receiver_func = appcmd_receiver_default;
726         info.gen_cmd_func = appcmd_uninstall_gen_shellcmd;
727         run_appcmd_with_shell_process(&info);
728     } else if (strncmp(service_name, "appinfo", 7) == 0) {
729         info.gen_cmd_func = appcmd_appinfo_gen_shellcmd;
730         info.receiver_func = appcmd_receiver_appinfo;
731         run_appcmd_with_shell_process(&info);
732     } else if (strncmp(service_name, "packageinfo", 11) == 0) {
733 #if APPCMD_USING_PKGMGR
734         run_appcmd_packageinfo(&info);
735 #else
736         info.gen_cmd_func = appcmd_packageinfo_gen_shellcmd;
737         info.receiver_func = appcmd_receiver_packageinfo;
738         run_appcmd_with_shell_process(&info);
739 #endif
740     } else if (strncmp(service_name, "packagelist", 11) == 0) {
741         info.gen_cmd_func = appcmd_packagelist_gen_shellcmd;
742         info.receiver_func = appcmd_receiver_packagelist;
743         run_appcmd_with_shell_process(&info);
744     } else if (strncmp(service_name, "appinstallpath", 14) == 0) {
745         run_appcmd_appinstallpath(&info);
746     } else if (strncmp(service_name, "runapp", 6) == 0) {
747         info.receiver_func = appcmd_receiver_default;
748         info.gen_cmd_func = appcmd_runapp_gen_shellcmd;
749         run_appcmd_with_shell_process(&info);
750     } else if (strncmp(service_name, "rununittestapp", 14) == 0) {
751         info.receiver_func = appcmd_receiver_default;
752         info.gen_cmd_func = appcmd_rununittestapp_gen_shellcmd;
753         run_appcmd_with_shell_process(&info);
754     } else if (strncmp(service_name, "killapp", 7) == 0) {
755         info.receiver_func = appcmd_receiver_default;
756         info.gen_cmd_func = appcmd_killapp_gen_shellcmd;
757         run_appcmd_with_shell_process(&info);
758     } else if (strncmp(service_name, "debugwebapp", 11) == 0) {
759         info.gen_cmd_func = appcmd_debugwebapp_gen_shellcmd;
760         info.receiver_func = appcmd_receiver_debugwebapp;
761         run_appcmd_with_shell_process(&info);
762     } else if (strncmp(service_name, "debugnativeapp", 14) == 0) {
763         info.gen_cmd_func = appcmd_debugnativeapp_gen_shellcmd;
764         run_appcmd_with_shell_process(&info);
765     } else {
766         D("not supported appcmd service. (%s)\n", service_name);
767         info.exitcode = -1;
768         goto appcmd_done;
769     }
770
771 appcmd_done:
772     free_strings(info.args, info.args_cnt);
773
774     snprintf(result_buf, sizeof(result_buf), "\n%s:%d\n", MESSAGE_PREFIX_APPCMD_EXITCODE, info.exitcode);
775     writex(out_fd, result_buf, strlen(result_buf));
776
777     if (info.exitcode != 0) {
778         return PLUGIN_CMD_FAIL;
779     }
780
781     return PLUGIN_CMD_SUCCESS;
782 }