lxcpp: fix cgroup unit tests
[platform/core/security/vasum.git] / server / server.hpp
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Jan Olszak (j.olszak@samsung.com)
5  *
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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
17  */
18
19 /**
20  * @file
21  * @author  Jan Olszak (j.olszak@samsung.com)
22  * @brief   Server class declaration
23  */
24
25
26 #ifndef SERVER_SERVER_HPP
27 #define SERVER_SERVER_HPP
28
29 #include "zones-manager.hpp"
30
31 #include "utils/latch.hpp"
32 #include "utils/signalfd.hpp"
33 #include "utils/glib-loop.hpp"
34 #include "ipc/epoll/event-poll.hpp"
35
36 #include <atomic>
37 #include <string>
38 #include <pthread.h>
39
40
41 namespace vasum {
42
43
44 class Server {
45 public:
46     Server(const std::string& configPath);
47
48     /**
49      * Starts all the zones and blocks until SIGINT, SIGTERM or SIGUSR1
50      */
51     void run(bool asRoot);
52
53     /**
54      * Reload the server by launching execve on itself if SIGUSR1 was sent to server.
55      */
56     void reloadIfRequired(char* argv[]);
57
58     /**
59      * Terminates the server.
60      * Equivalent of sending SIGINT or SIGTERM signal
61      */
62     void terminate();
63
64     /**
65      * Check server runtime environment
66     */
67     static bool checkEnvironment();
68
69 private:
70     bool mIsRunning;
71     bool mIsUpdate;
72     std::string mConfigPath;
73     utils::ScopedGlibLoop loop;
74     ipc::epoll::EventPoll mEventPoll;
75     utils::SignalFD mSignalFD;
76     ZonesManager mZonesManager;
77     ::pthread_t mDispatchingThread;
78
79     /**
80      * Set needed caps, groups and drop root privileges.
81      */
82     static bool prepareEnvironment(const std::string& configPath, bool runAsRoot);
83
84     void handleUpdate();
85     void handleStop();
86
87 };
88
89
90 } // namespace vasum
91
92
93 #endif // SERVER_SERVER_HPP