From: Takashi Iwai Subject: Re: [PATCH v2] aplay: Fix error message when writing captured data Date: Fri, 07 Apr 2017 16:30:41 +0200 Message-ID: References: <1491571236-23476-1-git-send-email-daniel.baluta@nxp.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id F0C042673D4 for ; Fri, 7 Apr 2017 16:30:42 +0200 (CEST) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Daniel Baluta Cc: alsa-devel@alsa-project.org, shengjiu.wang@nxp.com, o-takashi@sakamocchi.jp, Mark Brown , viorel.suman@nxp.com, mihai.serban@nxp.com, Daniel Baluta List-Id: alsa-devel@alsa-project.org On Fri, 07 Apr 2017 15:45:42 +0200, Daniel Baluta wrote: > > On Fri, Apr 7, 2017 at 4:27 PM, Takashi Iwai wrote: > > On Fri, 07 Apr 2017 15:20:36 +0200, > > Daniel Baluta wrote: > >> > >> Read can return less then requested bytes, but we treat > >> this as an error. > > > s/read/write here :)). > > > Actually that's the bug -- we should loop the write until it reaches > > to the real error. Once when we get the proper errno, the error > > message via perror() itself will be enough. > > Correct. But I think aplay decided to keep things simple and fail in case > couldn't write all requested bytes. And that's wrong. We should loop instead. > This pattern can be noticed all over the places where write is used. All wrong :) We can implement a simple helper function and replace each write call with it. > Given the fact that write is blocking (meaning that it must write > at least one byte until return) this should work most of the time, > excepting corner cases like disk full, etc. Yes, and such corner cases must be handled properly, too -- in the end, it's what you wanted to achieve by your patch, but into a different direction. Takashi