diff --git a/alsapid/alsapid.h b/alsapid/alsapid.h index 7e89d15a..d5afbb0e 100644 --- a/alsapid/alsapid.h +++ b/alsapid/alsapid.h @@ -27,7 +27,10 @@ #ifndef ALSAPID_H__0A27F284_7538_4791_8023_0FBED929EAF3__INCLUDED #define ALSAPID_H__0A27F284_7538_4791_8023_0FBED929EAF3__INCLUDED +#include + void alsapid_compose_src_link(int alsa_client_id, char * buffer); void alsapid_compose_dst_link(char * buffer); +bool alsapid_get_pid(int alsa_client_id, pid_t * pid_ptr); #endif /* #ifndef ALSAPID_H__0A27F284_7538_4791_8023_0FBED929EAF3__INCLUDED */ diff --git a/alsapid/helper.c b/alsapid/helper.c index 75c25990..cd3760a7 100644 --- a/alsapid/helper.c +++ b/alsapid/helper.c @@ -24,9 +24,14 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _GNU_SOURCE +#include /* GNU basename() */ + #include +#include /* atoll */ #include #include +#include #include "alsapid.h" @@ -40,3 +45,29 @@ void alsapid_compose_dst_link(char * buffer) sprintf(buffer, "/proc/%lld", (long long)getpid()); } +bool alsapid_get_pid(int alsa_client_id, pid_t * pid_ptr) +{ + char src[PATH_MAX]; + char dst[PATH_MAX + 1]; + ssize_t ret; + pid_t pid; + + alsapid_compose_src_link(alsa_client_id, src); + + ret = readlink(src, dst, PATH_MAX); + if (ret == -1) + { + return false; + } + + dst[ret] = 0; + + pid = (pid_t)atoll(basename(dst)); + if (pid <= 1) + { + return false; + } + + *pid_ptr = pid; + return true; +} diff --git a/wscript b/wscript index 3ec1a586..680dec2b 100644 --- a/wscript +++ b/wscript @@ -412,6 +412,8 @@ def build(bld): ]: daemon.source.append(os.path.join("common", source)) + daemon.source.append(os.path.join("alsapid", "helper.c")) + # process dbus.service.in -> ladish.service create_service_taskgen(bld, DBUS_NAME_BASE + '.service', DBUS_NAME_BASE, daemon.target)