Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
audiowmark
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
audiowmark
Commits
289c4e72
Commit
289c4e72
authored
Jul 16, 2020
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HLS: improve error handling for run()
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
d972eb75
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
6 deletions
+35
-6
hls.cc
src/hls.cc
+35
-6
No files found.
src/hls.cc
View file @
289c4e72
...
...
@@ -56,6 +56,8 @@ args2string (const vector<string>& args)
Error
run
(
const
vector
<
string
>&
args
,
vector
<
string
>
*
pipe_out
=
nullptr
)
{
auto
report_error
=
[
=
]
{
error
(
"audiowmark: failed to execute %s
\n
"
,
args2string
(
args
).
c_str
());
};
char
*
argv
[
args
.
size
()
+
1
];
for
(
size_t
i
=
0
;
i
<
args
.
size
();
i
++
)
argv
[
i
]
=
(
char
*
)
args
[
i
].
c_str
();
...
...
@@ -65,21 +67,39 @@ run (const vector<string>& args, vector<string> *pipe_out = nullptr)
if
(
pipe_out
)
{
if
(
pipe
(
pipe_fds
)
==
-
1
)
{
report_error
();
return
Error
(
"pipe() failed"
);
}
}
pid_t
pid
=
fork
();
if
(
pid
<
0
)
{
if
(
pipe_out
)
{
close
(
pipe_fds
[
0
]);
close
(
pipe_fds
[
1
]);
}
report_error
();
return
Error
(
"fork() failed"
);
}
if
(
pid
==
0
)
/* child process */
{
if
(
pipe_out
)
{
// replace stdout with pipe
dup2
(
pipe_fds
[
1
],
STDOUT_FILENO
);
if
(
dup2
(
pipe_fds
[
1
],
STDOUT_FILENO
)
==
-
1
)
{
perror
(
"audiowmark: dup2() failed"
);
exit
(
127
);
}
// close remaining pipe fds
close
(
pipe_fds
[
0
]);
close
(
pipe_fds
[
1
]);
}
execvp
(
argv
[
0
],
argv
);
perror
(
"audiowmark: execvp() failed"
);
// should not be reached in normal operation, so exec failed
exit
(
127
);
...
...
@@ -91,6 +111,12 @@ run (const vector<string>& args, vector<string> *pipe_out = nullptr)
close
(
pipe_fds
[
1
]);
// close pipe write fd
FILE
*
f
=
fdopen
(
pipe_fds
[
0
],
"r"
);
if
(
!
f
)
{
close
(
pipe_fds
[
0
]);
report_error
();
return
Error
(
"fdopen() pipe failed"
);
}
char
buffer
[
1024
];
while
(
fgets
(
buffer
,
1024
,
f
))
{
...
...
@@ -104,19 +130,22 @@ run (const vector<string>& args, vector<string> *pipe_out = nullptr)
int
status
;
pid_t
exited
=
waitpid
(
pid
,
&
status
,
0
);
if
(
exited
<
0
)
{
report_error
();
return
Error
(
"waitpid() failed"
);
}
if
(
WIFEXITED
(
status
))
{
int
exit_status
=
WEXITSTATUS
(
status
);
if
(
exit_status
!=
0
)
{
error
(
"audiowmark: failed to execute %s
\n
"
,
args2string
(
args
).
c_str
()
);
report_error
(
);
return
Error
(
string_printf
(
"subprocess failed / exit status %d"
,
exit_status
));
}
}
else
{
error
(
"audiowmark: failed to execute %s
\n
"
,
args2string
(
args
).
c_str
()
);
report_error
(
);
return
Error
(
"child didn't exit normally"
);
}
return
Error
::
Code
::
NONE
;
...
...
@@ -252,7 +281,7 @@ validate_input_segment (const string& filename)
Error
err
=
run
({
"ffprobe"
,
"-v"
,
"error"
,
"-print_format"
,
"compact"
,
"-show_streams"
,
filename
},
&
format_out
);
if
(
err
)
{
error
(
"audiowmark: hls: failed
validating input"
);
error
(
"audiowmark: hls: failed
to validate input file: %s
\n
"
,
filename
.
c_str
()
);
return
err
;
}
for
(
auto
o
:
format_out
)
...
...
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