diff options
Diffstat (limited to 'configd')
-rw-r--r-- | configd/src/apps/sentinel/command-connection.cpp | 5 | ||||
-rw-r--r-- | configd/src/apps/sentinel/line-splitter.cpp | 6 | ||||
-rw-r--r-- | configd/src/apps/sentinel/line-splitter.h | 2 | ||||
-rw-r--r-- | configd/src/apps/sentinel/service.cpp | 4 |
4 files changed, 10 insertions, 7 deletions
diff --git a/configd/src/apps/sentinel/command-connection.cpp b/configd/src/apps/sentinel/command-connection.cpp index 9b35d801ecb..bd3988bdbba 100644 --- a/configd/src/apps/sentinel/command-connection.cpp +++ b/configd/src/apps/sentinel/command-connection.cpp @@ -50,7 +50,10 @@ CommandConnection::printf(const char *fmt, ...) int ret = vsnprintf(buf, sizeof buf, fmt, args); va_end(args); - write(_fd, buf, strlen(buf)); + ssize_t len = strlen(buf); + if (write(_fd, buf, len) != len) { + perror("CommandConnection::printf failed"); + } return ret; } 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(); }; diff --git a/configd/src/apps/sentinel/service.cpp b/configd/src/apps/sentinel/service.cpp index 9a1f3dc9c82..49944043259 100644 --- a/configd/src/apps/sentinel/service.cpp +++ b/configd/src/apps/sentinel/service.cpp @@ -337,7 +337,7 @@ Service::runChild(int pipes[2]) char buf[200]; snprintf(buf, sizeof buf, "open /dev/null for fd 0: got %d " "(%s)", fd, strerror(errno)); - write(pipes[1], buf, strlen(buf)); + (void) write(pipes[1], buf, strlen(buf)); _exit(EXIT_FAILURE); } fcntl(0, F_SETFD, 0); // Don't close on exec @@ -347,7 +347,7 @@ Service::runChild(int pipes[2]) char buf[200]; snprintf(buf, sizeof buf, "exec error: %s for /bin/sh -c '%s'", strerror(errno), _config->command.c_str()); - write(pipes[1], buf, strlen(buf)); + (void) write(pipes[1], buf, strlen(buf)); _exit(EXIT_FAILURE); } |