diff options
| author | Simon Rettberg | 2017-11-08 16:14:32 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2017-11-08 16:14:32 +0100 |
| commit | 01a2ebb9a402dc4c3f9183d457565685885f6fb9 (patch) | |
| tree | b54fd8702865fcb02abf865536734987e1b52a01 /src/shared | |
| parent | [SERVER] Add multiple config options for limiting stuff (diff) | |
| download | dnbd3-01a2ebb9a402dc4c3f9183d457565685885f6fb9.tar.gz dnbd3-01a2ebb9a402dc4c3f9183d457565685885f6fb9.tar.xz dnbd3-01a2ebb9a402dc4c3f9183d457565685885f6fb9.zip | |
[SERVER] rpc: Add q=logfile, q=altservers and q=config to /query
Diffstat (limited to 'src/shared')
| -rw-r--r-- | src/shared/log.c | 12 | ||||
| -rw-r--r-- | src/shared/log.h | 3 |
2 files changed, 7 insertions, 8 deletions
diff --git a/src/shared/log.c b/src/shared/log.c index 701bc89..a3ffe4a 100644 --- a/src/shared/log.c +++ b/src/shared/log.c @@ -129,17 +129,17 @@ void logadd(const logmask_t mask, const char *fmt, ...) } } -bool log_fetch(char *buffer, int size) +ssize_t log_fetch(char *buffer, int size) { if ( logFile == NULL || size <= 1 ) - return false; + return -1; int fd = open( logFile, O_RDONLY ); if ( fd < 0 ) - return false; + return -1; off_t off = lseek( fd, 0, SEEK_END ); if ( off == (off_t)-1 ) { close( fd ); - return false; + return -1; } if ( (off_t)size <= off ) { off -= size; @@ -148,10 +148,8 @@ bool log_fetch(char *buffer, int size) } ssize_t ret = pread( fd, buffer, size - 1, off ); close( fd ); - if ( ret < 0 ) - return false; buffer[ret] = '\0'; - return true; + return ret; } static int writeLevel(char *buffer, logmask_t level) diff --git a/src/shared/log.h b/src/shared/log.h index ac5bb92..da34fc3 100644 --- a/src/shared/log.h +++ b/src/shared/log.h @@ -22,6 +22,7 @@ #define LOG_H_ #include <stdbool.h> +#include <unistd.h> typedef unsigned int logmask_t; #define LOG_ERROR ((logmask_t)1) // Fatal error, server will terminate @@ -57,6 +58,6 @@ void logadd(const logmask_t mask, const char *text, ...) /** * Return last size bytes of log. */ -bool log_fetch(char *buffer, int size); +ssize_t log_fetch(char *buffer, int size); #endif /* LOG_H_ */ |
