소스 검색

[PATCH] Fix getdelays.c - cpumask length and error reporting

Fix the length passed while (un)registering cpumask.  We were passing sizeof
the array, make it strlen().

Error value printed in fatal errors should be derived from the message.  The
message contains an nlmsgerr embedded with an error value.  We must report
that value to the user.

Signed-off-by: Balbir Singh <balbir@in.ibm.com>
Cc: Jamal Hadi <hadi@cyberus.ca>
Cc: Shailabh Nagar <nagar@watson.ibm.com>
Cc: Thomas Graf <tgraf@suug.ch>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jay Lan <jlan@engr.sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Balbir Singh 18 년 전
부모
커밋
7d1bdca9b0
1개의 변경된 파일4개의 추가작업 그리고 3개의 파일을 삭제
  1. 4 3
      Documentation/accounting/getdelays.c

+ 4 - 3
Documentation/accounting/getdelays.c

@@ -285,7 +285,7 @@ int main(int argc, char *argv[])
 	if (maskset) {
 	if (maskset) {
 		rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
 		rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
 			      TASKSTATS_CMD_ATTR_REGISTER_CPUMASK,
 			      TASKSTATS_CMD_ATTR_REGISTER_CPUMASK,
-			      &cpumask, sizeof(cpumask));
+			      &cpumask, strlen(cpumask) + 1);
 		PRINTF("Sent register cpumask, retval %d\n", rc);
 		PRINTF("Sent register cpumask, retval %d\n", rc);
 		if (rc < 0) {
 		if (rc < 0) {
 			printf("error sending register cpumask\n");
 			printf("error sending register cpumask\n");
@@ -315,7 +315,8 @@ int main(int argc, char *argv[])
 		}
 		}
 		if (msg.n.nlmsg_type == NLMSG_ERROR ||
 		if (msg.n.nlmsg_type == NLMSG_ERROR ||
 		    !NLMSG_OK((&msg.n), rep_len)) {
 		    !NLMSG_OK((&msg.n), rep_len)) {
-			printf("fatal reply error,  errno %d\n", errno);
+			struct nlmsgerr *err = NLMSG_DATA(&msg);
+			printf("fatal reply error,  errno %d\n", err->error);
 			goto done;
 			goto done;
 		}
 		}
 
 
@@ -383,7 +384,7 @@ done:
 	if (maskset) {
 	if (maskset) {
 		rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
 		rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
 			      TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK,
 			      TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK,
-			      &cpumask, sizeof(cpumask));
+			      &cpumask, strlen(cpumask) + 1);
 		printf("Sent deregister mask, retval %d\n", rc);
 		printf("Sent deregister mask, retval %d\n", rc);
 		if (rc < 0)
 		if (rc < 0)
 			err(rc, "error sending deregister cpumask\n");
 			err(rc, "error sending deregister cpumask\n");