mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
pipewire: improve get_prgname()
This commit is contained in:
parent
581d4521fd
commit
854d019343
1 changed files with 24 additions and 8 deletions
|
|
@ -473,15 +473,31 @@ const char *pw_get_application_name(void)
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
const char *pw_get_prgname(void)
|
const char *pw_get_prgname(void)
|
||||||
{
|
{
|
||||||
static char tcomm[16 + 1];
|
static char prgname[PATH_MAX];
|
||||||
spa_zero(tcomm);
|
spa_memzero(prgname, sizeof(prgname));
|
||||||
|
#if defined(__linux__) || defined(__FreeBSD_kernel__)
|
||||||
#ifndef __FreeBSD__
|
{
|
||||||
if (prctl(PR_GET_NAME, (unsigned long) tcomm, 0, 0, 0) == 0)
|
ssize_t len;
|
||||||
return tcomm;
|
if ((len = readlink("/proc/self/exe", prgname, sizeof(prgname)-1)) > 0)
|
||||||
|
return strrchr(prgname, '/') + 1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if defined __FreeBSD__
|
||||||
return NULL;
|
{
|
||||||
|
ssize_t len;
|
||||||
|
spa_memzero(prgname, sizeof(prgname));
|
||||||
|
if ((len = readlink("/proc/curproc/file", prgname, sizeof(prgname)-1)) > 0)
|
||||||
|
return strrchr(prgname, '/') + 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifndef __FreeBSD__
|
||||||
|
{
|
||||||
|
if (prctl(PR_GET_NAME, (unsigned long) prgname, 0, 0, 0) == 0)
|
||||||
|
return prgname;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
snprintf(prgname, sizeof(prgname)-1, "pid-%d", getpid());
|
||||||
|
return prgname;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the user name \memberof pw_pipewire */
|
/** Get the user name \memberof pw_pipewire */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue