From patchwork Tue Oct 7 17:44:11 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Katiyar X-Patchwork-Id: 3192 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 51F5FDDF6F for ; Wed, 8 Oct 2008 04:44:16 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752961AbYJGRoP (ORCPT ); Tue, 7 Oct 2008 13:44:15 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753370AbYJGRoO (ORCPT ); Tue, 7 Oct 2008 13:44:14 -0400 Received: from ti-out-0910.google.com ([209.85.142.190]:29704 "EHLO ti-out-0910.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752961AbYJGRoN (ORCPT ); Tue, 7 Oct 2008 13:44:13 -0400 Received: by ti-out-0910.google.com with SMTP id b6so2012393tic.23 for ; Tue, 07 Oct 2008 10:44:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:mime-version:content-type:content-transfer-encoding :content-disposition; bh=Rnzu7jYSZR1K/6Nzgi/LMgGTM+NKDRnEUhOUXp0Vj3g=; b=nUbkfJnixQlCGC2jTyVFptlUJLNqNRlAzXLwgBZntEJDCa0ID8zvm0Sc4554Uah9um DLILS/AyNS+vDBffPKBv9oA1LEHSiil5WMUUyQCrne/pwlC/G7KtCamtT9BzVQMNWBEY tjuFtKHt4bTjE1/HdKpy/fnWMR89IBj4l9nms= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:mime-version:content-type :content-transfer-encoding:content-disposition; b=Ki1ghN+EbBARt+vGijD5sz2MD+jsRgFI7v91WvrNV+0WR3oGvC9tWHMKS1OtFoDJVq UGRyyHy6vM2FHx38vVH+m1H24iPvkKH5xcm2fmJXy0Cw7yDXG1jld6t4b+Zw40vaOrcT EYMUinZnhLhcgiBpQ2pf5NAMwKfo1MbP0Nl2s= Received: by 10.110.46.3 with SMTP id t3mr8433790tit.30.1223401451770; Tue, 07 Oct 2008 10:44:11 -0700 (PDT) Received: by 10.110.39.8 with HTTP; Tue, 7 Oct 2008 10:44:11 -0700 (PDT) Message-ID: Date: Tue, 7 Oct 2008 23:14:11 +0530 From: "Manish Katiyar" To: ext4 , "Theodore Tso" Subject: [PATCH] logsave : Avoid unnecessary backgrounding of logsave in case of failures Cc: mkatiyar@gmail.com MIME-Version: 1.0 Content-Disposition: inline Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Hi Ted, I am not sure why we wan't to background the logsave and keep retrying opening the fd in case of failures. But there may be situations when we will never be able to succeed and thus create unnecessary process. For example invoking it /home/mkatiyar/sbin> ./logsave /testfile ls as a normal user will never succeed. Below patch adds some of the error conditions where we can just avoid it. Signed-off-by : Manish Katiyar --- misc/logsave.c | 19 +++++++++++++++++-- 1 files changed, 17 insertions(+), 2 deletions(-) diff --git a/misc/logsave.c b/misc/logsave.c index f0011f8..77a0a16 100644 --- a/misc/logsave.c +++ b/misc/logsave.c @@ -203,6 +203,17 @@ static int copy_from_stdin(void) return 0; } +static void should_background(int err, int *nobackground) { + switch (err) { + case EPERM: + case EACCES: + *nobackground = err; + break; + default : + *nobackground = 0; + } + return ; +} int main(int argc, char **argv) @@ -211,7 +222,7 @@ int main(int argc, char **argv) char *outfn, **cpp; int openflags = O_CREAT|O_WRONLY|O_TRUNC; int send_flag = SEND_LOG; - int do_stdin; + int do_stdin, nobackground = 0; time_t t; while ((c = getopt(argc, argv, "+asv")) != EOF) { @@ -237,6 +248,8 @@ int main(int argc, char **argv) argc -= optind; outfd = open(outfn, openflags, 0644); + if (outfd < 0) + should_background(errno, &nobackground); do_stdin = !strcmp(argv[0], "-"); send_output("Log of ", 0, send_flag); @@ -263,7 +276,7 @@ int main(int argc, char **argv) send_output(ctime(&t), 0, send_flag); send_output("----------------\n", 0, send_flag); - if (outbuf) { + if (!nobackground) { pid = fork(); if (pid < 0) { perror("fork"); @@ -282,6 +295,8 @@ int main(int argc, char **argv) } write(outfd, outbuf, outbufsize); free(outbuf); + } else { + printf("Unable to save log to %s : %s\n", outfn, strerror(nobackground)); } close(outfd);