From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 067E51382C5 for ; Wed, 14 Feb 2018 23:37:25 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 02784E0BB5; Wed, 14 Feb 2018 23:37:24 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D34A5E0BB5 for ; Wed, 14 Feb 2018 23:37:23 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 3974C335C2C for ; Wed, 14 Feb 2018 23:37:22 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 6CD961F5 for ; Wed, 14 Feb 2018 23:37:20 +0000 (UTC) From: "William Hubbs" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "William Hubbs" Message-ID: <1518648624.74cfb455c59298f86849541e724ae346ff205c3d.williamh@OpenRC> Subject: [gentoo-commits] proj/openrc:master commit in: src/rc/ X-VCS-Repository: proj/openrc X-VCS-Files: src/rc/kill_all.c X-VCS-Directories: src/rc/ X-VCS-Committer: williamh X-VCS-Committer-Name: William Hubbs X-VCS-Revision: 74cfb455c59298f86849541e724ae346ff205c3d X-VCS-Branch: master Date: Wed, 14 Feb 2018 23:37:20 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 1cd8db88-36a7-463d-a3e1-88a9eab405ad X-Archives-Hash: 10d4b6190e401ca29a9f8aee8810ae72 commit: 74cfb455c59298f86849541e724ae346ff205c3d Author: William Hubbs gmail com> AuthorDate: Wed Feb 14 22:50:24 2018 +0000 Commit: William Hubbs gentoo org> CommitDate: Wed Feb 14 22:50:24 2018 +0000 URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=74cfb455 kill_all: create strings with xasprintf src/rc/kill_all.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/rc/kill_all.c b/src/rc/kill_all.c index f3500227..d6ce354b 100644 --- a/src/rc/kill_all.c +++ b/src/rc/kill_all.c @@ -87,10 +87,11 @@ static int mount_proc(void) static bool is_user_process(pid_t pid) { - char buf[PATH_MAX+1]; + char *buf = NULL; FILE *fp; - char path[PATH_MAX+1]; + char *path = NULL; pid_t temp_pid; + size_t size; bool user_process = true; while (pid >0 && user_process) { @@ -98,8 +99,9 @@ static bool is_user_process(pid_t pid) user_process = false; continue; } - snprintf(path, sizeof(path), "/proc/%d/status", pid); + xasprintf(&path, "/proc/%d/status", pid); fp = fopen(path, "r"); + free(path); /* * if we could not open the file, the process disappeared, which * leaves us no way to determine for sure whether it was a user @@ -112,11 +114,14 @@ static bool is_user_process(pid_t pid) } temp_pid = -1; while (! feof(fp)) { - buf[0] = 0; - if (fgets(buf, sizeof(buf), fp)) + buf = NULL; + if (getline(&buf, &size, fp) != -1) { sscanf(buf, "PPid: %d", &temp_pid); - else + free(buf); + } else { + free(buf); break; + } } fclose(fp); if (temp_pid == -1) { @@ -135,7 +140,7 @@ static int signal_processes(int sig, RC_STRINGLIST *omits, bool dryrun) sigset_t oldsigs; DIR *dir; struct dirent *d; - char buf[PATH_MAX+1]; + char *buf = NULL; pid_t pid; int sendcount = 0; @@ -170,7 +175,11 @@ static int signal_processes(int sig, RC_STRINGLIST *omits, bool dryrun) continue; /* Is this a process we have been requested to omit? */ - sprintf(buf, "%d", pid); + if (buf) { + free(buf); + buf = NULL; + } + xasprintf(&buf, "%d", pid); if (rc_stringlist_find(omits, buf)) continue;