From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15845 invoked by alias); 15 May 2009 23:02:23 -0000 Received: (qmail 15589 invoked by uid 22791); 15 May 2009 23:02:21 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 15 May 2009 23:02:12 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n4FN2BRZ012896 for ; Fri, 15 May 2009 19:02:11 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n4FN2AB8003963 for ; Fri, 15 May 2009 19:02:10 -0400 Received: from host0.dyn.jankratochvil.net (sebastian-int.corp.redhat.com [172.16.52.221]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n4FN28gu016045 for ; Fri, 15 May 2009 19:02:09 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.3/8.14.3) with ESMTP id n4FN2749015046 for ; Sat, 16 May 2009 01:02:07 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.3/Submit) id n4FN26qt015036 for gdb-patches@sourceware.org; Sat, 16 May 2009 01:02:06 +0200 Date: Fri, 15 May 2009 23:02:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] Remove unused PROT from openp() Message-ID: <20090515230206.GA14982@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-05/txt/msg00338.txt.bz2 Hi, currently openp() contains a bug - the PROT parameter is not passed to one of its two open() syscalls. Apparently no one uses openp() with O_CREAT - it also does not make sense with the searching semantics openp() does. Therefore rather removed the excessive PROT parameter. Regression tested on x86_64-unknown-linux-gnu. Thanks, Jan gdb/ 2009-05-15 Jan Kratochvil Remove the PROT parameter from openp. * source.c (openp): Remove the parameter PROT. Assertion check MODE. defs.h (openp): Update the prototype. Update all the openp callers. --- gdb/source.c 21 Apr 2009 10:13:05 -0000 1.97 +++ gdb/source.c 15 May 2009 22:42:54 -0000 @@ -658,7 +658,8 @@ is_regular_file (const char *name) } /* Open a file named STRING, searching path PATH (dir names sep by some char) - using mode MODE and protection bits PROT in the calls to open. + using mode MODE in the calls to open. You cannot use this function to + create files (O_CREAT). OPTS specifies the function behaviour in specific cases. @@ -685,8 +686,7 @@ is_regular_file (const char *name) >>>> eg executable, non-directory */ int openp (const char *path, int opts, const char *string, - int mode, int prot, - char **filename_opened) + int mode, char **filename_opened) { int fd; char *filename; @@ -695,6 +695,9 @@ openp (const char *path, int opts, const int len; int alloclen; + /* The open syscall MODE parameter is not specified. */ + gdb_assert ((mode & O_CREAT) == 0); + if (!path) path = "."; @@ -708,7 +711,7 @@ openp (const char *path, int opts, const { filename = alloca (strlen (string) + 1); strcpy (filename, string); - fd = open (filename, mode, prot); + fd = open (filename, mode); if (fd >= 0) goto done; } @@ -827,7 +830,7 @@ source_full_path_of (const char *filenam int fd; fd = openp (source_path, OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH, filename, - O_RDONLY, 0, full_pathname); + O_RDONLY, full_pathname); if (fd < 0) { *full_pathname = NULL; @@ -1017,13 +1020,13 @@ find_and_open_source (struct objfile *ob } } - result = openp (path, OPF_SEARCH_IN_PATH, filename, OPEN_MODE, 0, fullname); + result = openp (path, OPF_SEARCH_IN_PATH, filename, OPEN_MODE, fullname); if (result < 0) { /* Didn't work. Try using just the basename. */ p = lbasename (filename); if (p != filename) - result = openp (path, OPF_SEARCH_IN_PATH, p, OPEN_MODE, 0, fullname); + result = openp (path, OPF_SEARCH_IN_PATH, p, OPEN_MODE, fullname); } return result; --- gdb/defs.h 23 Apr 2009 21:28:19 -0000 1.249 +++ gdb/defs.h 15 May 2009 22:42:53 -0000 @@ -619,7 +619,7 @@ extern void print_address (CORE_ADDR, st #define OPF_TRY_CWD_FIRST 0x01 #define OPF_SEARCH_IN_PATH 0x02 -extern int openp (const char *, int, const char *, int, int, char **); +extern int openp (const char *, int, const char *, int, char **); extern int source_full_path_of (const char *, char **); --- gdb/exec.c 22 Feb 2009 19:35:47 -0000 1.82 +++ gdb/exec.c 15 May 2009 22:42:53 -0000 @@ -197,7 +197,7 @@ exec_file_attach (char *filename, int fr int scratch_chan; scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename, - write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY, 0, + write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY, &scratch_pathname); #if defined(__GO32__) || defined(_WIN32) || defined(__CYGWIN__) if (scratch_chan < 0) @@ -205,7 +205,7 @@ exec_file_attach (char *filename, int fr char *exename = alloca (strlen (filename) + 5); strcat (strcpy (exename, filename), ".exe"); scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, exename, - write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY, 0, + write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY, &scratch_pathname); } #endif --- gdb/nto-tdep.c 22 Feb 2009 01:02:19 -0000 1.30 +++ gdb/nto-tdep.c 15 May 2009 22:42:53 -0000 @@ -145,7 +145,7 @@ nto_find_and_open_solib (char *solib, un else base++; /* Skip over '/'. */ - ret = openp (buf, 1, base, o_flags, 0, temp_pathname); + ret = openp (buf, 1, base, o_flags, temp_pathname); if (ret < 0 && base != solib) { sprintf (arch_path, "/%s", solib); --- gdb/solib.c 15 May 2009 16:53:44 -0000 1.116 +++ gdb/solib.c 15 May 2009 22:42:54 -0000 @@ -210,14 +210,14 @@ solib_find (char *in_pathname, int *fd) /* If not found, search the solib_search_path (if any). */ if (found_file < 0 && solib_search_path != NULL) found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST, - in_pathname, O_RDONLY | O_BINARY, 0, &temp_pathname); + in_pathname, O_RDONLY | O_BINARY, &temp_pathname); /* If not found, next search the solib_search_path (if any) for the basename only (ignoring the path). This is to allow reading solibs from a path that differs from the opened path. */ if (found_file < 0 && solib_search_path != NULL) found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST, - lbasename (in_pathname), O_RDONLY | O_BINARY, 0, + lbasename (in_pathname), O_RDONLY | O_BINARY, &temp_pathname); /* If not found, try to use target supplied solib search method */ @@ -228,14 +228,14 @@ solib_find (char *in_pathname, int *fd) /* If not found, next search the inferior's $PATH environment variable. */ if (found_file < 0 && gdb_sysroot_is_empty) found_file = openp (get_in_environ (inferior_environ, "PATH"), - OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY, 0, + OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY, &temp_pathname); /* If not found, next search the inferior's $LD_LIBRARY_PATH environment variable. */ if (found_file < 0 && gdb_sysroot_is_empty) found_file = openp (get_in_environ (inferior_environ, "LD_LIBRARY_PATH"), - OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY, 0, + OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY, &temp_pathname); *fd = found_file; --- gdb/symfile.c 14 May 2009 23:33:08 -0000 1.226 +++ gdb/symfile.c 15 May 2009 22:42:55 -0000 @@ -1585,14 +1585,14 @@ symfile_bfd_open (char *name) /* Look down path for it, allocate 2nd new malloc'd copy. */ desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, name, - O_RDONLY | O_BINARY, 0, &absolute_name); + O_RDONLY | O_BINARY, &absolute_name); #if defined(__GO32__) || defined(_WIN32) || defined (__CYGWIN__) if (desc < 0) { char *exename = alloca (strlen (name) + 5); strcat (strcpy (exename, name), ".exe"); desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, exename, - O_RDONLY | O_BINARY, 0, &absolute_name); + O_RDONLY | O_BINARY, &absolute_name); } #endif if (desc < 0) --- gdb/cli/cli-cmds.c 25 Mar 2009 21:42:34 -0000 1.86 +++ gdb/cli/cli-cmds.c 15 May 2009 22:42:55 -0000 @@ -451,7 +451,7 @@ source_script (char *file, int from_tty) /* Search for and open 'file' on the search path used for source files. Put the full location in 'full_pathname'. */ fd = openp (source_path, OPF_TRY_CWD_FIRST, - file, O_RDONLY, 0, &full_pathname); + file, O_RDONLY, &full_pathname); make_cleanup (xfree, full_pathname); /* Use the full path name, if it is found. */