mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-31 22:25:33 -04:00
use pa_fopen_cloexec() where applicable
This commit is contained in:
parent
88b72958be
commit
168be3830a
14 changed files with 27 additions and 27 deletions
|
|
@ -577,7 +577,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) {
|
||||||
c->config_file = NULL;
|
c->config_file = NULL;
|
||||||
|
|
||||||
f = filename ?
|
f = filename ?
|
||||||
fopen(c->config_file = pa_xstrdup(filename), "r") :
|
pa_fopen_cloexec(c->config_file = pa_xstrdup(filename), "r") :
|
||||||
pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file);
|
pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file);
|
||||||
|
|
||||||
if (!f && errno != ENOENT) {
|
if (!f && errno != ENOENT) {
|
||||||
|
|
@ -652,7 +652,7 @@ FILE *pa_daemon_conf_open_default_script_file(pa_daemon_conf *c) {
|
||||||
else
|
else
|
||||||
f = pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE, &c->default_script_file);
|
f = pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER, ENV_SCRIPT_FILE, &c->default_script_file);
|
||||||
} else
|
} else
|
||||||
f = fopen(c->default_script_file, "r");
|
f = pa_fopen_cloexec(c->default_script_file, "r");
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ int pa__init(pa_module*m) {
|
||||||
* of log messages, particularly because if stdout and stderr are
|
* of log messages, particularly because if stdout and stderr are
|
||||||
* dup'ed they share the same O_NDELAY, too. */
|
* dup'ed they share the same O_NDELAY, too. */
|
||||||
|
|
||||||
if ((fd = open("/dev/tty", O_RDWR|O_CLOEXEC|O_NONBLOCK)) >= 0) {
|
if ((fd = pa_open_cloexec("/dev/tty", O_RDWR|O_NONBLOCK, 0)) >= 0) {
|
||||||
io = pa_iochannel_new(m->core->mainloop, fd, fd);
|
io = pa_iochannel_new(m->core->mainloop, fd, fd);
|
||||||
pa_log_debug("Managed to open /dev/tty.");
|
pa_log_debug("Managed to open /dev/tty.");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ static void load(struct userdata *u) {
|
||||||
|
|
||||||
if (u->core->default_sink)
|
if (u->core->default_sink)
|
||||||
pa_log_info("Manually configured default sink, not overwriting.");
|
pa_log_info("Manually configured default sink, not overwriting.");
|
||||||
else if ((f = fopen(u->sink_filename, "r"))) {
|
else if ((f = pa_fopen_cloexec(u->sink_filename, "r"))) {
|
||||||
char ln[256] = "";
|
char ln[256] = "";
|
||||||
pa_sink *s;
|
pa_sink *s;
|
||||||
|
|
||||||
|
|
@ -81,7 +81,7 @@ static void load(struct userdata *u) {
|
||||||
|
|
||||||
if (u->core->default_source)
|
if (u->core->default_source)
|
||||||
pa_log_info("Manually configured default source, not overwriting.");
|
pa_log_info("Manually configured default source, not overwriting.");
|
||||||
else if ((f = fopen(u->source_filename, "r"))) {
|
else if ((f = pa_fopen_cloexec(u->source_filename, "r"))) {
|
||||||
char ln[256] = "";
|
char ln[256] = "";
|
||||||
pa_source *s;
|
pa_source *s;
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ static void save(struct userdata *u) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (u->sink_filename) {
|
if (u->sink_filename) {
|
||||||
if ((f = fopen(u->sink_filename, "w"))) {
|
if ((f = pa_fopen_cloexec(u->sink_filename, "w"))) {
|
||||||
pa_sink *s = pa_namereg_get_default_sink(u->core);
|
pa_sink *s = pa_namereg_get_default_sink(u->core);
|
||||||
fprintf(f, "%s\n", s ? s->name : "");
|
fprintf(f, "%s\n", s ? s->name : "");
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
@ -117,7 +117,7 @@ static void save(struct userdata *u) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (u->source_filename) {
|
if (u->source_filename) {
|
||||||
if ((f = fopen(u->source_filename, "w"))) {
|
if ((f = pa_fopen_cloexec(u->source_filename, "w"))) {
|
||||||
pa_source *s = pa_namereg_get_default_source(u->core);
|
pa_source *s = pa_namereg_get_default_source(u->core);
|
||||||
fprintf(f, "%s\n", s ? s->name : "");
|
fprintf(f, "%s\n", s ? s->name : "");
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ static int detect_alsa(pa_core *c, int just_one) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int n = 0, n_sink = 0, n_source = 0;
|
int n = 0, n_sink = 0, n_source = 0;
|
||||||
|
|
||||||
if (!(f = fopen("/proc/asound/devices", "r"))) {
|
if (!(f = pa_fopen_cloexec("/proc/asound/devices", "r"))) {
|
||||||
|
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
pa_log_error("open(\"/proc/asound/devices\") failed: %s", pa_cstrerror(errno));
|
pa_log_error("open(\"/proc/asound/devices\") failed: %s", pa_cstrerror(errno));
|
||||||
|
|
@ -124,9 +124,9 @@ static int detect_oss(pa_core *c, int just_one) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int n = 0, b = 0;
|
int n = 0, b = 0;
|
||||||
|
|
||||||
if (!(f = fopen("/dev/sndstat", "r")) &&
|
if (!(f = pa_fopen_cloexec("/dev/sndstat", "r")) &&
|
||||||
!(f = fopen("/proc/sndstat", "r")) &&
|
!(f = pa_fopen_cloexec("/proc/sndstat", "r")) &&
|
||||||
!(f = fopen("/proc/asound/oss/sndstat", "r"))) {
|
!(f = pa_fopen_cloexec("/proc/asound/oss/sndstat", "r"))) {
|
||||||
|
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
pa_log_error("failed to open OSS sndstat device: %s", pa_cstrerror(errno));
|
pa_log_error("failed to open OSS sndstat device: %s", pa_cstrerror(errno));
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ static int load_rules(struct userdata *u, const char *filename) {
|
||||||
pa_assert(u);
|
pa_assert(u);
|
||||||
|
|
||||||
if (filename)
|
if (filename)
|
||||||
f = fopen(fn = pa_xstrdup(filename), "r");
|
f = pa_fopen_cloexec(fn = pa_xstrdup(filename), "r");
|
||||||
else
|
else
|
||||||
f = pa_open_config_file(DEFAULT_MATCH_TABLE_FILE, DEFAULT_MATCH_TABLE_FILE_USER, NULL, &fn);
|
f = pa_open_config_file(DEFAULT_MATCH_TABLE_FILE, DEFAULT_MATCH_TABLE_FILE_USER, NULL, &fn);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ static pa_bool_t is_card_busy(const char *id) {
|
||||||
if (status_file)
|
if (status_file)
|
||||||
fclose(status_file);
|
fclose(status_file);
|
||||||
|
|
||||||
if (!(status_file = fopen(sub_status, "r"))) {
|
if (!(status_file = pa_fopen_cloexec(sub_status, "r"))) {
|
||||||
pa_log_warn("Failed to open %s: %s", sub_status, pa_cstrerror(errno));
|
pa_log_warn("Failed to open %s: %s", sub_status, pa_cstrerror(errno));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -349,9 +349,9 @@ int pa_oss_get_hw_description(const char *dev, char *name, size_t l) {
|
||||||
if ((n = get_device_number(dev)) < 0)
|
if ((n = get_device_number(dev)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!(f = fopen("/dev/sndstat", "r")) &&
|
if (!(f = pa_fopen_cloexec("/dev/sndstat", "r")) &&
|
||||||
!(f = fopen("/proc/sndstat", "r")) &&
|
!(f = pa_fopen_cloexec("/proc/sndstat", "r")) &&
|
||||||
!(f = fopen("/proc/asound/oss/sndstat", "r"))) {
|
!(f = pa_fopen_cloexec("/proc/asound/oss/sndstat", "r"))) {
|
||||||
|
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
pa_log_warn("failed to open OSS sndstat device: %s", pa_cstrerror(errno));
|
pa_log_warn("failed to open OSS sndstat device: %s", pa_cstrerror(errno));
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ int pa_client_conf_load(pa_client_conf *c, const char *filename) {
|
||||||
|
|
||||||
if (filename) {
|
if (filename) {
|
||||||
|
|
||||||
if (!(f = fopen(filename, "r"))) {
|
if (!(f = pa_fopen_cloexec(filename, "r"))) {
|
||||||
pa_log(_("Failed to open configuration file '%s': %s"), fn, pa_cstrerror(errno));
|
pa_log(_("Failed to open configuration file '%s': %s"), fn, pa_cstrerror(errno));
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1804,7 +1804,7 @@ int pa_cli_command_execute_file(pa_core *c, const char *fn, pa_strbuf *buf, pa_b
|
||||||
if (!fail)
|
if (!fail)
|
||||||
fail = &_fail;
|
fail = &_fail;
|
||||||
|
|
||||||
if (!(f = fopen(fn, "r"))) {
|
if (!(f = pa_fopen_cloexec(fn, "r"))) {
|
||||||
pa_strbuf_printf(buf, "open('%s') failed: %s\n", fn, pa_cstrerror(errno));
|
pa_strbuf_printf(buf, "open('%s') failed: %s\n", fn, pa_cstrerror(errno));
|
||||||
if (!*fail)
|
if (!*fail)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,7 @@ int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, void
|
||||||
pa_assert(filename);
|
pa_assert(filename);
|
||||||
pa_assert(t);
|
pa_assert(t);
|
||||||
|
|
||||||
if (!f && !(f = fopen(filename, "r"))) {
|
if (!f && !(f = pa_fopen_cloexec(filename, "r"))) {
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
pa_log_debug("Failed to open configuration file '%s': %s", filename, pa_cstrerror(errno));
|
pa_log_debug("Failed to open configuration file '%s': %s", filename, pa_cstrerror(errno));
|
||||||
r = 0;
|
r = 0;
|
||||||
|
|
|
||||||
|
|
@ -1600,7 +1600,7 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env
|
||||||
fn = buf;
|
fn = buf;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((f = fopen(fn, "r"))) {
|
if ((f = pa_fopen_cloexec(fn, "r"))) {
|
||||||
if (result)
|
if (result)
|
||||||
*result = pa_xstrdup(fn);
|
*result = pa_xstrdup(fn);
|
||||||
|
|
||||||
|
|
@ -1634,7 +1634,7 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env
|
||||||
fn = buf;
|
fn = buf;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((f = fopen(fn, "r"))) {
|
if ((f = pa_fopen_cloexec(fn, "r"))) {
|
||||||
if (result)
|
if (result)
|
||||||
*result = pa_xstrdup(fn);
|
*result = pa_xstrdup(fn);
|
||||||
|
|
||||||
|
|
@ -1661,7 +1661,7 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env
|
||||||
global = buf;
|
global = buf;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((f = fopen(global, "r"))) {
|
if ((f = pa_fopen_cloexec(global, "r"))) {
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
*result = pa_xstrdup(global);
|
*result = pa_xstrdup(global);
|
||||||
|
|
@ -2560,7 +2560,7 @@ char *pa_machine_id(void) {
|
||||||
* since it fits perfectly our needs and is not as volatile as the
|
* since it fits perfectly our needs and is not as volatile as the
|
||||||
* hostname which might be set from dhcp. */
|
* hostname which might be set from dhcp. */
|
||||||
|
|
||||||
if ((f = fopen(PA_MACHINE_ID, "r"))) {
|
if ((f = pa_fopen_cloexec(PA_MACHINE_ID, "r"))) {
|
||||||
char ln[34] = "", *r;
|
char ln[34] = "", *r;
|
||||||
|
|
||||||
r = fgets(ln, sizeof(ln)-1, f);
|
r = fgets(ln, sizeof(ln)-1, f);
|
||||||
|
|
|
||||||
|
|
@ -237,7 +237,7 @@ pa_database* pa_database_open(const char *fn, pa_bool_t for_write) {
|
||||||
path = pa_sprintf_malloc("%s."CANONICAL_HOST".simple", fn);
|
path = pa_sprintf_malloc("%s."CANONICAL_HOST".simple", fn);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
f = fopen(path, "r");
|
f = pa_fopen_cloexec(path, "r");
|
||||||
|
|
||||||
if (f || errno == ENOENT) { /* file not found is ok */
|
if (f || errno == ENOENT) { /* file not found is ok */
|
||||||
db = pa_xnew0(simple_data, 1);
|
db = pa_xnew0(simple_data, 1);
|
||||||
|
|
@ -480,7 +480,7 @@ int pa_database_sync(pa_database *database) {
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
f = fopen(db->tmp_filename, "w");
|
f = pa_fopen_cloexec(db->tmp_filename, "w");
|
||||||
|
|
||||||
if (!f)
|
if (!f)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ static int proc_name_ours(pid_t pid, const char *procname) {
|
||||||
|
|
||||||
pa_snprintf(bn, sizeof(bn), "/proc/%lu/stat", (unsigned long) pid);
|
pa_snprintf(bn, sizeof(bn), "/proc/%lu/stat", (unsigned long) pid);
|
||||||
|
|
||||||
if (!(f = fopen(bn, "r"))) {
|
if (!(f = pa_fopen_cloexec(bn, "r"))) {
|
||||||
pa_log_info("Failed to open %s: %s", bn, pa_cstrerror(errno));
|
pa_log_info("Failed to open %s: %s", bn, pa_cstrerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1007,7 +1007,7 @@ void pa_memchunk_dump_to_file(pa_memchunk *c, const char *fn) {
|
||||||
|
|
||||||
/* Only for debugging purposes */
|
/* Only for debugging purposes */
|
||||||
|
|
||||||
f = fopen(fn, "a");
|
f = pa_fopen_cloexec(fn, "a");
|
||||||
|
|
||||||
if (!f) {
|
if (!f) {
|
||||||
pa_log_warn("Failed to open '%s': %s", fn, pa_cstrerror(errno));
|
pa_log_warn("Failed to open '%s': %s", fn, pa_cstrerror(errno));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue