Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
df5cc3f0
Commit
df5cc3f0
authored
Aug 10, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/FileSystem: OpenFile() returns UniqueFileDescriptor
parent
eb0ff32e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
16 deletions
+13
-16
LogInit.cxx
src/LogInit.cxx
+1
-1
FileSystem.cxx
src/fs/FileSystem.cxx
+1
-0
FileSystem.hxx
src/fs/FileSystem.hxx
+5
-8
FifoOutputPlugin.cxx
src/output/plugins/FifoOutputPlugin.cxx
+2
-2
PidFile.hxx
src/unix/PidFile.hxx
+4
-5
No files found.
src/LogInit.cxx
View file @
df5cc3f0
...
...
@@ -62,7 +62,7 @@ open_log_file(void)
{
assert
(
!
out_path
.
IsNull
());
return
OpenFile
(
out_path
,
O_CREAT
|
O_WRONLY
|
O_APPEND
,
0666
);
return
OpenFile
(
out_path
,
O_CREAT
|
O_WRONLY
|
O_APPEND
,
0666
)
.
Steal
()
;
}
static
void
...
...
src/fs/FileSystem.cxx
View file @
df5cc3f0
...
...
@@ -22,6 +22,7 @@
#include "AllocatedPath.hxx"
#include "Limits.hxx"
#include "system/Error.hxx"
#include "system/fd_util.h"
#include <errno.h>
#include <fcntl.h>
...
...
src/fs/FileSystem.hxx
View file @
df5cc3f0
...
...
@@ -22,9 +22,8 @@
#include "check.h"
#include "Traits.hxx"
#include "system/fd_util.h"
#include "Path.hxx"
#include "system/UniqueFileDescriptor.hxx"
#ifdef WIN32
#include <fileapi.h>
...
...
@@ -53,14 +52,12 @@ FOpen(Path file, PathTraitsFS::const_pointer_type mode)
/**
* Wrapper for open_cloexec() that uses #Path names.
*/
static
inline
int
static
inline
UniqueFileDescriptor
OpenFile
(
Path
file
,
int
flags
,
int
mode
)
{
#ifdef WIN32
return
_topen
(
file
.
c_str
(),
flags
,
mode
);
#else
return
open_cloexec
(
file
.
c_str
(),
flags
,
mode
);
#endif
UniqueFileDescriptor
fd
;
fd
.
Open
(
file
.
c_str
(),
flags
,
mode
);
return
fd
;
}
/*
...
...
src/output/plugins/FifoOutputPlugin.cxx
View file @
df5cc3f0
...
...
@@ -153,12 +153,12 @@ FifoOutput::OpenFifo()
try
{
Check
();
input
=
OpenFile
(
path
,
O_RDONLY
|
O_NONBLOCK
|
O_BINARY
,
0
);
input
=
OpenFile
(
path
,
O_RDONLY
|
O_NONBLOCK
|
O_BINARY
,
0
)
.
Steal
()
;
if
(
input
<
0
)
throw
FormatErrno
(
"Could not open FIFO
\"
%s
\"
for reading"
,
path_utf8
.
c_str
());
output
=
OpenFile
(
path
,
O_WRONLY
|
O_NONBLOCK
|
O_BINARY
,
0
);
output
=
OpenFile
(
path
,
O_WRONLY
|
O_NONBLOCK
|
O_BINARY
,
0
)
.
Steal
()
;
if
(
output
<
0
)
throw
FormatErrno
(
"Could not open FIFO
\"
%s
\"
for writing"
,
path_utf8
.
c_str
());
...
...
src/unix/PidFile.hxx
View file @
df5cc3f0
...
...
@@ -38,7 +38,7 @@ public:
if
(
path
.
IsNull
())
return
;
fd
=
OpenFile
(
path
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0666
);
fd
=
OpenFile
(
path
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0666
)
.
Steal
()
;
if
(
fd
<
0
)
{
const
std
::
string
utf8
=
path
.
ToUTF8
();
FormatFatalSystemError
(
"Failed to create pid file
\"
%s
\"
"
,
...
...
@@ -90,14 +90,14 @@ gcc_pure
static
inline
pid_t
ReadPidFile
(
Path
path
)
noexcept
{
int
fd
=
OpenFile
(
path
,
O_RDONLY
,
0
);
if
(
fd
<
0
)
auto
fd
=
OpenFile
(
path
,
O_RDONLY
,
0
);
if
(
!
fd
.
IsDefined
()
)
return
-
1
;
pid_t
pid
=
-
1
;
char
buffer
[
32
];
auto
nbytes
=
read
(
fd
,
buffer
,
sizeof
(
buffer
)
-
1
);
auto
nbytes
=
fd
.
Read
(
buffer
,
sizeof
(
buffer
)
-
1
);
if
(
nbytes
>
0
)
{
buffer
[
nbytes
]
=
0
;
...
...
@@ -107,7 +107,6 @@ ReadPidFile(Path path) noexcept
pid
=
value
;
}
close
(
fd
);
return
pid
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment