2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 * @file listener-daemon.cpp
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
20 * @brief Listener daemon handle some events for key-manager
26 #include <package_manager.h>
27 #include <ckm/ckm-control.h>
28 #include <ckm/ckm-type.h>
31 #define CKM_LISTENER_TAG "CKM_LISTENER"
34 const char* const CKM_LOCK = "/var/run/key-manager.pid";
39 int lock = TEMP_FAILURE_RETRY(open(CKM_LOCK, O_RDWR));
43 int ret = lockf(lock, F_TEST, 0);
46 // if lock test fails because of an error assume ckm is running
50 void packageUninstalledEventCallback(
53 package_manager_event_type_e eventType,
54 package_manager_event_state_e eventState,
56 package_manager_error_e error,
64 if (eventType != PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL ||
65 eventState != PACKAGE_MANAGER_EVENT_STATE_STARTED ||
67 SLOG(LOG_DEBUG, CKM_LISTENER_TAG, "PackageUninstalled Callback error of Invalid Param");
70 SLOG(LOG_DEBUG, CKM_LISTENER_TAG, "PackageUninstalled Callback. Uninstalation of: %s", package);
71 auto control = CKM::Control::create();
73 if ( CKM_API_SUCCESS != (ret = control->removeApplicationData(std::string(package))) ) {
74 SLOG(LOG_ERROR, CKM_LISTENER_TAG, "CKM::Control::removeApplicationData error. ret : %d\n", ret);
77 SLOG(LOG_DEBUG, CKM_LISTENER_TAG,
78 "CKM::Control::removeApplicationData success. Uninstallation package : %s\n", package);
85 SLOG(LOG_DEBUG, CKM_LISTENER_TAG, "%s", "Start!");
87 // Let's start to listen
88 GMainLoop *main_loop = g_main_loop_new(NULL, FALSE);
90 package_manager_h manager;
93 if (PACKAGE_MANAGER_ERROR_NONE != package_manager_create(&manager)) {
94 SLOG(LOG_ERROR, CKM_LISTENER_TAG, "%s", "Error in create package_manager");
100 if (PACKAGE_MANAGER_ERROR_NONE != package_manager_set_event_cb(manager, packageUninstalledEventCallback, NULL)) {
101 SLOG(LOG_ERROR, CKM_LISTENER_TAG, "%s", "Error in package_manager_set_event_cb");
102 package_manager_destroy(manager);
111 g_main_loop_run(main_loop);
113 package_manager_destroy(manager);