This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Remove unused PROT from openp()


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  <jan.kratochvil@redhat.com>

	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.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]