From patchwork Thu Jan 12 10:01:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janne Blomqvist X-Patchwork-Id: 135606 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id EAB70B6EE8 for ; Thu, 12 Jan 2012 21:01:42 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1326967303; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:In-Reply-To:References:Date: Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=JFIQfUGAF4lRJ6rn6zkxlinYfN4=; b=B7uHCiE3AQM6Px4QRE/stR00YNawhvsqQtU9CSpzF2ytNch8WwcCADYEJOS1yS phUxOBul1hEwP95GaBk/0815CIsuaUnVsb4DHLyluHJseqsVNLs/XntpVAjjVvHo oPprqe0vuAxg/0RxKe2JIwtSZVIS4V+VlOeaUzSaVqopA= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:Received:Received:In-Reply-To:References:Date:Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=usylxapB37T01V982Sgel1mbFSpcuLAnZCE8wm1h8iEINqXSQhCahJt+esfBjM lLo9FJNizEHONMwgjmOmLagR0rgs/gtFN3dSFYm5m0MwCKxC2sDIlYJiKGvZydpl ltAjr7/FrvzLEU9ycOWc8DxSHSOIl6cvdMSBRCgxiR2tc=; Received: (qmail 31844 invoked by alias); 12 Jan 2012 10:01:36 -0000 Received: (qmail 31829 invoked by uid 22791); 12 Jan 2012 10:01:35 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-lpp01m010-f47.google.com (HELO mail-lpp01m010-f47.google.com) (209.85.215.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 12 Jan 2012 10:01:22 +0000 Received: by lami14 with SMTP id i14so836092lam.20 for ; Thu, 12 Jan 2012 02:01:21 -0800 (PST) MIME-Version: 1.0 Received: by 10.112.25.74 with SMTP id a10mr618815lbg.58.1326362481098; Thu, 12 Jan 2012 02:01:21 -0800 (PST) Received: by 10.152.11.198 with HTTP; Thu, 12 Jan 2012 02:01:21 -0800 (PST) In-Reply-To: <4F0D86B2.1080509@net-b.de> References: <4F0D424F.4030808@net-b.de> <4F0D86B2.1080509@net-b.de> Date: Thu, 12 Jan 2012 12:01:21 +0200 Message-ID: Subject: Re: [Patch libfortran] PR 51803 getcwd() failure From: Janne Blomqvist To: Tobias Burnus Cc: Fortran List , GCC Patches Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On Wed, Jan 11, 2012 at 14:55, Tobias Burnus wrote: > Dear all, > > this is a follow up patch, which I think provides a better handling if > either getcwd fails or is not availble - or if the pathname in argv[0] > already is an absolute patch, in which case concatenating > current-working-directory + '/' + argv[0] does not really make sense. > > Build on x86-64-linux. > OK for the trunk? Committed the patch below, which implements Tobias' suggestion, as obvious. Index: runtime/main.c =================================================================== --- runtime/main.c (revision 183121) +++ runtime/main.c (working copy) @@ -124,12 +124,17 @@ store_exe_path (const char * argv0) #ifdef HAVE_GETCWD cwd = getcwd (buf, sizeof (buf)); - if (!cwd) - cwd = "."; #else - cwd = "."; + cwd = NULL; #endif + if (!cwd) + { + exe_path = argv0; + please_free_exe_path_when_done = 0; + return; + } + /* exe_path will be cwd + "/" + argv[0] + "\0". This will not work if the executable is not in the cwd, but at this point we're out of better ideas. */ Index: ChangeLog =================================================================== --- ChangeLog (revision 183121) +++ ChangeLog (working copy) @@ -1,3 +1,10 @@ +2012-01-12 Janne Blomqvist + Tobias Burnus + + PR libfortran/51803 + * runtime/main.c (store_exe_path): Avoid malloc if getcwd fails or + is not available. + 2012-01-11 Tobias Burnus * runtime/main.c (store_exe_path): Fix absolute path @@ -5,6 +12,7 @@ 2012-01-11 Janne Blomqvist Mike Stump + PR libfortran/51803 * runtime/main.c (store_exe_path): Handle getcwd failure and lack of the function better.