r7787 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r7786‎ | r7787 | r7788 >
Date:17:53, 20 March 2005
Author:kateturner
Status:old
Tags:
Comment:
truncate long lines; write->writev
Modified paths:
  • /trunk/servmon/smlogmsg.c (modified) (history)

Diff [purge]

Index: trunk/servmon/smlogmsg.c
@@ -14,14 +14,14 @@
1515 struct sockaddr_un sa;
1616 socklen_t len;
1717 int s;
18 - char *logmsg;
19 -
 18+ struct iovec iovec[3];
 19+
2020 if (argc != 3) {
2121 fprintf(stderr, "usage: %s <log level> <message>\n", argv[0]);
2222 exit(8);
2323 }
2424
25 - memset(&sa, 0, sizeof(sa));
 25+ bzero(&sa, sizeof(sa));
2626 sa.sun_family = AF_UNIX;
2727 strcpy(sa.sun_path, "/tmp/servmon.log");
2828 len = SUN_LEN(&sa);
@@ -31,16 +31,28 @@
3232 exit(8);
3333 }
3434
35 - if (connect(s, (struct sockaddr *)&sa, len) < 0) {
 35+ if (connect(s, (struct sockaddr *) &sa, len) < 0) {
3636 perror("connect");
3737 exit(8);
3838 }
3939
40 - logmsg = malloc(strlen(argv[1]) + strlen(argv[2]) + 2);
41 - sprintf(logmsg, "%s %s", argv[1], argv[2]);
42 - if (write(s, logmsg, strlen(logmsg)) < 0) {
 40+ /*
 41+ * servmon truncates messages longer than this.
 42+ */
 43+ if (strlen(argv[2]) > 4096)
 44+ argv[2][4096] = '\0';
 45+
 46+ iovec[0].iov_base = argv[1];
 47+ iovec[0].iov_len = strlen(argv[1]);
 48+ iovec[1].iov_base = " ";
 49+ iovec[1].iov_len = 1;
 50+ iovec[2].iov_base = argv[2];
 51+ iovec[2].iov_len = strlen(argv[2]);
 52+
 53+ if (writev(s, iovec, 3) < 0) {
4354 perror("write");
4455 exit(8);
4556 }
 57+
4658 exit(0);
4759 }

Status & tagging log