projects
/
lttng-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix: utils: unhandled close return value
[lttng-tools.git]
/
src
/
common
/
utils.cpp
diff --git
a/src/common/utils.cpp
b/src/common/utils.cpp
index b4b7f749f1ef1a6e5286225437f639d01f2966d2..89ef0e54fd01714ea866c05dd2424cd1f21c26e5 100644
(file)
--- a/
src/common/utils.cpp
+++ b/
src/common/utils.cpp
@@
-212,30
+212,43
@@
end:
*/
int utils_create_pid_file(pid_t pid, const char *filepath)
{
*/
int utils_create_pid_file(pid_t pid, const char *filepath)
{
- int ret;
- FILE *fp;
+ int ret
, fd = -1
;
+ FILE *fp
= NULL
;
LTTNG_ASSERT(filepath);
LTTNG_ASSERT(filepath);
- fp = fopen(filepath, "w");
+ fd = open(filepath, O_CREAT | O_WRONLY, S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH);
+ if (fd < 0) {
+ PERROR("open file %s", filepath);
+ ret = -1;
+ goto error;
+ }
+
+ fp = fdopen(fd, "w");
if (fp == NULL) {
if (fp == NULL) {
- PERROR("
open pid
file %s", filepath);
+ PERROR("
fdopen
file %s", filepath);
ret = -1;
ret = -1;
+ if (close(fd)) {
+ PERROR("Failed to close `%s` file descriptor while handling fdopen error", filepath);
+ }
+
goto error;
}
ret = fprintf(fp, "%d\n", (int) pid);
if (ret < 0) {
goto error;
}
ret = fprintf(fp, "%d\n", (int) pid);
if (ret < 0) {
- PERROR("fprintf pid file");
+ PERROR("fprintf file %s", filepath);
+ ret = -1;
goto error;
}
goto error;
}
- if (fclose(fp)) {
- PERROR("fclose");
- }
- DBG("Pid %d written in file %s", (int) pid, filepath);
+ DBG("'%d' written in file %s", (int) pid, filepath);
ret = 0;
ret = 0;
+
error:
error:
+ if (fp && fclose(fp)) {
+ PERROR("fclose file %s", filepath);
+ }
return ret;
}
return ret;
}
This page took
0.035031 seconds
and
4
git commands to generate.