From a833f980ecebaeca2a45571d6fe74c862f11fb55 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Wed, 26 Oct 2016 12:05:51 +0900 Subject: Change spec and service file to launch murphyd for system-wide and to change UID/GID to multimedia_fw Change-Id: I5f43dc25215d427e7e90f8ab198763e7888bb6a8 Signed-off-by: Sangchul Lee --- packaging/murphy.spec | 11 +++++------ packaging/murphyd.service | 7 +++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packaging/murphy.spec b/packaging/murphy.spec index eca92a8..f8c9355 100644 --- a/packaging/murphy.spec +++ b/packaging/murphy.spec @@ -293,9 +293,8 @@ mkdir -p %{buildroot}%{_tmpfilesdir} cp packaging/murphyd.conf %{buildroot}%{_tmpfilesdir} # Copy the systemd files in place. -#mkdir -p %%{buildroot}%%{_unitdir} -mkdir -p %{buildroot}%{_unitdir_user} -cp packaging/murphyd.service %{buildroot}%{_unitdir_user} +mkdir -p %{buildroot}%{_unitdir} +cp packaging/murphyd.service %{buildroot}%{_unitdir} %if %{with dbus} mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d @@ -309,13 +308,13 @@ cp packaging/org.Murphy.conf \ rm -rf %{buildroot} %post -/bin/systemctl --user enable --global murphyd.service +/bin/systemctl enable murphyd.service #setcap 'cap_net_admin=+ep' %{_bindir}/murphyd ldconfig %postun if [ "$1" = "0" ]; then -systemctl --user disable --global murphyd.service +systemctl disable murphyd.service fi ldconfig @@ -356,7 +355,7 @@ ldconfig %manifest murphy.manifest %{_bindir}/murphyd %config %{_sysconfdir}/murphy -%{_unitdir_user}/murphyd.service +%{_unitdir}/murphyd.service %{_tmpfilesdir}/murphyd.conf %if %{with dbus} %{_sysconfdir}/dbus-1/system.d diff --git a/packaging/murphyd.service b/packaging/murphyd.service index 60842b1..c31e165 100644 --- a/packaging/murphyd.service +++ b/packaging/murphyd.service @@ -2,9 +2,12 @@ Description=Murphy Resource Policy Daemon [Service] -Type=simple ExecStart=/usr/bin/murphyd -t dlog -vvv -f -KillSignal=SIGTERM +Restart=always +RestartSec=0 +User=multimedia_fw +Group=multimedia_fw +SmackProcessLabel=System [Install] WantedBy=default.target -- cgit v1.2.3 From a9290218c24ee95ac918ac85ea56bedd22c44c05 Mon Sep 17 00:00:00 2001 From: Volodymyr Brynza Date: Wed, 9 Nov 2016 16:46:43 +0200 Subject: Update glib-glue for suporting non default context Change-Id: Ia3163c7822627d64acfe1d49a3c3e3a5c9f93716 Signed-off-by: Volodymyr Brynza --- src/common/glib-glue.c | 75 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/src/common/glib-glue.c b/src/common/glib-glue.c index 1678b96..bea7f98 100644 --- a/src/common/glib-glue.c +++ b/src/common/glib-glue.c @@ -91,7 +91,48 @@ static void *add_defer(void *glue_data, void *user_data); static void del_defer(void *glue_data, void *id); static void mod_defer(void *glue_data, void *id, int enabled); +static guint add_timeout(void *glue_data, GSourceFunc cb, unsigned int msecs, void *user_data); +static guint add_io_watch(void *glue_data, GSourceFunc cb, GIOCondition mask, GIOChannel *ioc, void *user_data); +static void remove_source(void *glue_data, guint id); +static guint add_timeout(void *glue_data, GSourceFunc cb, unsigned int msecs, void *user_data) +{ + guint id = 0; + + glib_glue_t *glue = (glib_glue_t *)glue_data; + GMainContext *ctx = g_main_loop_get_context(glue->gml); + GSource *timesource = g_timeout_source_new(msecs); + g_source_set_callback(timesource, cb, user_data, NULL); + id = g_source_attach(timesource, ctx); + g_source_unref(timesource); + + return id; +} + +static guint add_io_watch(void *glue_data, GSourceFunc cb, GIOCondition mask, GIOChannel *ioc, void *user_data) +{ + guint id = 0; + + glib_glue_t *glue = (glib_glue_t *)glue_data; + GMainContext *ctx = g_main_loop_get_context(glue->gml); + GSource *source = g_io_create_watch (ioc, mask); + g_source_set_callback (source, cb, user_data, NULL); + id = g_source_attach (source, ctx); + g_source_unref (source); + + return id; +} + +static void remove_source(void *glue_data, guint id) +{ + glib_glue_t *glue = (glib_glue_t *)glue_data; + GMainContext *ctx = g_main_loop_get_context(glue->gml); + GSource *source; + + source = g_main_context_find_source_by_id (ctx, id); + if (source) + g_source_destroy (source); +} static gboolean io_cb(GIOChannel *ioc, GIOCondition cond, gpointer user_data) { @@ -138,7 +179,8 @@ static void *add_io(void *glue_data, int fd, mrp_io_event_t events, io->mask = events; io->gl_ioc = ioc; - io->gl_iow = g_io_add_watch(ioc, mask, io_cb, io); + + io->gl_iow = add_io_watch(glue_data, (GSourceFunc)io_cb, mask, ioc, io); if (io->gl_iow != 0) { io->cb = cb; @@ -161,9 +203,7 @@ static void del_io(void *glue_data, void *id) { io_t *io = (io_t *)id; - MRP_UNUSED(glue_data); - - g_source_remove(io->gl_iow); + remove_source(glue_data, io->gl_iow); g_io_channel_unref(io->gl_ioc); mrp_free(io); } @@ -194,7 +234,7 @@ static void *add_timer(void *glue_data, unsigned int msecs, t = mrp_allocz(sizeof(*t)); if (t != NULL) { - t->gl_t = g_timeout_add(msecs, timer_cb, t); + t->gl_t = add_timeout(glue_data, (GSourceFunc)timer_cb, msecs, t); if (t->gl_t != 0) { t->cb = cb; @@ -215,9 +255,7 @@ static void del_timer(void *glue_data, void *id) { tmr_t *t = (tmr_t *)id; - MRP_UNUSED(glue_data); - - g_source_remove(t->gl_t); + remove_source(glue_data, t->gl_t); mrp_free(t); } @@ -226,11 +264,9 @@ static void mod_timer(void *glue_data, void *id, unsigned int msecs) { tmr_t *t = (tmr_t *)id; - MRP_UNUSED(glue_data); - if (t != NULL) { - g_source_remove(t->gl_t); - t->gl_t = g_timeout_add(msecs, timer_cb, t); + remove_source(glue_data, t->gl_t); + t->gl_t = add_timeout(glue_data, (GSourceFunc)timer_cb, msecs, t); } } @@ -260,7 +296,7 @@ static void *add_defer(void *glue_data, d = mrp_allocz(sizeof(*d)); if (d != NULL) { - d->gl_t = g_timeout_add(1, defer_cb, d); + d->gl_t = add_timeout(glue_data, (GSourceFunc)defer_cb, 1, d); if (d->gl_t != 0) { d->cb = cb; @@ -281,10 +317,8 @@ static void del_defer(void *glue_data, void *id) { dfr_t *d = (dfr_t *)id; - MRP_UNUSED(glue_data); - if (d->gl_t != 0) - g_source_remove(d->gl_t); + remove_source(glue_data, d->gl_t); mrp_free(d); } @@ -294,15 +328,14 @@ static void mod_defer(void *glue_data, void *id, int enabled) { dfr_t *d = (dfr_t *)id; - MRP_UNUSED(glue_data); - if (d == NULL) return; - if (enabled && !d->gl_t) - d->gl_t = g_timeout_add(0, defer_cb, d); + if (enabled && !d->gl_t) { + d->gl_t = add_timeout(glue_data, (GSourceFunc)defer_cb, 0, d); + } else if (!enabled && d->gl_t) { - g_source_remove(d->gl_t); + remove_source(glue_data, d->gl_t); d->gl_t = 0; } } -- cgit v1.2.3 From f5366d1b9446ba6d270382ccabe67681862c815d Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Tue, 15 Nov 2016 11:09:32 +0900 Subject: Modify spec and service file Change value of WantedBy field to multi-user.target Change-Id: I6fae41114ed53f461543c5351d2e5cef630c63bb Signed-off-by: Sangchul Lee (cherry picked from commit 0cb0a08aae506e747a5a57fbd98f8bc01886c440) --- packaging/murphy.spec | 4 +++- packaging/murphyd.service | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packaging/murphy.spec b/packaging/murphy.spec index f8c9355..45511b7 100644 --- a/packaging/murphy.spec +++ b/packaging/murphy.spec @@ -293,8 +293,9 @@ mkdir -p %{buildroot}%{_tmpfilesdir} cp packaging/murphyd.conf %{buildroot}%{_tmpfilesdir} # Copy the systemd files in place. -mkdir -p %{buildroot}%{_unitdir} +mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants cp packaging/murphyd.service %{buildroot}%{_unitdir} +ln -sf ../murphyd.service %{buildroot}%{_unitdir}/multi-user.target.wants/murphyd.service %if %{with dbus} mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d @@ -355,6 +356,7 @@ ldconfig %manifest murphy.manifest %{_bindir}/murphyd %config %{_sysconfdir}/murphy +%{_unitdir}/multi-user.target.wants/murphyd.service %{_unitdir}/murphyd.service %{_tmpfilesdir}/murphyd.conf %if %{with dbus} diff --git a/packaging/murphyd.service b/packaging/murphyd.service index c31e165..dba4be5 100644 --- a/packaging/murphyd.service +++ b/packaging/murphyd.service @@ -10,4 +10,4 @@ Group=multimedia_fw SmackProcessLabel=System [Install] -WantedBy=default.target +WantedBy=multi-user.target -- cgit v1.2.3 From 3b82a369364544fe41127c9d84d7076975c6f221 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Fri, 25 Nov 2016 20:25:15 +0900 Subject: Remove systemctl enable/disable for duplicated installation [Version] 0.0.74-3 [Profile] Common [Issue Type] systemd Change-Id: I5a60d551913e20a57dac7b8702878875257ae04e (cherry picked from commit 06d0ba2d2501fac59f2d1b96782412afd1194b81) --- packaging/murphy.spec | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packaging/murphy.spec b/packaging/murphy.spec index 45511b7..8151e22 100644 --- a/packaging/murphy.spec +++ b/packaging/murphy.spec @@ -29,16 +29,14 @@ Summary: Resource policy framework Name: murphy Version: 0.0.74 -Release: 3 +Release: 4 License: BSD-2.0 Group: System/Service URL: http://01.org/murphy/ Source0: %{name}-%{version}.tar.gz Source1001: %{name}.manifest -Requires(post): /bin/systemctl #Requires(post): libcap-tools -Requires(postun): /bin/systemctl BuildRequires: flex BuildRequires: bison @@ -309,14 +307,10 @@ cp packaging/org.Murphy.conf \ rm -rf %{buildroot} %post -/bin/systemctl enable murphyd.service #setcap 'cap_net_admin=+ep' %{_bindir}/murphyd ldconfig %postun -if [ "$1" = "0" ]; then -systemctl disable murphyd.service -fi ldconfig %if %{with glib} -- cgit v1.2.3 From b6a583e98aaa2b09fb2d54dbf198684831d82694 Mon Sep 17 00:00:00 2001 From: Volodymyr Brynza Date: Wed, 14 Dec 2016 14:32:26 +0200 Subject: Fix fd leak Change-Id: Ib2f8153d2a8e13bc8f0edf6cbbc2ecf3de274044 Signed-off-by: Volodymyr Brynza --- src/common/socket-utils.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/common/socket-utils.c b/src/common/socket-utils.c index 4f7d957..236ba91 100644 --- a/src/common/socket-utils.c +++ b/src/common/socket-utils.c @@ -99,3 +99,9 @@ int mrp_reject_connection(int sock, struct sockaddr *addr, socklen_t *alen) return (fd >= 0 ? 0 : -1); } + +MRP_EXIT static void mrp_close_reserved_fd() +{ + if (reject_fd > 0) + close(reject_fd); +} -- cgit v1.2.3 From 7a283dbb2ef34dc24492029f39ba182c3fee1326 Mon Sep 17 00:00:00 2001 From: Volodymyr Brynza Date: Mon, 19 Dec 2016 22:22:14 +0200 Subject: Implement thread cretaion. Add mutex to prevent data races in callback Change-Id: Ic2aad19a9bf9269955e825c8b77af75ffeb96efa Signed-off-by: Volodymyr Brynza --- packaging/murphy.spec | 2 +- src/common/glib-glue.c | 108 +++++++++++++++++++++++++++++++++++++++++++++---- src/common/mainloop.c | 19 ++++++--- 3 files changed, 114 insertions(+), 15 deletions(-) diff --git a/packaging/murphy.spec b/packaging/murphy.spec index 8151e22..3a61976 100644 --- a/packaging/murphy.spec +++ b/packaging/murphy.spec @@ -29,7 +29,7 @@ Summary: Resource policy framework Name: murphy Version: 0.0.74 -Release: 4 +Release: 5 License: BSD-2.0 Group: System/Service URL: http://01.org/murphy/ diff --git a/src/common/glib-glue.c b/src/common/glib-glue.c index bea7f98..e2097d5 100644 --- a/src/common/glib-glue.c +++ b/src/common/glib-glue.c @@ -36,8 +36,13 @@ #include +static GMutex g_murphy_glue_callback_lock; +static GMutex g_murphy_glue_internal_lock; + + typedef struct { GMainLoop *gml; + GThread *worker; } glib_glue_t; @@ -136,6 +141,7 @@ static void remove_source(void *glue_data, guint id) static gboolean io_cb(GIOChannel *ioc, GIOCondition cond, gpointer user_data) { + g_mutex_lock(&g_murphy_glue_callback_lock); io_t *io = (io_t *)user_data; mrp_io_event_t events = MRP_IO_EVENT_NONE; int fd = g_io_channel_unix_get_fd(ioc); @@ -151,6 +157,7 @@ static gboolean io_cb(GIOChannel *ioc, GIOCondition cond, gpointer user_data) io->cb(io->glue_data, io, fd, events, io->user_data); + g_mutex_unlock(&g_murphy_glue_callback_lock); return TRUE; } @@ -164,10 +171,13 @@ static void *add_io(void *glue_data, int fd, mrp_io_event_t events, GIOChannel *ioc; io_t *io; + g_mutex_lock(&g_murphy_glue_internal_lock); ioc = g_io_channel_unix_new(fd); - if (ioc == NULL) + if (ioc == NULL) { + g_mutex_unlock(&g_murphy_glue_internal_lock); return NULL; + } io = mrp_allocz(sizeof(*io)); @@ -187,6 +197,7 @@ static void *add_io(void *glue_data, int fd, mrp_io_event_t events, io->user_data = user_data; io->glue_data = glue_data; + g_mutex_unlock(&g_murphy_glue_internal_lock); return io; } else { @@ -195,6 +206,7 @@ static void *add_io(void *glue_data, int fd, mrp_io_event_t events, } } + g_mutex_unlock(&g_murphy_glue_internal_lock); return NULL; } @@ -203,24 +215,31 @@ static void del_io(void *glue_data, void *id) { io_t *io = (io_t *)id; + g_mutex_lock(&g_murphy_glue_internal_lock); remove_source(glue_data, io->gl_iow); g_io_channel_unref(io->gl_ioc); mrp_free(io); + g_mutex_unlock(&g_murphy_glue_internal_lock); } static gboolean timer_cb(gpointer user_data) { - if (user_data == NULL) + if (user_data == NULL) { return FALSE; + } + g_mutex_lock(&g_murphy_glue_callback_lock); tmr_t *t = (tmr_t *)user_data; - if (t->cb == NULL) + if (t->cb == NULL) { + g_mutex_unlock(&g_murphy_glue_callback_lock); return FALSE; + } t->cb(t->glue_data, t, t->user_data); + g_mutex_unlock(&g_murphy_glue_callback_lock); return TRUE; } @@ -231,6 +250,7 @@ static void *add_timer(void *glue_data, unsigned int msecs, { tmr_t *t; + g_mutex_lock(&g_murphy_glue_internal_lock); t = mrp_allocz(sizeof(*t)); if (t != NULL) { @@ -241,12 +261,14 @@ static void *add_timer(void *glue_data, unsigned int msecs, t->user_data = user_data; t->glue_data = glue_data; + g_mutex_unlock(&g_murphy_glue_internal_lock); return t; } else mrp_free(t); } + g_mutex_unlock(&g_murphy_glue_internal_lock); return NULL; } @@ -255,8 +277,10 @@ static void del_timer(void *glue_data, void *id) { tmr_t *t = (tmr_t *)id; + g_mutex_lock(&g_murphy_glue_internal_lock); remove_source(glue_data, t->gl_t); mrp_free(t); + g_mutex_unlock(&g_murphy_glue_internal_lock); } @@ -264,25 +288,32 @@ static void mod_timer(void *glue_data, void *id, unsigned int msecs) { tmr_t *t = (tmr_t *)id; + g_mutex_lock(&g_murphy_glue_internal_lock); if (t != NULL) { remove_source(glue_data, t->gl_t); t->gl_t = add_timeout(glue_data, (GSourceFunc)timer_cb, msecs, t); } + g_mutex_unlock(&g_murphy_glue_internal_lock); } static gboolean defer_cb(void *user_data) { - if (user_data == NULL) + if (user_data == NULL) { return FALSE; + } + g_mutex_lock(&g_murphy_glue_callback_lock); dfr_t *d = (dfr_t *)user_data; - if (d->cb == NULL) + if (d->cb == NULL) { + g_mutex_unlock(&g_murphy_glue_callback_lock); return FALSE; + } d->cb(d->glue_data, d, d->user_data); + g_mutex_unlock(&g_murphy_glue_callback_lock); return TRUE; } @@ -293,6 +324,7 @@ static void *add_defer(void *glue_data, { dfr_t *d; + g_mutex_lock(&g_murphy_glue_internal_lock); d = mrp_allocz(sizeof(*d)); if (d != NULL) { @@ -303,12 +335,14 @@ static void *add_defer(void *glue_data, d->user_data = user_data; d->glue_data = glue_data; + g_mutex_unlock(&g_murphy_glue_internal_lock); return d; } else mrp_free(d); } + g_mutex_unlock(&g_murphy_glue_internal_lock); return NULL; } @@ -317,10 +351,12 @@ static void del_defer(void *glue_data, void *id) { dfr_t *d = (dfr_t *)id; + g_mutex_lock(&g_murphy_glue_internal_lock); if (d->gl_t != 0) remove_source(glue_data, d->gl_t); mrp_free(d); + g_mutex_unlock(&g_murphy_glue_internal_lock); } @@ -328,9 +364,11 @@ static void mod_defer(void *glue_data, void *id, int enabled) { dfr_t *d = (dfr_t *)id; - if (d == NULL) + if (d == NULL) { return; + } + g_mutex_lock(&g_murphy_glue_internal_lock); if (enabled && !d->gl_t) { d->gl_t = add_timeout(glue_data, (GSourceFunc)defer_cb, 0, d); } @@ -338,14 +376,32 @@ static void mod_defer(void *glue_data, void *id, int enabled) remove_source(glue_data, d->gl_t); d->gl_t = 0; } + g_mutex_unlock(&g_murphy_glue_internal_lock); } static void unregister(void *data) { glib_glue_t *glue = (glib_glue_t *)data; + GMainContext *def_ctx = g_main_context_default(); + GMainContext *loop_ctx = g_main_loop_get_context(glue->gml); + if (loop_ctx && def_ctx != loop_ctx) { + GSource *idle = g_idle_source_new(); + + g_source_set_callback(idle, (GSourceFunc) g_main_loop_quit, + glue->gml, NULL); + + g_source_attach(idle, g_main_loop_get_context(glue->gml)); + g_source_unref(idle); + g_thread_join(glue->worker); + g_thread_unref(glue->worker); + glue->worker = NULL; + } - g_main_loop_unref(glue->gml); + if (glue->gml) { + g_main_loop_unref(glue->gml); + glue->gml = NULL; + } mrp_free(glue); } @@ -363,6 +419,21 @@ static mrp_superloop_ops_t glib_ops = { .unregister = unregister, }; +static gpointer +thread_main (gpointer data) +{ + glib_glue_t *glue = (glib_glue_t *)data; + GMainContext *thread_main_context = g_main_loop_get_context(glue->gml); + + /* Set up the thread’s context and run it. */ + g_main_context_push_thread_default (thread_main_context); + + g_main_loop_run (glue->gml); + + g_main_context_pop_thread_default (thread_main_context); + + return NULL; +} int mrp_mainloop_register_with_glib(mrp_mainloop_t *ml, GMainLoop *gml) { @@ -373,8 +444,15 @@ int mrp_mainloop_register_with_glib(mrp_mainloop_t *ml, GMainLoop *gml) if (glue != NULL) { glue->gml = g_main_loop_ref(gml); - if (mrp_set_superloop(ml, &glib_ops, glue)) + if (mrp_set_superloop(ml, &glib_ops, glue)) { + /* Create new thread for context iteration only in case when + * glue context isn't default */ + GMainContext *def_ctx = g_main_context_default(); + GMainContext *loop_ctx = g_main_loop_get_context(glue->gml); + if (loop_ctx && def_ctx != loop_ctx) + glue->worker = g_thread_new(NULL, thread_main, glue); return TRUE; + } else { g_main_loop_unref(gml); mrp_free(glue); @@ -408,3 +486,17 @@ mrp_mainloop_t *mrp_mainloop_glib_get(GMainLoop *gml) return NULL; } + + +MRP_INIT static void mrp_main_loop_init_lock() +{ + g_mutex_init(&g_murphy_glue_callback_lock); + g_mutex_init(&g_murphy_glue_internal_lock); +} + + +MRP_EXIT static void mrp_main_loop_clear_lock() +{ + g_mutex_clear(&g_murphy_glue_callback_lock); + g_mutex_clear(&g_murphy_glue_internal_lock); +} diff --git a/src/common/mainloop.c b/src/common/mainloop.c index 5702c15..bf46cd8 100644 --- a/src/common/mainloop.c +++ b/src/common/mainloop.c @@ -1291,13 +1291,20 @@ static void super_work_cb(void *super_data, void *id, void *user_data) ops->mod_defer(ml->super_data, ml->work, FALSE); } else { - ops->del_io(ml->super_data, ml->iow); - ops->del_timer(ml->super_data, ml->timer); - ops->del_defer(ml->super_data, ml->work); + if (ml->iow != NULL) { + ops->del_io(ml->super_data, ml->iow); + ml->iow = NULL; + } + + if (ml->work != NULL) { + ops->del_defer(ml->super_data, ml->work); + ml->work = NULL; + } - ml->iow = NULL; - ml->timer = NULL; - ml->work = NULL; + if (ml->timer != NULL) { + ops->del_timer(ml->super_data, ml->timer); + ml->timer = NULL; + } } } -- cgit v1.2.3