alsapid_get_pid() for use in ladishd virtualizer

This commit is contained in:
Nedko Arnaudov 2010-10-31 10:17:42 +02:00
parent bbee2910ce
commit 9592afef25
3 changed files with 36 additions and 0 deletions

View File

@ -27,7 +27,10 @@
#ifndef ALSAPID_H__0A27F284_7538_4791_8023_0FBED929EAF3__INCLUDED
#define ALSAPID_H__0A27F284_7538_4791_8023_0FBED929EAF3__INCLUDED
#include <stdbool.h>
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 */

View File

@ -24,9 +24,14 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define _GNU_SOURCE
#include <string.h> /* GNU basename() */
#include <stdio.h>
#include <stdlib.h> /* atoll */
#include <unistd.h>
#include <sys/types.h>
#include <linux/limits.h>
#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;
}

View File

@ -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)