From: lhh@sourceware.org <lhh@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] cluster/rgmanager/src/utils clustat.c
Date: 6 Dec 2007 17:52:32 -0000 [thread overview]
Message-ID: <20071206175232.28410.qmail@sourceware.org> (raw)
CVSROOT: /cvs/cluster
Module name: cluster
Branch: RHEL5
Changes by: lhh at sourceware.org 2007-12-06 17:52:32
Modified files:
rgmanager/src/utils: clustat.c
Log message:
Fix format warnings on newer GCC
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/utils/clustat.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.25.2.7&r2=1.25.2.8
--- cluster/rgmanager/src/utils/clustat.c 2007/11/30 19:47:15 1.25.2.7
+++ cluster/rgmanager/src/utils/clustat.c 2007/12/06 17:52:32 1.25.2.8
@@ -451,10 +451,9 @@
void
_txt_rg_state(rg_state_t *rs, cluster_member_list_t *members, int flags,
- char *fmt_buf, int ns)
+ int svcsize, int nodesize, int statsize)
{
char owner[MAXHOSTNAMELEN+1];
- char owner_fmt[16];
char *name = rs->rs_name, *ptr;
int l;
@@ -469,27 +468,24 @@
}
memset(owner, 0, sizeof(owner));
- memset(owner_fmt, 0, sizeof(owner_fmt));
if (rs->rs_state == RG_STATE_STOPPED ||
rs->rs_state == RG_STATE_DISABLED ||
rs->rs_state == RG_STATE_ERROR ||
rs->rs_state == RG_STATE_FAILED) {
- snprintf(owner_fmt, sizeof(owner_fmt)-1, "(%%-.%ds)", ns-2);
- snprintf(owner, sizeof(owner)-1, owner_fmt,
+ snprintf(owner, sizeof(owner)-1, "(%-.*s)", nodesize-2,
my_memb_id_to_name(members, rs->rs_last_owner));
} else {
- snprintf(owner_fmt, sizeof(owner_fmt)-1, "%%-.%ds", ns);
- snprintf(owner, sizeof(owner)-1, owner_fmt,
+ snprintf(owner, sizeof(owner)-1, "%-.*s", nodesize,
my_memb_id_to_name(members, rs->rs_owner));
}
- printf(fmt_buf,
- name,
- owner,
- rg_state_str(rs->rs_state));
+ printf(" %-*.*s %-*.*s %-*.*s\n",
+ svcsize, svcsize, rs->rs_name,
+ nodesize, nodesize, owner,
+ statsize, statsize, rg_state_str(rs->rs_state));
}
@@ -509,12 +505,13 @@
void
-txt_rg_state(rg_state_t *rs, cluster_member_list_t *members, int flags, char *fmt_buf, int ns)
+txt_rg_state(rg_state_t *rs, cluster_member_list_t *members, int flags, int svcsize,
+ int nodesize, int statsize)
{
if (flags & RG_VERBOSE)
_txt_rg_state_v(rs, members, flags);
else
- _txt_rg_state(rs, members, flags, fmt_buf, ns);
+ _txt_rg_state(rs, members, flags, svcsize, nodesize, statsize);
}
@@ -548,27 +545,20 @@
void
-build_service_format(char *buf, int buflen, int cols, int *ns)
+build_service_field_sizes(int cols, int *svcsize, int *nodesize, int *statsize)
{
/* Based on 80 columns */
- int svcsize = 30;
- int nodesize = 30;
- int statsize = 14; /* uninitialized */
+ *svcsize = 30;
+ *nodesize = 30;
+ *statsize = 14; /* uninitialized */
int pad = 6; /* Spaces and such; newline */
- svcsize = (cols - (statsize + pad)) / 2;
- nodesize = (cols - (statsize + pad)) / 2;
- if (svcsize > MAXHOSTNAMELEN)
- svcsize = MAXHOSTNAMELEN;
- if (nodesize > MAXHOSTNAMELEN)
- nodesize = MAXHOSTNAMELEN;
-
- memset(buf, 0, buflen);
- snprintf(buf, buflen-1, " %%-%d.%ds %%-%d.%ds %%-%d.%ds\n",
- svcsize, svcsize, nodesize, nodesize, statsize,
- statsize);
-
- *ns = nodesize;
+ *svcsize = (cols - (*statsize + pad)) / 2;
+ *nodesize = (cols - (*statsize + pad)) / 2;
+ if (*svcsize > MAXHOSTNAMELEN)
+ *svcsize = MAXHOSTNAMELEN;
+ if (*nodesize > MAXHOSTNAMELEN)
+ *nodesize = MAXHOSTNAMELEN;
}
@@ -576,8 +566,7 @@
txt_rg_states(rg_state_list_t *rgl, cluster_member_list_t *members,
char *svcname, int flags)
{
- int x, ret = 0, ns;
- char fmt_buf[80];
+ int x, ret = 0, svcsize, nodesize, statsize;
if (!rgl || !members)
return -1;
@@ -585,14 +574,18 @@
if (svcname)
ret = -1;
- build_service_format(fmt_buf, sizeof(fmt_buf), dimx, &ns);
+ build_service_field_sizes(dimx, &svcsize, &nodesize, &statsize);
if (!(flags & RG_VERBOSE)) {
- printf(fmt_buf,
- "Service Name", "Owner (Last)", "State");
- printf(fmt_buf,
- "------- ----", "----- ------", "-----");
+ printf(" %-*.*s %-*.*s %-*.*s\n",
+ svcsize, svcsize, "Service Name",
+ nodesize, nodesize, "Owner (Last)",
+ statsize, statsize, "State");
+ printf(" %-*.*s %-*.*s %-*.*s\n",
+ svcsize, svcsize, "------- ----",
+ nodesize, nodesize, "----- ------",
+ statsize, statsize, "-----");
} else {
printf("Service Information\n"
"------- -----------\n\n");
@@ -602,7 +595,8 @@
if (svcname &&
strcmp(rgl->rgl_states[x].rs_name, svcname))
continue;
- txt_rg_state(&rgl->rgl_states[x], members, flags, fmt_buf, ns);
+ txt_rg_state(&rgl->rgl_states[x], members, flags,
+ svcsize, nodesize, statsize);
if (svcname) {
switch (rgl->rgl_states[x].rs_state) {
case RG_STATE_STARTING:
@@ -706,25 +700,21 @@
}
void
-build_member_format(char *buf, int buflen, int cols)
+build_member_field_size(int cols, int *nodesize)
{
/* Based on 80 columns */
- int nodesize = 40;
-
- nodesize = (cols / 2);
- if (nodesize > MAXHOSTNAMELEN)
- nodesize = MAXHOSTNAMELEN;
+ *nodesize = 40;
- memset(buf, 0, buflen);
- snprintf(buf, buflen-1, " %%-%d.%ds ",
- nodesize, nodesize);
+ *nodesize = (cols / 2);
+ if (*nodesize > MAXHOSTNAMELEN)
+ *nodesize = MAXHOSTNAMELEN;
}
void
-txt_member_state(cman_node_t *node, char *fmt_buf)
+txt_member_state(cman_node_t *node, int nodesize)
{
- printf(fmt_buf, node->cn_name);
+ printf(" %-*.*s ", nodesize, nodesize, node->cn_name);
printf("%4d ", node->cn_nodeid);
if (node->cn_member & FLAG_UP)
@@ -776,25 +766,24 @@
int
txt_member_states(cluster_member_list_t *membership, char *name)
{
- char buf[80];
- int x, ret = 0;
+ int x, ret = 0, nodesize;
if (!membership) {
printf("Membership information not available\n");
return -1;
}
- build_member_format(buf, sizeof(buf), dimx);
+ build_member_field_size(dimx, &nodesize);
- printf(buf, "Member Name");
+ printf(" %-*.*s", nodesize, nodesize, "Member Name");
printf("%-4.4s %s\n", "ID", "Status");
- printf(buf, "------ ----");
+ printf(" %-*.*s", nodesize, nodesize, "------ ----");
printf("%-4.4s %s\n", "----", "------");
for (x = 0; x < membership->cml_count; x++) {
if (name && strcmp(membership->cml_members[x].cn_name, name))
continue;
- txt_member_state(&membership->cml_members[x], buf);
+ txt_member_state(&membership->cml_members[x], nodesize);
ret = !(membership->cml_members[x].cn_member & FLAG_UP);
}
@@ -1072,8 +1061,12 @@
ret = !(cman_is_quorate(ch));
goto cleanup;
case VERSION_ONLY:
+#ifdef RELEASE_VERSION
printf("%s version %s\n", basename(argv[0]),
- PACKAGE_VERSION);
+ RELEASE_VERSION);
+#else
+ printf("%s version DEVEL\n", basename(argv[0]));
+#endif
if (!ch)
break;
goto cleanup;
next reply other threads:[~2007-12-06 17:52 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-06 17:52 lhh [this message]
-- strict thread matches above, loose matches on Subject: below --
2007-12-10 18:24 [Cluster-devel] cluster/rgmanager/src/utils clustat.c lhh
2007-12-10 18:11 lhh
2007-12-06 17:47 lhh
2007-11-30 19:47 lhh
2007-09-19 10:56 pcaulfield
2007-02-06 20:22 lhh
2007-02-06 20:21 lhh
2007-02-06 20:20 lhh
2007-02-06 20:18 lhh
2007-02-06 19:54 lhh
2007-01-29 19:42 lhh
2007-01-29 19:41 lhh
2007-01-29 19:40 lhh
2007-01-29 19:40 lhh
2007-01-26 21:38 lhh
2007-01-17 16:21 lhh
2007-01-17 16:20 lhh
2007-01-17 16:19 lhh
2006-12-13 18:36 lhh
2006-12-13 17:12 lhh
2006-10-12 22:07 lhh
2006-09-27 16:43 lhh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071206175232.28410.qmail@sourceware.org \
--to=lhh@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.