From patchwork Thu Sep 10 04:14:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9566 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 304FEBDB1D for ; Thu, 10 Sep 2020 04:15:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B6C1762D04; Thu, 10 Sep 2020 06:15:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nBGzonrL"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 39FA962B90 for ; Thu, 10 Sep 2020 06:15:31 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AAC7739; Thu, 10 Sep 2020 06:15:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1599711330; bh=P7YQUOjIi0+EItlJhsjhnZkHqt0uuWUU1z9OYnQ9jZ8=; h=From:To:Cc:Subject:Date:From; b=nBGzonrLNZGGnHUMWkUkkjzu41gFpU3O7UbtE87Ot3O20y3bBzWjVLo0UXcmrm825 gkJHpw0WYkEaOj3AgjShg18heF5M2JfucAiEaf/TNTnwV698gJVTQ6w9d6n5bUgMgv HH3vM9ghKkq2Ci2zTGQE4fx+YPc6qEA8oDiCHCQM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 10 Sep 2020 07:14:59 +0300 Message-Id: <20200910041459.17110-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] android: jpeg: exif: Use reentrant localtime_r() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The std::localtime() function isn't thread-safe, and we have no guarantee whether other threads in the camera service may or may not call it. Replace it with localtime_r(). This requires switching from ctime to time.h, as there is no std::localtime_r() function. Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain Reviewed-by: Niklas Söderlund --- src/android/jpeg/exif.cpp | 6 ++++-- src/android/jpeg/exif.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp index 1ced55343ee9..c0dbfcc216b9 100644 --- a/src/android/jpeg/exif.cpp +++ b/src/android/jpeg/exif.cpp @@ -186,9 +186,11 @@ void Exif::setSize(const Size &size) void Exif::setTimestamp(time_t timestamp) { + struct tm tm; + localtime_r(×tamp, &tm); + char str[20]; - std::strftime(str, sizeof(str), "%Y:%m:%d %H:%M:%S", - std::localtime(×tamp)); + strftime(str, sizeof(str), "%Y:%m:%d %H:%M:%S", &tm); std::string ts(str); setString(EXIF_IFD_0, EXIF_TAG_DATE_TIME, EXIF_FORMAT_ASCII, ts); diff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h index 622de4cfd593..f04cefcea74a 100644 --- a/src/android/jpeg/exif.h +++ b/src/android/jpeg/exif.h @@ -7,8 +7,8 @@ #ifndef __ANDROID_JPEG_EXIF_H__ #define __ANDROID_JPEG_EXIF_H__ -#include #include +#include #include