mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	util: Try finding out application name using dladdr if available
This fixes getting the binary name in the Hurd, or any other port using the GNU C library, but only in the case where the library is directly linked to. Opening with dlopen will not work. Change in v3: reorder header includes and definitions Change in v2: use a weak reference to main, so that we don't crash when main cannot be found.
This commit is contained in:
		
							parent
							
								
									c45c0b1490
								
							
						
					
					
						commit
						93c698c9fc
					
				
					 2 changed files with 25 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -64,6 +64,15 @@
 | 
			
		|||
 | 
			
		||||
#include "util.h"
 | 
			
		||||
 | 
			
		||||
#if defined(HAVE_DLADDR) && defined(PA_GCC_WEAKREF)
 | 
			
		||||
#ifndef _GNU_SOURCE
 | 
			
		||||
#define _GNU_SOURCE 1
 | 
			
		||||
#endif
 | 
			
		||||
#include <dlfcn.h>
 | 
			
		||||
 | 
			
		||||
static int _main() PA_GCC_WEAKREF(main);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
char *pa_get_user_name(char *s, size_t l) {
 | 
			
		||||
    const char *p;
 | 
			
		||||
    char *name = NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -218,6 +227,20 @@ char *pa_get_binary_name(char *s, size_t l) {
 | 
			
		|||
    }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if defined(HAVE_DLADDR) && defined(PA_GCC_WEAKREF)
 | 
			
		||||
    {
 | 
			
		||||
        Dl_info info;
 | 
			
		||||
        if(_main) {
 | 
			
		||||
            int err = dladdr(&_main, &info);
 | 
			
		||||
            if (err != 0) {
 | 
			
		||||
                char *p = pa_realpath(info.dli_fname);
 | 
			
		||||
                if (p)
 | 
			
		||||
                    return p;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if defined(HAVE_SYS_PRCTL_H) && defined(PR_GET_NAME)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue