mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	add new functions pa_state_path()/pa_get_state_dir(), change return value of pa_startswith()/pa_endswith() pa_bool, add pa_in_system_mode() and pa_streq(); alow pa_unlock_lockfile() without file name spec
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2470 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
		
							parent
							
								
									d65b901e37
								
							
						
					
					
						commit
						a9c80b4383
					
				
					 2 changed files with 61 additions and 13 deletions
				
			
		| 
						 | 
					@ -1144,13 +1144,14 @@ fail:
 | 
				
			||||||
/* Unlock a temporary lcok file */
 | 
					/* Unlock a temporary lcok file */
 | 
				
			||||||
int pa_unlock_lockfile(const char *fn, int fd) {
 | 
					int pa_unlock_lockfile(const char *fn, int fd) {
 | 
				
			||||||
    int r = 0;
 | 
					    int r = 0;
 | 
				
			||||||
    pa_assert(fn);
 | 
					 | 
				
			||||||
    pa_assert(fd >= 0);
 | 
					    pa_assert(fd >= 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (fn) {
 | 
				
			||||||
        if (unlink(fn) < 0) {
 | 
					        if (unlink(fn) < 0) {
 | 
				
			||||||
            pa_log_warn("Unable to remove lock file '%s': %s", fn, pa_cstrerror(errno));
 | 
					            pa_log_warn("Unable to remove lock file '%s': %s", fn, pa_cstrerror(errno));
 | 
				
			||||||
            r = -1;
 | 
					            r = -1;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (pa_lock_fd(fd, 0) < 0) {
 | 
					    if (pa_lock_fd(fd, 0) < 0) {
 | 
				
			||||||
        pa_log_warn("Failed to unlock file '%s'.", fn);
 | 
					        pa_log_warn("Failed to unlock file '%s'.", fn);
 | 
				
			||||||
| 
						 | 
					@ -1165,14 +1166,15 @@ int pa_unlock_lockfile(const char *fn, int fd) {
 | 
				
			||||||
    return r;
 | 
					    return r;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char *pa_get_runtime_dir(void) {
 | 
					static char *get_dir(mode_t m, const char *env_name) {
 | 
				
			||||||
    const char *e;
 | 
					    const char *e;
 | 
				
			||||||
    char *d;
 | 
					    char *d;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((e = getenv("PULSE_RUNTIME_PATH")))
 | 
					    if ((e = getenv(env_name)))
 | 
				
			||||||
        d = pa_xstrdup(e);
 | 
					        d = pa_xstrdup(e);
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
        char h[PATH_MAX];
 | 
					        char h[PATH_MAX];
 | 
				
			||||||
 | 
					        struct stat st;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!pa_get_home_dir(h, sizeof(h))) {
 | 
					        if (!pa_get_home_dir(h, sizeof(h))) {
 | 
				
			||||||
            pa_log_error("Failed to get home directory.");
 | 
					            pa_log_error("Failed to get home directory.");
 | 
				
			||||||
| 
						 | 
					@ -1180,9 +1182,21 @@ char *pa_get_runtime_dir(void) {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        d = pa_sprintf_malloc("%s" PA_PATH_SEP ".pulse", h);
 | 
					        d = pa_sprintf_malloc("%s" PA_PATH_SEP ".pulse", h);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (stat(d, &st) < 0) {
 | 
				
			||||||
 | 
					            pa_log_error("Failed to state home directory %s: %s", d, pa_cstrerror(errno));
 | 
				
			||||||
 | 
					            pa_xfree(d);
 | 
				
			||||||
 | 
					            return NULL;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (pa_make_secure_dir(d, 0700, (pid_t) -1, (pid_t) -1) < 0)  {
 | 
					        if (st.st_uid != getuid()) {
 | 
				
			||||||
 | 
					            pa_log_error("Home directory %s not ours.", d);
 | 
				
			||||||
 | 
					            pa_xfree(d);
 | 
				
			||||||
 | 
					            return NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (pa_make_secure_dir(d, m, (pid_t) -1, (pid_t) -1) < 0)  {
 | 
				
			||||||
        pa_log_error("Failed to create secure directory: %s", pa_cstrerror(errno));
 | 
					        pa_log_error("Failed to create secure directory: %s", pa_cstrerror(errno));
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -1190,6 +1204,14 @@ char *pa_get_runtime_dir(void) {
 | 
				
			||||||
    return d;
 | 
					    return d;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char *pa_get_runtime_dir(void) {
 | 
				
			||||||
 | 
					    return get_dir(pa_in_system_mode() ? 0755 : 0700, "PULSE_RUNTIME_PATH");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char *pa_get_state_dir(void) {
 | 
				
			||||||
 | 
					    return get_dir(0700, "PULSE_STATE_PATH");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Try to open a configuration file. If "env" is specified, open the
 | 
					/* Try to open a configuration file. If "env" is specified, open the
 | 
				
			||||||
 * value of the specified environment variable. Otherwise look for a
 | 
					 * value of the specified environment variable. Otherwise look for a
 | 
				
			||||||
 * file "local" in the home directory or a file "global" in global
 | 
					 * file "local" in the home directory or a file "global" in global
 | 
				
			||||||
| 
						 | 
					@ -1418,7 +1440,7 @@ size_t pa_parsehex(const char *p, uint8_t *d, size_t dlength) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Returns nonzero when *s starts with *pfx */
 | 
					/* Returns nonzero when *s starts with *pfx */
 | 
				
			||||||
int pa_startswith(const char *s, const char *pfx) {
 | 
					pa_bool_t pa_startswith(const char *s, const char *pfx) {
 | 
				
			||||||
    size_t l;
 | 
					    size_t l;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert(s);
 | 
					    pa_assert(s);
 | 
				
			||||||
| 
						 | 
					@ -1430,7 +1452,7 @@ int pa_startswith(const char *s, const char *pfx) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Returns nonzero when *s ends with *sfx */
 | 
					/* Returns nonzero when *s ends with *sfx */
 | 
				
			||||||
int pa_endswith(const char *s, const char *sfx) {
 | 
					pa_bool_t pa_endswith(const char *s, const char *sfx) {
 | 
				
			||||||
    size_t l1, l2;
 | 
					    size_t l1, l2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert(s);
 | 
					    pa_assert(s);
 | 
				
			||||||
| 
						 | 
					@ -1472,13 +1494,16 @@ char *pa_make_path_absolute(const char *p) {
 | 
				
			||||||
/* if fn is null return the PulseAudio run time path in s (~/.pulse)
 | 
					/* if fn is null return the PulseAudio run time path in s (~/.pulse)
 | 
				
			||||||
 * if fn is non-null and starts with / return fn
 | 
					 * if fn is non-null and starts with / return fn
 | 
				
			||||||
 * otherwise append fn to the run time path and return it */
 | 
					 * otherwise append fn to the run time path and return it */
 | 
				
			||||||
char *pa_runtime_path(const char *fn) {
 | 
					static char *get_path(const char *fn, pa_bool_t rt) {
 | 
				
			||||||
    char *rtp;
 | 
					    char *rtp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (pa_is_path_absolute(fn))
 | 
					    if (pa_is_path_absolute(fn))
 | 
				
			||||||
        return pa_xstrdup(fn);
 | 
					        return pa_xstrdup(fn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rtp = pa_get_runtime_dir();
 | 
					    rtp = rt ? pa_get_runtime_dir() : pa_get_state_dir();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!rtp)
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (fn) {
 | 
					    if (fn) {
 | 
				
			||||||
        char *r;
 | 
					        char *r;
 | 
				
			||||||
| 
						 | 
					@ -1489,6 +1514,14 @@ char *pa_runtime_path(const char *fn) {
 | 
				
			||||||
        return rtp;
 | 
					        return rtp;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char *pa_runtime_path(const char *fn) {
 | 
				
			||||||
 | 
					    return get_path(fn, 1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char *pa_state_path(const char *fn) {
 | 
				
			||||||
 | 
					    return get_path(fn, 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Convert the string s to a signed integer in *ret_i */
 | 
					/* Convert the string s to a signed integer in *ret_i */
 | 
				
			||||||
int pa_atoi(const char *s, int32_t *ret_i) {
 | 
					int pa_atoi(const char *s, int32_t *ret_i) {
 | 
				
			||||||
    char *x = NULL;
 | 
					    char *x = NULL;
 | 
				
			||||||
| 
						 | 
					@ -2009,3 +2042,12 @@ void pa_set_env(const char *key, const char *value) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    putenv(pa_sprintf_malloc("%s=%s", key, value));
 | 
					    putenv(pa_sprintf_malloc("%s=%s", key, value));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pa_bool_t pa_in_system_mode(void) {
 | 
				
			||||||
 | 
					    const char *e;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!(e = getenv("PULSE_SYSTEM")))
 | 
				
			||||||
 | 
					        return FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return !!atoi(e);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -114,14 +114,16 @@ int pa_unlock_lockfile(const char *fn, int fd);
 | 
				
			||||||
char *pa_hexstr(const uint8_t* d, size_t dlength, char *s, size_t slength);
 | 
					char *pa_hexstr(const uint8_t* d, size_t dlength, char *s, size_t slength);
 | 
				
			||||||
size_t pa_parsehex(const char *p, uint8_t *d, size_t dlength);
 | 
					size_t pa_parsehex(const char *p, uint8_t *d, size_t dlength);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int pa_startswith(const char *s, const char *pfx) PA_GCC_PURE;
 | 
					pa_bool_t pa_startswith(const char *s, const char *pfx) PA_GCC_PURE;
 | 
				
			||||||
int pa_endswith(const char *s, const char *sfx) PA_GCC_PURE;
 | 
					pa_bool_t pa_endswith(const char *s, const char *sfx) PA_GCC_PURE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FILE *pa_open_config_file(const char *global, const char *local, const char *env, char **result);
 | 
					FILE *pa_open_config_file(const char *global, const char *local, const char *env, char **result);
 | 
				
			||||||
char* pa_find_config_file(const char *global, const char *local, const char *env);
 | 
					char* pa_find_config_file(const char *global, const char *local, const char *env);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char *pa_get_runtime_dir(void);
 | 
					char *pa_get_runtime_dir(void);
 | 
				
			||||||
 | 
					char *pa_get_state_dir(void);
 | 
				
			||||||
char *pa_runtime_path(const char *fn);
 | 
					char *pa_runtime_path(const char *fn);
 | 
				
			||||||
 | 
					char *pa_state_path(const char *fn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int pa_atoi(const char *s, int32_t *ret_i);
 | 
					int pa_atoi(const char *s, int32_t *ret_i);
 | 
				
			||||||
int pa_atou(const char *s, uint32_t *ret_u);
 | 
					int pa_atou(const char *s, uint32_t *ret_u);
 | 
				
			||||||
| 
						 | 
					@ -180,4 +182,8 @@ int pa_reset_sigsv(const int except[]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void pa_set_env(const char *key, const char *value);
 | 
					void pa_set_env(const char *key, const char *value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pa_bool_t pa_in_system_mode(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define pa_streq(a,b) (!strcmp((a),(b)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue