tizen 2.4 release accepted/tizen_2.4_mobile accepted/tizen/2.4/mobile/20151029.033840 submit/tizen_2.4/20151028.063914 tizen_2.4_mobile_release
authorjk7744.park <jk7744.park@samsung.com>
Sat, 24 Oct 2015 07:32:10 +0000 (16:32 +0900)
committerjk7744.park <jk7744.park@samsung.com>
Sat, 24 Oct 2015 07:32:10 +0000 (16:32 +0900)
12 files changed:
AUTHORS [new file with mode: 0755]
CMakeLists.txt [new file with mode: 0755]
LICENSE [new file with mode: 0755]
include/pkgmgr-server.h [new file with mode: 0755]
include/pm-queue.h [new file with mode: 0755]
org.tizen.pkgmgr.service.in [new file with mode: 0755]
packaging/pkgmgr-server.spec [new file with mode: 0755]
pkgmgr-server.manifest [new file with mode: 0755]
slp-pkgmgr.service [new file with mode: 0755]
src/pkgmgr-server-internal.c [new file with mode: 0755]
src/pkgmgr-server.c [new file with mode: 0755]
src/pm-queue.c [new file with mode: 0755]

diff --git a/AUTHORS b/AUTHORS
new file mode 100755 (executable)
index 0000000..d908bc1
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,4 @@
+Jayoun Lee <airjany@samsung.com>
+Sewook Park <sewook7.park@samsung.com>
+Jaeho Lee <jaeho81.lee@samsung.com>
+Shobhit Srivastava <shobhit.s@samsung.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..14e02ef
--- /dev/null
@@ -0,0 +1,67 @@
+#
+# Copyright (c) 2008 ~ 2010 Samsung Electronics Co., Ltd.
+# All rights reserved
+#
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(pkgmgr-server C)
+
+SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
+SET(VERSION 0.1.68)
+SET(VERSION_MAJOR 0)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+SET(CMAKE_SKIP_BUILD_RPATH true)
+
+#Verbose
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+
+INCLUDE(FindPkgConfig)
+IF(_APPFW_FEATURE_DRM_ENABLE)
+pkg_check_modules(pkgs REQUIRED security-server dlog pkgmgr pkgmgr-info pkgmgr-parser dbus-1 glib-2.0 gio-2.0 vasum drm-service-core-tizen minizip aul)
+ELSE(_APPFW_FEATURE_DRM_ENABLE)
+pkg_check_modules(pkgs REQUIRED security-server dlog pkgmgr pkgmgr-info pkgmgr-parser dbus-1 glib-2.0 gio-2.0 vasum minizip aul)
+ENDIF(_APPFW_FEATURE_DRM_ENABLE)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+## About debug
+SET(debug_type "-DPM_CONSOLE_USE")             # for debug - use console window
+
+## Additional flag
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+IF(_APPFW_FEATURE_DRM_ENABLE)
+       ADD_DEFINITIONS("-D_APPFW_FEATURE_DRM_ENABLE")
+ENDIF(_APPFW_FEATURE_DRM_ENABLE)
+
+IF(_APPFW_FEATURE_EXPANSION_PKG_INSTALL)
+       ADD_DEFINITIONS("-D_APPFW_FEATURE_EXPANSION_PKG_INSTALL")
+ENDIF(_APPFW_FEATURE_EXPANSION_PKG_INSTALL)
+
+###################################################################################################
+## for pkgmgr-server (binary)
+SET(pkgmgr-server_SOURCES
+               ${CMAKE_SOURCE_DIR}/src/pkgmgr-server-internal.c
+               ${CMAKE_SOURCE_DIR}/src/pkgmgr-server.c
+               ${CMAKE_SOURCE_DIR}/src/pm-queue.c)
+
+ADD_EXECUTABLE(pkgmgr-server ${pkgmgr-server_SOURCES})
+TARGET_LINK_LIBRARIES(pkgmgr-server pkgmgr_installer pkgmgr_installer_pkg_mgr_server ${pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(pkgmgr-server PROPERTIES COMPILE_FLAGS ${CFLAGS} "${debug_type} -fPIE")
+SET_TARGET_PROPERTIES(pkgmgr-server PROPERTIES LINK_FLAGS "-pie")
+####################################################################################################
+
+configure_file(org.tizen.pkgmgr.service.in org.tizen.pkgmgr.service @ONLY)
+INSTALL(FILES ${CMAKE_BINARY_DIR}/pkgmgr-server DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.tizen.pkgmgr.service DESTINATION ${PREFIX}/share/dbus-1/system-services/)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/slp-pkgmgr.service DESTINATION ${PREFIX}/lib/systemd/system/)
+
+####################################################################################################
+# i18n
diff --git a/LICENSE b/LICENSE
new file mode 100755 (executable)
index 0000000..a06208b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,204 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   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.
+
diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h
new file mode 100755 (executable)
index 0000000..c154290
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * slp-pkgmgr
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+#ifndef _PKGMGR_SERVER_H_
+#define _PKGMGR_SERVER_H_
+
+#include <vasum.h>
+
+#define CONF_FILE      "/usr/etc/package-manager/server/.config"
+#define DESKTOP_FILE_DIRS      "/usr/share/install-info/desktop.conf"
+
+#define PKG_BACKEND    "backend:"
+#define PKG_CONF_PATH  "/usr/etc/package-manager/pkg_path.conf"
+
+#define MAX_PKG_STR_LEN        1024
+#define MAX_REQ_ID_LEN         256
+#define MAX_PKG_TYPE_LEN       128
+#define MAX_PKG_NAME_LEN       256
+#define MAX_PKG_PATH_LEN       4096
+#define MAX_PKG_ARGS_LEN       4096
+#define MAX_COOKIE_LEN         32
+#define DESKTOP_FILE_DIRS_NUM          1024
+#define MAX_ZONE_NAME_LEN 128
+
+typedef struct {
+       char req_id[MAX_REQ_ID_LEN];
+       int req_type;
+       char pkg_type[MAX_PKG_TYPE_LEN];
+       char pkgid[MAX_PKG_PATH_LEN];
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+       char tep_path[MAX_PKG_PATH_LEN];
+#endif
+       char args[MAX_PKG_ARGS_LEN];
+       char cookie[MAX_COOKIE_LEN];
+       char zone[MAX_ZONE_NAME_LEN];
+       char backend_installer[MAX_PKG_TYPE_LEN];
+} pm_dbus_msg;
+
+typedef struct backend_info_t {
+       int pid;
+       char pkgtype[MAX_PKG_TYPE_LEN];
+       char pkgid[MAX_PKG_PATH_LEN];
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+       char tep_path[MAX_PKG_PATH_LEN];
+#endif
+       char args[MAX_PKG_ARGS_LEN];
+       char zone[MAX_ZONE_NAME_LEN];
+       char backend_installer[MAX_PKG_TYPE_LEN];
+}backend_info;
+
+struct pm_inotify_paths_t {
+       int wd;
+       char *path;
+};
+typedef struct pm_inotify_paths_t pm_inotify_paths;
+
+typedef struct pm_appinfo_t {
+       const char *apppath;
+       int option;
+       int pid;
+} pm_appinfo;
+
+char *_get_backend_cmd(char *type);
+int _zone_set_type_and_backend(pm_dbus_msg *item, const char *zone);
+void _pm_desktop_file_monitor_init();
+void _pm_desktop_file_monitor_fini();
+int _pm_desktop_file_dir_search(pm_inotify_paths *paths, int number);
+
+#endif                         /*  _PKGMGR_SERVER_H_ */
diff --git a/include/pm-queue.h b/include/pm-queue.h
new file mode 100755 (executable)
index 0000000..64d4b2d
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * slp-pkgmgr
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+#ifndef _PM_QUEUE_H_
+#define _PM_QUEUE_H_
+
+#include "pkgmgr-server.h"
+
+#define STATUS_FILE    "/usr/etc/package-manager/server/queue_status"
+/* #define STATUS_FILE   "./queue_status" */
+
+typedef struct _pm_queue_data {
+       pm_dbus_msg *msg;
+       struct _pm_queue_data *next;
+} pm_queue_data;
+
+typedef struct queue_info_map_t {
+       char pkgtype[MAX_PKG_TYPE_LEN];
+       char backend[MAX_PKG_NAME_LEN];
+       int queue_slot;
+       pm_queue_data *head;
+} queue_info_map;
+
+#define MAX_QUEUE_NUM 128
+
+int _pm_queue_init();
+int _pm_queue_push(pm_dbus_msg *item);
+/*position specifies the queue from which to pop request*/
+pm_dbus_msg *_pm_queue_pop(int position);
+void _pm_queue_final();
+void _pm_queue_delete(pm_dbus_msg *item);
+pm_queue_data *_add_node();
+void _save_queue_status(pm_dbus_msg *item, char *status);
+void _print_queue(int position);
+
+#endif                         /* _PM_QUEUE_H_ */
diff --git a/org.tizen.pkgmgr.service.in b/org.tizen.pkgmgr.service.in
new file mode 100755 (executable)
index 0000000..d12c996
--- /dev/null
@@ -0,0 +1,5 @@
+[D-BUS Service]
+Name=org.tizen.pkgmgr
+Exec=/bin/false
+SystemdService=slp-pkgmgr.service
+User=root
diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec
new file mode 100755 (executable)
index 0000000..dc0cd89
--- /dev/null
@@ -0,0 +1,81 @@
+Name:       pkgmgr-server
+Summary:    Packager Manager server package
+Version:    0.3.37
+Release:    1
+Group:      System/Libraries
+License:    Apache-2.0
+Source0:    %{name}-%{version}.tar.gz
+BuildRequires:  cmake
+BuildRequires:  pkgconfig(security-server)
+BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(dbus-1)
+BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(pkgmgr-info)
+BuildRequires:  pkgconfig(minizip)
+BuildRequires:  pkgconfig(vasum)
+BuildRequires:  pkgmgr-info-parser-devel
+BuildRequires:  pkgconfig(pkgmgr)
+BuildRequires:  pkgconfig(pkgmgr-installer)
+BuildRequires:  pkgconfig(aul)
+
+%define appfw_feature_expansion_pkg_install 1
+%define appfw_feature_drm_enable 1
+
+%if 0%{?appfw_feature_drm_enable}
+BuildRequires:  pkgconfig(drm-service-core-tizen)
+%endif
+
+Requires(post): /sbin/ldconfig
+
+%description
+Packager Manager server package for packaging
+
+%prep
+%setup -q
+
+%if 0%{?tizen_build_binary_release_type_eng}
+export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE"
+export CXXFLAGS="$CXXFLAGS ?DTIZEN_ENGINEER_MODE"
+export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE"
+%endif
+
+%if 0%{?appfw_feature_expansion_pkg_install}
+_EXPANSION_PKG_INSTALL=ON
+%else
+_EXPANSION_PKG_INSTALL=OFF
+%endif
+
+
+%if 0%{?appfw_feature_drm_enable}
+_DRM_ENABLE=ON
+%else
+_DRM_ENABLE=OFF
+%endif
+
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
+               -D_APPFW_FEATURE_DRM_ENABLE:BOOL=${_DRM_ENABLE} \
+               -D_APPFW_FEATURE_EXPANSION_PKG_INSTALL:BOOL=${_EXPANSION_PKG_INSTALL}
+
+%build
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE %{buildroot}/usr/share/license/%{name}
+
+%post
+/sbin/ldconfig
+mkdir -p /usr/etc/package-manager/server
+
+%files
+%manifest pkgmgr-server.manifest
+%defattr(-,root,root,-)
+%{_datadir}/dbus-1/system-services/org.tizen.pkgmgr.service
+%{_libdir}/systemd/system/slp-pkgmgr.service
+%{_bindir}/pkgmgr-server
+/usr/share/license/%{name}
+
diff --git a/pkgmgr-server.manifest b/pkgmgr-server.manifest
new file mode 100755 (executable)
index 0000000..4016e45
--- /dev/null
@@ -0,0 +1,42 @@
+<manifest>
+       <define>
+               <domain name="pkgmgr-server"/>
+               <request>
+                       <smack request="_" type="rwx"/>
+                       <smack request="deviced::display" type="rw"/>
+                       <smack request="device::sys_logging" type="rw"/>
+                       <smack request="device::app_logging" type="rw"/>
+                       <smack request="dbus" type="x"/>
+                       <smack request="pkgmgr" type="rx"/>
+                       <smack request="pkgmgr::db" type="rwl"/>
+                       <smack request="privacy-manager::db" type="rw"/>
+                       <smack request="pkgmgr-parser" type="rx"/>
+                       <smack request="rpm-backend" type="r"/>
+                       <smack request="systemd" type="rx"/>
+                       <smack request="systemd::no-label" type="rx"/>
+                       <smack request="syslogd" type="x"/>
+                       <smack request="sdbd" type="rx"/>
+                       <smack request="system::homedir" type="rwxat"/>
+                       <smack request="security-server" type="x"/>
+                       <smack request="security-server::label" type="w"/>
+                       <smack request="security-server::api-permissions" type="w"/>
+                       <smack request="security-server::api-cookie-check" type="w"/>
+                       <smack request="system::use_internet" type="w"/>
+                       <smack request="system::media" type="rx"/>
+                       <smack request="tizen::vconf::setting::admin" type="rl"/>
+                       <smack request="wrt-installer" type="rx"/>
+                       <smack request="deviced::display" type="rw"/>
+                       <smack request="system::ext_storage" type="rxl"/>
+               </request>
+               <permit>
+                       <smack permit="system::use_internet" type="w"/>
+               </permit>
+       </define>
+       <request>
+               <domain name="pkgmgr-server"/>
+       </request>
+       <assign>
+               <filesystem path="/usr/bin/pkgmgr-server" exec_label="pkgmgr-server"/>
+               <filesystem path="/usr/share/dbus-1/system-services/org.tizen.pkgmgr.service" label="_" exec_label="none"/>
+       </assign>
+</manifest>
diff --git a/slp-pkgmgr.service b/slp-pkgmgr.service
new file mode 100755 (executable)
index 0000000..0682793
--- /dev/null
@@ -0,0 +1,6 @@
+[Unit]
+Description=SLP Package Manager
+
+[Service]
+BusName=org.tizen.pkgmgr
+ExecStart=/usr/bin/pkgmgr-server
\ No newline at end of file
diff --git a/src/pkgmgr-server-internal.c b/src/pkgmgr-server-internal.c
new file mode 100755 (executable)
index 0000000..26375fd
--- /dev/null
@@ -0,0 +1,365 @@
+/*
+ * slp-pkgmgr
+ *
+ * Copyright (c) 2000 - 2015 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.
+ *
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <minizip/unzip.h>
+
+#include <pkgmgr-info.h>
+#include <vasum.h>
+
+#include "pkgmgr-server.h"
+#include <package-manager.h>
+#include <package-manager-debug.h>
+
+#undef LOG_TAG
+#ifndef LOG_TAG
+#define LOG_TAG "PKGMGR_SERVER"
+#endif                         /* LOG_TAG */
+
+#define WGT_XML_FILE           "config.xml"
+#define TPK_XML_FILE           "info/manifest.xml"
+#define CORE_XML_FILE          "tizen-manifest.xml"
+#define HYBRID_XML_FILE        "res/wgt/config.xml"
+
+#define ZONE_HOST "host"
+
+#define PKG_STRING_LEN_MAX 1024
+
+static int __is_rpm_pkg(const char *filename)
+{
+       char *pkg_type = NULL;
+       char pkg_file[PKG_STRING_LEN_MAX] = { '\0', };
+
+       if (strrchr(filename, '/')) {
+               strncpy(pkg_file, strrchr(filename, '/') + 1, PKG_STRING_LEN_MAX - 1);
+       } else {
+               strncpy(pkg_file, filename, PKG_STRING_LEN_MAX - 1);
+       }
+
+       pkg_type = strrchr(pkg_file, '.');
+       if (pkg_type == NULL) {
+               _LOGE("pkg_type is null[%s]", filename);
+               return -1;
+       } else {
+               pkg_type++;
+       }
+
+       if (strcmp(pkg_type, "rpm") == 0) {
+               return 0;
+       } else {
+               return -1;
+       }
+}
+
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+/**
+* @brief __get_installed_pkg_type() returns the installed package type for which input tep file should belong to.
+*
+* @param filename - tep file name
+*
+* @return returns NULL if pkgid for which tep belongs doesn't exists. Else, returns pkgtype.
+*/
+static int __get_installed_pkg_type(const char *filename, char **pkg_type, char **backend_installer)
+{
+       char *backend = NULL;
+       char *_pkg_type = NULL;
+       char pkg_file[PKG_STRING_LEN_MAX] = { '\0', };
+       char *tmp = NULL;
+       char *pkgid = NULL;
+       size_t pkgid_len = 0;
+       int ret = 0;
+       char *type = NULL;
+
+       if (strrchr(filename, '/')) {
+               strncpy(pkg_file, strrchr(filename, '/') + 1, PKG_STRING_LEN_MAX - 1);
+       } else {
+               strncpy(pkg_file, filename, PKG_STRING_LEN_MAX - 1);
+       }
+
+       /*Checking for valid tep file*/
+       _pkg_type = strrchr(pkg_file, '.');
+       retvm_if(_pkg_type == NULL, PMINFO_R_ERROR, "pkg_type is null[%s]", filename);
+
+       _pkg_type++;
+       retvm_if((_pkg_type == NULL || strcmp(_pkg_type, "tep") != 0), PMINFO_R_ERROR, "Invalid tep file[%s]", filename);
+
+       _pkg_type = NULL;
+
+       /*e.g., Input filename --> org.tizen.sample-1.0.0-arm.tep
+           e.g., Output should be --> org.tizen.sample*/
+       tmp = strchr(pkg_file, '-');
+       retvm_if((tmp == NULL || strlen(tmp) == 0), NULL, "Invalid tep file name!!!\n");
+
+       pkgid_len = tmp - pkg_file;
+       retvm_if(pkgid_len < 1, NULL, "Invalid tep file name!!!\n");
+
+       pkgid = calloc(1, pkgid_len + 1);
+       retvm_if(pkgid == NULL, NULL, "Out of Memory!!!\n");
+
+       memcpy((void *)pkgid, (const void *)pkg_file, pkgid_len);
+       trym_if((strlen(pkgid) == 0), "pkgid is NULL");
+
+       pkgmgrinfo_pkginfo_h handle = NULL;
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       trym_if(ret < 0, "pkgmgrinfo_pkginfo_get_pkginfo(%s) failed.", pkgid);
+
+       ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
+       trym_if(ret < 0 || type == NULL, "pkgmgrinfo_pkginfo_get_type(%s) failed.", pkgid);
+
+       ret = pkgmgrinfo_pkginfo_get_backend_installer(handle, &backend);
+       trym_if(ret < 0, "Cannot install .tep [Corresponding app is not installed], pkgmgrinfo_pkginfo_get_root_path(%s) failed.", pkgid);
+
+       *pkg_type = strdup(type);
+       *backend_installer = strdup(backend);
+
+catch:
+       free(pkgid);
+       pkgid = NULL;
+       if(handle)
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       return ret;
+}
+#endif
+
+char *_zone_get_root_path(const char *zone)
+{
+       vsm_context_h context = NULL;
+       vsm_zone_h handle = NULL;
+       char *rootpath = NULL;
+
+       context = vsm_create_context();
+       if (context == NULL) {
+               _LOGE("Failed to create vsm context");
+               return NULL;
+       }
+
+       handle = vsm_lookup_zone_by_name(context, zone);
+       if (handle == NULL) {
+               _LOGE("Failed to lookup zone by name");
+               return NULL;
+       }
+
+       rootpath = (char *)vsm_get_zone_rootpath(handle);
+       if (rootpath == NULL) {
+               _LOGE("Failed to get rootpath");
+               return NULL;
+       }
+
+       _LOGD("rootpath : %s", rootpath);
+
+       return rootpath;
+}
+
+int _zone_set_type_and_backend(pm_dbus_msg *item, const char *zone)
+{
+       char *filename = NULL;
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+       if (strlen(item->pkgid))
+               filename = item->pkgid;
+       else if (strlen(item->tep_path))
+               filename = item->tep_path;
+       _LOGE("tep_filepath [%s]", filename);
+#else
+       filename = item->pkgid;
+#endif
+
+       retvm_if(filename == NULL, PKGMGR_R_ERROR, "filename is NULL");
+
+       char *pkg_type = NULL;
+       char *pkg_backend = NULL;
+       unzFile uf = NULL;
+
+       char *_file_name = NULL;
+       int _name_len = 0;
+
+       int ret = 0;
+       pkgmgrinfo_pkginfo_h pkginfo_handle;
+       char *tmp_backend = NULL;
+       char *tmp_type = NULL;
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(filename, &pkginfo_handle);
+       if (ret) {
+               _LOGD("pkgid is wrong. maybe this process is for install");
+       } else {
+               ret = pkgmgrinfo_pkginfo_get_backend_installer(pkginfo_handle, &tmp_backend);
+               if (ret) {
+                       _LOGE(" pkgmgrinfo_pkginfo_get_backend_installer error : %d", ret);
+               } else {
+                       ret = pkgmgrinfo_pkginfo_get_type(pkginfo_handle, &tmp_type);
+                       if (ret) {
+                               _LOGE(" pkgmgrinfo_pkginfo_get_type error : %d", ret);
+                       } else{
+                               _LOGD("Successfully get pkg_type and pkg_backend [%s]", filename);
+                               pkg_backend = strdup(tmp_backend);
+                               pkg_type = strdup(tmp_type);
+                               pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_handle);
+                               goto out;
+                       }
+               }
+       }
+
+       if (pkginfo_handle)
+               pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_handle);
+
+
+       if (zone && strcmp(zone, ZONE_HOST) != 0) {
+               char *rootpath = NULL;
+               rootpath = _zone_get_root_path(zone);
+               retvm_if(rootpath == NULL, PKGMGR_R_ERROR, "rootpath is NULL");
+
+               _name_len = strlen(filename) + strlen(rootpath) + 1; /* for '\0' */
+               _file_name = calloc(1, _name_len);
+               if (_file_name) {
+                       snprintf(_file_name, _name_len, "%s%s", rootpath, filename);
+                       _LOGD("new file name is %s", _file_name);
+
+                       if (access(_file_name, F_OK) != 0) {
+                               _LOGE("can not access to [%s], retry to [%s]", _file_name, filename);
+                               free(_file_name);
+                               _file_name = NULL;
+                               _name_len = strlen(filename) + 1; /* for '\0' */
+                               _file_name = calloc(1, _name_len);
+                               if (_file_name) {
+                                       snprintf(_file_name, _name_len, "%s", filename);
+                                       if (access(_file_name, F_OK) != 0) {
+                                               _LOGE("can not access to [%s]", _file_name);
+                                               free(_file_name);
+                                               return PKGMGR_R_ERROR;
+                                       }
+                               }
+                       }
+               }
+       } else {
+               _name_len = strlen(filename) + 1; /* for '\0' */
+               _file_name = calloc(1, _name_len);
+               if (_file_name) {
+                       snprintf(_file_name, _name_len, "%s", filename);
+                       if (access(_file_name, F_OK) != 0) {
+                               _LOGE("can not access to [%s]", _file_name);
+                               free(_file_name);
+                               return PKGMGR_R_ERROR;
+                       }
+               }
+       }
+
+       if (!_file_name) {
+               _LOGE("_file_name alloc failed");
+               return PKGMGR_R_ERROR;
+       }
+
+       // rpm
+       if (__is_rpm_pkg(_file_name) == 0) {
+               _LOGE("%s is rpm", _file_name);
+               pkg_type = strdup("rpm");
+               pkg_backend = strdup("rpm");
+               goto out;
+       }
+
+       uf = unzOpen(_file_name);
+       if (uf == NULL) {
+               pkg_type = strdup(item->pkg_type);
+               pkg_backend = strdup(item->pkg_type);
+               _LOGD("unzOpen[%s] fail. pkg_type[%s] backend[%s]", _file_name, pkg_type, pkg_backend);
+               goto out;
+       }
+
+       //hybrid for web-core
+       if ((unzLocateFile(uf, HYBRID_XML_FILE, 0) == 0) && (unzLocateFile(uf, CORE_XML_FILE, 0) == 0)) {
+               _LOGE("%s is hybrid[web-core]", _file_name);
+               pkg_type = strdup("wgt");
+               pkg_backend = strdup("wgt");
+
+       //hybrid for web-tpk
+       } else if ((unzLocateFile(uf, HYBRID_XML_FILE, 0) == 0) && (unzLocateFile(uf, TPK_XML_FILE, 0) == 0)) {
+               _LOGE("%s is hybrid[web-tpk]", _file_name);
+               pkg_type = strdup("wgt");
+               pkg_backend = strdup("wgt");
+
+       //core
+       } else if (unzLocateFile(uf, CORE_XML_FILE, 0) == 0) {
+               _LOGD("%s is core", filename);
+               pkg_type = strdup("tpk");
+               pkg_backend = strdup("coretpk");
+
+       //wgt
+       } else if (unzLocateFile(uf, WGT_XML_FILE, 0) == 0) {
+               _LOGE("%s is wgt", _file_name);
+               pkg_type = strdup("wgt");
+               pkg_backend = strdup("wgt");
+
+       //tpk
+       } else if (unzLocateFile(uf, TPK_XML_FILE, 0) == 0) {
+               _LOGE("%s is tpk", _file_name);
+               pkg_type = strdup("tpk");
+               pkg_backend = strdup("tpk");
+
+       //error case
+       } else {
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+               if (__get_installed_pkg_type(_file_name, &pkg_type, &pkg_backend) == PMINFO_R_OK){
+                       _LOGE("tep pkg type is %s\n", pkg_type);
+                       _LOGE("tep backend installer is %s\n", pkg_backend);
+               } else{
+                       _LOGE("Invalid tep file name!!");
+               }
+#else
+               if (item->pkg_type) {
+                       pkg_type = strdup(item->pkg_type);
+                       pkg_backend = strdup(item->pkg_type);
+               }
+
+               _LOGD("%s's type = %s, backend = %s ", _file_name, pkg_type, pkg_backend);
+#endif
+
+       }
+
+       if (uf) {
+               unzCloseCurrentFile(uf);
+               unzClose(uf);
+       }
+
+out:
+       if (_file_name)
+               free(_file_name);
+
+       if (pkg_type && pkg_backend) {
+               _LOGD("pkg type = %s, pkg backend = %s, file = %s", pkg_type, pkg_backend, item->pkgid);
+
+               memset((item->pkg_type),0,MAX_PKG_TYPE_LEN);
+               strncpy(item->pkg_type, pkg_type, sizeof(item->pkg_type) - 1);
+               memset((item->backend_installer),0,MAX_PKG_TYPE_LEN);
+               strncpy(item->backend_installer, pkg_backend, sizeof(item->backend_installer) - 1);
+
+               free(pkg_backend);
+               free(pkg_type);
+       } else {
+               if (pkg_type)
+                       free(pkg_type);
+               if (pkg_backend)
+                       free(pkg_backend);
+
+               _LOGE("pkgtype or pkg_backend is null for %s", filename);
+               return PKGMGR_R_ERROR;
+       }
+
+
+       return PKGMGR_R_OK;
+}
diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c
new file mode 100755 (executable)
index 0000000..3487272
--- /dev/null
@@ -0,0 +1,2268 @@
+/*
+ * slp-pkgmgr
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/inotify.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/xattr.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <ctype.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <signal.h>
+#include <dbus/dbus.h>
+#include <security-server.h>
+#include <pkgmgr-info.h>
+#include <pkgmgr_parser.h>
+#include <pkgmgrinfo_zone.h>
+#include <vasum.h>
+#include <aul.h>
+#ifdef _APPFW_FEATURE_DRM_ENABLE
+#include <drm-tizen-apps.h>
+#endif
+
+#include "pm-queue.h"
+#include "pkgmgr-server.h"
+#include <package-manager.h>
+#include <package-manager-debug.h>
+#include <pkgmgr/pkgmgr_installer.h>
+#include <pkgmgr/comm_pkg_mgr_server.h>
+#include <pkgmgr/comm_config.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "PKGMGR_SERVER"
+
+#define IS_WHITESPACE(CHAR) \
+((CHAR == ' ' || CHAR == '\t' || CHAR == '\r' || CHAR == '\n') ? TRUE : FALSE)
+
+#define PACKAGE_RECOVERY_DIR "/opt/share/packages/.recovery/pkgmgr"
+#define ZONE_HOST "host"
+#define PKG_DATA_PATH  "/opt/usr/data/pkgmgr"
+
+#define DESKTOP_W   720.0
+
+#define NO_MATCHING_FILE 11
+
+typedef struct checkapp_data {
+       char *sub_cmd;
+       char *zone_name;
+} checkapp_data_s;
+
+static int backend_flag = 0;   /* 0 means that backend process is not running */
+
+/*
+8 bit value to represent maximum 8 backends.
+Each bit position corresponds to a queue slot which
+is dynamically determined.
+*/
+char backend_busy = 0;
+int drm_busy = 0;
+
+/*
+8 bit value to represent quiet mode operation for maximum 8 backends
+1->quiet 0->non-quiet
+Each bit position corresponds to a queue slot which
+is dynamically determined.
+*/
+char backend_mode = 63; /*00111111*/
+extern int num_of_backends;
+
+backend_info *begin;
+extern queue_info_map *start;
+extern int entries;
+int pos = 0;
+/*To store info in case of backend crash*/
+char pname[MAX_PKG_NAME_LEN] = {'\0'};
+char ptype[MAX_PKG_TYPE_LEN] = {'\0'};
+char args[MAX_PKG_ARGS_LEN] = {'\0'};
+
+GMainLoop *mainloop = NULL;
+
+static int __check_backend_status_for_exit();
+static int __check_queue_status_for_exit();
+static int __is_backend_busy(int position);
+static void __set_backend_busy(int position);
+static void __set_backend_free(int position);
+static void __set_backend_mode(int position);
+static void __unset_backend_mode(int position);
+
+static void sighandler(int signo);
+gboolean queue_job(void *data);
+gboolean send_fail_signal(void *data);
+gboolean exit_server(void *data);
+
+/* To check whether a particular backend is free/busy*/
+static int __is_backend_busy(int position)
+{
+       return backend_busy & 1<<position;
+}
+static void __set_drm_busy(int position)
+{
+       drm_busy = position;
+}
+/*To set a particular backend as busy*/
+static void __set_backend_busy(int position)
+{
+       backend_busy = backend_busy | 1<<position;
+}
+/*To set a particular backend as free */
+static void __set_backend_free(int position)
+{
+       backend_busy = backend_busy & ~(1<<position);
+}
+
+/*To set a particular backend mode as quiet*/
+static void __set_backend_mode(int position)
+{
+       backend_mode = backend_mode | 1<<position;
+}
+/*To unset a particular backend mode */
+static void __unset_backend_mode(int position)
+{
+       backend_mode = backend_mode & ~(1<<position);
+}
+
+static void __set_recovery_mode(char *pkgid, char *pkg_type, const char *zone)
+{
+       char recovery_file[MAX_PKG_NAME_LEN] = { 0, };
+       char buffer[MAX_PKG_NAME_LEN] = { 0 };
+       char temp_path[MAX_PKG_NAME_LEN] = { 0 };
+       char *pkgid_tmp = NULL;
+       FILE *rev_file = NULL;
+
+       if (pkgid == NULL) {
+               _LOGE("pkgid is null");
+               return;
+       }
+
+       if (zone && strlen(zone) && strcmp(zone, ZONE_HOST) != 0) {
+               char *rootpath = NULL;
+
+               rootpath = _zone_get_root_path(zone);
+               if (rootpath == NULL) {
+                       _LOGE("rootpath is null");
+                       return;
+               }
+               snprintf(temp_path, MAX_PKG_NAME_LEN, "%s%s", rootpath, PACKAGE_RECOVERY_DIR);
+               dbg("temp_path(%s)", temp_path);
+       } else {
+               snprintf(temp_path, MAX_PKG_NAME_LEN, "%s", PACKAGE_RECOVERY_DIR);
+       }
+
+       /*if pkgid has a "/"charactor, that is a path name for installation, then extract pkgid from absolute path*/
+       if (strstr(pkgid, "/")) {
+               pkgid_tmp = strrchr(pkgid, '/') + 1;
+               if (pkgid_tmp == NULL) {
+                       _LOGE("pkgid_tmp[%s] is null", pkgid);
+                       return;
+               }
+               snprintf(recovery_file, MAX_PKG_NAME_LEN, "%s/%s", temp_path, pkgid_tmp);
+       } else {
+               snprintf(recovery_file, MAX_PKG_NAME_LEN, "%s/%s", temp_path, pkgid);
+       }
+
+       rev_file = fopen(recovery_file, "w");
+       if (rev_file== NULL) {
+               _LOGE("rev_file[%s] is null", recovery_file);
+               return;
+       }
+
+       snprintf(buffer, MAX_PKG_NAME_LEN, "pkgid : %s\n", pkgid);
+       fwrite(buffer, sizeof(char), strlen(buffer), rev_file);
+
+       fclose(rev_file);
+}
+
+static void __unset_recovery_mode(char *pkgid, char *pkg_type, const char *zone)
+{
+       int ret = -1;
+       char recovery_file[MAX_PKG_NAME_LEN] = { 0, };
+       char temp_path[MAX_PKG_NAME_LEN] = { 0, };
+       char *pkgid_tmp = NULL;
+
+       if (pkgid == NULL) {
+               _LOGE("pkgid is null");
+               return;
+       }
+
+       if (zone && strlen(zone) && strcmp(zone, ZONE_HOST) != 0) {
+               char *rootpath = NULL;
+               rootpath = _zone_get_root_path(zone);
+               if (rootpath == NULL) {
+                       _LOGE("rootpath is null");
+                       return;
+               }
+               snprintf(temp_path, MAX_PKG_NAME_LEN, "%s%s", rootpath, PACKAGE_RECOVERY_DIR);
+       } else {
+               snprintf(temp_path, MAX_PKG_NAME_LEN, "%s", PACKAGE_RECOVERY_DIR);
+       }
+
+       /*if pkgid has a "/"charactor, that is a path name for installation, then extract pkgid from absolute path*/
+       if (strstr(pkgid, "/")) {
+               pkgid_tmp = strrchr(pkgid, '/') + 1;
+               if (pkgid_tmp == NULL) {
+                       _LOGE("pkgid_tmp[%s] is null", pkgid);
+                       return;
+               }
+               snprintf(recovery_file, MAX_PKG_NAME_LEN, "%s/%s", temp_path, pkgid_tmp);
+       } else {
+               snprintf(recovery_file, MAX_PKG_NAME_LEN, "%s/%s", temp_path, pkgid);
+       }
+
+       ret = remove(recovery_file);
+       if (ret < 0)
+               _LOGE("remove recovery_file[%s] fail", recovery_file);
+}
+
+static int __check_privilege_by_cookie(const char *e_cookie, int req_type)
+{
+       guchar *cookie = NULL;
+       gsize size;
+       int ret = PMINFO_R_ERROR;
+
+       if (e_cookie == NULL)   {
+               _LOGE("e_cookie is NULL!!!");
+               return PMINFO_R_ERROR;
+       }
+
+       cookie = g_base64_decode(e_cookie, &size);
+       if (cookie == NULL)     {
+               _LOGE("Unable to decode cookie!!!");
+               return PMINFO_R_ERROR;
+       }
+
+       switch (req_type) {
+               case COMM_REQ_TO_INSTALL:
+               case COMM_REQ_TO_UNINSTALL:
+                       ret = security_server_check_privilege_by_cookie((const char*)cookie, "pkgmgr::svc", "r");
+                       if (SECURITY_SERVER_API_SUCCESS == ret)
+                               ret = PMINFO_R_OK;
+                       break;
+
+               case COMM_REQ_TO_MOVER:
+                       ret = security_server_check_privilege_by_cookie((const char*)cookie, "pkgmgr::svc", "x");
+                       if (SECURITY_SERVER_API_SUCCESS == ret)
+                               ret = PMINFO_R_OK;
+                       break;
+
+               case COMM_REQ_GET_SIZE:
+                       ret = security_server_check_privilege_by_cookie((const char*)cookie, "pkgmgr::info", "r");
+                       if (SECURITY_SERVER_API_SUCCESS == ret)
+                               ret = PMINFO_R_OK;
+                       break;
+
+               case COMM_REQ_CLEAR_CACHE_DIR:
+                       ret = security_server_check_privilege_by_cookie((const char*)cookie, "pkgmgr::cache", "w");
+                       if (SECURITY_SERVER_API_SUCCESS == ret)
+                               ret = PMINFO_R_OK;
+                       break;
+
+               default:
+                       _LOGE("Check your request[%d]..", req_type);
+                       break;
+       }
+
+       _LOGD("security_server[req-type:%d] check cookie result = %d", req_type, ret);
+
+       if (cookie){
+               g_free(cookie);
+               cookie = NULL;
+       }
+
+       return ret;
+}
+
+static int __check_admin_privilege_by_cookie(const char *e_cookie)
+{
+       guchar *cookie = NULL;
+       gsize size;
+       int ret = PMINFO_R_ERROR;
+
+       if (e_cookie == NULL)   {
+               _LOGE("e_cookie is NULL!!!");
+               return PMINFO_R_ERROR;
+       }
+
+       cookie = g_base64_decode(e_cookie, &size);
+       if (cookie == NULL)     {
+               _LOGE("Unable to decode cookie!!!");
+               return PMINFO_R_ERROR;
+       }
+
+       ret = security_server_check_privilege_by_cookie((const char *)cookie, "privilege::tizen::packagemanager.admin rw", "rw");
+       if (ret == SECURITY_SERVER_API_SUCCESS)
+               ret = PMINFO_R_OK;
+
+
+       if (cookie){
+               g_free(cookie);
+               cookie = NULL;
+       }
+
+       return ret;
+}
+
+
+static int __get_position_from_pkg_type(char *pkgtype)
+{
+       int i = 0;
+       queue_info_map *ptr;
+       ptr = start;
+       for(i = 0; i < entries; i++)
+       {
+               if (!strncmp(ptr->pkgtype, pkgtype, MAX_PKG_TYPE_LEN))
+                       return ptr->queue_slot;
+               else
+                       ptr++;
+
+       }
+       return -1;
+}
+
+gboolean send_fail_signal(void *data)
+{
+       _LOGD("send_fail_signal start");
+       gboolean ret_parse;
+       gint argcp;
+       gchar **argvp;
+       GError *gerr = NULL;
+       pkgmgr_installer *pi;
+       pi = pkgmgr_installer_new();
+       if (!pi) {
+               _LOGE("Failure in creating the pkgmgr_installer object");
+               return FALSE;
+       }
+       ret_parse = g_shell_parse_argv(args,
+                                      &argcp, &argvp, &gerr);
+       if (FALSE == ret_parse) {
+               _LOGE("Failed to split args: %s", args);
+               _LOGE("messsage: %s", gerr->message);
+               pkgmgr_installer_free(pi);
+               return FALSE;
+       }
+
+       pkgmgr_installer_receive_request(pi, argcp, argvp);
+       pkgmgr_installer_send_signal(pi, ptype, pname, "end", "fail");
+       pkgmgr_installer_free(pi);
+       return FALSE;
+}
+
+static void sighandler(int signo)
+{
+       int status;
+       pid_t cpid;
+       int i = 0;
+       backend_info *ptr = NULL;
+       ptr = begin;
+
+       while ((cpid = waitpid(-1, &status, WNOHANG)) > 0) {
+               _LOGD("child exit [%d]", cpid);
+               if (WIFEXITED(status)) {
+                       for(i = 0; i < num_of_backends; i++)
+                       {
+                               if (cpid == (ptr + i)->pid) {
+                                       __set_backend_free(i);
+                                       __set_backend_mode(i);
+                                       __unset_recovery_mode((ptr + i)->pkgid, (ptr + i)->pkgtype, (ptr + i)->zone);
+                                       if (WEXITSTATUS(status)) {
+                                               strncpy(pname, (ptr + i)->pkgid, MAX_PKG_NAME_LEN-1);
+                                               strncpy(ptype, (ptr + i)->pkgtype, MAX_PKG_TYPE_LEN-1);
+                                               strncpy(args, (ptr + i)->args, MAX_PKG_ARGS_LEN-1);
+                                               g_idle_add(send_fail_signal, NULL);
+                                               _LOGE("child exit [%d] with error code:%d", cpid, WEXITSTATUS(status));
+                                       } else {
+                                               _LOGE("child NORMAL exit [%d]", cpid);
+                                       }
+                                       break;
+                               }
+                       }
+               }
+               else if (WIFSIGNALED(status)) {
+                       _LOGE("child SIGNALED exit [%d]", cpid);
+                       /*get the pkgid and pkgtype to send fail signal*/
+                       for(i = 0; i < num_of_backends; i++)
+                       {
+                               if (cpid == (ptr + i)->pid) {
+                                       __set_backend_free(i);
+                                       __set_backend_mode(i);
+                                       __unset_recovery_mode((ptr + i)->pkgid, (ptr + i)->pkgtype, (ptr + i)->zone);
+                                       strncpy(pname, (ptr + i)->pkgid, MAX_PKG_NAME_LEN-1);
+                                       strncpy(ptype, (ptr + i)->pkgtype, MAX_PKG_TYPE_LEN-1);
+                                       strncpy(args, (ptr + i)->args, MAX_PKG_ARGS_LEN-1);
+                                       g_idle_add(send_fail_signal, NULL);
+                                       break;
+                               }
+                       }
+               }
+       }
+
+}
+
+static void __register_signal_handler(void)
+{
+       static int sig_reg = 0;
+
+       if (sig_reg == 0) {
+               struct sigaction act;
+
+               act.sa_handler = sighandler;
+               sigemptyset(&act.sa_mask);
+               act.sa_flags = SA_NOCLDSTOP;
+
+               if (sigaction(SIGCHLD, &act, NULL) < 0) {
+                       _LOGE("signal: SIGCHLD failed");
+               }
+               if (!g_timeout_add_seconds(2, exit_server, NULL)) {
+                       _LOGE("Add g_timeout_add_seconds() to Main Loop is failed.");
+               }
+
+               sig_reg = 1;
+       }
+}
+
+#ifdef _APPFW_FEATURE_DRM_ENABLE
+int decrypt_pkg_cb(const char *drm_file_path, const char *decrypted_file_path, const char *cookie, int *ret)
+{
+       __register_signal_handler();
+
+       _LOGE(">> in callback >> package_manager_drm_decrypt_license is called.");
+
+       if (drm_file_path == NULL || decrypted_file_path == NULL || cookie == NULL) {
+               _LOGE("Invalid parameter.");
+               *ret = PKGMGR_R_EINVAL;
+               __set_drm_busy(0);
+               return -1;
+       }
+       int retval = 0;
+       const char *smack_label = "*";
+       int cookie_result = 0;
+
+       cookie_result = __check_admin_privilege_by_cookie(cookie);
+       if (cookie_result < 0){
+               _LOGE("__check_admin_privilege_by_cookie result fail[%d]", cookie_result);
+               *ret = PKGMGR_R_EPRIV;
+               return -1;
+       }
+
+       retval = drm_tizen_decrypt_package(drm_file_path, strlen(drm_file_path), decrypted_file_path, strlen(decrypted_file_path));
+       if (retval != 1) {
+               _LOGE("drm_tizen_decrypt_package is failed.");
+               *ret = PKGMGR_R_ERROR;
+               __set_drm_busy(0);
+               return -1;
+       }
+
+       if (security_server_label_access(decrypted_file_path, smack_label) != 0) {
+               _LOGE("error(%d) in setting smack label.", errno);
+       } else {
+               _LOGD("security_server_label_access(%s, %s) is ok.", decrypted_file_path, smack_label);
+       }
+
+       _LOGD("[%s] smack label is changed.", decrypted_file_path);
+
+       _LOGD("package_manager_drm_decrypt_package is successful.");
+       *ret = PKGMGR_R_OK;
+       __set_drm_busy(0);
+
+       return 0;
+}
+
+int reg_license_cb(const char *resp_data, const char *cookie, int *ret)
+{
+       __register_signal_handler();
+
+       _LOGE(">> in callback >> package_manager_drm_register_license is called.");
+
+       if (resp_data == NULL || cookie == NULL) {
+               _LOGE("Invalid parameter.");
+               *ret = PKGMGR_R_EINVAL;
+               __set_drm_busy(0);
+               return -1;
+       }
+       int retval = 0;
+       int cookie_result = 0;
+
+       cookie_result = __check_admin_privilege_by_cookie(cookie);
+       if (cookie_result < 0){
+               _LOGE("__check_admin_privilege_by_cookie result fail[%d]", cookie_result);
+               *ret = PKGMGR_R_EPRIV;
+               return -1;
+       }
+
+       retval = drm_tizen_register_license(resp_data, strlen(resp_data));
+       if (retval != 1) {
+               _LOGE("drm_tizen_register_license is failed.");
+               *ret = PKGMGR_R_ERROR;
+               __set_drm_busy(0);
+               return -1;
+       }
+
+       _LOGE("package_manager_drm_register_license is successful.");
+       *ret = PKGMGR_R_OK;
+
+       return 0;
+}
+
+int gen_license_req_cb(const char *resp_data, const char *cookie, char **req_data, char **license_url, int *ret)
+{
+       __register_signal_handler();
+
+       _LOGE(">> in callback >> package_manager_drm_generate_license_request is called.");
+
+       if (resp_data == NULL || req_data == NULL || license_url == NULL || cookie == NULL) {
+               _LOGE("Invalid parameter.");
+               *ret = PKGMGR_R_EINVAL;
+               __set_drm_busy(0);
+               return -1;
+       }
+       int retval = 0;
+       char temp_req_data[1024] = {0,};
+       unsigned int temp_req_len = sizeof(temp_req_data);
+       char temp_license_url[1024] = {0,};
+       unsigned int temp_license_url_len = sizeof(temp_license_url);
+       int cookie_result = 0;
+
+       cookie_result = __check_admin_privilege_by_cookie(cookie);
+       if (cookie_result < 0){
+               _LOGE("__check_admin_privilege_by_cookie result fail[%d]", cookie_result);
+               *ret = PKGMGR_R_EPRIV;
+               return -1;
+       }
+
+       retval = drm_tizen_generate_license_request(resp_data, strlen(resp_data), temp_req_data, &temp_req_len, temp_license_url, &temp_license_url_len);
+       if (retval != 1) {
+               _LOGE("drm_tizen_generate_license_request is failed.");
+               *ret = PKGMGR_R_ERROR;
+               __set_drm_busy(0);
+               return -1;
+       }
+
+       *req_data = strdup(temp_req_data);
+       *license_url = strdup(temp_license_url);
+
+       _LOGD("package_manager_drm_generate_license_request is successful.");
+       *ret = PKGMGR_R_OK;
+       __set_drm_busy(1);
+
+       return 0;
+}
+#endif
+
+int create_external_dir_cb(const char *zone)
+{
+       int err = -1;
+       int p = 0;
+
+       SECURE_LOGD(">> in callback >> External storage has been mounted");
+
+       __register_signal_handler();
+
+       pm_dbus_msg *item = calloc(1, sizeof(pm_dbus_msg));
+       if (item == NULL)
+       {
+               _LOGE("Out of memory");
+               return err;
+       }
+
+       item->req_type = COMM_REQ_MAKE_EXTERNAL_DIR;
+       strncpy(item->pkg_type, "rpm", sizeof(item->pkg_type) - 1);
+       strncpy(item->backend_installer, "rpm", sizeof(item->backend_installer) - 1);
+       if (zone) {
+               strncpy(item->zone, zone, sizeof(item->zone) - 1);
+               _LOGD("zone(%s), item->zone(%s)", zone, item->zone);
+       }
+
+       err = _pm_queue_push(item);
+       p = __get_position_from_pkg_type(item->pkg_type);
+       __set_backend_mode(p);
+       if (err == 0)
+       {
+               g_idle_add(queue_job, NULL);
+       }
+
+       free(item);
+
+       return err;
+}
+
+void req_cb(void *cb_data, const char *req_id, const int req_type,
+           const char *pkg_type, const char *pkgid, const char *args,
+           const char *cookie, const char *zone, int *ret)
+{
+       int err = -1;
+       int p = 0;
+       int cookie_result = 0;
+
+       SECURE_LOGD(">> in callback >> Got request: [%s] [%d] [%s] [%s] [%s] [%s] [%s]",
+           req_id, req_type, pkg_type, pkgid, args, cookie, zone);
+
+       __register_signal_handler();
+
+       pm_dbus_msg *item = calloc(1, sizeof(pm_dbus_msg));
+       if (item == NULL)
+       {
+               _LOGE("Out of memory");
+               return;
+       }
+
+       strncpy(item->req_id, req_id, sizeof(item->req_id) - 1);
+       item->req_type = req_type;
+       strncpy(item->pkg_type, pkg_type, sizeof(item->pkg_type) - 1);
+
+       strncpy(item->pkgid, pkgid, sizeof(item->pkgid) - 1);
+       strncpy(item->args, args, sizeof(item->args) - 1);
+       strncpy(item->cookie, cookie, sizeof(item->cookie) - 1);
+       if (zone) {
+               strncpy(item->zone, zone, sizeof(item->zone) - 1);
+               _LOGD("req_type=(%d)  backend_flag=(%d) zone(%s)",
+                               req_type, backend_flag, item->zone);
+       }
+
+       switch (item->req_type) {
+       case COMM_REQ_TO_INSTALL:
+               /* check caller privilege */
+               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
+               if (cookie_result < 0){
+                       _LOGE("__check_privilege_by_cookie result fail[%d]", cookie_result);
+                       *ret = PKGMGR_R_EPRIV;
+                       goto err;
+               }
+
+               /* get pkgtype from msg-args */
+               if (_zone_set_type_and_backend(item, zone)) {
+                       *ret = PKGMGR_R_ERROR;
+                       goto err;
+               }
+
+               /* quiet mode */
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               if (p < 0) {
+                       _LOGE("invalid or unsupported package");
+                       *ret = PKGMGR_R_ERROR;
+                       break;
+               }
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_TO_UNINSTALL:
+               /* check caller privilege */
+               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
+               if (cookie_result < 0){
+                       _LOGE("__check_privilege_by_cookie result fail[%d]", cookie_result);
+                       *ret = PKGMGR_R_EPRIV;
+                       goto err;
+               }
+
+               /* quiet mode */
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               if (p < 0) {
+                       _LOGE("invalid or unsupported package");
+                       *ret = PKGMGR_R_ERROR;
+                       break;
+               }
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_ACTIVATE_PKG:
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_DEACTIVATE_PKG:
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_ACTIVATE_APP:
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_DEACTIVATE_APP:
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_ENABLE_BG_OPERATION:
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_DISABLE_BG_OPERATION:
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+
+       case COMM_REQ_ACTIVATE_APP_WITH_LABEL:
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_TO_CLEARER:
+               /* In case of clearer, there is no popup */
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               /*the backend shows the success/failure popup
+               so this request is non quiet*/
+               __unset_backend_mode(p);
+
+/*             g_idle_add(queue_job, NULL); */
+               if (err == 0)
+                       queue_job(NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_TO_MOVER:
+               /* check caller privilege */
+               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
+               if (cookie_result < 0){
+                       _LOGD("__check_privilege_by_cookie result fail[%d]", cookie_result);
+                       *ret = PKGMGR_R_EPRIV;
+                       goto err;
+               }
+
+               /* In case of mover, there is no popup */
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               if (p < 0) {
+                       _LOGE("invalid or unsupported package");
+                       *ret = PKGMGR_R_ERROR;
+                       goto err;
+               }
+
+               /*the backend shows the success/failure popup
+               so this request is non quiet*/
+               __unset_backend_mode(p);
+               if (err == 0)
+                       queue_job(NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_CANCEL:
+               _pm_queue_delete(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __unset_backend_mode(p);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_GET_SIZE:
+               /* check caller privilege */
+#ifdef _APPFW_PKGMGR_PRIV_SUPPORT //XXX: Temporary define
+               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
+               if (cookie_result < 0){
+                       _LOGE("__check_privilege_by_cookie result fail[%d]", cookie_result);
+                       *ret = PKGMGR_R_EPRIV;
+                       goto err;
+               }
+#endif
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+
+       case COMM_REQ_CHECK_APP:
+       case COMM_REQ_KILL_APP:
+               /* In case of activate, there is no popup */
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+
+/*             g_idle_add(queue_job, NULL); */
+               if (err == 0)
+                       queue_job(NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+
+       case COMM_REQ_CLEAR_CACHE_DIR:
+               /* check caller privilege */
+#ifdef _APPFW_PKGMGR_PRIV_SUPPORT //XXX: Temporary define
+               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
+               if (cookie_result < 0){
+                       _LOGE("__check_privilege_by_cookie result fail[%d]", cookie_result);
+                       *ret = PKGMGR_R_EPRIV;
+                       goto err;
+               }
+#endif
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+
+       default:
+               _LOGE("Check your request..");
+               *ret = PKGMGR_R_ERROR;
+               break;
+       }
+err:
+       if (*ret != PKGMGR_R_OK) {
+               _LOGD("Failed to handle request %s %s", item->pkg_type, item->pkgid);
+               pkgmgr_installer *pi;
+               gboolean ret_parse;
+               gint argcp;
+               gchar **argvp;
+               GError *gerr = NULL;
+
+               pi = pkgmgr_installer_new();
+               if (!pi) {
+                       _LOGE("Failure in creating the pkgmgr_installer object");
+                       if(item){
+                               free(item);
+                               item = NULL;
+                       }
+                       return;
+               }
+
+               ret_parse = g_shell_parse_argv(args, &argcp, &argvp, &gerr);
+               if (FALSE == ret_parse) {
+                       _LOGE("Failed to split args: %s", args);
+                       _LOGE("messsage: %s", gerr->message);
+                       pkgmgr_installer_free(pi);
+                       if(item){
+                               free(item);
+                               item = NULL;
+                       }
+                       return;
+               }
+
+               pkgmgr_installer_receive_request(pi, argcp, argvp);
+
+               pkgmgr_installer_send_signal(pi, item->pkg_type,
+                                            item->pkgid, "end",
+                                            "fail");
+
+               pkgmgr_installer_free(pi);
+
+       }
+
+       if(item){
+               free(item);
+               item = NULL;
+       }
+       return;
+}
+
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+void req_tep_cb(void *cb_data, const char *req_id, const int req_type,
+               const char *pkg_type, const char *pkgid,const char *tep_path,
+               const char *args, const char *cookie, const char *zone, int *ret)
+{
+       int err = -1;
+       int p = 0;
+       int cookie_result = 0;
+
+       _LOGE("req_id=[%s], req_type=[%d], pkg_type=[%s], pkgid=[%s], tep_path[%s], args=[%s], cookie=[%s], backend_flag=[%d], zone=[%s]",
+                       req_id, req_type, pkg_type, pkgid, tep_path, args, cookie, backend_flag, zone);
+
+       __register_signal_handler();
+
+       pm_dbus_msg *item = calloc(1, sizeof(pm_dbus_msg));
+       if (item == NULL)
+       {
+               _LOGE("Out of memory");
+               return;
+       }
+
+       strncpy(item->req_id, req_id, sizeof(item->req_id) - 1);
+       item->req_type = req_type;
+       if (pkg_type)
+               strncpy(item->pkg_type, pkg_type, sizeof(item->pkg_type) - 1);
+
+       if (pkgid && strlen(pkgid)>0)
+               strncpy(item->pkgid, pkgid, sizeof(item->pkgid) - 1);
+       else
+               item->pkgid[0] = '\0';
+
+       if (tep_path)
+               strncpy(item->tep_path, tep_path, sizeof(item->tep_path) - 1);
+
+       strncpy(item->args, args, sizeof(item->args) - 1);
+       strncpy(item->cookie, cookie, sizeof(item->cookie) - 1);
+       if (zone) {
+               strncpy(item->zone, zone, sizeof(item->zone) - 1);
+               _LOGD("req_type=(%d)  backend_flag=(%d) zone(%s)",
+                               req_type, backend_flag, item->zone);
+       }
+
+       switch (item->req_type) {
+       case COMM_REQ_TO_INSTALL:
+               /* check caller privilege */
+               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
+               if (cookie_result < 0){
+                       _LOGE("__check_privilege_by_cookie result fail[%d]\n", cookie_result);
+                       *ret = PKGMGR_R_EPRIV;
+                       goto err;
+               }
+
+               /* get pkgtype from msg-args */
+               if (_zone_set_type_and_backend(item, zone)) {
+                       *ret = PKGMGR_R_ERROR;
+                       goto err;
+               }
+               _LOGE("pkg type[%s]", item->pkg_type);
+
+               /* quiet mode */
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               if (p < 0) {
+                       _LOGE("invalid or unsupported package");
+                       *ret = PKGMGR_R_ERROR;
+                       break;
+               }
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_TO_UNINSTALL:
+               /* check caller privilege */
+               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
+               if (cookie_result < 0){
+                       _LOGE("__check_privilege_by_cookie result fail[%d]\n", cookie_result);
+                       *ret = PKGMGR_R_EPRIV;
+                       goto err;
+               }
+
+               _LOGE("pkg type[%s]", item->pkg_type);
+
+               /* quiet mode */
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               if (p < 0) {
+                       _LOGE("invalid or unsupported package");
+                       *ret = PKGMGR_R_ERROR;
+                       break;
+               }
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+
+
+       case COMM_REQ_ACTIVATE_PKG:
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_DEACTIVATE_PKG:
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_ACTIVATE_APP:
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_DEACTIVATE_APP:
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_ACTIVATE_APP_WITH_LABEL:
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_TO_CLEARER:
+               /* In case of clearer, there is no popup */
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               /*the backend shows the success/failure popup
+               so this request is non quiet*/
+               __unset_backend_mode(p);
+
+               /*              g_idle_add(queue_job, NULL); */
+               if (err == 0)
+                       queue_job(NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_TO_MOVER:
+               /* check caller privilege */
+               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
+               if (cookie_result < 0){
+                       _LOGD("__check_privilege_by_cookie result fail[%d]\n", cookie_result);
+                       *ret = PKGMGR_R_EPRIV;
+                       goto err;
+               }
+
+               /* In case of mover, there is no popup */
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               /*the backend shows the success/failure popup
+               so this request is non quiet*/
+               __unset_backend_mode(p);
+               if (err == 0)
+                       queue_job(NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_CANCEL:
+               _pm_queue_delete(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __unset_backend_mode(p);
+               *ret = PKGMGR_R_OK;
+               break;
+       case COMM_REQ_GET_SIZE:
+               /* check caller privilege */
+               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
+               if (cookie_result < 0){
+                       _LOGE("__check_privilege_by_cookie result fail[%d]\n", cookie_result);
+                       *ret = PKGMGR_R_EPRIV;
+                       goto err;
+               }
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+
+       case COMM_REQ_CHECK_APP:
+       case COMM_REQ_KILL_APP:
+               /* In case of activate, there is no popup */
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+
+               /*              g_idle_add(queue_job, NULL); */
+               if (err == 0)
+                       queue_job(NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+
+       case COMM_REQ_CLEAR_CACHE_DIR:
+               /* check caller privilege */
+               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
+               if (cookie_result < 0){
+                       _LOGE("__check_privilege_by_cookie result fail[%d]\n", cookie_result);
+                       *ret = PKGMGR_R_EPRIV;
+                       goto err;
+               }
+#if 0
+               if (__is_clearing_cache_running(item->pkgid)) {
+                       *ret = PKGMGR_R_OK;
+                       break;
+               }
+#endif
+               err = _pm_queue_push(item);
+               p = __get_position_from_pkg_type(item->pkg_type);
+               __set_backend_mode(p);
+
+               if (err == 0)
+                       g_idle_add(queue_job, NULL);
+               *ret = PKGMGR_R_OK;
+               break;
+
+       default:
+               _LOGE("Check your request..\n");
+               *ret = PKGMGR_R_ERROR;
+               break;
+       }
+err:
+       if (*ret != PKGMGR_R_OK) {
+               _LOGD("Failed to handle request %s %s\n",item->pkg_type, item->pkgid);
+               pkgmgr_installer *pi;
+               gboolean ret_parse;
+               gint argcp;
+               gchar **argvp;
+               GError *gerr = NULL;
+
+               pi = pkgmgr_installer_new();
+               if (!pi) {
+                       _LOGE("Failure in creating the pkgmgr_installer object");
+                       if(item){
+                               free(item);
+                               item = NULL;
+                       }
+                       return;
+               }
+
+               ret_parse = g_shell_parse_argv(args, &argcp, &argvp, &gerr);
+               if (FALSE == ret_parse) {
+                       _LOGE("Failed to split args: %s", args);
+                       _LOGE("messsage: %s", gerr->message);
+                       pkgmgr_installer_free(pi);
+                       if(item){
+                               free(item);
+                               item = NULL;
+                       }
+                       return;
+               }
+
+               pkgmgr_installer_receive_request(pi, argcp, argvp);
+
+               pkgmgr_installer_send_signal(pi, item->pkg_type,
+                               item->pkgid, "end",
+                               "fail");
+
+               pkgmgr_installer_free(pi);
+
+       }
+
+       if(item){
+               free(item);
+               item = NULL;
+       }
+       return;
+}
+#endif
+
+static int __check_drm_status_for_exit()
+{
+       if (drm_busy)
+               return 0;
+       else
+               return 1;
+}
+
+static int __check_backend_status_for_exit()
+{
+       int i = 0;
+       for(i = 0; i < num_of_backends; i++)
+       {
+               if (!__is_backend_busy(i))
+                       continue;
+               else
+                       return 0;
+       }
+       return 1;
+}
+
+static int __check_queue_status_for_exit()
+{
+       pm_queue_data *head[MAX_QUEUE_NUM] = {NULL,};
+       queue_info_map *ptr = NULL;
+       ptr = start;
+       int i = 0;
+       int c = 0;
+       int slot = -1;
+       for(i = 0; i < entries; i++)
+       {
+               if (ptr->queue_slot <= slot) {
+                       ptr++;
+                       continue;
+               }
+               else {
+                       head[c] = ptr->head;
+                       slot = ptr->queue_slot;
+                       c++;
+                       ptr++;
+               }
+       }
+       for(i = 0; i < num_of_backends; i++)
+       {
+               if (!head[i])
+                       continue;
+               else
+                       return 0;
+       }
+       return 1;
+}
+
+gboolean exit_server(void *data)
+{
+       _LOGE("exit_server Start [backend_status=%d, queue_status=%d, drm_status=%d] \n", __check_backend_status_for_exit(), __check_queue_status_for_exit(), __check_drm_status_for_exit());
+       if (__check_backend_status_for_exit() && __check_queue_status_for_exit() && __check_drm_status_for_exit()) {
+               if (!getenv("PMS_STANDALONE")) {
+                       g_main_loop_quit(mainloop);
+                       return FALSE;
+               }
+       }
+       return TRUE;
+}
+
+static int __terminate_app(const aul_app_info *ainfo, void *data)
+{
+       retvm_if(ainfo == NULL, -1, "ainfo is null\n");
+       retvm_if(ainfo->appid == NULL, -1, "appid is null\n");
+
+       int ret = 0;
+
+       if (!strcmp(ainfo->appid, (char *)data)) {
+
+               ret = aul_terminate_pid_without_restart(ainfo->pid);
+               retvm_if(ret < 0, -1, "aul_terminate_pid[%d] fail\n", ret);
+
+               int i = 0;
+               for (i = 0; i < 50; i++) {
+                       if (aul_app_is_running(ainfo->appid))
+                               usleep(100 * 1000); /* 100ms sleep*/
+                       else
+                               break;
+               }
+       }
+
+    return 0;
+}
+
+static int __terminate_running_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+       retvm_if(handle == NULL, -1, "handle is null\n");
+
+       int ret = 0;
+       char *appid = NULL;
+
+       ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+       retvm_if(ret < 0, -1, "get_appid fail\n");
+
+       if (aul_app_is_running(appid)) {
+           ret = aul_app_get_running_app_info(__terminate_app, appid);
+               retvm_if(ret < 0, -1, "terminate_app[%s] fail\n", appid);
+       }
+
+       return 0;
+}
+
+int __terminate_running_app(const char *pkgid)
+{
+       int ret = 0;
+       pkgmgrinfo_pkginfo_h handle = NULL;
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       if (ret == 0) {
+               ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __terminate_running_app_cb, NULL);
+               if (ret < 0) {
+                       _LOGE("pkgmgrinfo_appinfo_get_list() failed\n");
+               }
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       }
+       return 0;
+}
+
+static int __iter_cb(const aul_app_info *ainfo, void *data)
+{
+       pm_appinfo *pmappinfo = (pm_appinfo *)data;
+       int pgid;
+
+       if (strcmp(ainfo->app_path, pmappinfo->apppath) == 0) {
+               _LOGD("terminate app apppath[%s], pid[%d]\n", ainfo->app_path, ainfo->pid);
+               if (pmappinfo->option == 0) {
+                       pmappinfo->pid  = ainfo->pid;
+                       return ainfo->pid;
+               }
+
+               pgid = getpgid(ainfo->pid);
+               if (pgid <= 1) {
+                       return -1;
+               }
+               if (killpg(pgid, SIGKILL) < 0) {
+                       return -1;
+               }
+               pmappinfo->pid  = ainfo->pid;
+               return ainfo->pid;
+       }
+
+       return 0;
+}
+
+static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath,
+               const char *zone, int option)
+{
+       int ret;
+
+       pm_appinfo pmappinfo;
+       pmappinfo.apppath = apppath;
+       pmappinfo.option = option;
+
+       ret = aul_app_get_running_app_info(__iter_cb, &pmappinfo);
+       if (ret < 0)
+               return 0;
+
+       return pmappinfo.pid;
+}
+
+static void __make_pid_info_file(char *req_key, int size, int is_zone)
+{
+       int ret = 0;
+       FILE* file = NULL;
+       int fd = 0;
+       char buf[MAX_PKG_TYPE_LEN] = {0};
+       const char* app_info_label = "*";
+       char info_file[PATH_MAX] = {'\0'};
+       char *cano_path = NULL;
+
+       if(req_key == NULL)
+               return;
+
+       snprintf(info_file, PATH_MAX, "tmp/%s", req_key);
+       if (is_zone) {
+               ret = vsm_canonicalize_path(info_file, &cano_path);
+               if (ret < 0) {
+                       _LOGE("vsm canonicalize path error(%d)", ret);
+                       return;
+               }
+               if (cano_path == NULL) {
+                       _LOGE("cano_path is NULL");
+                       return;
+               }
+       }
+
+       if (!cano_path) {
+               cano_path = strdup(info_file);
+               if (!cano_path) {
+                       _LOGE("strdup failed");
+                       return;
+               }
+       }
+
+       _LOGD("cano_path(%s)", cano_path);
+       file = fopen(cano_path, "w");
+       if (file == NULL) {
+               _LOGE("Couldn't open the file(%s)", cano_path);
+               goto out;
+       }
+
+       snprintf(buf, MAX_PKG_TYPE_LEN, "%d\n", size);
+       fwrite(buf, 1, strlen(buf), file);
+
+       fflush(file);
+       fd = fileno(file);
+       fsync(fd);
+       fclose(file);
+
+       if (security_server_label_access(info_file, app_info_label) != 0) {
+               _LOGE("error(%d) in setting smack label", errno);
+               goto out;
+       } else {
+               _LOGD("security_server_label_access(%s, %s) is ok.", info_file, app_info_label);
+       }
+
+       ret = chmod(cano_path, 0777);
+       if(ret < 0)
+               goto out;
+
+       ret = chown(cano_path, 5000, 5000);
+       if(ret < 0)
+               goto out;
+
+out:
+       if (cano_path)
+               free(cano_path);
+}
+
+static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+       char *pkgid = NULL;
+       char *exec = NULL;
+       int ret = 0;
+       int pid = -1;
+
+       struct vsm_context *ctx = NULL;
+       vsm_zone_h effective_zone, real_zone;
+
+       if (handle == NULL) {
+               perror("appinfo handle is NULL");
+               exit(1);
+       }
+       ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
+       if (ret) {
+               perror("Failed to get app exec path");
+               exit(1);
+       }
+       ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
+       if (ret) {
+               perror("Failed to get appid");
+               exit(1);
+       }
+
+       if (!user_data) {
+               _LOGE("user_data is NULL");
+               return 0;
+       }
+
+       checkapp_data_s *kc_data = (checkapp_data_s *)user_data;
+       char *sub_cmd = kc_data->sub_cmd;
+       char *zone_name = kc_data->zone_name;
+       int is_zone = 0;
+
+       if (zone_name && strlen(zone_name) && strcmp(zone_name, ZONE_HOST) != 0) {
+               is_zone = 1;
+       }
+
+       dbg("sub_cmd(%s), zone_name(%s)", sub_cmd, zone_name);
+
+       if (is_zone) {
+               ctx = vsm_create_context();
+               if (!ctx) {
+                       _LOGE("failed to create vsm context");
+                       return -1;
+               }
+               effective_zone = vsm_lookup_zone_by_name(ctx, zone_name);
+               real_zone = vsm_join_zone(effective_zone);
+       }
+
+       if (strcmp(sub_cmd, "kill") == 0)
+               pid = __terminate_running_app(pkgid);
+       else if (strcmp(sub_cmd, "check") == 0)
+               pid = __pkgcmd_proc_iter_kill_cmdline(exec, zone_name, 0);
+
+       __make_pid_info_file(pkgid, pid ,is_zone);
+
+       if (is_zone) {
+               vsm_join_zone(real_zone);
+               vsm_cleanup_context(ctx);
+       }
+
+       return 0;
+}
+
+static char *__get_signal_name(char *post_name, const char *pre_name, const char *zone)
+{
+       memset(post_name, 0, MAX_ZONE_NAME_LEN);
+       if (zone && strlen(zone) && strcmp(zone, ZONE_HOST) != 0) {
+               snprintf(post_name, MAX_ZONE_NAME_LEN, "%s_", pre_name);
+               strncat(post_name, zone, MAX_ZONE_NAME_LEN - strlen(post_name) - 1);
+       } else {
+               snprintf(post_name, MAX_ZONE_NAME_LEN, "%s", pre_name);
+       }
+       dbg("signal name : (%s -> %s)", pre_name, post_name);
+
+       return post_name;
+}
+
+void __pm_send_sub_signal(const char *req_id, const char *pkg_type, const char *pkgid,
+               const char *key, const char *val, const char *zone)
+{
+       dbus_uint32_t serial = 0;
+       DBusMessage *msg = NULL;
+       DBusMessageIter args;
+       DBusError err;
+       DBusConnection *conn = NULL;
+       const char *values[] = {
+               req_id,
+               pkg_type,
+               pkgid,
+               key,
+               val
+       };
+       int i;
+
+       dbus_error_init(&err);
+
+       conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+       if (dbus_error_is_set(&err)) {
+               _LOGE("Connection error: %s", err.message);
+               dbus_error_free(&err);
+       }
+       dbus_error_free(&err);
+       if (NULL == conn) {
+               _LOGE("conn is NULL");
+               return;
+       }
+
+       char signal_name[128] = {0, };
+
+       if (strcmp(key,PKGMGR_INSTALLER_START_KEY_STR) == 0) {
+               if (strcmp(val,PKGMGR_INSTALLER_INSTALL_EVENT_STR) == 0) {
+                       msg = dbus_message_new_signal(COMM_STATUS_BROADCAST_DBUS_INSTALL_PATH, COMM_STATUS_BROADCAST_DBUS_INSTALL_INTERFACE,
+                               __get_signal_name(signal_name, COMM_STATUS_BROADCAST_EVENT_INSTALL, zone));
+               } else if (strcmp(val,PKGMGR_INSTALLER_UNINSTALL_EVENT_STR) == 0) {
+                       msg = dbus_message_new_signal(COMM_STATUS_BROADCAST_DBUS_UNINSTALL_PATH, COMM_STATUS_BROADCAST_DBUS_UNINSTALL_INTERFACE,
+                               __get_signal_name(signal_name, COMM_STATUS_BROADCAST_EVENT_UNINSTALL, zone));
+               } else if (strcmp(val,PKGMGR_INSTALLER_UPGRADE_EVENT_STR) == 0) {
+                       msg = dbus_message_new_signal(COMM_STATUS_BROADCAST_DBUS_UPGRADE_PATH, COMM_STATUS_BROADCAST_DBUS_UPGRADE_INTERFACE,
+                               __get_signal_name(signal_name, COMM_STATUS_BROADCAST_EVENT_UPGRADE, zone));
+               }
+       } else if (strcmp(key,PKGMGR_INSTALLER_END_KEY_STR) == 0) {
+               if (strcmp(req_id,PKGMGR_INSTALLER_INSTALL_EVENT_STR) == 0) {
+                       msg = dbus_message_new_signal(COMM_STATUS_BROADCAST_DBUS_INSTALL_PATH, COMM_STATUS_BROADCAST_DBUS_INSTALL_INTERFACE,
+                               __get_signal_name(signal_name, COMM_STATUS_BROADCAST_EVENT_INSTALL, zone));
+               } else if (strcmp(req_id,PKGMGR_INSTALLER_UNINSTALL_EVENT_STR) == 0) {
+                       msg = dbus_message_new_signal(COMM_STATUS_BROADCAST_DBUS_UNINSTALL_PATH, COMM_STATUS_BROADCAST_DBUS_UNINSTALL_INTERFACE,
+                               __get_signal_name(signal_name, COMM_STATUS_BROADCAST_EVENT_UNINSTALL, zone));
+               } else if (strcmp(req_id,PKGMGR_INSTALLER_UPGRADE_EVENT_STR) == 0) {
+                       msg = dbus_message_new_signal(COMM_STATUS_BROADCAST_DBUS_UPGRADE_PATH, COMM_STATUS_BROADCAST_DBUS_UPGRADE_INTERFACE,
+                               __get_signal_name(signal_name, COMM_STATUS_BROADCAST_EVENT_UPGRADE, zone));
+               }
+       }
+       if (NULL == msg) {
+               _LOGE("msg NULL");
+               return;
+       }
+
+       dbus_message_iter_init_append(msg, &args);
+
+       for (i = 0; i < 5; i++) {
+               if (!dbus_message_iter_append_basic
+                   (&args, DBUS_TYPE_STRING, &(values[i]))) {
+                       _LOGE("dbus_message_iter_append_basic failed:"
+                       " Out of memory");
+                       return;
+               }
+       }
+       if (!dbus_connection_send(conn, msg, &serial)) {
+               _LOGE("dbus_connection_send failed: Out of memory");
+               return;
+       }
+       dbus_connection_flush(conn);
+       dbus_message_unref(msg);
+}
+
+void __pm_send_signal(const char *req_id, const char *pkg_type, const char *pkgid,
+               const char *key, const char *val, const char *zone)
+{
+       dbus_uint32_t serial = 0;
+       DBusMessage *msg;
+       DBusMessageIter args;
+       DBusError err;
+       DBusConnection *conn;
+       const char *values[] = {
+               req_id,
+               pkg_type,
+               pkgid,
+               key,
+               val
+       };
+       int i;
+
+       dbus_error_init(&err);
+
+       conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+       if (dbus_error_is_set(&err)) {
+               _LOGE("Connection error: %s", err.message);
+               dbus_error_free(&err);
+       }
+       dbus_error_free(&err);
+       if (NULL == conn) {
+               _LOGE("conn is NULL");
+               return;
+       }
+
+       char signal_name[128] = {0, };
+
+       msg = dbus_message_new_signal(COMM_STATUS_BROADCAST_DBUS_PATH, COMM_STATUS_BROADCAST_DBUS_INTERFACE,
+               __get_signal_name(signal_name, COMM_STATUS_BROADCAST_SIGNAL_STATUS, zone));
+       if (NULL == msg) {
+               _LOGE("msg NULL");
+               return;
+       }
+
+       dbus_message_iter_init_append(msg, &args);
+
+       for (i = 0; i < 5; i++) {
+               if (!dbus_message_iter_append_basic
+                   (&args, DBUS_TYPE_STRING, &(values[i]))) {
+                       _LOGE("dbus_message_iter_append_basic failed: Out of memory");
+                       return;
+               }
+       }
+       if (!dbus_connection_send(conn, msg, &serial)) {
+               _LOGE("dbus_connection_send failed: Out of memory");
+               return;
+       }
+       dbus_connection_flush(conn);
+       dbus_message_unref(msg);
+
+       __pm_send_sub_signal(req_id, pkg_type, pkgid, key, val, zone);
+}
+
+void __change_item_info(pm_dbus_msg *item)
+{
+       int ret = 0;
+       char *pkgid = NULL;
+       pkgmgrinfo_appinfo_h handle = NULL;
+
+       ret = pkgmgrinfo_appinfo_get_appinfo(item->pkgid, &handle);
+       if (ret != PMINFO_R_OK)
+               return;
+
+       ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+               return;
+       }
+
+       memset((item->pkgid),0,MAX_PKG_NAME_LEN);
+       strncpy(item->pkgid, pkgid, sizeof(item->pkgid) - 1);
+
+       pkgmgrinfo_appinfo_destroy_appinfo(handle);
+}
+
+static char **__generate_argv(const char *args)
+{
+       /* Create args vector
+        * req_id + pkgid + args
+        *
+        * vector size = # of args +
+        *(req_id + pkgid + NULL termination = 3)
+        * Last value must be NULL for execv.
+        */
+       gboolean ret_parse;
+       gint argcp;
+       gchar **argvp;
+       GError *gerr = NULL;
+       ret_parse = g_shell_parse_argv(args,
+                                          &argcp, &argvp, &gerr);
+       if (FALSE == ret_parse) {
+               _LOGE("Failed to split args: %s", args);
+               _LOGE("messsage: %s", gerr->message);
+               exit(1);
+       }
+
+       /* Setup argument !!! */
+       /*char **args_vector =
+          calloc(argcp + 4, sizeof(char *)); */
+       char **args_vector = calloc(argcp + 1, sizeof(char *));
+       if (args_vector == NULL)
+       {
+               _LOGE("Out of memory");
+               exit(1);
+       }
+       /*args_vector[0] = strdup(backend_cmd);
+          args_vector[1] = strdup(item->req_id);
+          args_vector[2] = strdup(item->pkgid); */
+       int arg_idx;
+       for (arg_idx = 0; arg_idx < argcp; arg_idx++) {
+               /* args_vector[arg_idx+3] = argvp[arg_idx]; */
+               args_vector[arg_idx] = argvp[arg_idx];
+       }
+
+       /* dbg */
+       /*for(arg_idx = 0; arg_idx < argcp+3; arg_idx++) { */
+       for (arg_idx = 0; arg_idx < argcp + 1; arg_idx++) {
+               _LOGD(">>>>>> args_vector[%d]=%s", arg_idx, args_vector[arg_idx]);
+       }
+
+       return args_vector;
+}
+
+static void __exec_with_arg_vector(const char *cmd, char **argv, const char *zone)
+{
+       char *backend_cmd = strdup(cmd);
+       if (NULL == backend_cmd)
+       {
+               perror("Out of memory");
+               exit(1);
+       }
+
+       _LOGD("Try to exec [%s]", backend_cmd);
+       fprintf(stdout, "Try to exec [%s]\n", backend_cmd);
+
+       /* Execute backend !!! */
+       int ret = 0;
+
+       char **zone_args = NULL;
+       int is_zone = 0;
+
+       if (zone && strlen(zone) && strcmp(zone, ZONE_HOST) != 0) {
+               _LOGD("Try to exec [%s] zone[%s]", backend_cmd, zone);
+               fprintf(stdout, "Try to exec [%s] [%s]\n", backend_cmd, zone);
+
+               is_zone = 1;
+       }
+
+       if (is_zone) {
+               int count = 0;
+               while (NULL != argv) {
+                       if (NULL == argv[count])
+                               break;
+                       const char *arv_str = argv[count];
+                       _LOGD("backend argv[%d] = %s", count, arv_str);
+                       count++;
+               }
+               count++; /* for last NULL argument*/
+
+               _LOGD("backend argv count = %d", count);
+
+               char *zone_cmd = "/usr/bin/lxc-attach";
+               zone_args = calloc(count + 5, sizeof(char *));
+               if (NULL == zone_args) {
+                       _LOGE("out of memory for zone_args");
+                       exit(1);
+               }
+               zone_args[count + 4] = NULL;
+               zone_args[0] = "/usr/bin/lxc-attach";
+               zone_args[1] = "-n";
+               zone_args[2] = (char *)zone;
+               zone_args[3] = "--";
+               zone_args[4] = backend_cmd;
+
+               char cmd_buff[256] = {0, };
+               char tmp_buff[256] = {0, };
+               snprintf(cmd_buff, 256, "%s", backend_cmd);
+               int i;
+               for (i = 0; i < count; i++) {
+                       const char *arv_str = argv[i];
+                       snprintf(tmp_buff, 256, "%s %s", cmd_buff, arv_str);
+                       snprintf(cmd_buff, 256, "%s", tmp_buff);
+                       zone_args[5 + i] = argv[i];
+               }
+               _LOGD("zone cmd_buff = %s", cmd_buff);
+               for (i = 0; i < (count + 5); i++) {
+                       _LOGD("zone_args[%d] = %s", i, zone_args[i]);
+               }
+
+               ret = execv(zone_cmd, zone_args);
+       } else {
+               ret = execv(backend_cmd, argv);
+       }
+
+       /* Code below: exec failure. Should not be happened! */
+       _LOGD(">>>>>> OOPS 2!!!");
+
+       /* g_strfreev(args_vector); *//* FIXME: causes error */
+
+       if (ret == -1) {
+               perror("fail to exec");
+               exit(1);
+       }
+       if (NULL != backend_cmd)
+               free(backend_cmd);
+       if (NULL != zone_args)
+               free(zone_args);
+}
+
+static int __zone_set_activation_info(char *pkgid, int is_active, char *label, const char *zone)
+{
+       char activation_info_file[MAX_PKG_NAME_LEN] = { 0, };
+
+       if (zone && strlen(zone) && strcmp(zone, ZONE_HOST) != 0) {
+               char *rootpath = NULL;
+               rootpath = _zone_get_root_path(zone);
+               if (rootpath == NULL) {
+                       _LOGE("rootpath is null");
+                       return PMINFO_R_ERROR;
+               }
+               snprintf(activation_info_file, MAX_PKG_NAME_LEN, "%s%s/%s", rootpath, PKG_DATA_PATH, pkgid);
+       } else {
+               snprintf(activation_info_file, MAX_PKG_NAME_LEN, "%s/%s", PKG_DATA_PATH, pkgid);
+       }
+
+       if (is_active) {
+               int ret = 0;
+               const char* app_info_label = "_";
+
+               if (security_server_label_access(activation_info_file, app_info_label) != 0) {
+                       _LOGE("error(%d) in setting smack label",errno);
+                       return PMINFO_R_ERROR;
+               }  else {
+                       _LOGD("security_server_label_access(%s, %s) is ok.", activation_info_file, app_info_label);
+               }
+
+               ret = chmod(activation_info_file, 0755);
+               if(ret < 0) {
+                       _LOGE("chmod[%s] fail",activation_info_file);
+                       return PMINFO_R_ERROR;
+               }
+               ret = chown(activation_info_file, 5000, 5000);
+               if(ret < 0) {
+                       _LOGE("chmod[%s] fail",activation_info_file);
+                       return PMINFO_R_ERROR;
+               }
+       } else {
+               (void)remove(activation_info_file);
+       }
+       return PMINFO_R_OK;
+}
+
+gboolean queue_job(void *data)
+{
+       /* _LOGD("queue_job start"); */
+       pm_dbus_msg *item;
+       backend_info *ptr = NULL;
+       ptr = begin;
+       int x = 0;
+       pkgmgrinfo_pkginfo_h handle;
+       char old_zone[MAX_ZONE_NAME_LEN] = {'\0',};
+
+       /* Pop a job from queue */
+pop:
+       if (!__is_backend_busy(pos % num_of_backends)) {
+               item = _pm_queue_pop(pos % num_of_backends);
+               pos = (pos + 1) % num_of_backends;
+       }
+       else {
+               pos = (pos + 1) % num_of_backends;
+               goto pop;
+       }
+
+       int ret = 0;
+       char *backend_cmd = NULL;
+       char **args_vector = NULL;
+
+       /* queue is empty and backend process is not running */
+       if ( (item == NULL) || (item->req_type == -1) ) {
+               if(item)
+                       free(item);
+               goto pop;
+       }
+       __set_backend_busy((pos + num_of_backends - 1) % num_of_backends);
+       __set_recovery_mode(item->pkgid, item->pkg_type, item->zone);
+
+       /* fork */
+       x = (pos + num_of_backends - 1) % num_of_backends;
+       strncpy((ptr + x)->pkgtype, item->pkg_type, MAX_PKG_TYPE_LEN-1);
+       strncpy((ptr + x)->backend_installer, item->backend_installer, MAX_PKG_TYPE_LEN-1);
+       strncpy((ptr + x)->pkgid, item->pkgid, MAX_PKG_PATH_LEN-1);
+       strncpy((ptr + x)->args, item->args, MAX_PKG_ARGS_LEN-1);
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+       strncpy((ptr + x)->tep_path, item->tep_path, MAX_PKG_PATH_LEN-1);
+#endif
+
+       if (strlen(item->zone)) {
+               strncpy((ptr + x)->zone, item->zone, MAX_ZONE_NAME_LEN-1);
+               _LOGD("target zone(%s, %s)", item->zone, (ptr + x)->zone);
+       }
+
+       (ptr + x)->pid = fork();
+       _LOGD("child forked [%d] for request type [%d]", (ptr + x)->pid, item->req_type);
+
+       switch ((ptr + x)->pid) {
+       case 0: /* child */
+               if (strlen(item->zone) && strcmp(item->zone, ZONE_HOST) != 0) {
+                       if (pkgmgrinfo_pkginfo_set_zone(item->zone, old_zone,
+                               sizeof(old_zone)-1) < 0) {
+                               _LOGE("pkgmgrinfo_pkginfo_set_zone failed," \
+                                       "zone(%s)", item->zone);
+                               exit(1);
+                       }
+               }
+
+               switch (item->req_type) {
+               case COMM_REQ_TO_INSTALL:
+                       _LOGD("before run _get_backend_path(%s)", item->backend_installer);
+                       backend_cmd = _get_backend_cmd(item->backend_installer);
+                       if (NULL == backend_cmd) {
+                               backend_cmd = _get_backend_cmd(item->pkg_type);
+
+                               if (NULL == backend_cmd) {
+                                       _LOGE("_get_backend_cmd failed");
+                                       exit(1);
+                               }
+                       }
+
+                       _LOGD("Try to exec [%s][%s]", item->pkg_type, backend_cmd);
+                       fprintf(stdout, "Try to exec [%s][%s]\n", item->pkg_type, backend_cmd);
+
+                       args_vector = __generate_argv(item->args);
+                       args_vector[0] = backend_cmd;
+
+                       /* Execute backend !!! */
+                       __exec_with_arg_vector(backend_cmd, args_vector, item->zone);
+                       free(backend_cmd);
+                       break;
+               case COMM_REQ_TO_UNINSTALL:
+                       args_vector = __generate_argv(item->args);
+
+                       _LOGD("Try to exec [%s][%s]", item->pkg_type, args_vector[0]);
+                       fprintf(stdout, "Try to exec [%s][%s]\n", item->pkg_type, args_vector[0]);
+
+                       /* Execute backend !!! */
+                       __exec_with_arg_vector(args_vector[0], args_vector, item->zone);
+               case COMM_REQ_ACTIVATE_PKG:
+                       _LOGE("ACTIVATE_PKG start [pkgid = %s]",item->pkgid);
+
+                       __pm_send_signal(PKGMGR_INSTALLER_INSTALL_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_INSTALL_EVENT_STR, item->zone);
+
+                       ret = zone_pkgmgr_parser_enable_pkg(item->pkgid, NULL, item->zone);
+                       if (ret < 0) {
+                               __pm_send_signal(PKGMGR_INSTALLER_INSTALL_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->zone);
+                               _LOGE("COMM_REQ_TO_ACTIVATOR failed");
+                               exit(1);
+                       }
+                       __pm_send_signal(PKGMGR_INSTALLER_INSTALL_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, item->zone);
+
+                       _LOGE("ACTIVATE_PKG end [pkgid = %s, ret = %d]",item->pkgid, ret);
+                       break;
+               case COMM_REQ_DEACTIVATE_PKG:
+                       _LOGE("DEACTIVATE_PKG start [pkgid = %s]",item->pkgid);
+
+                       __terminate_running_app(item->pkgid);
+
+                       __pm_send_signal(PKGMGR_INSTALLER_UNINSTALL_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_UNINSTALL_EVENT_STR, item->zone);
+
+                       /*listener need 100ms sleep to get pkginfo */
+                       usleep(100 * 1000);
+                       ret = zone_pkgmgr_parser_disable_pkg(item->pkgid, NULL, item->zone);
+                       if (ret < 0) {
+                               __pm_send_signal(PKGMGR_INSTALLER_UNINSTALL_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->zone);
+                               _LOGE("COMM_REQ_DEACTIVATE_PKG failed");
+                               exit(1);
+                       }
+                       __pm_send_signal(PKGMGR_INSTALLER_UNINSTALL_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, item->zone);
+
+                       _LOGE("DEACTIVATE_PKG end [pkgid = %s, ret = %d]",item->pkgid, ret);
+                       break;
+               case COMM_REQ_ACTIVATE_APP:
+                       _LOGE("ACTIVATE_APP [appid = %s]",item->pkgid);
+
+                       ret = __zone_set_activation_info(item->pkgid, 1, NULL, item->zone);
+
+                       __change_item_info(item);
+
+                       __pm_send_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->zone);
+                       if (ret != PMINFO_R_OK) {
+                               __pm_send_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->zone);
+                               _LOGE("COMM_REQ_ACTIVATE_APP failed");
+                               exit(1);
+                       }
+                       __pm_send_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, item->zone);
+
+                       _LOGE("ACTIVATE_APP end [pkgid = %s, ret = %d]",item->pkgid, ret);
+                       break;
+               case COMM_REQ_DEACTIVATE_APP:
+                       _LOGE("DEACTIVATE_APP [appid = %s]",item->pkgid);
+
+                       ret = __zone_set_activation_info(item->pkgid, 0, NULL, item->zone);
+
+                       __change_item_info(item);
+
+                       __pm_send_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->zone);
+                       if (ret != PMINFO_R_OK) {
+                               __pm_send_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->zone);
+                               _LOGE("COMM_REQ_ACTIVATE_APP failed");
+                               exit(1);
+                       }
+                       __pm_send_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, item->zone);
+
+                       _LOGE("DEACTIVATE_APP end [pkgid = %s, ret = %d]",item->pkgid, ret);
+                       break;
+               case COMM_REQ_ENABLE_BG_OPERATION:
+                       ret = zone_pkgmgr_parser_set_app_background_operation(item->pkgid, FALSE, item->zone);
+
+                       __change_item_info(item);
+
+                       __pm_send_sub_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->zone);
+                       if (ret != PMINFO_R_OK) {
+                               __pm_send_sub_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->zone);
+                               _LOGE("COMM_REQ_ENABLE_BG_OPERATION failed");
+                               exit(1);
+                       }
+                       __pm_send_sub_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, item->zone);
+
+                       break;
+               case COMM_REQ_DISABLE_BG_OPERATION:
+                       ret = zone_pkgmgr_parser_set_app_background_operation(item->pkgid, TRUE, item->zone);
+
+                       __change_item_info(item);
+
+                       __pm_send_sub_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->zone);
+                       if (ret != PMINFO_R_OK) {
+                               __pm_send_sub_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->zone);
+                               _LOGE("COMM_REQ_DISABLE_BG_OPERATION failed");
+                               exit(1);
+                       }
+                       __pm_send_sub_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, item->zone);
+
+                       break;
+               case COMM_REQ_ACTIVATE_APP_WITH_LABEL:
+                       _LOGE("ACTIVATE_APP_WITH_LABEL [appid = %s, label = %s]",item->pkgid, item->args);
+
+                       __zone_set_activation_info(item->pkgid, 1, item->args, item->zone);
+
+                       __change_item_info(item);
+
+                       __pm_send_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->zone);
+                       if (ret != PMINFO_R_OK) {
+                               __pm_send_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->zone);
+                               _LOGE("COMM_REQ_TO_ACTIVATOR failed");
+                               exit(1);
+                       }
+                       __pm_send_signal(PKGMGR_INSTALLER_UPGRADE_EVENT_STR, item->pkg_type, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, item->zone);
+
+                       _LOGE("ACTIVATE_APP_WITH_LABEL end [pkgid = %s, ret = %d]",item->pkgid, ret);
+                       break;
+               case COMM_REQ_TO_MOVER:
+               case COMM_REQ_TO_CLEARER:
+                       args_vector = __generate_argv(item->args);
+
+                       _LOGD("Try to exec [%s][%s]", item->pkg_type, args_vector[0]);
+                       fprintf(stdout, "Try to exec [%s][%s]\n", item->pkg_type, args_vector[0]);
+
+                       /* Execute backend !!! */
+                       __exec_with_arg_vector(args_vector[0], args_vector, item->zone);
+                       break;
+               case COMM_REQ_GET_SIZE:
+                       __exec_with_arg_vector("usr/bin/pkg_getsize", __generate_argv(item->args), item->zone);
+                       break;
+
+               case COMM_REQ_KILL_APP:
+               case COMM_REQ_CHECK_APP:
+                       _LOGD("kill/check request");
+
+                       checkapp_data_s kc_data = {NULL, NULL};
+                       char *sub_cmd = NULL;
+                       void *checkapp_user_data = NULL;
+
+                       ret = pkgmgrinfo_pkginfo_get_pkginfo(item->pkgid, &handle);
+                       if (ret < 0) {
+                               _LOGE("Failed to get handle");
+                               exit(1);
+                       }
+                       if (item->req_type == COMM_REQ_KILL_APP) {
+                               kc_data.zone_name = item->zone;
+                               kc_data.sub_cmd = strdup("kill");
+                               sub_cmd = kc_data.sub_cmd;
+                               checkapp_user_data = (void *)&kc_data;
+                               if (!sub_cmd) {
+                                       _LOGE("out_of_memory");
+                                       exit(1);
+                               }
+
+                               ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP,
+                                       __pkgcmd_app_cb, checkapp_user_data);
+                               if (ret < 0) {
+                                       _LOGE("pkgmgrinfo_appinfo_get_list() failed");
+                                       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+                                       free(sub_cmd);
+                                       exit(1);
+                               }
+                       } else if (item->req_type == COMM_REQ_CHECK_APP) {
+                               kc_data.zone_name = item->zone;
+                               kc_data.sub_cmd = strdup("check");
+                               sub_cmd = kc_data.sub_cmd;
+                               checkapp_user_data = (void *)&kc_data;
+                               if (!sub_cmd) {
+                                       _LOGE("out_of_memory");
+                                       exit(1);
+                               }
+
+                               ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP,
+                                       __pkgcmd_app_cb, checkapp_user_data);
+                               if (ret < 0) {
+                                       _LOGE("pkgmgrinfo_appinfo_get_list() failed");
+                                       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+                                       free(sub_cmd);
+                                       exit(1);
+                               }
+                       }
+                       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+                       break;
+
+               case COMM_REQ_CLEAR_CACHE_DIR:
+                       __exec_with_arg_vector("/usr/bin/pkg_clearcache", __generate_argv(item->pkgid), item->zone);
+                       break;
+
+               case COMM_REQ_MAKE_EXTERNAL_DIR:
+                       __exec_with_arg_vector("/usr/bin/pkg_mkext", NULL, item->zone);
+                       break;
+               }
+               /* exit child */
+               exit(0);
+               break;
+
+       case -1:        /* error */
+               fprintf(stderr, "Fail to execute fork()\n");
+               exit(1);
+               break;
+
+       default:        /* parent */
+               _LOGD("parent exit");
+               break;
+       }
+
+       free(item);
+
+       return FALSE;
+}
+
+void _app_str_trim(char *input)
+{
+       char *trim_str = input;
+
+       if (input == NULL)
+               return;
+
+       while (*input != 0) {
+               if (!IS_WHITESPACE(*input)) {
+                       *trim_str = *input;
+                       trim_str++;
+               }
+               input++;
+       }
+
+       *trim_str = 0;
+       return;
+}
+
+char *_get_backend_cmd(char *type)
+{
+       FILE *fp = NULL;
+       char buffer[1024] = { 0 };
+       char *command = NULL;
+       int size = 0;
+       fp = fopen(PKG_CONF_PATH, "r");
+       if (fp == NULL) {
+               return NULL;
+       }
+
+       char *path = NULL;
+       while (fgets(buffer, 1024, fp) != NULL) {
+               if (buffer[0] == '#')
+                       continue;
+
+               _app_str_trim(buffer);
+
+               if ((path = strstr(buffer, PKG_BACKEND)) != NULL) {
+//                     _LOGD("buffer [%s]", buffer);
+                       path = path + strlen(PKG_BACKEND);
+//                     _LOGD("path [%s]", path);
+
+                       command = (char *)malloc(sizeof(char) * strlen(path) + strlen(type) + 1);
+                       if (command == NULL) {
+                               fclose(fp);
+                               _LOGE("command is null for [path=%s, type=%s]", path, type);
+                               return NULL;
+                       }
+
+                       size = strlen(path) + strlen(type) + 1;
+                       snprintf(command, size, "%s%s", path, type);
+                       command[strlen(path) + strlen(type)] = '\0';
+//                     _LOGD("command [%s]", command);
+
+                       if (fp != NULL)
+                               fclose(fp);
+
+                       return command;
+               }
+
+               memset(buffer, 0x00, 1024);
+       }
+
+       if (fp != NULL)
+               fclose(fp);
+
+       return NULL;            /* cannot find proper command */
+}
+
+int main(int argc, char *argv[])
+{
+       backend_info *ptr = NULL;
+       int r;
+
+       _LOGE("package manager server start");
+
+       r = _pm_queue_init();
+       if (r) {
+               _LOGE("Queue Initialization Failed\n");
+               return -1;
+       }
+
+       /*Allocate memory for holding pid, pkgtype and pkgid*/
+       ptr = (backend_info*)calloc(num_of_backends, sizeof(backend_info));
+       if (ptr == NULL) {
+               _LOGD("Malloc Failed\n");
+               return -1;
+       }
+       memset(ptr, '\0', num_of_backends * sizeof(backend_info));
+       begin = ptr;
+
+#if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36)
+       g_type_init();
+#endif
+       mainloop = g_main_loop_new(NULL, FALSE);
+       if (!mainloop){
+               _LOGE("g_main_loop_new failed\n");
+               return -1;
+       }
+
+       pkgmgr_server_gdbus_h pkg_mgr;
+       r = pkg_mgr_server_gdbus_init(&pkg_mgr);
+       if (r) {
+               _LOGE("gdbus_init failed\n");
+               return -1;
+       }
+
+       // register callback
+       pkg_mgr_set_request_callback(pkg_mgr, req_cb, NULL);
+
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+       pkg_mgr_set_request_tep_callback(pkg_mgr, req_tep_cb, NULL);
+#endif
+
+       pkg_mgr_set_callback_to_create_directory(pkg_mgr, create_external_dir_cb);
+#ifdef _APPFW_FEATURE_DRM_ENABLE
+       pkg_mgr_set_drm_generate_license_request_callback(pkg_mgr, gen_license_req_cb);
+       pkg_mgr_set_drm_register_license_callback(pkg_mgr, reg_license_cb);
+       pkg_mgr_set_drm_decrypt_package_callback(pkg_mgr, decrypt_pkg_cb);
+#endif
+
+       g_main_loop_run(mainloop);
+       _pm_queue_final();
+       /*Free backend info */
+       if (begin) {
+               free(begin);
+               begin = NULL;
+       }
+       pkg_mgr_server_gdbus_fini(pkg_mgr);
+
+       _LOGE("package manager server terminated.");
+
+       return 0;
+}
diff --git a/src/pm-queue.c b/src/pm-queue.c
new file mode 100755 (executable)
index 0000000..a778c2b
--- /dev/null
@@ -0,0 +1,535 @@
+/*
+ * slp-pkgmgr
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "pkgmgr-server.h"
+#include "pm-queue.h"
+
+#define BACKEND_INFO_DIR       "/usr/etc/package-manager/backend"
+
+static pm_queue_data *__get_head_from_pkgtype(pm_dbus_msg *item);
+static void __update_head_from_pkgtype(pm_queue_data *data);
+static int __entry_exist(char *backend);
+static int __is_pkg_supported(char *pkgtype);
+
+queue_info_map *start = NULL;
+int entries = 0;
+int slot = 0;
+int num_of_backends = 0;
+
+/*Function to check whether a particular package type
+is supported or not. It parses the queue info map
+to get the information.
+It will prevent the accidental hanging of server.
+Returns 1 if found.*/
+static int __is_pkg_supported(char *pkgtype)
+{
+       queue_info_map *ptr = NULL;
+       ptr = start;
+       int i = 0;
+
+       for(i = 0; i < entries; i++)
+       {
+               if (!strncmp(ptr->pkgtype, pkgtype, MAX_PKG_TYPE_LEN))
+                       return 1;
+               else {
+                       ptr++;
+                       continue;
+               }
+       }
+       return 0;
+}
+
+/*tells whether a particular backend exists in the
+* info map or not.
+* on Success it return the queue slot of the already present entry
+* on Failure -1 is returned*/
+static int __entry_exist(char *backend)
+{
+       queue_info_map *ptr = NULL;
+       ptr = start;
+       int i = 0;
+       for(i = 0; i < entries; i++)
+       {
+               if (!strncmp(ptr->backend, backend, MAX_PKG_NAME_LEN))
+                       return ptr->queue_slot;
+               else {
+                       ptr++;
+                       continue;
+               }
+       }
+       return -1;
+}
+
+/*In case of first push, it updates the queue head
+and copies it to all duplicate entries in queue info map*/
+static void __update_head_from_pkgtype(pm_queue_data *data)
+{
+       queue_info_map *ptr = NULL;
+       ptr = start;
+       int slot = -1;
+       int i = 0;
+       for(i = 0; i < entries; i++)
+       {
+               if (!strncmp(ptr->pkgtype, data->msg->pkg_type, MAX_PKG_TYPE_LEN)) {
+                       ptr->head = data;
+                       slot = ptr->queue_slot;
+               }
+               else {
+                       ptr++;
+                       continue;
+               }
+       }
+       /*update head for each duplicate entry*/
+       ptr = start;
+       for(i = 0; i < entries; i++)
+       {
+               if(ptr->queue_slot == slot && !ptr->head) {
+                       ptr->head = data;
+               }
+               ptr++;
+       }
+       return;
+}
+
+/*Gets the queue head based on pkg type*/
+static pm_queue_data *__get_head_from_pkgtype(pm_dbus_msg *item)
+{
+       queue_info_map *ptr = NULL;
+       ptr = start;
+       int i = 0;
+       for(i = 0; i < entries; i++)
+       {
+               if (!strncmp(ptr->pkgtype, item->pkg_type, MAX_PKG_TYPE_LEN))
+                       return ptr->head;
+               else {
+                       ptr++;
+                       continue;
+               }
+       }
+       return NULL;
+
+}
+
+int _pm_queue_init()
+{
+       /*Find the num of backends currently supported and initialize
+       that many queues. It is dynamically determined.*/
+       struct dirent **namelist;
+       struct stat fileinfo;
+       queue_info_map *ptr = NULL;
+       int n = 0;
+       int c = 0;
+       int i = 0;
+       int ret = 0;
+       char abs_filename[MAX_PKG_NAME_LEN] = {'\0'};
+       char buf[MAX_PKG_NAME_LEN] = {'\0'};
+       n = scandir(BACKEND_INFO_DIR, &namelist, NULL, alphasort);
+       if (n < 0) {
+               perror("scandir");
+               return -1;
+       }
+       i = n;
+       /*Find number of backends (symlinks + executables)
+       The /usr/etc/package-manager/backend dir should not conatin
+       any other file except the backends.*/
+       while(n--)
+       {
+               if(!strcmp(namelist[n]->d_name, ".") ||
+                       !strcmp(namelist[n]->d_name, ".."))
+                               continue;
+               snprintf(abs_filename, MAX_PKG_NAME_LEN, "%s/%s",
+                       BACKEND_INFO_DIR, namelist[n]->d_name);
+               if (lstat(abs_filename, &fileinfo)) {
+                       perror("lstat");
+                       continue;
+               }
+               if (S_ISDIR(fileinfo.st_mode))
+                       continue;
+               c++;
+               memset(abs_filename, 0x00, MAX_PKG_NAME_LEN);
+       }
+       /*Add entries to info map.*/
+       ptr = (queue_info_map*)calloc(c , sizeof(queue_info_map));
+       if(ptr == NULL){
+               fprintf(stderr,"calloc failed!!");
+               n = i;
+               while(n--){
+                       if(namelist[n]){
+                               free(namelist[n]);
+                               namelist[n] = NULL;
+                       }
+               }
+               if(namelist){
+                       free(namelist);
+                       namelist = NULL;
+               }
+               return -1;
+       }
+       memset(ptr, '\0', c * sizeof(queue_info_map));
+       start = ptr;
+       for(n = 0; n < c ; n++)
+       {
+               ptr->backend[0] = '\0';
+               ptr->head = NULL;
+               ptr->queue_slot = -2;/*-1 can be error return*/
+               ptr->pkgtype[0] = '\0';
+               ptr++;
+       }
+       n = i;
+       ptr = start;
+       while(n--)
+       {
+               if(!strcmp(namelist[n]->d_name, ".") ||
+                       !strcmp(namelist[n]->d_name, ".."))
+               {
+                       free(namelist[n]);
+                       continue;
+               }
+               snprintf(abs_filename, MAX_PKG_NAME_LEN, "%s/%s",
+                       BACKEND_INFO_DIR, namelist[n]->d_name);
+               if (lstat(abs_filename, &fileinfo) < 0) {
+                       perror(abs_filename);
+                       free(namelist);
+                       return -1;
+               }
+               if (S_ISDIR(fileinfo.st_mode))
+               {
+                       free(namelist[n]);
+                       continue;
+               }
+               /*Found backend*/
+               if (S_ISLNK(fileinfo.st_mode)) {
+                       /*found a symlink*/
+                       ret = readlink(abs_filename, buf, MAX_PKG_NAME_LEN - 1);
+                       if (ret == -1) {
+                               perror("readlink");
+                               free(namelist);
+                               return -1;
+                       }
+                       buf[ret] = '\0';
+               }
+               /*executable*/
+               else {
+                       strncpy(buf, abs_filename, MAX_PKG_NAME_LEN - 1);
+               }
+               ret = __entry_exist(buf);
+               if (ret == -1) {
+                       strncpy(ptr->backend, buf, MAX_PKG_NAME_LEN - 1);
+                       if (!strcmp(namelist[n]->d_name, "coretpk")) {
+                               strncpy(ptr->pkgtype, "tpk", MAX_PKG_TYPE_LEN - 1);
+                       } else {
+                               strncpy(ptr->pkgtype, namelist[n]->d_name, MAX_PKG_TYPE_LEN - 1);
+                       }
+                       ptr->queue_slot = slot;
+                       ptr->head = NULL;
+                       entries++;
+                       slot++;
+                       ptr++;
+               }
+               else {
+                       strncpy(ptr->backend, buf, MAX_PKG_NAME_LEN - 1);
+                       if (!strcmp(namelist[n]->d_name, "coretpk")) {
+                               strncpy(ptr->pkgtype, "tpk", MAX_PKG_TYPE_LEN - 1);
+                       } else {
+                               strncpy(ptr->pkgtype, namelist[n]->d_name, MAX_PKG_TYPE_LEN - 1);
+                       }
+                       ptr->queue_slot = ret;
+                       ptr->head = NULL;
+                       entries++;
+                       ptr++;
+               }
+               free(namelist[n]);
+               memset(buf, 0x00, MAX_PKG_NAME_LEN);
+               continue;
+       }
+       free(namelist);
+       num_of_backends = slot;
+#ifdef DEBUG_INFO
+       /*Debug info*/
+       printf("Queue Info Map\n");
+       printf("Number of Backends is %d\n", num_of_backends);
+       printf("Number of Entries is %d\n", entries);
+       printf("Backend\tType\tSlot\tHead\n");
+       ptr = start;
+       for(n = 0; n < entries; n++)
+       {
+               printf("%s\t%s\t%d\t%p\n", ptr->backend, ptr->pkgtype, ptr->queue_slot, ptr->head);
+               ptr++;
+       }
+#endif
+       return 0;
+}
+
+int _pm_queue_push(pm_dbus_msg *item)
+{
+       pm_queue_data *data = NULL;
+       pm_queue_data *cur = NULL;
+       pm_queue_data *tmp = NULL;
+       int ret = 0;
+       ret = __is_pkg_supported(item->pkg_type);
+       if (ret == 0)
+               return -1;
+
+       cur = __get_head_from_pkgtype(item);
+       tmp = cur;
+
+       data = _add_node();
+       if (!data) {            /* fail to allocate mem */
+               fprintf(stderr, "Fail to allocate memory\n");
+               return -2;
+       }
+
+       strncpy(data->msg->req_id, item->req_id, sizeof(data->msg->req_id) - 1);
+       data->msg->req_type = item->req_type;
+       strncpy(data->msg->pkg_type, item->pkg_type, sizeof(data->msg->pkg_type) - 1);
+       strncpy(data->msg->backend_installer, item->backend_installer, sizeof(data->msg->backend_installer) - 1);
+       strncpy(data->msg->pkgid, item->pkgid, sizeof(data->msg->pkgid) - 1);
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+       strncpy(data->msg->tep_path, item->tep_path, sizeof(data->msg->tep_path) - 1);
+#endif
+       strncpy(data->msg->args, item->args, sizeof(data->msg->args) - 1);
+       strncpy(data->msg->cookie, item->cookie, sizeof(data->msg->cookie) - 1);
+       strncpy(data->msg->zone, item->zone, sizeof(data->msg->zone) - 1);
+
+       data->next = NULL;
+
+       if (cur == NULL) {
+               /* first push */
+               cur = data;
+               __update_head_from_pkgtype(data);
+       }
+       else {
+               while (tmp->next)
+                       tmp = tmp->next;
+
+               tmp->next = data;
+       }
+       return 0;
+}
+
+/*pop request from queue slot "position" */
+pm_dbus_msg *_pm_queue_pop(int position)
+{
+       pm_dbus_msg *ret;
+       pm_queue_data *cur = NULL;
+       pm_queue_data *saveptr = NULL;
+       queue_info_map *ptr = start;
+       int i = 0;
+
+       ret = (pm_dbus_msg *) malloc(sizeof(pm_dbus_msg));
+       if (!ret) {
+               fprintf(stderr, "Mem alloc error\n");
+               return NULL;
+       }
+       memset(ret, 0x00, sizeof(pm_dbus_msg));
+
+       for(i = 0; i < entries; i++)
+       {
+               if (ptr->queue_slot == position) {
+                               cur = ptr->head;
+                               break;
+               }
+               ptr++;
+       }
+
+       if (!cur) {             /* queue is empty */
+               ret->req_type = -1;
+               return ret;
+       }
+
+       strncpy(ret->req_id, cur->msg->req_id, sizeof(ret->req_id) - 1);
+       ret->req_type = cur->msg->req_type;
+       strncpy(ret->pkg_type, cur->msg->pkg_type, sizeof(ret->pkg_type) - 1);
+       strncpy(ret->backend_installer, cur->msg->backend_installer, sizeof(ret->backend_installer) - 1);
+       strncpy(ret->pkgid, cur->msg->pkgid, sizeof(ret->pkgid) - 1);
+       strncpy(ret->args, cur->msg->args, sizeof(ret->args) - 1);
+       strncpy(ret->cookie, cur->msg->cookie, sizeof(ret->cookie) - 1);
+#ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
+       strncpy(ret->tep_path, cur->msg->tep_path, strlen(cur->msg->tep_path));
+#endif
+
+       if (cur->msg->zone[0] != '\0')
+               strncpy(ret->zone, cur->msg->zone, sizeof(ret->zone) - 1);
+
+       ptr->head = cur->next;
+       saveptr = ptr->head;
+       cur->next = NULL;
+       free(cur->msg);
+       free(cur);
+       /*update head for each duplicate queue entry*/
+       ptr = start;
+       for(i = 0; i < entries; i++)
+       {
+               if(ptr->queue_slot == position) {
+                       ptr->head = saveptr;
+               }
+               ptr++;
+       }
+       return ret;
+}
+
+/*populate an array of all queue heads and delete them one by one*/
+void _pm_queue_final()
+{
+       int c = 0;
+       int i = 0;
+       int slot = -1;
+       pm_queue_data *cur = NULL;
+       pm_queue_data *tail = NULL;
+       pm_queue_data *prev = NULL;
+       pm_queue_data *head[MAX_QUEUE_NUM] = {NULL,};
+       queue_info_map *ptr = NULL;
+       ptr = start;
+
+       for(i = 0; i < num_of_backends; i++)
+       {
+               head[i] = NULL;
+       }
+
+       for(i = 0; i < entries; i++)
+       {
+               if (ptr->queue_slot <= slot) {
+                       ptr++;
+                       continue;
+               }
+               else {
+                       head[c] = ptr->head;
+                       slot = ptr->queue_slot;
+                       c++;
+                       ptr++;
+               }
+       }
+
+       c = 0;
+       while(c < num_of_backends) {
+               if (!head[c]) {         /* in case of head is NULL */
+                       fprintf(stderr, "queue is NULL\n");
+                       c = c + 1;
+                       continue;
+               }
+
+               while (head[c]->next) {
+                       cur = head[c]->next;
+
+                       while (cur->next) {
+                               prev = cur;
+                               cur = cur->next;
+                       }
+
+                       tail = cur;
+
+                       free(tail->msg);
+                       free(tail);
+                       prev->next = NULL;
+               }
+
+               free(head[c]->msg);
+               free(head[c]);
+
+               head[c] = NULL;
+               c = c + 1;
+       }
+       /*Free the info map*/
+       if (start) {
+               free(start);
+               start = NULL;
+       }
+}
+
+pm_queue_data *_add_node()
+{
+       pm_queue_data *newnode = NULL;
+
+       newnode = (pm_queue_data *) malloc(sizeof(pm_queue_data));
+       if (!newnode) {         /* if NULL */
+               fprintf(stderr, "Mem alloc error\n");
+               return NULL;
+       }
+       memset(newnode, 0x00, sizeof(pm_queue_data));
+
+       newnode->msg = (pm_dbus_msg *) malloc(sizeof(pm_dbus_msg));
+       if (!newnode->msg) {
+               fprintf(stderr, "Mem alloc error\n");
+               free(newnode);
+               return NULL;
+       }
+       memset(newnode->msg, 0x00, sizeof(pm_dbus_msg));
+
+       return newnode;
+}
+
+void _pm_queue_delete(pm_dbus_msg *item)
+{
+       /* Assume that pacakge name is unique */
+       pm_queue_data *cur = NULL;
+       pm_queue_data *prev = NULL;
+       cur = __get_head_from_pkgtype(item);
+       prev = cur;
+       if (cur) {
+               while (cur->next) {
+                       if (!strcmp(item->pkgid, cur->msg->pkgid)) {
+                               prev->next = cur->next;
+                               free(cur->msg);
+                               free(cur);
+                               break;
+                       }
+                       prev = cur;
+                       cur = cur->next;
+               }
+       }
+}
+
+void _print_queue(int position)
+{
+       pm_queue_data *cur = NULL;
+       queue_info_map *ptr = start;
+       int i = 0;
+       for(i =0; i < entries; i++)
+       {
+               if (ptr->queue_slot == position) {
+                               cur = ptr->head;
+                               break;
+               }
+               ptr++;
+       }
+       int index = 1;
+       if (!cur) {
+               return;
+       }
+
+       while (cur) {
+               index++;
+               cur = cur->next;
+       }
+}