diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2014-04-14 10:29:42 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2014-04-14 10:29:42 +0000 |
commit | 529e84e103100f6c2e97e4bdc3ad5159cbe3d232 (patch) | |
tree | 0ec2b02326e1636ca62191a77ae68802317dfdd0 | |
parent | aa6773226ac327ef27035a74695e3db08f757024 (diff) |
print pid in error messages; ok reyk@
-rw-r--r-- | lib/libc/stdlib/malloc.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 446a1ca2543..2cd443191d0 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.c,v 1.152 2014/04/03 16:18:11 schwarze Exp $ */ +/* $OpenBSD: malloc.c,v 1.153 2014/04/14 10:29:41 otto Exp $ */ /* * Copyright (c) 2008, 2010, 2011 Otto Moerbeek <otto@drijf.net> * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> @@ -235,28 +235,32 @@ static void wrterror(char *msg, void *p) { char *q = " error: "; - struct iovec iov[6]; + struct iovec iov[7]; + char pidbuf[20]; char buf[20]; int saved_errno = errno; iov[0].iov_base = __progname; iov[0].iov_len = strlen(__progname); - iov[1].iov_base = malloc_func; - iov[1].iov_len = strlen(malloc_func); - iov[2].iov_base = q; - iov[2].iov_len = strlen(q); - iov[3].iov_base = msg; - iov[3].iov_len = strlen(msg); - iov[4].iov_base = buf; + iov[1].iov_base = pidbuf; + snprintf(pidbuf, sizeof(pidbuf), "(%d)", getpid()); + iov[1].iov_len = strlen(pidbuf); + iov[2].iov_base = malloc_func; + iov[2].iov_len = strlen(malloc_func); + iov[3].iov_base = q; + iov[3].iov_len = strlen(q); + iov[4].iov_base = msg; + iov[4].iov_len = strlen(msg); + iov[5].iov_base = buf; if (p == NULL) - iov[4].iov_len = 0; + iov[5].iov_len = 0; else { snprintf(buf, sizeof(buf), " %p", p); - iov[4].iov_len = strlen(buf); + iov[5].iov_len = strlen(buf); } - iov[5].iov_base = "\n"; - iov[5].iov_len = 1; - writev(STDERR_FILENO, iov, 6); + iov[6].iov_base = "\n"; + iov[6].iov_len = 1; + writev(STDERR_FILENO, iov, 7); #ifdef MALLOC_STATS if (mopts.malloc_stats) |