From patchwork Tue Jan 2 16:40:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10140997 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BEB116035E for ; Tue, 2 Jan 2018 16:40:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABBDC28C26 for ; Tue, 2 Jan 2018 16:40:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA1C028C61; Tue, 2 Jan 2018 16:40:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 068D728C26 for ; Tue, 2 Jan 2018 16:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751101AbeABQkt (ORCPT ); Tue, 2 Jan 2018 11:40:49 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:40699 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751097AbeABQks (ORCPT ); Tue, 2 Jan 2018 11:40:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1514911249; x=1546447249; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=AlbMClYPweFI5O4ngiKrLKJY12S2UPc7tFcMox7lhm4=; b=NrBZoIlYOrph+2KkepUHdCWz6cGJNNpXilzjEcck5YEDvfaSOdKhUAcA bgM7zNU8gG3/DwMcrA+75xHOg+lGlayF5DEbAv61pjmP/j9opRboMXvPn vdo60ZoAn/hXXGlnxmq2fMTbh2Jlg5hBNuWC0l7ng+fjW8MRFFj2WDk6+ J7DTyIoSWYSHVGigSXy7UoeSrCUT4U/OrBnfCyr55AmayAmKaiNC+hnsZ m44YlgdREMoPif+7J1UnPGZY8DZBLFeGyyr8SoNUuOIisDDp+LmKaQ9D6 d7xjEmKV4caDhNftSm4rtFEGtI7lIw3uU5MYPHDmVjysm5cVZqP5IsaWh A==; X-IronPort-AV: E=Sophos;i="5.45,498,1508774400"; d="scan'208";a="67309889" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 03 Jan 2018 00:40:49 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 02 Jan 2018 08:36:59 -0800 Received: from thinkpad-bart.sdcorp.global.sandisk.com (HELO [10.11.171.236]) ([10.11.171.236]) by uls-op-cesaip02.wdc.com with ESMTP; 02 Jan 2018 08:40:48 -0800 Subject: Re: [RFC] sg3_utils: sgp_dd: work around on pthread_cancel for android To: "Bean Huo (beanhuo)" , "linux-scsi@vger.kernel.org" , "dgilbert@interlog.com" Cc: "hare@suse.de" References: From: Bart Van Assche Message-ID: Date: Tue, 2 Jan 2018 08:40:48 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 12/26/17 14:21, Bean Huo (beanhuo) wrote: >My changes are below: > > Configure.ac: > +# check for pthread_cancel > +AC_SEARCH_LIBS(pthread_cancel, pthread, > + [AC_DEFINE(HAVE_PTHREAD_CANCEL, 1, [have pthread_cancel])], [], []) > > Src/Makefile.am > -sgp_dd_LDADD = ../lib/libsgutils2.la @os_libs@ -lpthread > +sgp_dd_LDADD = ../lib/libsgutils2.la @os_libs@ @LIBS@ > > In the Src/sgp_dd.c, I can use macro definition " HAVE_PTHREAD_CANCEL" to differentiate > pthread_cancel supports or not. > > It works. > But I got one warning below while run autoreconf , do you know what is wrong with that? > configure.ac:15: warning: AC_PROG_LIBTOOL was called before AM_PROG_AR > configure.ac:15: warning: LT_INIT was called before AM_PROG_AR Hello Bean, Even if these warnings would get addressed, we still would need something like the following change for src/sgp_dd.c: My proposal is to leave out any ifdef HAVE_PTHREAD_CANCEL tests and to use pthread_kill() on all platforms. Since sgp_dd is the only tool that uses pthread_cancel() this approach will allow to leave out the pthread_cancel() configure test. I'm proposing this approach because it will make it easier to maintain and to test the sgp_dd tool. Thanks, Bart. diff --git a/src/sgp_dd.c b/src/sgp_dd.c --- a/src/sgp_dd.c +++ b/src/sgp_dd.c @@ -181,6 +181,7 @@ static int sg_finish_io(bool wr, Rq_elem * rep, static pthread_mutex_t strerr_mut = PTHREAD_MUTEX_INITIALIZER; +static bool shutting_down = false; static bool do_sync = false; static bool do_time = false; static Rq_coll rcoll; @@ -470,6 +471,8 @@ sig_listen_thread(void * v_clp) while (1) { sigwait(&signal_set, &sig_number); + if (shutting_down) + break; if (SIGINT == sig_number) { pr2serr(ME "interrupted by SIGINT\n"); guarded_stop_both(clp); @@ -1629,8 +1632,10 @@ main(int argc, char * argv[]) } } - status = pthread_cancel(sig_listen_thread_id); - if (0 != status) err_exit(status, "pthread_cancel"); + shutting_down = true; + + status = pthread_kill(sig_listen_thread_id, SIGINT); + if (0 != status) err_exit(status, "pthread_kill"); if (STDIN_FILENO != rcoll.infd) close(rcoll.infd);