summaryrefslogtreecommitdiffstats
path: root/configd
diff options
context:
space:
mode:
authorArne H Juul <arnej@yahoo-inc.com>2016-07-04 12:15:31 +0200
committerArne H Juul <arnej@yahoo-inc.com>2016-07-04 12:15:31 +0200
commit4520ca00d817f7b85cfa6be8fe06053b30de3ce2 (patch)
tree442f36e52eb41ca0a710cbedf486ed3db8d9787a /configd
parent107d5e3b4af3014469841fc1fe5ff005b5a5ede0 (diff)
stop faking input after EOF
* don't add extra newline after EOF received * eof() should only return true after all input is consumed * still need to handle EOF-without-newline, but do it in a more conservative manner.
Diffstat (limited to 'configd')
-rw-r--r--configd/src/apps/sentinel/line-splitter.cpp6
-rw-r--r--configd/src/apps/sentinel/line-splitter.h2
2 files changed, 4 insertions, 4 deletions
diff --git a/configd/src/apps/sentinel/line-splitter.cpp b/configd/src/apps/sentinel/line-splitter.cpp
index 8e990475b99..e52f4e3f33e 100644
--- a/configd/src/apps/sentinel/line-splitter.cpp
+++ b/configd/src/apps/sentinel/line-splitter.cpp
@@ -71,9 +71,6 @@ LineSplitter::fill()
}
} else if (readLen == 0) {
_eof = true;
- if (_buffer[_writePos] != '\n') {
- _buffer[_writePos++] = '\n'; // Fake a final separator
- }
} else {
_writePos += readLen;
}
@@ -90,6 +87,9 @@ LineSplitter::getLine()
if (bufLen > 0) {
char *start = &_buffer[_readPos];
char *end = static_cast<char *>(memchr(start, '\n', bufLen));
+ if (_eof && !end) {
+ end = &_buffer[_writePos-1]; // pretend last byte sent was \n
+ }
if (end) {
*end = '\0';
if (end - start > 0 && end[-1] == '\r') {
diff --git a/configd/src/apps/sentinel/line-splitter.h b/configd/src/apps/sentinel/line-splitter.h
index 28d183f3e15..5ccf7690fda 100644
--- a/configd/src/apps/sentinel/line-splitter.h
+++ b/configd/src/apps/sentinel/line-splitter.h
@@ -23,7 +23,7 @@ private:
public:
explicit LineSplitter(int fd);
char *getLine();
- bool eof() const { return _eof; }
+ bool eof() const { return _eof && _readPos >= _writePos; }
~LineSplitter();
};