Skip to content

Commit 5b2b80b

Browse files
committed
darwintrace: avoid snprintf(3); manually construct log messages.
git-svn-id: https://svn.macosforge.org/repository/darwinbuild/trunk@1052 10a61168-4876-4dac-953b-31e694342555
1 parent a05bbf4 commit 5b2b80b

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Darwin Build Scripts Change History
22
-----------------------------------
3+
Release 34.1 [14-Mar-2013]
34
Release 34 [12-Mar-2013]
4-
- darwintrace: use _simple_dprintf instead of snprintf.
5+
- darwintrace: avoid snprintf(3); manually construct log messages.
56

67
Release 33 [29-Aug-2012]
78
- darwinup: Fix uninitialised variable in Database.cpp.

darwintrace/darwintrace.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@
5151
#define DARWINTRACE_STOP_FD 200
5252
#define DARWINTRACE_BUFFER_SIZE 1024
5353

54-
extern void _simple_dprintf(int __fd, const char *__fmt, ...);
55-
5654
#if DARWINTRACE_DEBUG_OUTPUT
57-
#define dprintf(...) _simple_dprintf(STDERR_FILENO, __VA_ARGS__)
55+
#define dprintf(...) fprintf(stderr, __VA_ARGS__)
5856
#else
5957
#define dprintf(...)
6058
#endif
@@ -238,9 +236,29 @@ static inline void darwintrace_logpath(int fd, const char *procname, char *tag,
238236
}
239237
}
240238
}
241-
_simple_dprintf(fd, "%s[%d]\t%s\t%s\n",
242-
procname ? procname : darwintrace_progname, darwintrace_pid,
243-
tag, path);
239+
size_t size;
240+
char pidstr_bytes[16];
241+
char *pidstr = &pidstr_bytes[sizeof(pidstr_bytes)-1];
242+
char darwintrace_buf[DARWINTRACE_BUFFER_SIZE];
243+
244+
pid_t pid = darwintrace_pid;
245+
*pidstr = 0;
246+
do {
247+
--pidstr;
248+
*pidstr = '0' + (pid % 10);
249+
pid /= 10;
250+
} while (pid > 0);
251+
252+
/* "%s[%d]\t%s\t%s\n" */
253+
size = strlcpy(darwintrace_buf, procname ? procname : darwintrace_progname, sizeof(darwintrace_buf));
254+
size = strlcat(darwintrace_buf, "[", sizeof(darwintrace_buf));
255+
size = strlcat(darwintrace_buf, pidstr, sizeof(darwintrace_buf));
256+
size = strlcat(darwintrace_buf, "]\t", sizeof(darwintrace_buf));
257+
size = strlcat(darwintrace_buf, tag, sizeof(darwintrace_buf));
258+
size = strlcat(darwintrace_buf, "\t", sizeof(darwintrace_buf));
259+
size = strlcat(darwintrace_buf, path, sizeof(darwintrace_buf));
260+
size = strlcat(darwintrace_buf, "\n", sizeof(darwintrace_buf));
261+
write(fd, darwintrace_buf, size);
244262
}
245263

246264
/* remap resource fork access to the data fork.

0 commit comments

Comments
 (0)