Gentoo Archives: gentoo-commits

From: William Hubbs <williamh@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/openrc:master commit in: src/rc/
Date: Wed, 14 Feb 2018 23:37:25
Message-Id: 1518648624.74cfb455c59298f86849541e724ae346ff205c3d.williamh@OpenRC
1 commit: 74cfb455c59298f86849541e724ae346ff205c3d
2 Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
3 AuthorDate: Wed Feb 14 22:50:24 2018 +0000
4 Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
5 CommitDate: Wed Feb 14 22:50:24 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=74cfb455
7
8 kill_all: create strings with xasprintf
9
10 src/rc/kill_all.c | 25 +++++++++++++++++--------
11 1 file changed, 17 insertions(+), 8 deletions(-)
12
13 diff --git a/src/rc/kill_all.c b/src/rc/kill_all.c
14 index f3500227..d6ce354b 100644
15 --- a/src/rc/kill_all.c
16 +++ b/src/rc/kill_all.c
17 @@ -87,10 +87,11 @@ static int mount_proc(void)
18
19 static bool is_user_process(pid_t pid)
20 {
21 - char buf[PATH_MAX+1];
22 + char *buf = NULL;
23 FILE *fp;
24 - char path[PATH_MAX+1];
25 + char *path = NULL;
26 pid_t temp_pid;
27 + size_t size;
28 bool user_process = true;
29
30 while (pid >0 && user_process) {
31 @@ -98,8 +99,9 @@ static bool is_user_process(pid_t pid)
32 user_process = false;
33 continue;
34 }
35 - snprintf(path, sizeof(path), "/proc/%d/status", pid);
36 + xasprintf(&path, "/proc/%d/status", pid);
37 fp = fopen(path, "r");
38 + free(path);
39 /*
40 * if we could not open the file, the process disappeared, which
41 * leaves us no way to determine for sure whether it was a user
42 @@ -112,11 +114,14 @@ static bool is_user_process(pid_t pid)
43 }
44 temp_pid = -1;
45 while (! feof(fp)) {
46 - buf[0] = 0;
47 - if (fgets(buf, sizeof(buf), fp))
48 + buf = NULL;
49 + if (getline(&buf, &size, fp) != -1) {
50 sscanf(buf, "PPid: %d", &temp_pid);
51 - else
52 + free(buf);
53 + } else {
54 + free(buf);
55 break;
56 + }
57 }
58 fclose(fp);
59 if (temp_pid == -1) {
60 @@ -135,7 +140,7 @@ static int signal_processes(int sig, RC_STRINGLIST *omits, bool dryrun)
61 sigset_t oldsigs;
62 DIR *dir;
63 struct dirent *d;
64 - char buf[PATH_MAX+1];
65 + char *buf = NULL;
66 pid_t pid;
67 int sendcount = 0;
68
69 @@ -170,7 +175,11 @@ static int signal_processes(int sig, RC_STRINGLIST *omits, bool dryrun)
70 continue;
71
72 /* Is this a process we have been requested to omit? */
73 - sprintf(buf, "%d", pid);
74 + if (buf) {
75 + free(buf);
76 + buf = NULL;
77 + }
78 + xasprintf(&buf, "%d", pid);
79 if (rc_stringlist_find(omits, buf))
80 continue;