Merge "library: Simplify subsession_event_wait_done() error path" into tizen
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 19 Aug 2022 16:17:56 +0000 (16:17 +0000)
committerGerrit Code Review <gerrit@review>
Fri, 19 Aug 2022 16:17:56 +0000 (16:17 +0000)
packaging/sessiond.spec
sessiond/CMakeLists.txt
sessiond/org.tizen.sessiond.conf
sessiond/src/fs_helpers.cpp
sessiond/src/main.cpp
sessiond/src/wait_manager.hpp

index 9d71c57..54f8e63 100644 (file)
@@ -1,6 +1,6 @@
 Name:       sessiond
 Summary:    Service to manage subsessions
-Version:    0.6.0
+Version:    0.7.1
 Release:    1
 Group:      System/Management
 License:    MIT
index 88111e0..4c134c3 100644 (file)
@@ -1,7 +1,8 @@
 find_package(PkgConfig)
 pkg_check_modules(DEPS REQUIRED IMPORTED_TARGET
-    gio-2.0
-    libsmack
+       gio-2.0
+       libsmack
+       dlog
 )
 
 set(
index ab8a772..35dce3d 100644 (file)
@@ -1,10 +1,22 @@
 <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
  "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
 <busconfig>
+       <policy user="root">
+               <allow own="org.tizen.sessiond"/>
+               <allow send_destination="org.tizen.sessiond"/>
+       </policy>
+       <policy user="system_fw">
+               <allow send_destination="org.tizen.sessiond"/>
+       </policy>
+       <policy user="app_fw">
+               <allow send_destination="org.tizen.sessiond"/>
+       </policy>
+       <policy group="users">
+               <check send_destination="org.tizen.sessiond"
+               privilege="http://tizen.org/privilege/internal/usermanagement"/>
+       </policy>
        <policy context="default">
                <deny own="org.tizen.sessiond"/>
                <deny send_destination="org.tizen.sessiond"/>
-               <allow own="org.tizen.sessiond"/>
-               <allow send_destination="org.tizen.sessiond"/>
     </policy>
 </busconfig>
index 2f8f2d1..35946c4 100644 (file)
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE. */
 
+#undef LOG_TAG
+#define LOG_TAG "SESSIOND"
+#include <dlog.h>
+
 #include <grp.h>
 #include <pwd.h>
 #include <sys/smack.h>
@@ -77,7 +81,7 @@ void fs_helpers::copy_ownership(std::string_view src_path, std::string_view dest
 std::string fs_helpers::get_smack_label(std::string_view src_path, smack_label_type type)
 {
        char *label_raw = nullptr;
-       int ret = smack_getlabel(src_path.data(), &label_raw, type);
+       int ret = smack_lgetlabel(src_path.data(), &label_raw, type);
 
        std::unique_ptr<char, decltype([] (char *p) {
                free(p);
@@ -110,10 +114,10 @@ void fs_helpers::copy_smack_attributes(std::string_view src_path, std::string_vi
                        // N.B. Setting TRANSMUTE attribute needs special attention:
                        // the only correct values are: NULL, "", "0" or "1".
                        if (label == "TRUE")
-                               ret = smack_setlabel(dest_path.data(), "1", type);
+                               ret = smack_lsetlabel(dest_path.data(), "1", type);
                }
                else
-                       ret = smack_setlabel(dest_path.data(), label.c_str(), type);
+                       ret = smack_lsetlabel(dest_path.data(), label.c_str(), type);
 
                if (ret)
                        throw std::runtime_error(
@@ -141,7 +145,7 @@ int fs_helpers::get_gid_from_name(std::string_view group_name)
 
 void fs_helpers::change_owner_and_group(std::string_view path, const int session_uid, const int group_id)
 {
-       if (chown(path.data(), session_uid, group_id) == -1)
+       if (lchown(path.data(), session_uid, group_id) == -1)
                throw std::system_error(errno, std::system_category(),
                        "Couldn't set owner/group of the `"s
                        + path.data()
@@ -179,9 +183,7 @@ bool fs_helpers::subsession_exists(const int session_uid, const std::string_view
        return fs::exists(subsession_path);
 }
 catch (std::exception const &ex) {
-       std::cerr << "Exception " << ex.what() << std::endl
-               << "while executing subsession_exists function [session_uid=" << session_uid
-               << " subsession_id=" << subsession_id << "]" << std::endl;
+       LOGE("Exception %s\nwhile executing subsession_exists function [session_uid=%d subsession_id=%s]", ex.what(), session_uid, subsession_id.data());
        return false;
 }
 
@@ -244,15 +246,11 @@ void fs_helpers::add_user_subsession(const int session_uid, const std::string_vi
 
        }
        catch (std::system_error const &ex) {
-               std::cerr << "Logic exception " << ex.what() << std::endl
-                       << "while copying user subsession data [session_uid=" << session_uid
-                       << " subsession_id=" << subsession_id << "]" << std::endl;
+               LOGE("Logic exception %s\nwhile copying user subsession data [session_uid=%d subsession_id=%s]", ex.what(), session_uid, subsession_id.data());
                throw;
        }
        catch (std::exception const &ex) {
-               std::cerr << "Exception " << ex.what() << std::endl
-                       << "while copying user subsession data [session_uid=" << session_uid
-                       << " subsession_id=" << subsession_id << "]" << std::endl;
+               LOGE("Exception %s\nwhile copying user subsession data [session_uid=%d subsession_id=%s]", ex.what(), session_uid, subsession_id.data());
                throw std::runtime_error("Couldn't add user subsession data");
        }
 }
@@ -272,15 +270,11 @@ void fs_helpers::remove_user_subsession(const int session_uid, const std::string
                fs::remove_all(subsession_path);
        }
        catch (std::system_error const &ex) {
-               std::cerr << "Logic exception " << ex.what() << std::endl
-                       << "while removing user subsession data [session_uid=" << session_uid
-                       << " subsession_id=" << subsession_id << "]" << std::endl;
+               LOGE("Logic exception %s\nwhile removing user subsession data [session_uid=%d subsession_id=%s]", ex.what(), session_uid, subsession_id.data());
                throw;
        }
        catch (std::exception const &ex) {
-               std::cerr << "Exception " << ex.what() << std::endl
-                       << "while removing user subsession data [session_uid=" << session_uid
-                       << " subsession_id=" << subsession_id << "]" << std::endl;
+               LOGE("Exception %s\nwhile removing user subsession data [session_uid=%d subsession_id=%s]", ex.what(), session_uid, subsession_id.data());
                throw std::runtime_error("Couldn't remove user subsession data");
        }
 }
@@ -318,9 +312,7 @@ std::vector<std::string> fs_helpers::get_user_list(const int session_uid) try
 } catch (std::runtime_error &ex) {
        return {};
 } catch (std::exception const &ex) {
-       std::cerr << "Exception " << ex.what() << std::endl
-               << "while enumerating user subsessions [session_uid="
-               << session_uid << "]" << std::endl;
+       LOGE("Exception %s\nwhile enumerating user subsessions [session_uid=%d]", ex.what(), session_uid);
        throw std::runtime_error("Couldn't enumerate user subsessions");
 }
 
index ba0c535..4254e17 100644 (file)
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE. */
 
+#undef LOG_TAG
+#define LOG_TAG "SESSIOND"
+#include <dlog.h>
+
 #include <algorithm>
-#include <iostream>
 #include <unordered_map>
 
 #include <gio/gio.h>
@@ -78,7 +81,7 @@ struct owner_id {
        {
                inner = g_bus_own_name_on_connection(connection, name.data(), G_BUS_NAME_OWNER_FLAGS_NONE,
                        on_name_acquired, on_name_lost, user_data, nullptr);
-               std::cout << "Acquiring " << name << std::endl;
+               LOGD("Acquiring %s", name.data());
        }
 
        ~owner_id()
@@ -134,7 +137,7 @@ struct sessiond_context {
 
        void on_name_acquired()
        {
-               std::cout << "Bus name acquired" << std::endl;
+               LOGD("Bus name acquired");
        }
 
        void on_name_lost()
@@ -400,7 +403,7 @@ struct sessiond_context {
                });
                if (to_call == methods.end())
                        throw std::runtime_error(std::string("Unknown method ") + method_name + " called");
-               std::cout << "Handling " << method_name << " call from " << sender << std::endl;
+               LOGD("Handling %s call from %s", method_name, sender);
                (self->*(to_call->second))(invocation, std::string_view(sender), parameters);
        } catch (const std::invalid_argument &ex) {
                g_dbus_method_invocation_return_dbus_error(invocation,
@@ -432,9 +435,7 @@ struct sessiond_context {
        }
        static void log_exception(const std::exception &ex, std::string_view sender, std::string_view method_name)
        {
-               // TODO: use dlog instead
-               std::cerr << "Exception " << ex.what() << std::endl <<
-                       "while handling " << method_name << " call from " << sender << std::endl;
+               LOGE("Exception %s\nwhile handling %s call from %s", ex.what(), method_name.data(), sender.data());
        }
 
        constexpr static GDBusInterfaceVTable table = {
@@ -555,6 +556,6 @@ struct sessiond_context {
 int main() try {
        sessiond_context().run();
 } catch (const std::exception &ex) {
-       std::cerr << "Exception " << ex.what() << " caught in top scope! Bailing out..." << std::endl;
+       LOGE("Exception %s caught in top scope! Bailing out...", ex.what());
        return EXIT_FAILURE;
 }
index a4aed59..5beb90f 100644 (file)
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE. */
 
+#undef LOG_TAG
+#define LOG_TAG "SESSIOND"
+#include <dlog.h>
+
 #include <algorithm>
 #include <exception>
 #include <iostream>
@@ -105,8 +109,7 @@ public:
                                finalize_if_empty(waiting_for.first, waiting_for.second.second);
                        }
                } catch (const std::exception &ex) {
-                       std::cerr << "Exception " << ex.what() << "\n" <<
-                               "while finalizing the wait manager\n";
+                       LOGE("Exception %s\nwhile finalizing the wait manager", ex.what());
                }
 
                for (auto &timeout : timeouts)
@@ -225,8 +228,7 @@ private:
                auto self = static_cast<wait_manager *>(user_data);
                self->on_client_disappeared(std::string(name));
        } catch (const std::exception &ex) {
-               std::cerr << "Exception " << ex.what() << "\n" <<
-                       "while handling " << name << " disappearing\n";
+               LOGE("Exception %s\nwhile handling %s disappearing", ex.what(), name);
        }
 
        struct timeout_data {
@@ -243,8 +245,7 @@ private:
                data->active = false;
                return G_SOURCE_REMOVE;
        } catch (const std::exception &ex) {
-               std::cerr << "Exception " << ex.what() << "\n" <<
-                       "while timeout\n";
+               LOGE("Exception %s\nwhile timeout", ex.what());
                return G_SOURCE_REMOVE;
        }