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 4AA2D138334 for ; Wed, 20 Jun 2018 14:38:40 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2F4D1E09A2; Wed, 20 Jun 2018 14:38:39 +0000 (UTC) Received: from smtp.gentoo.org (dev.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 DDFEAE09A2 for ; Wed, 20 Jun 2018 14:38:38 +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 209AC335CDD for ; Wed, 20 Jun 2018 14:38:37 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 74FB02AD for ; Wed, 20 Jun 2018 14:38:35 +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: <1529505440.64354831da2adeba5cb2f91a81fa0f56e1ce4ed9.williamh@OpenRC> Subject: [gentoo-commits] proj/openrc:master commit in: src/rc/ X-VCS-Repository: proj/openrc X-VCS-Files: src/rc/rc.c X-VCS-Directories: src/rc/ X-VCS-Committer: williamh X-VCS-Committer-Name: William Hubbs X-VCS-Revision: 64354831da2adeba5cb2f91a81fa0f56e1ce4ed9 X-VCS-Branch: master Date: Wed, 20 Jun 2018 14:38:35 +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: 1bbe9e85-95f1-49bb-8413-3a2f7020075a X-Archives-Hash: 762587007421537e31bc111a9e9a0b34 commit: 64354831da2adeba5cb2f91a81fa0f56e1ce4ed9 Author: William Hubbs gmail com> AuthorDate: Wed Jun 20 14:37:20 2018 +0000 Commit: William Hubbs gentoo org> CommitDate: Wed Jun 20 14:37:20 2018 +0000 URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=64354831 openrc: convert snprintf calls to xasprintf src/rc/rc.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/rc/rc.c b/src/rc/rc.c index f613b5b6..c6e453b3 100644 --- a/src/rc/rc.c +++ b/src/rc/rc.c @@ -101,7 +101,6 @@ clean_failed(void) { DIR *dp; struct dirent *d; - size_t l; char *path; /* Clean the failed services state dir now */ @@ -112,16 +111,11 @@ clean_failed(void) (d->d_name[1] == '.' && d->d_name[2] == '\0'))) continue; - l = strlen(RC_SVCDIR "/failed/") + - strlen(d->d_name) + 1; - path = xmalloc(sizeof(char) * l); - snprintf(path, l, RC_SVCDIR "/failed/%s", d->d_name); - if (path) { - if (unlink(path)) - eerror("%s: unlink `%s': %s", - applet, path, strerror(errno)); - free(path); - } + xasprintf(&path, RC_SVCDIR "/failed/%s", d->d_name); + if (unlink(path)) + eerror("%s: unlink `%s': %s", + applet, path, strerror(errno)); + free(path); } closedir(dp); } @@ -391,7 +385,7 @@ static void handle_signal(int sig) { int serrno = errno; - char signame[10] = { '\0' }; + char *signame = NULL; pid_t pid; RC_PID *pi; int status = 0; @@ -422,16 +416,16 @@ handle_signal(int sig) break; case SIGINT: - if (!signame[0]) - snprintf(signame, sizeof(signame), "SIGINT"); + if (!signame) + xasprintf(&signame, "SIGINT"); /* FALLTHROUGH */ case SIGTERM: - if (!signame[0]) - snprintf(signame, sizeof(signame), "SIGTERM"); + if (!signame) + xasprintf(&signame, "SIGTERM"); /* FALLTHROUGH */ case SIGQUIT: - if (!signame[0]) - snprintf(signame, sizeof(signame), "SIGQUIT"); + if (!signame) + xasprintf(&signame, "SIGQUIT"); eerrorx("%s: caught %s, aborting", applet, signame); /* NOTREACHED */ case SIGUSR1: @@ -512,14 +506,11 @@ runlevel_config(const char *service, const char *level) { char *init = rc_service_resolve(service); char *conf, *dir; - size_t l; bool retval; dir = dirname(init); dir = dirname(init); - l = strlen(dir) + strlen(level) + strlen(service) + 10; - conf = xmalloc(sizeof(char) * l); - snprintf(conf, l, "%s/conf.d/%s.%s", dir, service, level); + xasprintf(&conf, "%s/conf.d/%s.%s", dir, service, level); retval = exists(conf); free(conf); free(init); @@ -744,7 +735,7 @@ int main(int argc, char **argv) bool going_down = false; int depoptions = RC_DEP_STRICT | RC_DEP_TRACE; char *krunlevel = NULL; - char pidstr[10]; + char *pidstr = NULL; int opt; bool parallel; int regen = 0; @@ -844,8 +835,9 @@ int main(int argc, char **argv) setenv("EINFO_LOG", "openrc", 1); /* Export our PID */ - snprintf(pidstr, sizeof(pidstr), "%d", getpid()); + xasprintf(&pidstr, "%d", getpid()); setenv("RC_PID", pidstr, 1); + free(pidstr); /* Create a list of all services which should be started for the new or * current runlevel including those in boot, sysinit and hotplugged