[{"id":12398,"web_url":"https://patchwork.libcamera.org/comment/12398/","msgid":"<9d5e6570-ac22-5baa-41c7-834c1b4a8285@uajain.com>","date":"2020-09-10T05:49:17","subject":"Re: [libcamera-devel] [PATCH] android: jpeg: exif: Use reentrant\n\tlocaltime_r()","submitter":{"id":1,"url":"https://patchwork.libcamera.org/api/people/1/","name":"Umang Jain","email":"email@uajain.com"},"content":"Hi Laurent,\n\nOn 9/10/20 9:44 AM, Laurent Pinchart wrote:\n> The std::localtime() function isn't thread-safe, and we have no\n> guarantee whether other threads in the camera service may or may not\n> call it. Replace it with localtime_r(). This requires switching from\n> ctime to time.h, as there is no std::localtime_r() function.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Umang Jain <email@uajain.com>\n> ---\n>   src/android/jpeg/exif.cpp | 6 ++++--\n>   src/android/jpeg/exif.h   | 2 +-\n>   2 files changed, 5 insertions(+), 3 deletions(-)\n>\n> diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp\n> index 1ced55343ee9..c0dbfcc216b9 100644\n> --- a/src/android/jpeg/exif.cpp\n> +++ b/src/android/jpeg/exif.cpp\n> @@ -186,9 +186,11 @@ void Exif::setSize(const Size &size)\n>   \n>   void Exif::setTimestamp(time_t timestamp)\n>   {\n> +\tstruct tm tm;\n> +\tlocaltime_r(&timestamp, &tm);\n> +\n>   \tchar str[20];\n> -\tstd::strftime(str, sizeof(str), \"%Y:%m:%d %H:%M:%S\",\n> -\t\t      std::localtime(&timestamp));\n> +\tstrftime(str, sizeof(str), \"%Y:%m:%d %H:%M:%S\", &tm);\n>   \tstd::string ts(str);\n>   \n>   \tsetString(EXIF_IFD_0, EXIF_TAG_DATE_TIME, EXIF_FORMAT_ASCII, ts);\n> diff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h\n> index 622de4cfd593..f04cefcea74a 100644\n> --- a/src/android/jpeg/exif.h\n> +++ b/src/android/jpeg/exif.h\n> @@ -7,8 +7,8 @@\n>   #ifndef __ANDROID_JPEG_EXIF_H__\n>   #define __ANDROID_JPEG_EXIF_H__\n>   \n> -#include <ctime>\n>   #include <string>\n> +#include <time.h>\n>   \n>   #include <libexif/exif-data.h>\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 369A1BDB1D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 10 Sep 2020 05:49:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id ACD8462D04;\n\tThu, 10 Sep 2020 07:49:24 +0200 (CEST)","from mail.uajain.com (static.126.159.217.95.clients.your-server.de\n\t[95.217.159.126])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 65DB762B90\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Sep 2020 07:49:23 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=uajain.com header.i=@uajain.com\n\theader.b=\"mjOALPwX\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=uajain.com; s=mail;\n\tt=1599716962; bh=3GuUR2e5KUtTSIOB+sN/SAsT2HOdHuqfnVdsYExBWqg=;\n\th=Subject:To:References:From:In-Reply-To;\n\tb=mjOALPwXzgX2W1cbru4ttz0vCShfvXGpKwkzPVW8cGhvV3UzmE9T4VDmoTckO6aPT\n\tA0urLHfwHvn3FE1WKwEudxYh51VD3XUwAjHx6xLG4tUxbjvsgwdIVM2u7cFC/uruTw\n\tO7+HxCoU48k9PNl9oR3LvabP0lS3VYeBVaTC1sgrBkztgP8+GVZQpNYuTUkyEORI59\n\tZWYd/j2uFJCwbKEQGKb5a6bhr5TGiBOvG7SgHK7IDWTjWGrd5Ibrs/EeUvTiWLuBfY\n\t8Ltf48m9wKqobX5EscS+2/iLzJW2QeiRIedb6q4sX3JQkyh6EQcilbuT2L9yU/7i/m\n\t35CFIF7NTOIpw==","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20200910041459.17110-1-laurent.pinchart@ideasonboard.com>","From":"Umang Jain <email@uajain.com>","Message-ID":"<9d5e6570-ac22-5baa-41c7-834c1b4a8285@uajain.com>","Date":"Thu, 10 Sep 2020 11:19:17 +0530","Mime-Version":"1.0","In-Reply-To":"<20200910041459.17110-1-laurent.pinchart@ideasonboard.com>","Content-Language":"en-US","Subject":"Re: [libcamera-devel] [PATCH] android: jpeg: exif: Use reentrant\n\tlocaltime_r()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Content-Transfer-Encoding":"7bit","Content-Type":"text/plain; charset=\"us-ascii\"; Format=\"flowed\"","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":12400,"web_url":"https://patchwork.libcamera.org/comment/12400/","msgid":"<20200910102026.GA4095624@oden.dyn.berto.se>","date":"2020-09-10T10:20:26","subject":"Re: [libcamera-devel] [PATCH] android: jpeg: exif: Use reentrant\n\tlocaltime_r()","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your work.\n\nOn 2020-09-10 07:14:59 +0300, Laurent Pinchart wrote:\n> The std::localtime() function isn't thread-safe, and we have no\n> guarantee whether other threads in the camera service may or may not\n> call it. Replace it with localtime_r(). This requires switching from\n> ctime to time.h, as there is no std::localtime_r() function.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  src/android/jpeg/exif.cpp | 6 ++++--\n>  src/android/jpeg/exif.h   | 2 +-\n>  2 files changed, 5 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp\n> index 1ced55343ee9..c0dbfcc216b9 100644\n> --- a/src/android/jpeg/exif.cpp\n> +++ b/src/android/jpeg/exif.cpp\n> @@ -186,9 +186,11 @@ void Exif::setSize(const Size &size)\n>  \n>  void Exif::setTimestamp(time_t timestamp)\n>  {\n> +\tstruct tm tm;\n> +\tlocaltime_r(&timestamp, &tm);\n> +\n>  \tchar str[20];\n> -\tstd::strftime(str, sizeof(str), \"%Y:%m:%d %H:%M:%S\",\n> -\t\t      std::localtime(&timestamp));\n> +\tstrftime(str, sizeof(str), \"%Y:%m:%d %H:%M:%S\", &tm);\n>  \tstd::string ts(str);\n>  \n>  \tsetString(EXIF_IFD_0, EXIF_TAG_DATE_TIME, EXIF_FORMAT_ASCII, ts);\n> diff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h\n> index 622de4cfd593..f04cefcea74a 100644\n> --- a/src/android/jpeg/exif.h\n> +++ b/src/android/jpeg/exif.h\n> @@ -7,8 +7,8 @@\n>  #ifndef __ANDROID_JPEG_EXIF_H__\n>  #define __ANDROID_JPEG_EXIF_H__\n>  \n> -#include <ctime>\n>  #include <string>\n> +#include <time.h>\n>  \n>  #include <libexif/exif-data.h>\n>  \n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 4C359BDB1D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 10 Sep 2020 10:20:30 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B101862D04;\n\tThu, 10 Sep 2020 12:20:29 +0200 (CEST)","from mail-lj1-x234.google.com (mail-lj1-x234.google.com\n\t[IPv6:2a00:1450:4864:20::234])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8B15062C43\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Sep 2020 12:20:28 +0200 (CEST)","by mail-lj1-x234.google.com with SMTP id c2so7396231ljj.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Sep 2020 03:20:28 -0700 (PDT)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\tl15sm1238516lfk.71.2020.09.10.03.20.26\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 10 Sep 2020 03:20:26 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com\n\theader.b=\"QrrCoBvU\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=eepD/p6wxnDhCM96i6+O0tt1vTZELvuiSNyKmiPKYno=;\n\tb=QrrCoBvU/18wp2BVlcon7F9825vf0mefMazFuOKLVKgJxnukJ2JXpyNrNU7mFrTCGp\n\tPipyxndQ0cMfEQrd1RxnLvvUysFpOubwEdUyyRnyYt/jPfjy5wkYq1jZAHZg9AxFymJX\n\tIBcB2oGiQ4nkjiNsSVPvYqh+Tom77ppX7XpRC9vLfADsyLuV3zs5ahNxQX0VPF4u4Imh\n\tY4XypbQhfTyEsQBjVNccakG9c7dLIPW/t8dcgb2C7Y6GL3oqSy4lx9tDUmYvRUjCBIB2\n\tmmmO4crgR+54XiEgw91DcEKOA5nSAF4Oa5DGAkVGynHxV2qb+j+1dtIBdkXwIMsv9xsE\n\tebyw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=eepD/p6wxnDhCM96i6+O0tt1vTZELvuiSNyKmiPKYno=;\n\tb=Wjx6+1Y3MB5eD26SULzFyZn2KG5xPC/AvlfHUDicymruefUFy8ES6M27MjSHLeO9m1\n\ta30iVvo7nnWTYnZIfU9ySd5yD/M7hO70ReeVKoONPbr3XtsMGoL7omsIU0eNVoDv3uNQ\n\tiX73W5DcZ0ISXk/jMGEM4v6F2N01dKvJETzllyuoNCc17ChG3CRvPzo4fu8ggjps9vlm\n\tx94L57G+htJS3lmUNb0D5hhv82Tz6yu8SHa9HsW85dkvEJ9OisXUlQFlzy5ak1gjpNok\n\thrnFANv8/2z5G9MO0doCW3lVcDoQusql1tn5nwNjJIuBn4VMZTRi61dbJOWuzldav4Md\n\t/BAg==","X-Gm-Message-State":"AOAM531lsv6dPHz0va5wF3TKerjsnipyc/6ymgzVcJiHYtGEOktTsyyZ\n\t9Bios8aLlxtBlmMdpmZ7EoFcIQ==","X-Google-Smtp-Source":"ABdhPJwBMrMl0thndh/dczbCupFZtDneUOp8tMagUiqEsE8MpmRHkv2sQZIEswj9DZNwI0IDxN/fNQ==","X-Received":"by 2002:a2e:8906:: with SMTP id d6mr3845445lji.354.1599733227352;\n\tThu, 10 Sep 2020 03:20:27 -0700 (PDT)","Date":"Thu, 10 Sep 2020 12:20:26 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20200910102026.GA4095624@oden.dyn.berto.se>","References":"<20200910041459.17110-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200910041459.17110-1-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] android: jpeg: exif: Use reentrant\n\tlocaltime_r()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"iso-8859-1\"","Content-Transfer-Encoding":"quoted-printable","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]