2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Rafal Krypa <r.krypa@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
19 * @file server-main.cpp
20 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
22 * @brief Implementation of security-manager on basis of security-server
27 #include <dpl/log/log.h>
28 #include <dpl/singleton.h>
29 #include <dpl/singleton_safe_impl.h>
31 #include <socket-manager.h>
32 #include <file-lock.h>
36 IMPLEMENT_SAFE_SINGLETON(SecurityManager::Log::LogSystem);
38 #define REGISTER_SOCKET_SERVICE(manager, service) \
39 registerSocketService<service>(manager, #service)
42 void registerSocketService(SecurityManager::SocketManager &manager, const std::string& serviceName)
48 manager.RegisterSocketService(service);
50 } catch (const SecurityManager::Exception &exception) {
51 LogError("Error in creating service " << serviceName <<
52 ", details:\n" << exception.DumpToString());
53 } catch (const std::exception& e) {
54 LogError("Error in creating service " << serviceName <<
55 ", details:\n" << e.what());
57 LogError("Error in creating service " << serviceName <<
58 ", unknown exception occured");
66 UNHANDLED_EXCEPTION_HANDLER_BEGIN
68 SecurityManager::Singleton<SecurityManager::Log::LogSystem>::Instance().SetTag("SECURITY_MANAGER");
70 SecurityManager::FileLocker serviceLock(SecurityManager::SERVICE_LOCK_FILE,
75 sigaddset(&mask, SIGTERM);
76 sigaddset(&mask, SIGPIPE);
77 if (-1 == pthread_sigmask(SIG_BLOCK, &mask, NULL)) {
78 LogError("Error in pthread_sigmask");
83 SecurityManager::SocketManager manager;
85 REGISTER_SOCKET_SERVICE(manager, SecurityManager::Service);
88 } catch (const SecurityManager::FileLocker::Exception::Base &e) {
89 LogError("Unable to get a file lock. Exiting.");
92 UNHANDLED_EXCEPTION_HANDLER_END