Permalink
Browse files

darwintrace: avoid snprintf(3); manually construct log messages.

git-svn-id: https://svn.macosforge.org/repository/darwinbuild/trunk@1052 10a61168-4876-4dac-953b-31e694342555
  • Loading branch information...
kvanvechten committed Mar 14, 2013
1 parent a05bbf4 commit 5b2b80baa3ae9a74bde5d505fe4cfe8766a79ae0
Showing with 26 additions and 7 deletions.
  1. +2 −1 CHANGES
  2. +24 −6 darwintrace/darwintrace.c
@@ -1,7 +1,8 @@
Darwin Build Scripts Change History
-----------------------------------
Release 34.1 [14-Mar-2013]
Release 34 [12-Mar-2013]
- darwintrace: use _simple_dprintf instead of snprintf.
- darwintrace: avoid snprintf(3); manually construct log messages.

Release 33 [29-Aug-2012]
- darwinup: Fix uninitialised variable in Database.cpp.
@@ -51,10 +51,8 @@
#define DARWINTRACE_STOP_FD 200
#define DARWINTRACE_BUFFER_SIZE 1024

extern void _simple_dprintf(int __fd, const char *__fmt, ...);

#if DARWINTRACE_DEBUG_OUTPUT
#define dprintf(...) _simple_dprintf(STDERR_FILENO, __VA_ARGS__)
#define dprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define dprintf(...)
#endif
@@ -238,9 +236,29 @@ static inline void darwintrace_logpath(int fd, const char *procname, char *tag,
}
}
}
_simple_dprintf(fd, "%s[%d]\t%s\t%s\n",
procname ? procname : darwintrace_progname, darwintrace_pid,
tag, path);
size_t size;
char pidstr_bytes[16];
char *pidstr = &pidstr_bytes[sizeof(pidstr_bytes)-1];
char darwintrace_buf[DARWINTRACE_BUFFER_SIZE];

pid_t pid = darwintrace_pid;
*pidstr = 0;
do {
--pidstr;
*pidstr = '0' + (pid % 10);
pid /= 10;
} while (pid > 0);

/* "%s[%d]\t%s\t%s\n" */
size = strlcpy(darwintrace_buf, procname ? procname : darwintrace_progname, sizeof(darwintrace_buf));
size = strlcat(darwintrace_buf, "[", sizeof(darwintrace_buf));
size = strlcat(darwintrace_buf, pidstr, sizeof(darwintrace_buf));
size = strlcat(darwintrace_buf, "]\t", sizeof(darwintrace_buf));
size = strlcat(darwintrace_buf, tag, sizeof(darwintrace_buf));
size = strlcat(darwintrace_buf, "\t", sizeof(darwintrace_buf));
size = strlcat(darwintrace_buf, path, sizeof(darwintrace_buf));
size = strlcat(darwintrace_buf, "\n", sizeof(darwintrace_buf));
write(fd, darwintrace_buf, size);
}

/* remap resource fork access to the data fork.

0 comments on commit 5b2b80b

Please sign in to comment.