projects
/
lttng-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix: agent port file is o+w when launching as root
[lttng-tools.git]
/
src
/
common
/
utils.c
diff --git
a/src/common/utils.c
b/src/common/utils.c
index 210a7a6a1e1b6860fba64f2b82a842b5311ff7f2..7aed4442b5a635d6ba731ad6f2f8fc6224ae7643 100644
(file)
--- a/
src/common/utils.c
+++ b/
src/common/utils.c
@@
-224,30
+224,40
@@
end:
LTTNG_HIDDEN
int utils_create_pid_file(pid_t pid, const char *filepath)
{
LTTNG_HIDDEN
int utils_create_pid_file(pid_t pid, const char *filepath)
{
- int ret;
- FILE *fp;
+ int ret
, fd = -1
;
+ FILE *fp
= NULL
;
assert(filepath);
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;
+ close(fd);
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.024851 seconds
and
4
git commands to generate.