+typedef struct _csc_info {
+ int count ; /** Number of csc packages */
+ char ** type ; /** package type */
+ char ** description ; /** description */
+} csc_info ;
+
+static int __xsystem(const char *argv[])
+{
+ int status = 0;
+ pid_t pid;
+ pid = fork();
+ switch (pid) {
+ case -1:
+ perror("fork failed");
+ return -1;
+ case 0:
+ /* child */
+ execvp(argv[0], (char *const *)argv);
+ _exit(-1);
+ default:
+ /* parent */
+ break;
+ }
+ if (waitpid(pid, &status, 0) == -1) {
+ perror("waitpid failed");
+ return -1;
+ }
+ if (WIFSIGNALED(status)) {
+ perror("signal");
+ return -1;
+ }
+ if (!WIFEXITED(status)) {
+ /* shouldn't happen */
+ perror("should not happen");
+ return -1;
+ }
+ return WEXITSTATUS(status);
+}
+
+static int __csc_process(const char *csc_path, const char *result_path)
+{
+ int ret = 0;
+ int cnt = 0;
+ int count = 0;
+ int csc_fail = 0;
+ int fd = 0;
+ char *pkgtype = NULL;
+ char *des = NULL;
+ char buf[PKG_STRING_LEN_MAX] = {0,};
+ char type_buf[1024] = { 0 };
+ char des_buf[1024] = { 0 };
+ csc_info *csc = NULL;
+ FILE* file = NULL;
+
+ csc = iniparser_load(csc_path);
+ retvm_if(csc == NULL, PKGMGR_R_EINVAL, "cannot open parse file [%s]", csc_path);
+
+ file = fopen(result_path, "w");
+ retvm_if(file == NULL, PKGMGR_R_EINVAL, "cannot open result file [%s]", result_path);
+
+ count = iniparser_getint(csc, "csc packages:count", -1);
+ retvm_if(count == 0, PKGMGR_R_ERROR, "csc [%s] dont have packages", csc_path);
+
+ snprintf(buf, PKG_STRING_LEN_MAX, "[csc %d packages]\n", count);
+ fwrite(buf, 1, strlen(buf), file);
+
+ for(cnt = 1 ; cnt <= count ; cnt++)
+ {
+ snprintf(type_buf, PKG_STRING_LEN_MAX - 1, "csc packages:type_%03d", cnt);
+ snprintf(des_buf, PKG_STRING_LEN_MAX - 1, "csc packages:description_%03d", cnt);
+
+ pkgtype = iniparser_getstr(csc, type_buf);
+ des = iniparser_getstr(csc, des_buf);
+ ret = 0;
+
+ if (pkgtype == NULL) {
+ csc_fail++;
+ snprintf(buf, PKG_STRING_LEN_MAX, "[%03d]Fail to get information[%s]\n", cnt, type_buf);
+ fwrite(buf, 1, strlen(buf), file);
+ continue;
+ } else if (des == NULL) {
+ csc_fail++;
+ snprintf(buf, PKG_STRING_LEN_MAX, "[%03d]Fail to get information[%s]\n", cnt, des_buf);
+ fwrite(buf, 1, strlen(buf), file);
+ continue;
+ }
+
+ if (strcmp(pkgtype, "tpk") == 0) {
+ const char *ospinstaller_argv[] = { "/usr/bin/osp-installer", "-c", des, NULL };
+ ret = __xsystem(ospinstaller_argv);
+ } else if (strcmp(pkgtype, "wgt")== 0) {
+ const char *wrtinstaller_argv[] = { "/usr/bin/wrt-installer", "-c", des, NULL };
+ ret = __xsystem(wrtinstaller_argv);
+ } else {
+ csc_fail++;
+ ret = -1;
+ }
+
+ if (ret != 0)
+ snprintf(buf, PKG_STRING_LEN_MAX, "[%03d][%s] csc result : Fail\n", cnt, pkgtype);
+ else
+ snprintf(buf, PKG_STRING_LEN_MAX, "[%03d][%s] csc result : Sucess\n", cnt, pkgtype);
+
+ fwrite(buf, 1, strlen(buf), file);
+ }
+
+ if (csc_fail > 0) {
+ ret = PKGMGR_R_ERROR;
+ snprintf(buf, PKG_STRING_LEN_MAX, "[csc result] total : [%d], sucess : [%d]packages, fail : [%d]packages\n", count, count-csc_fail, csc_fail);
+
+ } else {
+ ret = PKGMGR_R_OK;
+ snprintf(buf, PKG_STRING_LEN_MAX, "[csc result] total : [%d], sucess : all packages\n", count);
+
+ }
+ fwrite(buf, 1, strlen(buf), file);
+
+ iniparser_freedict(csc);
+ fflush(file);
+ fd = fileno(file);
+ fsync(fd);
+ fclose(file);
+
+ return ret;
+}