commit: be7ad06d4a0efce2a1144b2cf6f0cc361f2a81e4
Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Tue Jun 19 22:06:33 2018 +0000
Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Tue Jun 19 22:06:33 2018 +0000
URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=be7ad06d
rc-status: convert snprintf calls to xasprintf
src/rc/rc-status.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/rc/rc-status.c b/src/rc/rc-status.c
index a6b8d299..85e71dbb 100644
--- a/src/rc/rc-status.c
+++ b/src/rc/rc-status.c
@@ -126,7 +126,7 @@ static char *get_uptime(const char *service)
static void
print_service(const char *service)
{
- char status[60];
+ char *status = NULL;
char *uptime = NULL;
char *child_pid = NULL;
char *start_time = NULL;
@@ -136,12 +136,12 @@ print_service(const char *service)
ECOLOR color = ECOLOR_BAD;
if (state & RC_SERVICE_STOPPING)
- snprintf(status, sizeof(status), "stopping ");
+ xasprintf(&status, "stopping ");
else if (state & RC_SERVICE_STARTING) {
- snprintf(status, sizeof(status), "starting ");
+ xasprintf(&status, "starting ");
color = ECOLOR_WARN;
} else if (state & RC_SERVICE_INACTIVE) {
- snprintf(status, sizeof(status), "inactive ");
+ xasprintf(&status, "inactive ");
color = ECOLOR_WARN;
} else if (state & RC_SERVICE_STARTED) {
errno = 0;
@@ -150,30 +150,31 @@ print_service(const char *service)
child_pid = rc_service_value_get(service, "child_pid");
start_time = rc_service_value_get(service,
"start_time");
if (start_time && child_pid)
- snprintf(status, sizeof(status), " unsupervised
");
+ xasprintf(&status, " unsupervised ");
else
- snprintf(status, sizeof(status), " crashed ");
+ xasprintf(&status, " crashed ");
free(child_pid);
free(start_time);
} else {
uptime = get_uptime(service);
if (uptime) {
- snprintf(status, sizeof(status), " started %s",
uptime);
+ xasprintf(&status, " started %s", uptime);
free(uptime);
} else
- snprintf(status, sizeof(status), " started ");
+ xasprintf(&status, " started ");
color = ECOLOR_GOOD;
}
} else if (state & RC_SERVICE_SCHEDULED) {
- snprintf(status, sizeof(status), "scheduled");
+ xasprintf(&status, "scheduled");
color = ECOLOR_WARN;
} else
- snprintf(status, sizeof(status), " stopped ");
+ xasprintf(&status, " stopped ");
errno = 0;
if (c && *c && isatty(fileno(stdout)))
printf("\n");
ebracket(cols, color, status);
+ free(status);
}
static void