linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [RFC] osm_log printing incorrectly assumes that pthread_t is not opaque type
@ 2012-12-09  9:26 Garrett Cooper
       [not found] ` <alpine.BSF.2.00.1212090125590.64779-Fqwm7F1mg36Nj9Bq2fkWzw@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Garrett Cooper @ 2012-12-09  9:26 UTC (permalink / raw)
  To: linux-rdma-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2237 bytes --]

Hi,
 	When porting a newer version of OFED to FreeBSD and running the compile 
against clang with all of the warnings enabled, I ran into build failures 
because osm_log, etc assumes that pthread_t is an integral type (which is valid 
on Linux, but not necessarily correct on other platforms). The fix I 
implemented was attached, but that doesn't necessarily seem correct either, so 
I was wondering what was trying to be gained by printing out the thread ID 
(especially because syslog(9) isn't necessarily an asynch safe syscall [1]).
Thanks,
-Garrett

1. http://linux.die.net/man/7/signal

>From 55c3bafa1d866dc045e16fbf792dc64d03d25431 Mon Sep 17 00:00:00 2001
From: Garrett Cooper <garrett.cooper-nKaf5Oxk4VbQT0dZR+AlfA@public.gmane.org>
Date: Thu, 6 Dec 2012 21:41:17 -0800
Subject: [PATCH 2/2] Use %p when printing out pthread_t in the logging fns on FreeBSD

A [slightly] more portable way to do this would be to use
pthread_set(_)?name_np, but even that is not super well-defined across
BSD versions, Linux, and OSX. See
http://stackoverflow.com/questions/2369738/can-i-set-the-name-of-a-thread-in-pthreads-linux
for more details.
---
  contrib/ofed/management/opensm/opensm/osm_log.c | 9 +++++++++
  1 file changed, 9 insertions(+)

diff --git a/contrib/ofed/management/opensm/opensm/osm_log.c 
b/contrib/ofed/management/opensm/opensm/osm_log.c
index deadc57..f4ef394 100644
--- a/contrib/ofed/management/opensm/opensm/osm_log.c
+++ b/contrib/ofed/management/opensm/opensm/osm_log.c
@@ -189,7 +189,11 @@ _retry:
  _retry:
  	ret =
  	    fprintf(p_log->out_port,
+#if defined(__FreeBSD__)
+		    "%s %02d %02d:%02d:%02d %06d [%p] 0x%02x -> %s",
+#else
  		    "%s %02d %02d:%02d:%02d %06d [%04X] 0x%02x -> %s",
+#endif
  		    (result.tm_mon <
  		     12 ? month_str[result.tm_mon] : "???"),
  		    result.tm_mday, result.tm_hour, result.tm_min,
@@ -302,7 +306,12 @@ _retry:
  _retry:
  	ret =
  	    fprintf(p_log->out_port,
+#if defined(__FreeBSD__)
+		    "%s %02d %02d:%02d:%02d %06d [%p] 0x%02x -> %s",
+#else
  		    "%s %02d %02d:%02d:%02d %06d [%04X] 0x%02x -> %s",
+
+#endif
  		    (result.tm_mon <
  		     12 ? month_str[result.tm_mon] : "???"),
  		    result.tm_mday, result.tm_hour, result.tm_min,
-- 
1.8.0.1

[-- Attachment #2: Type: TEXT/PLAIN, Size: 1646 bytes --]

From 55c3bafa1d866dc045e16fbf792dc64d03d25431 Mon Sep 17 00:00:00 2001
From: Garrett Cooper <garrett.cooper@isilon.com>
Date: Thu, 6 Dec 2012 21:41:17 -0800
Subject: [PATCH 2/2] Use %p when printing out pthread_t in the logging fns on
 FreeBSD

A [slightly] more portable way to do this would be to use
pthread_set(_)?name_np, but even that is not super well-defined across
BSD versions, Linux, and OSX. See
http://stackoverflow.com/questions/2369738/can-i-set-the-name-of-a-thread-in-pthreads-linux
for more details.
---
 contrib/ofed/management/opensm/opensm/osm_log.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/contrib/ofed/management/opensm/opensm/osm_log.c b/contrib/ofed/management/opensm/opensm/osm_log.c
index deadc57..f4ef394 100644
--- a/contrib/ofed/management/opensm/opensm/osm_log.c
+++ b/contrib/ofed/management/opensm/opensm/osm_log.c
@@ -189,7 +189,11 @@ _retry:
 _retry:
 	ret =
 	    fprintf(p_log->out_port,
+#if defined(__FreeBSD__)
+		    "%s %02d %02d:%02d:%02d %06d [%p] 0x%02x -> %s",
+#else
 		    "%s %02d %02d:%02d:%02d %06d [%04X] 0x%02x -> %s",
+#endif
 		    (result.tm_mon <
 		     12 ? month_str[result.tm_mon] : "???"),
 		    result.tm_mday, result.tm_hour, result.tm_min,
@@ -302,7 +306,12 @@ _retry:
 _retry:
 	ret =
 	    fprintf(p_log->out_port,
+#if defined(__FreeBSD__)
+		    "%s %02d %02d:%02d:%02d %06d [%p] 0x%02x -> %s",
+#else
 		    "%s %02d %02d:%02d:%02d %06d [%04X] 0x%02x -> %s",
+
+#endif
 		    (result.tm_mon <
 		     12 ? month_str[result.tm_mon] : "???"),
 		    result.tm_mday, result.tm_hour, result.tm_min,
-- 
1.8.0.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-12-10  6:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-09  9:26 [PATCH] [RFC] osm_log printing incorrectly assumes that pthread_t is not opaque type Garrett Cooper
     [not found] ` <alpine.BSF.2.00.1212090125590.64779-Fqwm7F1mg36Nj9Bq2fkWzw@public.gmane.org>
2012-12-09  9:54   ` Bart Van Assche
     [not found]     ` <50C45FE8.5020502-HInyCGIudOg@public.gmane.org>
2012-12-09 10:03       ` Garrett Cooper
2012-12-09 17:43   ` Alex Netes
     [not found]     ` <75EE638CB68A864F90627D3D06A189A859350715-SlGPd/IId7auSA5JZHE7gA@public.gmane.org>
2012-12-09 19:56       ` Garrett Cooper
     [not found]         ` <CAGH67wQ=-Mn3_HMy7=VOT2am99qbjrXcOpC6+_PCSW6xuyVvRA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-12-10  6:10           ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).