]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
processhelp.pm: improve `taskkill` calls (Windows)
authorViktor Szakats <commit@vsz.me>
Wed, 18 Sep 2024 12:36:36 +0000 (14:36 +0200)
committerViktor Szakats <commit@vsz.me>
Thu, 19 Sep 2024 10:43:54 +0000 (12:43 +0200)
- drop `tasklist` call before `taskkill`.
  `taskkill` offers two ways to kill a `pid`:
  1. `-pid <pid>`
     If `<pid>` is missing it returns 128 and outputs:
     ```
     ERROR: The process "<pid>" not found.
     ```
  2. `-fi "PID eq <pid>"`
     If `<pid>` is missing, it returns 0 and outputs:
     ```
     INFO: No tasks running with the specified criteria.
     ```
  The curl runner script doesn't check the result of the call and both
  stdout and stderr are redirected to NUL.
  Meaning the `tasklist` calls pre-verifying if the PID exists are not
  necessary and we can drop them to put less strain on the runner
  environment.

- log a `taskkill` call missed earlier.
  Follow-up to e53523fef07894991c69d907a7c7794c7ada4ff4 #14859

- streamline `taskkill` calls by using the `-pid` option
  (was `-fi <filter-expression>`).

- make `taskkill` in `pidterm()` use `-t` to kill the process tree.

Ref: #11009
Closes #14959

tests/processhelp.pm

index 44c6411cdac2f4a48f2cd289b8b20d219d78642f..0a0ce1939eee97704dccdf624f3700562c8987d9 100644 (file)
@@ -167,13 +167,10 @@ sub pidterm {
         if ($pid > 65536 && os_is_win()) {
             $pid -= 65536;
             if($^O ne 'MSWin32') {
-                my $filter = "PID eq $pid";
-                # https://ss64.com/nt/tasklist.html
-                my $result = `tasklist -fi \"$filter\" 2>nul`;
-                if(index($result, "$pid") != -1) {
-                    # https://ss64.com/nt/taskkill.html
-                    system("taskkill -fi \"$filter\" >nul 2>&1");
-                }
+                # https://ss64.com/nt/taskkill.html
+                my $cmd = "taskkill -t -pid $pid >nul 2>&1";
+                logmsg "Executing: '$cmd'\n";
+                system($cmd);
                 return;
             }
         }
@@ -195,17 +192,10 @@ sub pidkill {
         if ($pid > 65536 && os_is_win()) {
             $pid -= 65536;
             if($^O ne 'MSWin32') {
-                my $filter = "PID eq $pid";
-                # https://ss64.com/nt/tasklist.html
-                my $cmd = "tasklist -fi \"$filter\" 2>nul";
+                # https://ss64.com/nt/taskkill.html
+                my $cmd = "taskkill -f -t -pid $pid >nul 2>&1";
                 logmsg "Executing: '$cmd'\n";
-                my $result = `$cmd`;
-                if(index($result, "$pid") != -1) {
-                    # https://ss64.com/nt/taskkill.html
-                    my $cmd = "taskkill -f -t -fi \"$filter\" >nul 2>&1";
-                    logmsg "Executing: '$cmd'\n";
-                    system($cmd);
-                }
+                system($cmd);
                 return;
             }
         }