Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Jul 2010 17:38:02 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r210064 - in head/sys: kern sys
Message-ID:  <201007141738.o6EHc2Yo033482@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Wed Jul 14 17:38:01 2010
New Revision: 210064
URL: http://svn.freebsd.org/changeset/base/210064

Log:
  - Document layout of KTR_STRUCT payload in a comment.
  - Simplify ktrstruct() calling convention by having ktrstruct() use
    strlen() rather than requiring the caller to hand-code the length of
    constant strings.
  
  MFC after:	1 month

Modified:
  head/sys/kern/kern_ktrace.c
  head/sys/sys/ktrace.h

Modified: head/sys/kern/kern_ktrace.c
==============================================================================
--- head/sys/kern/kern_ktrace.c	Wed Jul 14 17:16:25 2010	(r210063)
+++ head/sys/kern/kern_ktrace.c	Wed Jul 14 17:38:01 2010	(r210064)
@@ -596,9 +596,8 @@ ktrcsw(out, user)
 }
 
 void
-ktrstruct(name, namelen, data, datalen)
+ktrstruct(name, data, datalen)
 	const char *name;
-	size_t namelen;
 	void *data;
 	size_t datalen;
 {
@@ -608,11 +607,10 @@ ktrstruct(name, namelen, data, datalen)
 
 	if (!data)
 		datalen = 0;
-	buflen = namelen + 1 + datalen;
+	buflen = strlen(name) + 1 + datalen;
 	buf = malloc(buflen, M_KTRACE, M_WAITOK);
-	bcopy(name, buf, namelen);
-	buf[namelen] = '\0';
-	bcopy(data, buf + namelen + 1, datalen);
+	strcpy(buf, name);
+	bcopy(data, buf + strlen(name) + 1, datalen);
 	if ((req = ktr_getrequest(KTR_STRUCT)) == NULL) {
 		free(buf, M_KTRACE);
 		return;

Modified: head/sys/sys/ktrace.h
==============================================================================
--- head/sys/sys/ktrace.h	Wed Jul 14 17:16:25 2010	(r210063)
+++ head/sys/sys/ktrace.h	Wed Jul 14 17:38:01 2010	(r210064)
@@ -154,6 +154,10 @@ struct ktr_csw {
  * KTR_STRUCT - misc. structs
  */
 #define KTR_STRUCT	8
+	/*
+	 * record contains null-terminated struct name followed by
+	 * struct contents
+	 */
 struct sockaddr;
 struct stat;
 
@@ -202,11 +206,11 @@ void	ktrsysctl(int *name, u_int namelen)
 void	ktrsysret(int, int, register_t);
 void	ktrprocexit(struct thread *);
 void	ktruserret(struct thread *);
-void	ktrstruct(const char *, size_t, void *, size_t);
+void	ktrstruct(const char *, void *, size_t);
 #define ktrsockaddr(s) \
-	ktrstruct("sockaddr", 8, (s), ((struct sockaddr *)(s))->sa_len)
+	ktrstruct("sockaddr", (s), ((struct sockaddr *)(s))->sa_len)
 #define ktrstat(s) \
-	ktrstruct("stat", 4, (s), sizeof(struct stat))
+	ktrstruct("stat", (s), sizeof(struct stat))
 
 #else
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007141738.o6EHc2Yo033482>