Hello,
Submitting my first patch here.
If add2line doesn't exist, connman's backtrace logic doesn't handle this
gracefully and triggers another signal.
Two fixes:
- Receiving an empty result from the fork()'ed addr2line isn't handled
correctly (see the "*pos++ = '\0';" below)
- The fork()'ed addr2line process will bail shortly, resulting in the pipe
being closed, and us getting EPIPE for subsequent lines of the backtrace.
The diff changes things to key receiving 0 bytes from infd[0] as a trigger
bailing checking for further symbolication.
There's still a chance of getting an EPIPE where during the first iteration
of write() in the loop is unguarded and the fork()'ed process can bail
before our first write() call.
As an enhancement, we could add in additional logic to check the existence
of addr2line, but I wanted to start with a simpler change first.
diff --git a/src/log.c b/src/log.c
index cb8596f..6ec676b 100644
--- a/src/log.c
+++ b/src/log.c
@@ -175,20 +175,39 @@ static void print_backtrace(unsigned int offset)
if (len < 0)
break;
- written = write(outfd[1], addr, len);
- if (written < 0)
- break;
-
- len = read(infd[0], buf, sizeof(buf) - 1);
- if (len < 0)
- break;
+ if (outfd[1] >= 0)
+ {
+ written = write(outfd[1], addr, len);
+ if (written < 0)
+ break;
+
+ len = read(infd[0], buf, sizeof(buf));
+ if (len < 0)
+ break;
+ else if (len == 0)
+ {
+ // if we got nothing, that means we got
EOF, which means the read end was closed
+ // so close the FD and set it to invalid so
we know to not to bother with further
+ // symbolication
+ close(outfd[1]);
+ outfd[1] = -1;
+ }
+ }
+ else
+ {
+ len = 0;
+ }
+
buf[len] = '\0';
pos = strchr(buf, '\n');
- *pos++ = '\0';
-
- if (strcmp(buf, "??") == 0) {
+ if (pos != NULL)
+ {
+ *pos++ = '\0';
+ }
+
+ if ((len == 0) || (strcmp(buf, "??") == 0)) {
connman_error("#%-2u %p in %s", i - offset,
frames[i], info.dli_fname);
continue;
@@ -208,7 +227,10 @@ static void print_backtrace(unsigned int offset)
kill(pid, SIGTERM);
- close(outfd[1]);
+ if (outfd[1] >= 0)
+ {
+ close(outfd[1]);
+ }
close(infd[0]);
}
--
-- Arjuna
_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman