Looked a bit further into tzset(), and from what I can see, this function is safe to call in a multi-threaded program:
http://www.gnu.org/software/libc/manual/html_node/Time-Zone-Functions.html So we could actually place the call to tzset() just before each call to localtime_r(), instead of calling it in a start-up function. The benefit would be that we handle the case when the TZ environment variable is modified. / Anders Widell On 07/16/2014 04:29 PM, Anders Widell wrote: > Yes, it seems like a good idea to call tzset(), e.g. in some library > function that is always called early at start-up. > > / Anders Widell > > On 07/16/2014 03:57 PM, Alex Jones wrote: >> One comment. From the man page of localtime_r: >> >> According to POSIX.1-2004, localtime() is required to behave as though >> tzset(3) was called, while localtime_r() does not have this >> require- >> ment. For portable code tzset(3) should be called before >> local- >> time_r(). >> >> Do we need to do this? >> >> Alex >> >> On 07/16/2014 04:37 AM, mathi.naic...@oracle.com wrote: >>> Summary: replace localtime with thread safe localtime_r [#958] >>> Review request for Trac Ticket(s): #958 >>> Peer Reviewer(s): ramesh, mahesh, hans, praveen, nagendra, alex >>> Pull request to: <<LIST THE PERSON WITH PUSH ACCESS HERE>> >>> Affected branch(es): 4.3.x, 4.4.x >>> Development branch: <<IF ANY GIVE THE REPO URL>> >>> >>> -------------------------------- >>> Impacted area Impact y/n >>> -------------------------------- >>> Docs n >>> Build system n >>> RPM/packaging n >>> Configuration files n >>> Startup scripts n >>> SAF services y >>> OpenSAF services y >>> Core libraries n >>> Samples n >>> Tests n >>> Other n >>> >>> >>> Comments (indicate scope for each "y" above): >>> --------------------------------------------- >>> localtime is not thread safe and because of this, crashes have been >>> observed in multithreaded opensaf services (for eg:- a crash in SMFD >>> because logtrace uses localtime). >>> The patch series replaces all occurrences of localtime with localtime_r. >>> >>> changeset 8cbe68c97884d76c15e3e65c04c1e677402676c3 >>> Author: mathi.naic...@oracle.com >>> Date: Wed, 16 Jul 2014 13:51:31 +0530 >>> >>> osaf: use thread safe localtime_r instead of localtime [#958] localtime >>> is >>> not thread safe and it can(has) cause crashes in services that are multi >>> threaded. >>> >>> changeset 3123adbd8bd655db83216e17d33ee4ae034496f3 >>> Author: mathi.naic...@oracle.com >>> Date: Wed, 16 Jul 2014 13:52:06 +0530 >>> >>> mds: use thread safe localtime_r instead of localtime [#958] localtime >>> is >>> not thread safe and it can(has) cause crashes in services that are multi >>> threaded. >>> >>> changeset 80940ead9b9233e895a10992d45d7a1b37c2e791 >>> Author: mathi.naic...@oracle.com >>> Date: Wed, 16 Jul 2014 13:55:09 +0530 >>> >>> amf: use thread safe localtime_r instead of localtime [#958] localtime >>> is >>> not thread safe and it can(has) cause crashes in services that are multi >>> threaded. >>> >>> changeset 24833293883ba7c68b7fe1e303cadc05cf361e94 >>> Author: mathi.naic...@oracle.com >>> Date: Wed, 16 Jul 2014 13:55:47 +0530 >>> >>> ntf: use thread safe localtime_r instead of localtime [#958] localtime >>> is >>> not thread safe and it can(has) cause crashes in services that are multi >>> threaded. >>> >>> changeset facf9779833cecd83118a88527e60d235f6af6c8 >>> Author: mathi.naic...@oracle.com >>> Date: Wed, 16 Jul 2014 13:57:46 +0530 >>> >>> plm: use thread safe localtime_r instead of localtime [#958] localtime >>> is >>> not thread safe and it can(has) cause crashes in services that are multi >>> threaded. >>> >>> >>> Complete diffstat: >>> ------------------ >>> osaf/libs/core/common/include/logtrace.h | 2 +- >>> osaf/libs/core/common/logtrace.c | 6 +++++- >>> osaf/libs/core/mds/mds_log.c | 6 +++++- >>> osaf/services/saf/amf/amfwdog/amf_wdog.c | 6 +++++- >>> osaf/services/saf/ntfsv/ntfs/ntfs_evt.c | 6 +++++- >>> osaf/services/saf/plmsv/plms/plms_dbg_utils.c | 6 +++++- >>> osaf/tools/safntf/src/ntfclient.c | 6 +++++- >>> 7 files changed, 31 insertions(+), 7 deletions(-) >>> >>> >>> Testing Commands: >>> ----------------- >>> Start opensaf, observe timestamp wherever(flows) applicable. >>> >>> Testing, Expected Results: >>> -------------------------- >>> Start opensaf, observe timestamp wherever applicable. >>> >>> >>> Conditions of Submission: >>> ------------------------- >>> Ack from Reviewers. >>> >>> Arch Built Started Linux distro >>> ------------------------------------------- >>> mips n n >>> mips64 n n >>> x86 n n >>> x86_64 y y >>> powerpc n n >>> powerpc64 n n >>> >>> >>> Reviewer Checklist: >>> ------------------- >>> [Submitters: make sure that your review doesn't trigger any checkmarks!] >>> >>> >>> Your checkin has not passed review because (see checked entries): >>> >>> ___ Your RR template is generally incomplete; it has too many blank entries >>> that need proper data filled in. >>> >>> ___ You have failed to nominate the proper persons for review and push. >>> >>> ___ Your patches do not have proper short+long header >>> >>> ___ You have grammar/spelling in your header that is unacceptable. >>> >>> ___ You have exceeded a sensible line length in your headers/comments/text. >>> >>> ___ You have failed to put in a proper Trac Ticket # into your commits. >>> >>> ___ You have incorrectly put/left internal data in your comments/files >>> (i.e. internal bug tracking tool IDs, product names etc) >>> >>> ___ You have not given any evidence of testing beyond basic build tests. >>> Demonstrate some level of runtime or other sanity testing. >>> >>> ___ You have ^M present in some of your files. These have to be removed. >>> >>> ___ You have needlessly changed whitespace or added whitespace crimes >>> like trailing spaces, or spaces before tabs. >>> >>> ___ You have mixed real technical changes with whitespace and other >>> cosmetic code cleanup changes. These have to be separate commits. >>> >>> ___ You need to refactor your submission into logical chunks; there is >>> too much content into a single commit. >>> >>> ___ You have extraneous garbage in your review (merge commits etc) >>> >>> ___ You have giant attachments which should never have been sent; >>> Instead you should place your content in a public tree to be pulled. >>> >>> ___ You have too many commits attached to an e-mail; resend as threaded >>> commits, or place in a public tree for a pull. >>> >>> ___ You have resent this content multiple times without a clear indication >>> of what has changed between each re-send. >>> >>> ___ You have failed to adequately and individually address all of the >>> comments and change requests that were proposed in the initial >>> review. >>> >>> ___ You have a misconfigured ~/.hgrc file (i.e. username, email etc) >>> >>> ___ Your computer have a badly configured date and time; confusing the >>> the threaded patch review. >>> >>> ___ Your changes affect IPC mechanism, and you don't present any results >>> for in-service upgradability test. >>> >>> ___ Your changes affect user manual and documentation, your patch series >>> do not contain the patch that updates the Doxygen manual. >>> >> ------------------------------------------------------------------------------ >> Want fast and easy access to all the code in your enterprise? Index and >> search up to 200,000 lines of code with a free copy of Black Duck >> Code Sight - the same software that powers the world's largest code >> search on Ohloh, the Black Duck Open Hub! Try it now. >> http://p.sf.net/sfu/bds >> _______________________________________________ >> Opensaf-devel mailing list >> Opensaf-devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/opensaf-devel >> >> > > ------------------------------------------------------------------------------ > Want fast and easy access to all the code in your enterprise? Index and > search up to 200,000 lines of code with a free copy of Black Duck > Code Sight - the same software that powers the world's largest code > search on Ohloh, the Black Duck Open Hub! Try it now. > http://p.sf.net/sfu/bds > _______________________________________________ > Opensaf-devel mailing list > Opensaf-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/opensaf-devel > > ------------------------------------------------------------------------------ Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck Code Sight - the same software that powers the world's largest code search on Ohloh, the Black Duck Open Hub! Try it now. http://p.sf.net/sfu/bds _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel