support preload install for wgt pkg. 03/93703/2
authorjongmyeongko <jongmyeong.ko@samsung.com>
Tue, 25 Oct 2016 10:12:59 +0000 (19:12 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Thu, 3 Nov 2016 12:11:37 +0000 (21:11 +0900)
Change-Id: I4e3abed6be5aa4578ab264503b509141e378c099
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
CMakeLists.txt
packaging/pkgmgr-tool.manifest
packaging/pkgmgr-tool.spec
src/install_preload_pkg.c [new file with mode: 0644]
src/install_preload_tpk.c [deleted file]

index bcdf03dba06b4a4445b23d47cd16943b9c3b0785..3eb3f0b3f1796e080df27b24453ec41396751f79 100644 (file)
@@ -54,9 +54,9 @@ ADD_EXECUTABLE(pkg_clearcache src/pkg_clearcache.c)
 TARGET_LINK_LIBRARIES(pkg_clearcache ${pkgs_test_LDFLAGS})
 INSTALL(TARGETS pkg_clearcache DESTINATION bin)
 
-ADD_EXECUTABLE(install_preload_tpk src/install_preload_tpk.c)
-TARGET_LINK_LIBRARIES(install_preload_tpk ${pkgs_test_LDFLAGS})
-INSTALL(TARGETS install_preload_tpk DESTINATION bin)
+ADD_EXECUTABLE(install_preload_pkg src/install_preload_pkg.c)
+TARGET_LINK_LIBRARIES(install_preload_pkg ${pkgs_test_LDFLAGS})
+INSTALL(TARGETS install_preload_pkg DESTINATION bin)
 
 ADD_EXECUTABLE(rsc-slice src/pkg_rsc_slice.c)
 TARGET_LINK_LIBRARIES(rsc-slice ${pkgs_test_LDFLAGS})
index 62a58f5b09f8b44ec2e55f0047cd746abf8ed9e7..7f2bbf11d62268fa5ff6999d339e16ec4806e8b4 100644 (file)
@@ -3,7 +3,7 @@
                <domain name="_" />
        </request>
        <assign>
-               <filesystem path="/usr/bin/install_preload_tpk" label="System" exec_label="none" />
+               <filesystem path="/usr/bin/install_preload_pkg" label="System" exec_label="none" />
                <filesystem path="/usr/bin/pkgcmd" label="User::Shell" exec_label="none" />
                <filesystem path="/usr/bin/pkg_clearcache" label="System" exec_label="none" />
                <filesystem path="/usr/bin/pkg_getsize" label="System" exec_label="none" />
index a419c35fe7497769193848b81a190a6b27145606..b07df4251bc4d0c4e22f7dfa047b666dccfa92c0 100644 (file)
@@ -61,7 +61,7 @@ if [ ! -f %{TZ_SYS_DB}/.pkgmgr_parser.db ]
 then
   pkg_initdb
 fi
-install_preload_tpk
+install_preload_pkg
 if [ -f /tmp/.preload_install_error ]
 then
   if [ ! -d /tmp/.postscript/error ]
@@ -82,7 +82,7 @@ fi
 %{_bindir}/pkg_clearcache
 %{_bindir}/pkginfo
 %{_bindir}/rsc-slice
-%attr(0755,root,root) %{_bindir}/install_preload_tpk
+%attr(0755,root,root) %{_bindir}/install_preload_pkg
 %attr(0700,root,root) /etc/package-manager/pkgmgr-unzip-pkg.sh
 %attr(0700,root,root) /etc/package-manager/pkgmgr-create-delta.sh
 %attr(0700,root,root) /usr/share/upgrade/scripts/300.pkgmgr.patch.sh
diff --git a/src/install_preload_pkg.c b/src/install_preload_pkg.c
new file mode 100644 (file)
index 0000000..ea797ca
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include <tzplatform_config.h>
+
+#define OWNER_ROOT 0
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+#define BUFSZE 4096
+
+#ifdef _E
+#undef _E
+#endif
+#define _E(fmt, arg...) fprintf(stderr, "[PKG_PRELOAD_INSTALL][E][%s,%d] \
+        "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+
+#ifdef _D
+#undef _D
+#endif
+#define _D(fmt, arg...) fprintf(stderr, "[PKG_PRELOAD_INSTALL][D][%s,%d] \
+       "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+
+#define TPK_BACKEND_CMD "/usr/bin/tpk-backend"
+#define WGT_BACKEND_CMD "/usr/bin/wgt-backend"
+#define TPK_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-tpk")
+#define WGT_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-wgt")
+
+static int _install_preload_pkg(const char *backend, const char *directory)
+{
+       DIR *dir;
+       struct dirent file_info, *result;
+       int ret;
+       char file_path[BUFSZE];
+       char err_buf[BUFSZE];
+
+       dir = opendir(directory);
+       if (!dir) {
+               if (errno == ENOENT) {
+                       _D("The directory for preloaded pkgs doesn't exist");
+                       return 0;
+               } else {
+                       _E("Failed to access the [%s] because [%s]", directory,
+                               strerror_r(errno, err_buf, sizeof(err_buf)));
+                       return -1;
+               }
+       }
+
+       _D("Loading pkg files from %s", directory);
+
+       for (ret = readdir_r(dir, &file_info, &result);
+                       ret == 0 && result != NULL;
+                       ret = readdir_r(dir, &file_info, &result)) {
+               if (file_info.d_name[0] == '.')
+                       continue;
+
+               snprintf(file_path, sizeof(file_path), "%s/%s", directory,
+                       file_info.d_name);
+               _D("pkg file %s", file_path);
+
+               pid_t pid = fork();
+               if (pid == 0) {
+                       execl(backend, backend, "-i", file_path,
+                               "--preload", (char *)NULL);
+               } else if (pid < 0) {
+                       _E("failed to fork and execute %s!", backend);
+                       closedir(dir);
+                       return -1;
+               }
+
+               if (pid > 0) {
+                       int status = 0;
+                       waitpid(pid, &status, 0);
+               }
+
+               /* remove a file after installation */
+               ret = remove(file_path);
+               if (ret < 0) {
+                       _E("Failed to remove the file [%s] because [%s]",
+                               file_path, strerror_r(errno, err_buf,
+                               sizeof(err_buf)));
+                       closedir(dir);
+                       return -1;
+               }
+       }
+
+       closedir(dir);
+
+       return 0;
+}
+
+static int _is_authorized(uid_t uid)
+{
+       /* install_preload_pkg should be called by as root privilege. */
+       if ((uid_t) OWNER_ROOT == uid)
+               return 1;
+       else
+               return 0;
+}
+
+int main(int argc, char *argv[])
+{
+       char err_msg[BUFSZE];
+       int handle = -1;
+       int ret = 0;
+
+       if (!_is_authorized(getuid())) {
+               _E("You are not an authorized user!");
+               return -1;
+       }
+
+       if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_DIR) < 0)
+               goto error;
+
+       if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_DIR) < 0)
+               goto error;
+
+       return 0;
+
+error:
+       handle = open("/tmp/.preload_install_error",
+               O_WRONLY | O_CREAT | O_APPEND | O_TRUNC, 0644);
+       if (handle == -1) {
+               _E("Failed to open error file");
+               return -1;
+       }
+       snprintf(err_msg, sizeof(err_msg),
+               "install_preload_pkg error!\n");
+       ret = write(handle, err_msg, strlen(err_msg));
+       if (ret == -1)
+               _E("Failed to write an error message. (%d)", errno);
+       close(handle);
+
+       return -1;
+}
diff --git a/src/install_preload_tpk.c b/src/install_preload_tpk.c
deleted file mode 100644 (file)
index b270b55..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#define _GNU_SOURCE
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#include <tzplatform_config.h>
-
-#define OWNER_ROOT 0
-#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-#define BUFSZE 4096
-
-#ifdef _E
-#undef _E
-#endif
-#define _E(fmt, arg...) fprintf(stderr, "[TPK_PRELOAD_INSTALL][E][%s,%d] \
-        "fmt"\n", __FUNCTION__, __LINE__, ##arg);
-
-#ifdef _D
-#undef _D
-#endif
-#define _D(fmt, arg...) fprintf(stderr, "[TPK_PRELOAD_INSTALL][D][%s,%d] \
-       "fmt"\n", __FUNCTION__, __LINE__, ##arg);
-
-#define BACKEND_CMD "/usr/bin/tpk-backend"
-
-static int _install_preload_tpk(const char *directory)
-{
-       DIR *dir;
-       struct dirent file_info, *result;
-       int ret;
-       char file_path[BUFSZE];
-       char err_buf[BUFSZE];
-
-       dir = opendir(directory);
-       if (!dir) {
-               if (errno == ENOENT) {
-                       _D("The directory for preloaded tpks doesn't exist");
-                       return 0;
-               } else {
-                       _E("Failed to access the [%s] because [%s]", directory,
-                               strerror_r(errno, err_buf, sizeof(err_buf)));
-                       return -1;
-               }
-       }
-
-       _D("Loading tpk files from %s", directory);
-
-       for (ret = readdir_r(dir, &file_info, &result);
-                       ret == 0 && result != NULL;
-                       ret = readdir_r(dir, &file_info, &result)) {
-               if (file_info.d_name[0] == '.')
-                       continue;
-
-               snprintf(file_path, sizeof(file_path), "%s/%s", directory,
-                       file_info.d_name);
-               _D("tpk file %s", file_path);
-
-               pid_t pid = fork();
-               if (pid == 0) {
-                       execl(BACKEND_CMD, BACKEND_CMD, "-i", file_path,
-                               "--preload", (char *)NULL);
-               } else if (pid < 0) {
-                       _E("failed to fork and execute %s!", BACKEND_CMD);
-                       closedir(dir);
-                       return -1;
-               }
-
-               if (pid > 0) {
-                       int status = 0;
-                       waitpid(pid, &status, 0);
-               }
-
-               /* remove a file after installation */
-               ret = remove(file_path);
-               if (ret < 0) {
-                       _E("Failed to remove the file [%s] because [%s]",
-                               file_path, strerror_r(errno, err_buf,
-                               sizeof(err_buf)));
-                       closedir(dir);
-                       return -1;
-               }
-       }
-
-       closedir(dir);
-
-       return 0;
-}
-
-static int _is_authorized(uid_t uid)
-{
-       /* install_preload_tpk should be called by as root privilege. */
-       if ((uid_t) OWNER_ROOT == uid)
-               return 1;
-       else
-               return 0;
-}
-
-int main(int argc, char *argv[])
-{
-       char err_msg[BUFSZE];
-       const char *dir = tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-tpk");
-       int handle = -1;
-       int ret = 0;
-
-       if (!_is_authorized(getuid())) {
-               _E("You are not an authorized user!");
-               return -1;
-       }
-
-       if (_install_preload_tpk(dir) < 0) {
-               handle = open("/tmp/.preload_install_error",
-                       O_WRONLY | O_CREAT | O_APPEND | O_TRUNC, 0644);
-               if (handle == -1) {
-                       _E("Failed to open error file");
-                       return -1;
-               }
-               snprintf(err_msg, sizeof(err_msg),
-                       "install_preload_tpk error!\n");
-               ret = write(handle, err_msg, strlen(err_msg));
-               if (ret == -1)
-                       _E("Failed to write an error message. (%d)", errno);
-               close(handle);
-               return -1;
-       }
-
-       return 0;
-}