pacman: update killall patch with suggestions from review

This commit is contained in:
Christoph Reiter
2020-05-22 12:51:37 +02:00
parent 209a4dd798
commit 4bfc7367ba
2 changed files with 42 additions and 42 deletions

View File

@@ -1195,65 +1195,65 @@ diff -Naur pacman-5.1.0-orig/src/pacman/sync.c pacman-5.1.0/src/pacman/sync.c
+static int kill_all_other_msys_processes() {
+ DIR *dir;
+ struct dirent *ent;
+ char kill_command[PATH_MAX];
+ char self_winpid[PATH_MAX];
+ char self_winpid[50];
+ int found_one = 0;
+ FILE *self = NULL;
+ char** args = NULL;
+ size_t proc_entries = 0;
+ char **args = NULL;
+ size_t pos = 0;
+
+ self = fopen("/proc/self/winpid", "r");
+ if (self == NULL)
+ return -1;
+ safe_fgets(self_winpid, sizeof(self_winpid), self);
+ strtrim(self_winpid);
+ fscanf(self, "%s", self_winpid);
+ fclose(self);
+
+ strcpy(kill_command, "taskkill /f");
+
+ dir = opendir ("/proc");
+ if (dir != NULL) {
+ while (ent = readdir (dir)) {
+ FILE *fp = NULL;
+ char winpid[PATH_MAX];
+
+ strcpy(winpid, "/proc/");
+ strcat(winpid, ent->d_name);
+ strcat(winpid, "/winpid");
+
+ fp = fopen(winpid, "r");
+ if (fp != NULL) {
+ char winpid[PATH_MAX];
+
+ safe_fgets(winpid, sizeof(winpid), fp);
+ strtrim(winpid);
+ if (strcmp(winpid, self_winpid) != 0) {
+ strcat(kill_command, " /pid ");
+ strcat(kill_command, winpid);
+ found_one = 1;
+ }
+
+ fclose(fp);
+ }
+ }
+
+ closedir (dir);
+ } else {
+ dir = opendir("/proc");
+ if (dir == NULL)
+ return -1;
+
+ while (ent = readdir(dir))
+ proc_entries++;
+ seekdir(dir, 0);
+
+ args = alloca(sizeof(char *) * (2 + (proc_entries * 2) + 1));
+ args[pos++] = "taskkill";
+ args[pos++] = "/F";
+
+ while (ent = readdir (dir)) {
+ FILE *fp = NULL;
+ char winpid_path[PATH_MAX];
+
+ strcpy(winpid_path, "/proc/");
+ strcat(winpid_path, ent->d_name);
+ strcat(winpid_path, "/winpid");
+
+ fp = fopen(winpid_path, "r");
+ if (fp != NULL) {
+ char winpid[50];
+ fscanf(fp, "%s", winpid);
+
+ if (strcmp(winpid, self_winpid) != 0) {
+ args[pos++] = "/pid";
+ char *pidarg = alloca(strlen(winpid) + 1);
+ strcpy(pidarg, winpid);
+ args[pos++] = pidarg;
+ found_one = 1;
+ }
+
+ fclose(fp);
+ }
+ }
+ args[pos] = NULL;
+ closedir(dir);
+
+ if (!found_one)
+ return 0;
+
+ args = wordsplit(kill_command);
+ if (args == NULL)
+ return -1;
+
+ setenv("MSYS2_ARG_CONV_EXCL", "*", 1);
+ if (execvp(args[0], args + 1) == -1) {
+ wordsplit_free(args);
+ return -1;
+ }
+ wordsplit_free(args);
+
+ return 0;
+}

View File

@@ -94,7 +94,7 @@ sha256sums=('1930c407265fd039cb3a8e6edc82f69e122aa9239d216d9d57b9d1b9315af312'
'70c01a440acc2ddfff1c3d5d52f48865a8a33c3f8b494fc77974c398aa5be8e0'
'8949cfd1fee9c965ec8afccee27937d4c15b4cccb2c367db4fb2b718bc66e74a'
'684648d5b1246af9ce5b3afaadf201873269c5208057e8cbdbd409b4c0f22564'
'b8ae396f6f4f083389b8536a6f769fa5c74089fa71a841d1869a7243cfc0ae13'
'1ee416608d34c8f44becb6f30f3a03383f28df7c3c41bc5507b626ad05e0404c'
'24ea2c8dca37847e04894ebfd05d1cf5df49dc0c8089f5581c99caa19b77a7ef'
'870b197b7d6379a9c1ebb5c449c902b21d75ec21e966a2e54af82501465180f7'
'23132552a388b238acf8bf650b5c2aa08cf3de63c647e84ad551807c4edfeb1e'