diff mbox series

[1/2] linux-user: remove useless variable

Message ID 20190714134028.315-1-laurent@vivier.eu
State New
Headers show
Series [1/2] linux-user: remove useless variable | expand

Commit Message

Laurent Vivier July 14, 2019, 1:40 p.m. UTC
filename is only used to open the file if AT_EXECFD is not provided.
But exec_path already contains the path of the file to open.
Remove filename as it is only used in main.c whereas exec_path is
also used in syscall.c.

Fixes: d088d664f201 ("linux-user: identify running binary in /proc/self/exe")
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/main.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Philippe Mathieu-Daudé July 14, 2019, 4:02 p.m. UTC | #1
On 7/14/19 3:40 PM, Laurent Vivier wrote:
> filename is only used to open the file if AT_EXECFD is not provided.
> But exec_path already contains the path of the file to open.
> Remove filename as it is only used in main.c whereas exec_path is
> also used in syscall.c.
> 
> Fixes: d088d664f201 ("linux-user: identify running binary in /proc/self/exe")
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
>  linux-user/main.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/linux-user/main.c b/linux-user/main.c
> index a59ae9439de1..ef8e8cb10eba 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -48,7 +48,6 @@
>  char *exec_path;
>  
>  int singlestep;
> -static const char *filename;
>  static const char *argv0;
>  static int gdbstub_port;
>  static envlist_t *envlist;
> @@ -580,7 +579,6 @@ static int parse_args(int argc, char **argv)
>          exit(EXIT_FAILURE);
>      }
>  
> -    filename = argv[optind];
>      exec_path = argv[optind];
>  
>      return optind;
> @@ -651,9 +649,9 @@ int main(int argc, char **argv, char **envp)
>  
>      execfd = qemu_getauxval(AT_EXECFD);
>      if (execfd == 0) {
> -        execfd = open(filename, O_RDONLY);
> +        execfd = open(exec_path, O_RDONLY);
>          if (execfd < 0) {
> -            printf("Error while loading %s: %s\n", filename, strerror(errno));
> +            printf("Error while loading %s: %s\n", exec_path, strerror(errno));
>              _exit(EXIT_FAILURE);
>          }
>      }
> @@ -778,10 +776,10 @@ int main(int argc, char **argv, char **envp)
>      cpu->opaque = ts;
>      task_settid(ts);
>  
> -    ret = loader_exec(execfd, filename, target_argv, target_environ, regs,
> +    ret = loader_exec(execfd, exec_path, target_argv, target_environ, regs,
>          info, &bprm);
>      if (ret != 0) {
> -        printf("Error while loading %s: %s\n", filename, strerror(-ret));
> +        printf("Error while loading %s: %s\n", exec_path, strerror(-ret));
>          _exit(EXIT_FAILURE);
>      }
>  
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Laurent Vivier Aug. 23, 2019, 3:31 p.m. UTC | #2
Le 14/07/2019 à 15:40, Laurent Vivier a écrit :
> filename is only used to open the file if AT_EXECFD is not provided.
> But exec_path already contains the path of the file to open.
> Remove filename as it is only used in main.c whereas exec_path is
> also used in syscall.c.
> 
> Fixes: d088d664f201 ("linux-user: identify running binary in /proc/self/exe")
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
>  linux-user/main.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/linux-user/main.c b/linux-user/main.c
> index a59ae9439de1..ef8e8cb10eba 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -48,7 +48,6 @@
>  char *exec_path;
>  
>  int singlestep;
> -static const char *filename;
>  static const char *argv0;
>  static int gdbstub_port;
>  static envlist_t *envlist;
> @@ -580,7 +579,6 @@ static int parse_args(int argc, char **argv)
>          exit(EXIT_FAILURE);
>      }
>  
> -    filename = argv[optind];
>      exec_path = argv[optind];
>  
>      return optind;
> @@ -651,9 +649,9 @@ int main(int argc, char **argv, char **envp)
>  
>      execfd = qemu_getauxval(AT_EXECFD);
>      if (execfd == 0) {
> -        execfd = open(filename, O_RDONLY);
> +        execfd = open(exec_path, O_RDONLY);
>          if (execfd < 0) {
> -            printf("Error while loading %s: %s\n", filename, strerror(errno));
> +            printf("Error while loading %s: %s\n", exec_path, strerror(errno));
>              _exit(EXIT_FAILURE);
>          }
>      }
> @@ -778,10 +776,10 @@ int main(int argc, char **argv, char **envp)
>      cpu->opaque = ts;
>      task_settid(ts);
>  
> -    ret = loader_exec(execfd, filename, target_argv, target_environ, regs,
> +    ret = loader_exec(execfd, exec_path, target_argv, target_environ, regs,
>          info, &bprm);
>      if (ret != 0) {
> -        printf("Error while loading %s: %s\n", filename, strerror(-ret));
> +        printf("Error while loading %s: %s\n", exec_path, strerror(-ret));
>          _exit(EXIT_FAILURE);
>      }
>  
> 

Applied to my linux-user branch.

Thanks,
Laurent
diff mbox series

Patch

diff --git a/linux-user/main.c b/linux-user/main.c
index a59ae9439de1..ef8e8cb10eba 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -48,7 +48,6 @@ 
 char *exec_path;
 
 int singlestep;
-static const char *filename;
 static const char *argv0;
 static int gdbstub_port;
 static envlist_t *envlist;
@@ -580,7 +579,6 @@  static int parse_args(int argc, char **argv)
         exit(EXIT_FAILURE);
     }
 
-    filename = argv[optind];
     exec_path = argv[optind];
 
     return optind;
@@ -651,9 +649,9 @@  int main(int argc, char **argv, char **envp)
 
     execfd = qemu_getauxval(AT_EXECFD);
     if (execfd == 0) {
-        execfd = open(filename, O_RDONLY);
+        execfd = open(exec_path, O_RDONLY);
         if (execfd < 0) {
-            printf("Error while loading %s: %s\n", filename, strerror(errno));
+            printf("Error while loading %s: %s\n", exec_path, strerror(errno));
             _exit(EXIT_FAILURE);
         }
     }
@@ -778,10 +776,10 @@  int main(int argc, char **argv, char **envp)
     cpu->opaque = ts;
     task_settid(ts);
 
-    ret = loader_exec(execfd, filename, target_argv, target_environ, regs,
+    ret = loader_exec(execfd, exec_path, target_argv, target_environ, regs,
         info, &bprm);
     if (ret != 0) {
-        printf("Error while loading %s: %s\n", filename, strerror(-ret));
+        printf("Error while loading %s: %s\n", exec_path, strerror(-ret));
         _exit(EXIT_FAILURE);
     }