projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
sysevent plugin initial commit
[collectd.git]
/
src
/
utils_tail.c
diff --git
a/src/utils_tail.c
b/src/utils_tail.c
index
565a224
..
b5dc5af
100644
(file)
--- a/
src/utils_tail.c
+++ b/
src/utils_tail.c
@@
-49,10
+49,8
@@
static int cu_tail_reopen(cu_tail_t *obj) {
status = stat(obj->file, &stat_buf);
if (status != 0) {
status = stat(obj->file, &stat_buf);
if (status != 0) {
- char errbuf[1024];
- ERROR("utils_tail: stat (%s) failed: %s", obj->file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
- return (-1);
+ ERROR("utils_tail: stat (%s) failed: %s", obj->file, STRERRNO);
+ return -1;
}
/* The file is already open.. */
}
/* The file is already open.. */
@@
-62,16
+60,14
@@
static int cu_tail_reopen(cu_tail_t *obj) {
INFO("utils_tail: File `%s' was truncated.", obj->file);
status = fseek(obj->fh, 0, SEEK_SET);
if (status != 0) {
INFO("utils_tail: File `%s' was truncated.", obj->file);
status = fseek(obj->fh, 0, SEEK_SET);
if (status != 0) {
- char errbuf[1024];
- ERROR("utils_tail: fseek (%s) failed: %s", obj->file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("utils_tail: fseek (%s) failed: %s", obj->file, STRERRNO);
fclose(obj->fh);
obj->fh = NULL;
fclose(obj->fh);
obj->fh = NULL;
- return
(-1)
;
+ return
-1
;
}
}
memcpy(&obj->stat, &stat_buf, sizeof(struct stat));
}
}
memcpy(&obj->stat, &stat_buf, sizeof(struct stat));
- return
(1)
;
+ return
1
;
}
/* Seek to the end if we re-open the same file again or the file opened
}
/* Seek to the end if we re-open the same file again or the file opened
@@
-81,20
+77,16
@@
static int cu_tail_reopen(cu_tail_t *obj) {
fh = fopen(obj->file, "r");
if (fh == NULL) {
fh = fopen(obj->file, "r");
if (fh == NULL) {
- char errbuf[1024];
- ERROR("utils_tail: fopen (%s) failed: %s", obj->file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
- return (-1);
+ ERROR("utils_tail: fopen (%s) failed: %s", obj->file, STRERRNO);
+ return -1;
}
if (seek_end != 0) {
status = fseek(fh, 0, SEEK_END);
if (status != 0) {
}
if (seek_end != 0) {
status = fseek(fh, 0, SEEK_END);
if (status != 0) {
- char errbuf[1024];
- ERROR("utils_tail: fseek (%s) failed: %s", obj->file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("utils_tail: fseek (%s) failed: %s", obj->file, STRERRNO);
fclose(fh);
fclose(fh);
- return
(-1)
;
+ return
-1
;
}
}
}
}
@@
-103,7
+95,7
@@
static int cu_tail_reopen(cu_tail_t *obj) {
obj->fh = fh;
memcpy(&obj->stat, &stat_buf, sizeof(struct stat));
obj->fh = fh;
memcpy(&obj->stat, &stat_buf, sizeof(struct stat));
- return
(0)
;
+ return
0
;
} /* int cu_tail_reopen */
cu_tail_t *cu_tail_create(const char *file) {
} /* int cu_tail_reopen */
cu_tail_t *cu_tail_create(const char *file) {
@@
-111,17
+103,17
@@
cu_tail_t *cu_tail_create(const char *file) {
obj = calloc(1, sizeof(*obj));
if (obj == NULL)
obj = calloc(1, sizeof(*obj));
if (obj == NULL)
- return
(NULL)
;
+ return
NULL
;
obj->file = strdup(file);
if (obj->file == NULL) {
free(obj);
obj->file = strdup(file);
if (obj->file == NULL) {
free(obj);
- return
(NULL)
;
+ return
NULL
;
}
obj->fh = NULL;
}
obj->fh = NULL;
- return
(obj)
;
+ return
obj
;
} /* cu_tail_t *cu_tail_create */
int cu_tail_destroy(cu_tail_t *obj) {
} /* cu_tail_t *cu_tail_create */
int cu_tail_destroy(cu_tail_t *obj) {
@@
-130,7
+122,7
@@
int cu_tail_destroy(cu_tail_t *obj) {
free(obj->file);
free(obj);
free(obj->file);
free(obj);
- return
(0)
;
+ return
0
;
} /* int cu_tail_destroy */
int cu_tail_readline(cu_tail_t *obj, char *buf, int buflen) {
} /* int cu_tail_destroy */
int cu_tail_readline(cu_tail_t *obj, char *buf, int buflen) {
@@
-138,13
+130,13
@@
int cu_tail_readline(cu_tail_t *obj, char *buf, int buflen) {
if (buflen < 1) {
ERROR("utils_tail: cu_tail_readline: buflen too small: %i bytes.", buflen);
if (buflen < 1) {
ERROR("utils_tail: cu_tail_readline: buflen too small: %i bytes.", buflen);
- return
(-1)
;
+ return
-1
;
}
if (obj->fh == NULL) {
status = cu_tail_reopen(obj);
if (status < 0)
}
if (obj->fh == NULL) {
status = cu_tail_reopen(obj);
if (status < 0)
- return
(status)
;
+ return
status
;
}
assert(obj->fh != NULL);
}
assert(obj->fh != NULL);
@@
-153,7
+145,7
@@
int cu_tail_readline(cu_tail_t *obj, char *buf, int buflen) {
clearerr(obj->fh);
if (fgets(buf, buflen, obj->fh) != NULL) {
buf[buflen - 1] = 0;
clearerr(obj->fh);
if (fgets(buf, buflen, obj->fh) != NULL) {
buf[buflen - 1] = 0;
- return
(0)
;
+ return
0
;
}
/* Check if we encountered an error */
}
/* Check if we encountered an error */
@@
-168,32
+160,31
@@
int cu_tail_readline(cu_tail_t *obj, char *buf, int buflen) {
status = cu_tail_reopen(obj);
/* error -> return with error */
if (status < 0)
status = cu_tail_reopen(obj);
/* error -> return with error */
if (status < 0)
- return
(status)
;
+ return
status
;
/* file end reached and file not reopened -> nothing more to read */
else if (status > 0) {
buf[0] = 0;
/* file end reached and file not reopened -> nothing more to read */
else if (status > 0) {
buf[0] = 0;
- return
(0)
;
+ return
0
;
}
/* If we get here: file was re-opened and there may be more to read.. Let's
* try again. */
if (fgets(buf, buflen, obj->fh) != NULL) {
buf[buflen - 1] = 0;
}
/* If we get here: file was re-opened and there may be more to read.. Let's
* try again. */
if (fgets(buf, buflen, obj->fh) != NULL) {
buf[buflen - 1] = 0;
- return
(0)
;
+ return
0
;
}
if (ferror(obj->fh) != 0) {
}
if (ferror(obj->fh) != 0) {
- char errbuf[1024];
WARNING("utils_tail: fgets (%s) returned an error: %s", obj->file,
WARNING("utils_tail: fgets (%s) returned an error: %s", obj->file,
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
fclose(obj->fh);
obj->fh = NULL;
fclose(obj->fh);
obj->fh = NULL;
- return
(-1)
;
+ return
-1
;
}
/* EOf, well, apparently the new file is empty.. */
buf[0] = 0;
}
/* EOf, well, apparently the new file is empty.. */
buf[0] = 0;
- return
(0)
;
+ return
0
;
} /* int cu_tail_readline */
int cu_tail_read(cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback,
} /* int cu_tail_readline */
int cu_tail_read(cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback,