[PATCH] execline: use pathexec_or_die

From: Rasmus Villemoes <rv_at_rasmusvillemoes.dk>
Date: Wed, 17 May 2017 22:31:17 +0200

In most cases, this is completely mechanical, generated by the Coccinelle script

_at_@
expression a, b, c;
_at_@
- pathexec_run
+ pathexec_run_or_die
  (a, b, c) ;
- strerr_dieexec(111, a);

In exec.c, we already win a little by doing a single call of
pathexec_run instead of having each branch do their own; after that,
we're in the same situation as the other 10 instances.

Signed-off-by: Rasmus Villemoes <rv_at_rasmusvillemoes.dk>
---
 src/execline/cd.c           | 3 +--
 src/execline/exec.c         | 4 +---
 src/execline/fdblock.c      | 3 +--
 src/execline/fdclose.c      | 3 +--
 src/execline/fdmove.c       | 3 +--
 src/execline/fdswap.c       | 3 +--
 src/execline/forbacktickx.c | 3 +--
 src/execline/heredoc.c      | 3 +--
 src/execline/piperw.c       | 3 +--
 src/execline/redirfd.c      | 3 +--
 src/execline/umask.c        | 3 +--
 11 files changed, 11 insertions(+), 23 deletions(-)
diff --git a/src/execline/cd.c b/src/execline/cd.c
index c774ce5..438383c 100644
--- a/src/execline/cd.c
+++ b/src/execline/cd.c
_at_@ -12,6 +12,5 @@ int main (int argc, char const *const *argv, char const *const *envp)
   if (argc < 3) strerr_dieusage(100, USAGE) ;
   if (chdir(argv[1]) == -1)
     strerr_diefu2sys(111, "chdir to ", argv[1]) ;
-  pathexec_run(argv[2], argv+2, envp) ;
-  strerr_dieexec(111, argv[2]) ;
+  pathexec_run_or_die(argv[2], argv+2, envp) ;
 }
diff --git a/src/execline/exec.c b/src/execline/exec.c
index e35d7ba..d698c6d 100644
--- a/src/execline/exec.c
+++ b/src/execline/exec.c
_at_@ -41,8 +41,6 @@ int main (int argc, char const **argv, char const *const *envp)
     dashed[0] = '-' ;
     memcpy(dashed+1, argv[0], n+1) ;
     argv[0] = (char const *)dashed ;
-    pathexec_run(executable, argv, envp) ;
   }
-  else pathexec_run(executable, argv, envp) ;
-  strerr_dieexec(111, executable) ;
+  pathexec_run_or_die(executable, argv, envp) ;
 }
diff --git a/src/execline/fdblock.c b/src/execline/fdblock.c
index ec68900..2712349 100644
--- a/src/execline/fdblock.c
+++ b/src/execline/fdblock.c
_at_@ -29,6 +29,5 @@ int main (int argc, char const *const *argv, char const *const *envp)
   if ((argc < 2) || !uint0_scan(argv[0], &fd)) strerr_dieusage(100, USAGE) ;
   if ((block ? ndelay_off(fd) : ndelay_on(fd)) < 0)
     strerr_diefu1sys(111, block ? "ndelay_off" : "ndelay_on") ;
-  pathexec_run(argv[1], argv+1, envp) ;
-  strerr_dieexec(111, argv[1]) ;
+  pathexec_run_or_die(argv[1], argv+1, envp) ;
 }
diff --git a/src/execline/fdclose.c b/src/execline/fdclose.c
index 47780c9..cd361ae 100644
--- a/src/execline/fdclose.c
+++ b/src/execline/fdclose.c
_at_@ -12,6 +12,5 @@ int main (int argc, char const *const *argv, char const *const *envp)
   PROG = "fdclose" ;
   if ((argc < 3) || !uint0_scan(argv[1], &fd)) strerr_dieusage(100, USAGE) ;
   fd_close(fd) ;
-  pathexec_run(argv[2], argv+2, envp) ;
-  strerr_dieexec(111, argv[2]) ;
+  pathexec_run_or_die(argv[2], argv+2, envp) ;
 }
diff --git a/src/execline/fdmove.c b/src/execline/fdmove.c
index 6f97b11..a6f4bc5 100644
--- a/src/execline/fdmove.c
+++ b/src/execline/fdmove.c
_at_@ -30,6 +30,5 @@ int main (int argc, char const *const *argv, char const *const *envp)
     strerr_dieusage(100, USAGE) ;
   if ((flagcopy ? fd_copy(to, from) : fd_move(to, from)) == -1)
     strerr_diefu4sys(111, "move fd ", argv[1], " to fd ", argv[0]) ;
-  pathexec_run(argv[2], argv+2, envp) ;
-  strerr_dieexec(111, argv[2]) ;
+  pathexec_run_or_die(argv[2], argv+2, envp) ;
 }
diff --git a/src/execline/fdswap.c b/src/execline/fdswap.c
index b19494e..2071a9a 100644
--- a/src/execline/fdswap.c
+++ b/src/execline/fdswap.c
_at_@ -13,6 +13,5 @@ int main (int argc, char const *const *argv, char const *const *envp)
   if ((argc < 4) || !uint0_scan(argv[1], &fd1) || !uint0_scan(argv[2], &fd2))
     strerr_dieusage(100, USAGE) ;
   if (fd_move2(fd1, fd2, fd2, fd1) < 0) strerr_diefu1sys(111, "swap fds") ;
-  pathexec_run(argv[3], argv+3, envp) ;
-  strerr_dieexec(111, argv[3]) ;
+  pathexec_run_or_die(argv[3], argv+3, envp) ;
 }
diff --git a/src/execline/forbacktickx.c b/src/execline/forbacktickx.c
index b1b49fa..9c088c4 100644
--- a/src/execline/forbacktickx.c
+++ b/src/execline/forbacktickx.c
_at_@ -110,7 +110,6 @@ int main (int argc, char const *const *argv, char const *const *envp)
     }
     while (argv[i]) newargv[m++] = argv[i++] ;
     newargv[m++] = 0 ;
-    pathexec_run(newargv[0], newargv, envp) ;
-    strerr_dieexec(111, newargv[0]) ;
+    pathexec_run_or_die(newargv[0], newargv, envp) ;
   }
 }
diff --git a/src/execline/heredoc.c b/src/execline/heredoc.c
index 77e69da..9c624b7 100644
--- a/src/execline/heredoc.c
+++ b/src/execline/heredoc.c
_at_@ -55,6 +55,5 @@ int main (int argc, char const *const *argv, char const *const *envp)
     if (fd_move(fdr, fd[0]) == -1)
       strerr_diefu2sys(111, "read on fd ", argv[0]) ;
   }
-  pathexec_run(argv[2], argv+2, envp) ;
-  strerr_dieexec(111, argv[2]) ;
+  pathexec_run_or_die(argv[2], argv+2, envp) ;
 }
diff --git a/src/execline/piperw.c b/src/execline/piperw.c
index 8affbde..461f101 100644
--- a/src/execline/piperw.c
+++ b/src/execline/piperw.c
_at_@ -24,6 +24,5 @@ int main (int argc, char const *const *argv, char const *const *envp)
    || (fd_move(fdr, p[0]) == -1)
    || (fd_move(fdw, p[1]) == -1))
     strerr_diefu1sys(111, "move fds") ;
-  pathexec_run(argv[3], argv+3, envp) ;
-  strerr_dieexec(111, argv[3]) ;
+  pathexec_run_or_die(argv[3], argv+3, envp) ;
 }
diff --git a/src/execline/redirfd.c b/src/execline/redirfd.c
index 8a5c8ef..f0cb13c 100644
--- a/src/execline/redirfd.c
+++ b/src/execline/redirfd.c
_at_@ -64,6 +64,5 @@ int main (int argc, char const *const *argv, char const *const *envp)
     if (((flags & O_NONBLOCK) ? ndelay_off(fd) : ndelay_on(fd)) < 0)
       strerr_diefu1sys(111, "change blocking mode") ;
   }
-  pathexec_run(argv[2], argv+2, envp) ;
-  strerr_dieexec(111, argv[2]) ;
+  pathexec_run_or_die(argv[2], argv+2, envp) ;
 }
diff --git a/src/execline/umask.c b/src/execline/umask.c
index ab91b37..866c216 100644
--- a/src/execline/umask.c
+++ b/src/execline/umask.c
_at_@ -14,6 +14,5 @@ int main (int argc, char const *const *argv, char const *const *envp)
   if (argc < 3) strerr_dieusage(100, USAGE) ;
   if (!uint_oscan(argv[1], &m)) strerr_dieusage(100, USAGE) ;
   umask(m) ;
-  pathexec_run(argv[2], argv+2, envp) ;
-  strerr_dieexec(111, argv[2]) ;
+  pathexec_run_or_die(argv[2], argv+2, envp) ;
 }
-- 
2.1.4
Received on Wed May 17 2017 - 20:31:17 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC