Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[packaging] Add dsme-plugin-devel package. Fixes JB#49564
dsme-plugin-devel package provides header files. It allows building DSME
modules outside of the main repository.

Signed-off-by: Bogdan Migunov <bogdanmigunov@yandex.ru>
  • Loading branch information
bmigunov committed Jun 5, 2020
1 parent 1e7e917 commit 7c104ac
Show file tree
Hide file tree
Showing 37 changed files with 271 additions and 255 deletions.
6 changes: 6 additions & 0 deletions Makefile.custom
Expand Up @@ -113,6 +113,12 @@ install_main::
install -d -m 755 $(DESTDIR)/etc/dbus-1/system.d
install -m 644 dsme/dsme.conf $(DESTDIR)/etc/dbus-1/system.d/

# devel headers dir
install -d -m 755 $(DESTDIR)/$(_INCLUDEDIR)/dsme-plugin

# dsme-plugin pkg-config file
install -D -m 644 dsme-plugin.pc $(DESTDIR)/$(_LIBDIR)/pkgconfig/dsme-plugin.pc

# tests
install -d -m 755 $(DESTDIR)/opt/tests/dsme-tests
install -m 644 tests/tests.xml $(DESTDIR)/opt/tests/dsme-tests
Expand Down
8 changes: 8 additions & 0 deletions dsme-plugin.pc
@@ -0,0 +1,8 @@
prefix=/usr
includedir=${prefix}/include

Name: dsme-plugin-devel
Description: Header files for building DSME plugins
Version: 0.80.0
Requires:
Cflags: -I${includedir}/dsme-plugin
20 changes: 14 additions & 6 deletions dsme/Makefile.am
Expand Up @@ -11,6 +11,8 @@ ACLOCAL_AMFLAGS = -I m4
#
dbusdir = @sysconfdir@/dbus-1/system.d
pkgsysconfdir = @sysconfdir@/@PACKAGE@
dsmeplugindir = $(includedir)/dsme-plugin
pkgconfigdir = $(libdir)/pkgconfig

#
# Binaries
Expand Down Expand Up @@ -49,15 +51,21 @@ dsme_server_LDADD = $(GLIB_LIBS) $(LIBCRYPTSETUP_LIBS) -ldsme -ldl
#
noinst_HEADERS = dsme-rd-mode.h \
utility.h \
../include/dsme/mainloop.h \
../include/dsme/modulebase.h \
../include/dsme/modules.h \
../include/dsme/dsmesock.h \
../include/dsme/logging.h \
../include/dsme/oom.h \
../include/dsme/timers.h
../include/dsme/oom.h

dsmeplugin_HEADERS = ../include/dsme/logging.h \
../include/dsme/modulebase.h \
../include/dsme/modules.h \
../include/dsme/timers.h \
../include/dsme/mainloop.h

#
# Data
#
dist_dbus_DATA = dsme.conf

#
# dsme-plugin pkgconfig
#
dist_pkgconfig_DATA = ../dsme-plugin.pc
4 changes: 2 additions & 2 deletions dsme/dsme-server.c
Expand Up @@ -224,7 +224,7 @@ static bool receive_and_queue_message(dsmesock_connection_t* conn)
if( !(msg = dsmesock_receive(conn)) )
goto EXIT;

broadcast_internally_from_socket(msg, conn);
modules_broadcast_internally_from_socket(msg, conn);

if( DSMEMSG_CAST(DSM_MSGTYPE_CLOSE, msg) ) {
keep_connection = false;
Expand Down Expand Up @@ -335,7 +335,7 @@ int main(int argc, char *argv[])
}
#endif
dsme_log(LOG_DEBUG, "Entering main loop");
dsme_main_loop_run(process_message_queue);
dsme_main_loop_run(modulebase_process_message_queue);

/* To eaze shutdown analysis, always log when dsme exits */
dsme_log(LOG_WARNING, "Exited main loop, quitting");
Expand Down
71 changes: 0 additions & 71 deletions dsme/logging.c
Expand Up @@ -167,12 +167,6 @@ bool dsme_log_open (log_method method, int verbosity,
void dsme_log_close (void);
void dsme_log_stop (void);

/* ------------------------------------------------------------------------- *
* Misc
* ------------------------------------------------------------------------- */

static char *pid2exe (pid_t pid);
char *pid2text (pid_t pid);

/* ========================================================================= *
* Dynamic Configuration
Expand Down Expand Up @@ -1053,68 +1047,3 @@ dsme_log_stop(void)
}
}
}

/* ========================================================================= *
* Misc
* ========================================================================= */

/** Map process identifier to process name
*
* @param pid process identifier
*
* @return process name
*/
static char *pid2exe(pid_t pid)
{
char *res = 0;
int fd = -1;
int rc;
char path[128];
char temp[128];

snprintf(path, sizeof path, "/proc/%ld/cmdline", (long)pid);

if( (fd = open(path, O_RDONLY)) == -1 )
goto EXIT;

if( (rc = read(fd, temp, sizeof temp - 1)) <= 0 )
goto EXIT;

temp[rc] = 0;
res = strdup(temp);

EXIT:
if( fd != -1 ) close(fd);

return res;
}

/** Map process identifier to IPC process identifier
*
* @param pid peer process or 0 for dsme itself
*
* @return string containing both pid and process name
*/
char* pid2text(pid_t pid)
{
static unsigned id = 0;

char *str = 0;
char *exe = 0;

if( pid == 0 ) {
str = strdup("<internal>");
goto EXIT;
}

exe = pid2exe(pid);

if( asprintf(&str, "external-%u/%ld (%s)", ++id,
(long)pid, exe ?: "unknown") < 0 )
str = 0;

EXIT:
free(exe);

return str ?: strdup("error");
}
70 changes: 34 additions & 36 deletions dsme/modulebase.c
Expand Up @@ -82,6 +82,19 @@ typedef struct {
} queued_msg_t;


/**
Adds a message to list of handlers
@param msg_type Type of the message to be registered
@param callback Function to be called when given msg_type is handled
@param owner Pointer to the module module who owns this callback
@return 0 on OK, -1 on error
*/
static int modulebase_add_single_handler(u_int32_t msg_type,
size_t msg_size,
handler_fn_t* callback,
const module_t* owner);

static int add_msghandlers(module_t* module);

static void remove_msghandlers(module_t* module);
Expand Down Expand Up @@ -184,18 +197,10 @@ static int name_comparator(const module_t* node, const char* name)
#endif


/**
Add single hadler in message handlers list
@param msg_type Type of the message to be registered
@param callback Function to be called when given msg_type is handled
@param owner Pointer to the module module who owns this callback
@return 0 on OK, -1 on error
*/
int add_single_handler(u_int32_t msg_type,
size_t msg_size,
handler_fn_t* callback,
const module_t* owner)
static int modulebase_add_single_handler(u_int32_t msg_type,
size_t msg_size,
handler_fn_t* callback,
const module_t* owner)
{
msg_handler_info_t* handler = 0;

Expand Down Expand Up @@ -238,7 +243,7 @@ static int add_msghandlers(module_t* module)
msg_handler_ptr && msg_handler_ptr->callback;
msg_handler_ptr++)
{
if (add_single_handler(msg_handler_ptr->msg_type,
if (modulebase_add_single_handler(msg_handler_ptr->msg_type,
msg_handler_ptr->msg_size,
msg_handler_ptr->callback,
module))
Expand Down Expand Up @@ -276,12 +281,12 @@ static void remove_msghandlers(module_t* module)

static const module_t* currently_handling_module = 0;

const module_t* current_module(void)
const module_t* modulebase_current_module(void)
{
return currently_handling_module;
}

const module_t* enter_module(const module_t* module)
const module_t* modulebase_enter_module(const module_t* module)
{
const module_t *previous = currently_handling_module;
currently_handling_module = module;
Expand Down Expand Up @@ -322,7 +327,7 @@ static void queue_message(const endpoint_t* from,
newmsg = NULL;
}

void broadcast_internally_with_extra(const void* msg,
void modules_broadcast_internally_with_extra(const void* msg,
size_t extra_size,
const void* extra)
{
Expand All @@ -336,12 +341,12 @@ void broadcast_internally_with_extra(const void* msg,
queue_message(&from, 0, msg, extra_size, extra);
}

void broadcast_internally(const void* msg)
void modules_broadcast_internally(const void* msg)
{
broadcast_internally_with_extra(msg, 0, 0);
modules_broadcast_internally_with_extra(msg, 0, 0);
}

void broadcast_internally_from_socket(const void* msg,
void modules_broadcast_internally_from_socket(const void* msg,
dsmesock_connection_t* conn)
{
endpoint_t from = {
Expand All @@ -360,7 +365,7 @@ void broadcast_internally_from_socket(const void* msg,
queue_message(&from, 0, msg, 0, 0);
}

void broadcast_with_extra(const void* msg, size_t extra_size, const void* extra)
void modules_broadcast_with_extra(const void* msg, size_t extra_size, const void* extra)
{
endpoint_t from = {
.module = currently_handling_module,
Expand All @@ -372,9 +377,9 @@ void broadcast_with_extra(const void* msg, size_t extra_size, const void* extra)
dsmesock_broadcast_with_extra(msg, extra_size, extra);
}

void broadcast(const void* msg)
void modules_broadcast(const void* msg)
{
broadcast_with_extra(msg, 0, 0);
modules_broadcast_with_extra(msg, 0, 0);
}

static void queue_for_module_with_extra(const module_t* recipient,
Expand Down Expand Up @@ -530,7 +535,7 @@ void endpoint_free(endpoint_t* endpoint)
}


void process_message_queue(void)
void modulebase_process_message_queue(void)
{
while (message_queue) {
queued_msg_t* front = (queued_msg_t*)message_queue->data;
Expand Down Expand Up @@ -588,7 +593,7 @@ static int handle_message(endpoint_t* from,
}


bool unload_module(module_t* module)
bool modulebase_unload_module(module_t* module)
{
bool unloaded = false;
GSList* node;
Expand Down Expand Up @@ -637,7 +642,7 @@ bool unload_module(module_t* module)
}


module_t* load_module(const char* filename, int priority)
module_t* modulebase_load_module(const char* filename, int priority)
{
void* dlhandle = 0;
module_t* module = 0;
Expand Down Expand Up @@ -718,7 +723,7 @@ bool modulebase_init(const struct _GSList* module_names)
const GSList* modname;

for (modname = module_names; modname; modname = g_slist_next(modname)) {
if (load_module((const char*)modname->data, 0) == NULL) {
if (modulebase_load_module((const char*)modname->data, 0) == NULL) {
dsme_log(LOG_CRIT,
"Error loading start-up module: %s",
(const char*)modname->data);
Expand All @@ -741,18 +746,11 @@ int modulebase_shutdown(void)
modules = g_slist_reverse(modules);

while (modules) {
process_message_queue();
unload_module((module_t*)modules->data);
modulebase_process_message_queue();
modulebase_unload_module((module_t*)modules->data);
}

process_message_queue();
modulebase_process_message_queue();

return 0;
}

void dsme_exit(int exit_code)
{
dsme_main_loop_quit(exit_code);
}


6 changes: 3 additions & 3 deletions dsme/timers.c
Expand Up @@ -69,9 +69,9 @@ timergate_timeout_cb(gpointer aptr)
dsme_log(LOG_DEBUG, "dispatch %ums timer at module: %s",
self->tg_interval, module_name(self->tg_module) ?: "unknown");

const module_t *cur = enter_module(self->tg_module);
const module_t *cur = modulebase_enter_module(self->tg_module);
int rc = self->tg_callback(self->tg_data);
enter_module(cur);
modulebase_enter_module(cur);

return rc != 0;
}
Expand All @@ -86,7 +86,7 @@ timergate_create(gint priority,

timergate_t *self = g_slice_alloc0(sizeof *self);

self->tg_module = current_module();
self->tg_module = modulebase_current_module();
self->tg_interval = interval;
self->tg_callback = callback;
self->tg_data = data;
Expand Down

0 comments on commit 7c104ac

Please sign in to comment.