fd_util: removed creat_cloexec()
Add a "mode" argument to open_cloexec() instead.
This commit is contained in:
parent
3d2a9d3545
commit
e0e6813a1d
@ -101,7 +101,7 @@ fd_set_nonblock(int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
open_cloexec(const char *path_fs, int flags)
|
open_cloexec(const char *path_fs, int flags, int mode)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
@ -109,26 +109,6 @@ open_cloexec(const char *path_fs, int flags)
|
|||||||
flags |= O_CLOEXEC;
|
flags |= O_CLOEXEC;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef O_NOCTTY
|
|
||||||
flags |= O_NOCTTY;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
fd = open(path_fs, flags, 0666);
|
|
||||||
fd_set_cloexec(fd, true);
|
|
||||||
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
creat_cloexec(const char *path_fs, int mode)
|
|
||||||
{
|
|
||||||
int flags = O_CREAT|O_WRONLY|O_TRUNC;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
#ifdef O_CLOEXEC
|
|
||||||
flags |= O_CLOEXEC;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef O_NOCTTY
|
#ifdef O_NOCTTY
|
||||||
flags |= O_NOCTTY;
|
flags |= O_NOCTTY;
|
||||||
#endif
|
#endif
|
||||||
|
@ -46,14 +46,7 @@ struct sockaddr;
|
|||||||
* supported by the OS).
|
* supported by the OS).
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
open_cloexec(const char *path_fs, int flags);
|
open_cloexec(const char *path_fs, int flags, int mode);
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper for creat(), which sets the CLOEXEC flag (atomically if
|
|
||||||
* supported by the OS).
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
creat_cloexec(const char *path_fs, int mode);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for pipe(), which sets the CLOEXEC flag (atomically if
|
* Wrapper for pipe(), which sets the CLOEXEC flag (atomically if
|
||||||
|
@ -51,7 +51,7 @@ input_file_open(struct input_stream *is, const char *filename)
|
|||||||
*slash = '\0';
|
*slash = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = open_cloexec(pathname, O_RDONLY);
|
fd = open_cloexec(pathname, O_RDONLY, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
is->error = errno;
|
is->error = errno;
|
||||||
g_debug("Failed to open \"%s\": %s",
|
g_debug("Failed to open \"%s\": %s",
|
||||||
|
@ -129,7 +129,7 @@ open_log_file(void)
|
|||||||
{
|
{
|
||||||
assert(out_filename != NULL);
|
assert(out_filename != NULL);
|
||||||
|
|
||||||
return open_cloexec(out_filename, O_CREAT | O_WRONLY | O_APPEND);
|
return open_cloexec(out_filename, O_CREAT | O_WRONLY | O_APPEND, 0666);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -123,7 +123,7 @@ oss_mixer_open(struct mixer *data, GError **error_r)
|
|||||||
{
|
{
|
||||||
struct oss_mixer *om = (struct oss_mixer *) data;
|
struct oss_mixer *om = (struct oss_mixer *) data;
|
||||||
|
|
||||||
om->device_fd = open_cloexec(om->device, O_RDONLY);
|
om->device_fd = open_cloexec(om->device, O_RDONLY, 0);
|
||||||
if (om->device_fd < 0) {
|
if (om->device_fd < 0) {
|
||||||
g_set_error(error_r, oss_mixer_quark(), errno,
|
g_set_error(error_r, oss_mixer_quark(), errno,
|
||||||
"failed to open %s: %s",
|
"failed to open %s: %s",
|
||||||
|
@ -153,7 +153,7 @@ fifo_open(struct fifo_data *fd, GError **error)
|
|||||||
if (!fifo_check(fd, error))
|
if (!fifo_check(fd, error))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
fd->input = open_cloexec(fd->path, O_RDONLY|O_NONBLOCK);
|
fd->input = open_cloexec(fd->path, O_RDONLY|O_NONBLOCK, 0);
|
||||||
if (fd->input < 0) {
|
if (fd->input < 0) {
|
||||||
g_set_error(error, fifo_output_quark(), errno,
|
g_set_error(error, fifo_output_quark(), errno,
|
||||||
"Could not open FIFO \"%s\" for reading: %s",
|
"Could not open FIFO \"%s\" for reading: %s",
|
||||||
@ -162,7 +162,7 @@ fifo_open(struct fifo_data *fd, GError **error)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd->output = open_cloexec(fd->path, O_WRONLY|O_NONBLOCK);
|
fd->output = open_cloexec(fd->path, O_WRONLY|O_NONBLOCK, 0);
|
||||||
if (fd->output < 0) {
|
if (fd->output < 0) {
|
||||||
g_set_error(error, fifo_output_quark(), errno,
|
g_set_error(error, fifo_output_quark(), errno,
|
||||||
"Could not open FIFO \"%s\" for writing: %s",
|
"Could not open FIFO \"%s\" for writing: %s",
|
||||||
|
@ -116,7 +116,7 @@ mvp_output_test_default_device(void)
|
|||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open_cloexec("/dev/adec_pcm", O_WRONLY);
|
fd = open_cloexec("/dev/adec_pcm", O_WRONLY, 0);
|
||||||
|
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -231,7 +231,7 @@ mvp_output_open(void *data, struct audio_format *audio_format, GError **error)
|
|||||||
int mix[5] = { 0, 2, 7, 1, 0 };
|
int mix[5] = { 0, 2, 7, 1, 0 };
|
||||||
bool success;
|
bool success;
|
||||||
|
|
||||||
md->fd = open_cloexec("/dev/adec_pcm", O_RDWR | O_NONBLOCK);
|
md->fd = open_cloexec("/dev/adec_pcm", O_RDWR | O_NONBLOCK, 0);
|
||||||
if (md->fd < 0) {
|
if (md->fd < 0) {
|
||||||
g_set_error(error, mvp_output_quark(), errno,
|
g_set_error(error, mvp_output_quark(), errno,
|
||||||
"Error opening /dev/adec_pcm: %s",
|
"Error opening /dev/adec_pcm: %s",
|
||||||
|
@ -344,7 +344,7 @@ oss_output_test_default_device(void)
|
|||||||
int fd, i;
|
int fd, i;
|
||||||
|
|
||||||
for (i = G_N_ELEMENTS(default_devices); --i >= 0; ) {
|
for (i = G_N_ELEMENTS(default_devices); --i >= 0; ) {
|
||||||
fd = open_cloexec(default_devices[i], O_WRONLY);
|
fd = open_cloexec(default_devices[i], O_WRONLY, 0);
|
||||||
|
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -519,7 +519,7 @@ oss_open(struct oss_data *od, GError **error)
|
|||||||
{
|
{
|
||||||
bool success;
|
bool success;
|
||||||
|
|
||||||
od->fd = open_cloexec(od->device, O_WRONLY);
|
od->fd = open_cloexec(od->device, O_WRONLY, 0);
|
||||||
if (od->fd < 0) {
|
if (od->fd < 0) {
|
||||||
g_set_error(error, oss_output_quark(), errno,
|
g_set_error(error, oss_output_quark(), errno,
|
||||||
"Error opening OSS device \"%s\": %s",
|
"Error opening OSS device \"%s\": %s",
|
||||||
|
@ -157,7 +157,8 @@ recorder_output_open(void *data, struct audio_format *audio_format,
|
|||||||
|
|
||||||
/* create the output file */
|
/* create the output file */
|
||||||
|
|
||||||
recorder->fd = creat_cloexec(recorder->path, 0666);
|
recorder->fd = open_cloexec(recorder->path, O_CREAT|O_WRONLY|O_TRUNC,
|
||||||
|
0666);
|
||||||
if (recorder->fd < 0) {
|
if (recorder->fd < 0) {
|
||||||
g_set_error(error_r, recorder_output_quark(), 0,
|
g_set_error(error_r, recorder_output_quark(), 0,
|
||||||
"Failed to create '%s': %s",
|
"Failed to create '%s': %s",
|
||||||
|
Loading…
Reference in New Issue
Block a user