1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains alsapid helper functionality
9 **************************************************************************
11 * LADI Session Handler is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * LADI Session Handler is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <string.h> /* GNU basename() */
32 #include <stdlib.h> /* atoll */
34 #include <sys/types.h>
36 void alsapid_compose_src_link(int alsa_client_id
, char * buffer
)
38 sprintf(buffer
, "/tmp/alsapid-%lld-%d", (long long)getuid(), alsa_client_id
);
41 void alsapid_compose_dst_link(char * buffer
)
43 sprintf(buffer
, "/proc/%lld", (long long)getpid());
46 bool alsapid_get_pid(int alsa_client_id
, pid_t
* pid_ptr
)
48 char src
[MAX_ALSAPID_PATH
];
49 char dst
[MAX_ALSAPID_PATH
+ 1];
53 alsapid_compose_src_link(alsa_client_id
, src
);
55 ret
= readlink(src
, dst
, MAX_ALSAPID_PATH
);
63 pid
= (pid_t
)atoll(basename(dst
));