From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1003645-garchives=archives.gentoo.org@lists.gentoo.org>
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 470B7138331
	for <garchives@archives.gentoo.org>; 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 13ECEE0BBE;
	Wed, 14 Feb 2018 23:37:24 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(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 E35C2E0BBE
	for <gentoo-commits@lists.gentoo.org>; Wed, 14 Feb 2018 23:37:23 +0000 (UTC)
Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84])
	(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 14F33335C09
	for <gentoo-commits@lists.gentoo.org>; Wed, 14 Feb 2018 23:37:22 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 815C0211
	for <gentoo-commits@lists.gentoo.org>; Wed, 14 Feb 2018 23:37:20 +0000 (UTC)
From: "William Hubbs" <williamh@gentoo.org>
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" <williamh@gentoo.org>
Message-ID: <1518648979.7b4879cb72e907414b70553663bd9b6fda8d4408.williamh@OpenRC>
Subject: [gentoo-commits] proj/openrc:master commit in: src/rc/
X-VCS-Repository: proj/openrc
X-VCS-Files: src/rc/mountinfo.c
X-VCS-Directories: src/rc/
X-VCS-Committer: williamh
X-VCS-Committer-Name: William Hubbs
X-VCS-Revision: 7b4879cb72e907414b70553663bd9b6fda8d4408
X-VCS-Branch: master
Date: Wed, 14 Feb 2018 23:37:20 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: 6469df91-0455-4c89-8b95-8be2412835ff
X-Archives-Hash: ddf5c0a210771cda1cfd8b3905628d0f

commit:     7b4879cb72e907414b70553663bd9b6fda8d4408
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Wed Feb 14 22:56:19 2018 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Wed Feb 14 22:56:19 2018 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=7b4879cb

mountinfo: create strings with xasprintf

 src/rc/mountinfo.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/rc/mountinfo.c b/src/rc/mountinfo.c
index d9c25a38..5bf97386 100644
--- a/src/rc/mountinfo.c
+++ b/src/rc/mountinfo.c
@@ -248,7 +248,6 @@ find_mounts(struct args *args)
 	struct opt *o;
 	int netdev;
 	char *tmp;
-	size_t l;
 
 	if ((nmnts = getmntinfo(&mnts, MNT_NOWAIT)) == 0)
 		eerrorx("getmntinfo: %s", strerror (errno));
@@ -264,11 +263,7 @@ find_mounts(struct args *args)
 				if (! options)
 					options = xstrdup(o->o_name);
 				else {
-					l = strlen(options) +
-					    strlen(o->o_name) + 2;
-					tmp = xmalloc(sizeof (char) * l);
-					snprintf(tmp, l, "%s,%s", options,
-					    o->o_name);
+					xasprintf(&tmp, "%s,%s", options, o->o_name);
 					free(options);
 					options = tmp;
 				}
@@ -315,6 +310,7 @@ find_mounts(struct args *args)
 {
 	FILE *fp;
 	char *buffer;
+	size_t size;
 	char *p;
 	char *from;
 	char *to;
@@ -329,8 +325,8 @@ find_mounts(struct args *args)
 
 	list = rc_stringlist_new();
 
-	buffer = xmalloc(sizeof(char) * PATH_MAX * 3);
-	while (fgets(buffer, PATH_MAX * 3, fp)) {
+	buffer = NULL;
+	while (getline(&buffer, &size, fp) != -1) {
 		netdev = -1;
 		p = buffer;
 		from = strsep(&p, " ");
@@ -346,6 +342,8 @@ find_mounts(struct args *args)
 		}
 
 		process_mount(list, args, from, to, fst, opts, netdev);
+		free(buffer);
+		buffer = NULL;
 	}
 	free(buffer);
 	fclose(fp);
@@ -380,7 +378,7 @@ int main(int argc, char **argv)
 	regex_t *skip_point_regex = NULL;
 	RC_STRINGLIST *nodes;
 	RC_STRING *s;
-	char real_path[PATH_MAX + 1];
+	char *real_path = NULL;
 	int opt;
 	int result;
 	char *this_path;
@@ -450,9 +448,12 @@ int main(int argc, char **argv)
 			eerrorx("%s: `%s' is not a mount point",
 			    argv[0], argv[optind]);
 		this_path = argv[optind++];
-		if (realpath(this_path, real_path))
+		real_path = realpath(this_path, NULL);
+		if (real_path)
 			this_path = real_path;
 		rc_stringlist_add(args.mounts, this_path);
+		free(real_path);
+		real_path = NULL;
 	}
 	nodes = find_mounts(&args);
 	rc_stringlist_free(args.mounts);