From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 22D02385828D for ; Fri, 22 Jul 2022 21:08:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 22D02385828D Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26MIYPZH030576 for ; Fri, 22 Jul 2022 21:08:28 GMT Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3hbm42rkrw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 22 Jul 2022 21:08:28 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 26MJCUUe039237 for ; Fri, 22 Jul 2022 21:08:27 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2104.outbound.protection.outlook.com [104.47.58.104]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3hc1k8dhf4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 22 Jul 2022 21:08:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=baeM3O5/hN16oBUA7V0rTbnC0icZb8AzlB8crF3uK599iSPCvK0G8txbwghU2MA0Qh1m1JUtJZOdGDEC5PW3yPZllaDh1G3wBP4xkUpZWSszUUFjbJbgSVHw98hVHbTV9jNJqs/cTZ2SCfgbBSewgZVjeniLpCsypMl8NahYvDkNiEdssWPk/lm/wsgr/WtvTjR2kmxERwYQPBCtmrLxgGAcG3/5TgM9rtZDUVkm2gX5ourovlQso6yT3UeWAyoOjx8DSzNsUxbGNBM6+a5BSkQ4Aq60TccDOlDKnuALFfde66aimweAqnbFJ5DMCZoO3cr0ny3ds6mn0LwMeZhORA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hLcN9Gd/1Malsv+Z6ftR9UQJYOhefNB+9EFdhr7sDF8=; b=j5+4WToiZGD0SU/YGaOklLtDAkcrKBhChjS8AHgQDhI9Z3V9Jf0cebQwFDaMzEEhrF7tk7OVbSYU6/K5OSsV5kLhi6DMn4K3xI3AMXzND2pvnizxJIUaxo6qi/I7kv1+VHIsKLGohBM5JMaNz7zB8ULWcAkINBZDfDr1SXie9EW5QlWFc7irBSdJhEyZzcKKYDo1Uv4m+OIVk5oVU6fwiRChLJyHi16SWSAYfKoD4hLFwY4NXzMaYKAJeJ72z5oHWiH2kFej88UvV0aDmOW1weu0x3qMSksdnrbG3ayNaaJXNRlEmyTHajkpaDPY8lMnorEGztoIK50N4WHydXSDow== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from CO1PR10MB4787.namprd10.prod.outlook.com (2603:10b6:303:9c::16) by SA2PR10MB4794.namprd10.prod.outlook.com (2603:10b6:806:113::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.19; Fri, 22 Jul 2022 21:08:25 +0000 Received: from CO1PR10MB4787.namprd10.prod.outlook.com ([fe80::3d2f:fd7e:15d2:b521]) by CO1PR10MB4787.namprd10.prod.outlook.com ([fe80::3d2f:fd7e:15d2:b521%3]) with mapi id 15.20.5458.019; Fri, 22 Jul 2022 21:08:25 +0000 From: ruud.vanderpas@oracle.com To: binutils@sourceware.org Subject: [PATCH] gprofng: fix bug 29356 - Execution fails if gprofng is not included in PATH Date: Fri, 22 Jul 2022 14:08:17 -0700 Message-Id: <20220722210817.1989805-1-ruud.vanderpas@oracle.com> X-Mailer: git-send-email 2.27.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: DM6PR12CA0002.namprd12.prod.outlook.com (2603:10b6:5:1c0::15) To CO1PR10MB4787.namprd10.prod.outlook.com (2603:10b6:303:9c::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8aafabb4-ef31-4187-a184-08da6c265100 X-MS-TrafficTypeDiagnostic: SA2PR10MB4794:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KXawYXFmFZbfEnY9TesO9AWwA1byT1xyzmGzMqbPdFyoacjCf5kkv4bbxLtmvNDdZ8A8pBvjQSqxcxrnkgThEd41TWfy/iAo0BY6QXa54KR19P2G/BAY23puCItEdGhtV7zjuMQhJWgBtxHeO9b/yfhJGsa7+taxfd1Ov/qNyNGwyYhqBD2v+27TeMgB5zJcNXMusGdkNej73nby+6OmFZ561HS97N+jLqvTfBzc4y27ss4d3loF76yToMgSfL0BJ3ix7Wbu6qBzpf6skMEq/2+fjd4zOqzmHlakdtNuJwG0q4qoZtnKX7AbCGFasw6xICy0DKeapNGLQNluvF3dI/caPTb7hsUTtofAsJENWb72E+RPL1KJKPvD9gkQnA7EUP4bjK4hjY1AF7HayYbvpt+KYfgzLgOJOchzgB3/nwSdVfSa0oAM6LpcLx5tPWY6SnZ/rs8FVfB9i8XAsrJZHnPinACzFBUKuwtkl7UBsuOVvm4G3tdXkJ5FwL5JaQz376utaGGo6k+DQj/ZO3RFILljjKfiHDQflMeJCSqyCxj1wICj8qiS5Au80ftvZ8x7lqSQ/8pmwm6R5IdJ1LYB8jk/P758er3geTq8nvOz9HyEfeUgMLE5gTJYsVCl6Qt76wS7YPl8RVmQCEps+2872jx9vmaygjqsrixhXluYKg9X/BqgiNAIX+WCFvz/o2z16dvN2vEozSYT2YXeVyYDlKRjx+rpLHWeBvkg7Ii62KXqfDembIPo6son6X7msQqh X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO1PR10MB4787.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(366004)(346002)(396003)(136003)(376002)(39860400002)(6506007)(38100700002)(52116002)(6486002)(86362001)(5660300002)(186003)(2616005)(107886003)(36756003)(316002)(6916009)(9686003)(6512007)(83380400001)(1076003)(8676002)(66556008)(4326008)(66476007)(8936002)(30864003)(2906002)(478600001)(66946007)(6666004)(41300700001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?XWfaWqpuazC7AE3ITBCY7DOkwdVhsp2bUtHJoPdPm5YfG5D4gELSdvG/UDk7?= =?us-ascii?Q?BIEOOE1JEEN3zmxpTml3iSGSvCjjeJLp1JbpfxF0rQV4GJAmA3TF0FlL/SNY?= =?us-ascii?Q?3z1krS53zrQJQNhWLJDclmqL7kw79MytBZXI+4xiNB5s4iAwiGIGtO0Kr9Rf?= =?us-ascii?Q?FgXL0BHCJ4unf3swHnjAeOqJ1v7uGBTD4zm4sLITN282meN4aKF+ZNY+trTO?= =?us-ascii?Q?UQ3YlMS5tpDctY6X9SN2KY3hMR1sK0BK0MiVls8cYxtnA6qRC+O6YcjIi2x7?= =?us-ascii?Q?KLmbwxu2icYuNjGzzkWeYZFyDvoYijjfJmdpY9ZrL+dMjxFw4Q96z+RFdx8N?= =?us-ascii?Q?FlC9MvEFDsXyD228x0zecAVpctWQxSDjERDL7Eve/If3Kyoaj87UXLes2bX8?= =?us-ascii?Q?hDh/lbb0Nv8pzmjsLe4oAaqLYPhRkwOMAsE5mINzYjZM2eZKoKaKIt5A59pP?= =?us-ascii?Q?jGrY8ch7tLbQgHF45cxVl9RRIobMTF0/DCyYj/qQuJNeBAQrED61LVaNTgFl?= =?us-ascii?Q?i/V1bBXXLwbWpg5LBPwMtD/pjbkAot8ku0nR+J+mh/zPrrwI6RhN6D9DeoGE?= =?us-ascii?Q?g+Wi9xOmszja4MLA8auywcLGQ2ywf68FP4lGXr8T/NPxBSBhpxcYDqpfsRzo?= =?us-ascii?Q?twctZgTVtohqDEukaxNt44SBD00FuLmNUwIyQphkMzn8YaCWBQ4ycK8kYk6V?= =?us-ascii?Q?Oj0Vm2L+/xNnzaEORHyc4GfIMk339OHENHnrOVOtaMppc06blQYZFzO4BAtb?= =?us-ascii?Q?322awTs8iTIO5fMPopz9pc7UsNEukwYpTqtF7GzUjCwfRifcLngIR+GdZ6UM?= =?us-ascii?Q?syIbN6eUM9ipxL10lAhxscAuY7lp55IU0dbTDS+Vn0fDDFPT/Lm+e+cA4Go8?= =?us-ascii?Q?QdmKbiVudEeRb3ees60priyIhKbEXg6hoci6OQJILyHAHmOorvbU+500qnRn?= =?us-ascii?Q?wMnyS0qoX5oZl9cnsgWOzXIx+p1kRD7h8PfNPcmvHkmc6wa6XIn4s4vSdCNW?= =?us-ascii?Q?yO0UXjPVZ+l5a4zs6UyjXjjT9Fpbixqx/HYyKFGg2wLkntjUA/FSUfzQNec/?= =?us-ascii?Q?aiBLYFRZAg0P3yaqmnqYomiLxGHMzEaETYpiiOjv4ypWVehpSu4/EY9jMCD1?= =?us-ascii?Q?g/CYwauWu935BCjYEAe6B8wFA3vu83B1yhoeCTINCuXhEvSHFysGnZCs6Ijc?= =?us-ascii?Q?MQt+TEESdtKqo9mAx2wEpAj1iYWS1ySCl7bwTlgYupSkpiqSjshvbSVfwYlx?= =?us-ascii?Q?FnPRZYFwBtQdV+tZY/JuwlUrFywnjpUZxG/0nalxfOc5gXL/PrEN5Z1eQpGX?= =?us-ascii?Q?XCpkeNhdj3yl4DcFCcUImlC+mspu0JuGNV8wizhcK+ke3QIZj6/b8VgaPRfv?= =?us-ascii?Q?8NjZqzblEyUV5bss/HjZL+IiKZPIZ0s9x8w4WKzpzsEJIhZGq9G3XqOmWeJw?= =?us-ascii?Q?qQD3pNT7Ea7vsS24drm7OSKOvujzzyjBwVP2bXCvk3lGcBjrM75WYe7gtK2w?= =?us-ascii?Q?3kiLjqWfoM7gh1WjAQjvaMp4xZmtBGuwgx7TDKU/NcGzDp3spDmjhTGB7fMM?= =?us-ascii?Q?cKJwadLIhy7P9A60bvu/83oQhnKYl9uAisL44b7EoHc5oFQfue7E6Dk1rZbT?= =?us-ascii?Q?/gAWKQbp2JMFdUMDiOSDe+0=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8aafabb4-ef31-4187-a184-08da6c265100 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4787.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2022 21:08:25.2412 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: C/UvR6HzQsk2GSb8vmuPrayfumfarvylRHnycEfOSsmxK+MYivaTwvYbYx0HDxqH08+qFUVySQ72xHqWfYMsHAtB0rjuqei+IvBO2fZdIXQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4794 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-22_06,2022-07-21_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207220086 X-Proofpoint-ORIG-GUID: dUEkhjdYdamgMCRn2UPxF1ClurdTFNQg X-Proofpoint-GUID: dUEkhjdYdamgMCRn2UPxF1ClurdTFNQg X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jul 2022 21:08:32 -0000 From: Ruud van der Pas gprofng/Changelog: 2022-07-22 Ruud van der Pas * gp-display-html/gp-display-html.in: fixed a problem to execute gp-display-text in case gprofng is not included in the search path. --- gprofng/gp-display-html/gp-display-html.in | 307 +++++++++++++++++++-- 1 file changed, 284 insertions(+), 23 deletions(-) diff --git a/gprofng/gp-display-html/gp-display-html.in b/gprofng/gp-display-html/gp-display-html.in index 54a87d7a3c7..d9ac79e496a 100644 --- a/gprofng/gp-display-html/gp-display-html.in +++ b/gprofng/gp-display-html/gp-display-html.in @@ -54,8 +54,16 @@ INIT my $TRUE = 1; my $FALSE = 0; +#------------------------------------------------------------------------------ +# Used to ensure correct alignment of columns. +#------------------------------------------------------------------------------ my $g_max_length_first_metric; +#------------------------------------------------------------------------------ +# This variable contains the path used to execute $GP_DISPAY_TEXT. +#------------------------------------------------------------------------------ +my $g_path_to_tools; + #------------------------------------------------------------------------------- # Code debugging flag #------------------------------------------------------------------------------- @@ -282,9 +290,16 @@ sub main #------------------------------------------------------------------------------ # OS commands executed and search paths. #------------------------------------------------------------------------------ - my @selected_os_cmds = qw (rm mv cat hostname locale which printenv ls + my @selected_os_cmds = qw (rm mv cat hostname locale which printenv ls uname readelf mkdir); - my @search_paths_os_cmds = qw (/usr/bin /bin); + my @search_paths_os_cmds = qw ( + /usr/bin + /bin + /usr/local/bin + /usr/local/sbin + /usr/sbin + /sbin + ); #------------------------------------------------------------------------------ # TBD: Eliminate these. @@ -410,6 +425,11 @@ sub main # things that are needed later on. #------------------------------------------------------------------------------ +#------------------------------------------------------------------------------ +# Store the absolute path of the command executed. +#------------------------------------------------------------------------------ + my $location_gp_command = $0; + #------------------------------------------------------------------------------ # The very first thing to do is to quickly determine if the user has enabled # one of the following options and take action accordingly: @@ -695,10 +715,30 @@ sub main gp_message ("debug", $subr_name, "base_va_executable = $base_va_executable"); #------------------------------------------------------------------------------ -# The gp-display-text tool is critical and has to be available in order to proceed. +# The $GP_DISPLAY_TEXT tool is critical and has to be available in order +# to proceed. +# This subroutine only returns a value if the tool can be found." #------------------------------------------------------------------------------ - $ignore_value = check_availability_tool (); + $g_path_to_tools = ${ check_availability_tool (\$location_gp_command)}; + + $GP_DISPLAY_TEXT = $g_path_to_tools . $GP_DISPLAY_TEXT; + gp_message ("debug", $subr_name, "updated GP_DISPLAY_TEXT = $GP_DISPLAY_TEXT"); + +#------------------------------------------------------------------------------ +# Check if $GP_DISPLAY_TEXT is executable for user, group, and other. +# If not, print a warning only, since this may not be fatal but could +# potentially lead to issues later on. +#------------------------------------------------------------------------------ + if (not is_file_executable ($GP_DISPLAY_TEXT)) + { + my $msg = "file $GP_DISPLAY_TEXT is not executable for user, group, and other"; + gp_message ("warning", $subr_name, $msg); + } + +#------------------------------------------------------------------------------ +# Find out what the decimal separator is, as set by the user. +#------------------------------------------------------------------------------ ($return_code, $decimal_separator, $convert_to_dot) = determine_decimal_separator (); @@ -711,7 +751,7 @@ sub main } else { - my $msg = "the decimal separator can not be determined - set to $decimal_separator"; + my $msg = "the decimal separator cannot be determined - set to $decimal_separator"; gp_message ("warning", $subr_name, $msg); } @@ -1275,10 +1315,11 @@ sub calculate_target_hex_address } #-- End of subroutine calculate_target_hex_address #------------------------------------------------------------------------------ -# This subroutine sets the absolute path to all commands in array @cmds. The -# commands and their respective paths are stored in hash "g_mapped_cmds". +# Sets the absolute path to all commands in array @cmds. The commands and +# their respective paths are stored in hash "g_mapped_cmds". # -# It is a fatal error if such a path can't be found. +# If no such mapping is found, a warning is issued, but execution continues. +# The warning(s) may help with troubleshooting, should a failure occur later. #------------------------------------------------------------------------------ sub check_and_define_cmds { @@ -1311,7 +1352,7 @@ sub check_and_define_cmds $found_match = $FALSE; for my $path (@search_path) { - $target_cmd = $path."/".$cmd; + $target_cmd = $path . "/" . $cmd; if (-x $target_cmd) { $found_match = $TRUE; @@ -1335,9 +1376,12 @@ sub check_and_define_cmds { if ($mapped eq "road_to_nowhere") { - gp_message ("error", $subr_name, "cannot find a path for command $cmd"); + my $msg = "cannot find a path for command $cmd - " . + "assume this will still work without a path"; + gp_message ("warning", $subr_name, $msg); $no_of_failed_mappings++; $failed_cmds .= $cmd; + $g_mapped_cmds{$cmd} = $cmd; } else { @@ -1346,8 +1390,8 @@ sub check_and_define_cmds } if ($no_of_failed_mappings != 0) { - gp_message ("error", $subr_name, "failed to find a mapping for $failed_cmds"); - gp_message ("error", $subr_name, "a total of $no_of_failed_mappings mapping failures"); + gp_message ("debug", $subr_name, "failed to find a mapping for $failed_cmds"); + gp_message ("debug", $subr_name, "a total of $no_of_failed_mappings mapping failures"); } return ($no_of_failed_mappings); @@ -1552,29 +1596,93 @@ sub check_and_proc_dis_func_call # Check for the $GP_DISPLAY_TEXT tool to be available. This is a critical tool # needed to provide the information. If it can not be found, execution is # terminated. +# +# We first search foe this tool in the current execution directory. If it +# cannot be found there, use $PATH to try to locate it. #------------------------------------------------------------------------------ sub check_availability_tool { my $subr_name = get_my_name (); - my $target_cmd; - my $output_which_gp_display_text; + my ($location_gp_command_ref) = @_; + my $error_code; + my $error_occurred; + my $msg; + my $output_which_gp_display_text; + my $return_value; + my $target_cmd; - $target_cmd = $g_mapped_cmds{"which"} . " $GP_DISPLAY_TEXT 2>&1"; +#------------------------------------------------------------------------------ +# Get the path to gp-display-text. +#------------------------------------------------------------------------------ + my ($error_occurred_ref, $return_value_ref) = find_path_to_gp_display_text ( + $location_gp_command_ref + ); + $error_occurred = ${ $error_occurred_ref}; + $return_value = ${ $return_value_ref}; - ($error_code, $output_which_gp_display_text) = execute_system_cmd ($target_cmd); - - if ($error_code == 0) + $msg = "error_occurred = $error_occurred return_value = $return_value"; + gp_message ("debugXL", $subr_name, $msg); + + if (not $error_occurred) +#------------------------------------------------------------------------------ +# All is well and gp-display-text has been located. +#------------------------------------------------------------------------------ { - gp_message ("debug", $subr_name, "tool $GP_DISPLAY_TEXT is in the search path"); - } + $g_path_to_tools = $return_value; + + $msg = "located $GP_DISPLAY_TEXT in execution directory"; + gp_message ("debug", $subr_name, $msg); + $msg = "g_path_to_tools = $g_path_to_tools"; + gp_message ("debug", $subr_name, $msg); + } else +#------------------------------------------------------------------------------ +# Something went wrong, but perhaps we can still continue. Try to find +# $GP_DISPLAY_TEXT through the search path. +#------------------------------------------------------------------------------ { - gp_message ("abort", $subr_name, "fatal error executing command $target_cmd"); - } + $msg = "error accessing $GP_DISPLAY_TEXT: $return_value - " . + "run time behaviour may be undefined"; + gp_message ("warning", $subr_name, $msg); + +#------------------------------------------------------------------------------ +# Check if we can find $GP_DISPLAY_TEXT in the search path. +#------------------------------------------------------------------------------ + $msg = "check for $GP_DISPLAY_TEXT in search path"; + gp_message ("debug", $subr_name, $msg); - return (0); + $target_cmd = $g_mapped_cmds{"which"} . " $GP_DISPLAY_TEXT 2>&1"; + + ($error_code, $output_which_gp_display_text) = + execute_system_cmd ($target_cmd); + + if ($error_code == 0) + { + my ($gp_file_name, $gp_path, $suffix_not_used) = + fileparse ($output_which_gp_display_text); + $g_path_to_tools = $gp_path; + + $msg = "using $GP_DISPLAY_TEXT in $g_path_to_tools instead"; + gp_message ("warning", $subr_name, $msg); + + $msg = "the $GP_DISPLAY_TEXT tool is in the search path"; + gp_message ("debug", $subr_name, $msg); + $msg = "g_path_to_tools = $g_path_to_tools"; + gp_message ("debug", $subr_name, $msg); + } + else + { + $msg = "failure to find $GP_DISPLAY_TEXT in the search path"; + gp_message ("debug", $subr_name, $msg); + + $msg = "fatal error executing command $target_cmd"; + gp_message ("abort", $subr_name, $msg); + } + } + + return (\$g_path_to_tools); } #-- End of subroutine check_availability_tool @@ -3874,6 +3982,58 @@ sub find_keyword_in_string } #-- End of subroutine find_keyword_in_string +#------------------------------------------------------------------------------ +# Retrieve the absolute path that was used to execute the command. This path +# is used to execute gp-display-text later on. +#------------------------------------------------------------------------------ +sub find_path_to_gp_display_text +{ + my $subr_name = get_my_name (); + + my ($full_command_ref) = @_; + + my $full_command = ${ $full_command_ref }; + + my $error_occurred = $TRUE; + my $return_value; + +#------------------------------------------------------------------------------ +# Get the path name. +#------------------------------------------------------------------------------ + my ($gp_file_name, $gp_path, $suffix_not_used) = fileparse ($full_command); + + gp_message ("debug", $subr_name, "full_command = $full_command"); + gp_message ("debug", $subr_name, "gp_path = $gp_path"); + + my $gp_display_text_instance = $gp_path . $GP_DISPLAY_TEXT; + +#------------------------------------------------------------------------------ +# Check if $GP_DISPLAY_TEXT exists, is not empty, and executable. +#------------------------------------------------------------------------------ + if (not -e $gp_display_text_instance) + { + $return_value = "file not found"; + } + else + { + if (is_file_empty ($gp_display_text_instance)) + { + $return_value = "file is empty"; + } + else + { +#------------------------------------------------------------------------------ +# All is well. Capture the path. +#------------------------------------------------------------------------------ + $error_occurred = $FALSE; + $return_value = $gp_path; + } + } + + return (\$error_occurred, \$return_value); + +} #-- End of subroutine find_path_to_gp_display_text + #------------------------------------------------------------------------------ # Scan the command line to see if the specified option is present. # @@ -9190,6 +9350,107 @@ sub is_file_empty } #-- End of subroutine is_file_empty +#------------------------------------------------------------------------------ +# Check if a file is executable and return $TRUE or $FALSE. +#------------------------------------------------------------------------------ +sub is_file_executable +{ + my $subr_name = get_my_name (); + + my ($filename) = @_; + + my $file_permissions; + my $index_offset; + my $is_executable; + my $mode; + my $number_of_bytes; + my @permission_settings = (); + my %permission_values = (); + + chomp ($filename); + + gp_message ("debug", $subr_name, "check if filename = $filename is executable"); + + if (not -e $filename) + { +#------------------------------------------------------------------------------ +# The return value is used in the caller. This is why we return the empty +# string in case the file does not exist. +#------------------------------------------------------------------------------ + gp_message ("debug", $subr_name, "filename = $filename not found"); + $is_executable = $FALSE; + } + else + { + $mode = stat ($filename)->mode; + + gp_message ("debugXL", $subr_name, "mode = $mode"); +#------------------------------------------------------------------------------ +# Get username. We currently do not do anything with this though and the +# code is commented out. +# +# my $my_name = getlogin () || getpwuid($<) || "Kilroy";; +# gp_message ("debug", $subr_name, "my_name = $my_name"); +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# Convert file permissions to octal, split the individual numbers and store +# the values for the respective users. +#------------------------------------------------------------------------------ + $file_permissions = sprintf("%o", $mode & 07777); + + @permission_settings = split (//, $file_permissions); + + $number_of_bytes = scalar (@permission_settings); + + gp_message ("debugXL", $subr_name, "file_permissions = $file_permissions"); + gp_message ("debugXL", $subr_name, "permission_settings = @permission_settings"); + gp_message ("debugXL", $subr_name, "number_of_settings = $number_of_bytes"); + + if ($number_of_bytes == 4) + { + $index_offset = 1; + } + elsif ($number_of_bytes == 3) + { + $index_offset = 0; + } + else + { + my $msg = "unexpected number of $number_of_bytes bytes " . + "in permission settings: @permission_settings"; + gp_message ("assertion", $subr_name, $msg); + } + + $permission_values{user} = $permission_settings[$index_offset++]; + $permission_values{group} = $permission_settings[$index_offset++]; + $permission_values{other} = $permission_settings[$index_offset]; + +#------------------------------------------------------------------------------ +# The executable bit should be set for user, group and other. If this fails +# we mark the file as not executable. Note that this is gprofng specific. +#------------------------------------------------------------------------------ + $is_executable = $TRUE; + for my $k (keys %permission_values) + { + my $msg = "permission_values{" . $k . "} = " . + $permission_values{$k}; + gp_message ("debugXL", $subr_name, $msg); + + if ($permission_values{$k} % 2 == 0) + { + $is_executable = $FALSE; + last; + } + } + } + + gp_message ("debug", $subr_name, "is_executable = $is_executable"); + + return ($is_executable); + +} #-- End of subroutine is_file_executable + #------------------------------------------------------------------------------- # TBD. #------------------------------------------------------------------------------- -- 2.27.0