Index: trunk/servmon/smlogmsg.c |
— | — | @@ -14,14 +14,14 @@ |
15 | 15 | struct sockaddr_un sa; |
16 | 16 | socklen_t len; |
17 | 17 | int s; |
18 | | - char *logmsg; |
19 | | - |
| 18 | + struct iovec iovec[3]; |
| 19 | + |
20 | 20 | if (argc != 3) { |
21 | 21 | fprintf(stderr, "usage: %s <log level> <message>\n", argv[0]); |
22 | 22 | exit(8); |
23 | 23 | } |
24 | 24 | |
25 | | - memset(&sa, 0, sizeof(sa)); |
| 25 | + bzero(&sa, sizeof(sa)); |
26 | 26 | sa.sun_family = AF_UNIX; |
27 | 27 | strcpy(sa.sun_path, "/tmp/servmon.log"); |
28 | 28 | len = SUN_LEN(&sa); |
— | — | @@ -31,16 +31,28 @@ |
32 | 32 | exit(8); |
33 | 33 | } |
34 | 34 | |
35 | | - if (connect(s, (struct sockaddr *)&sa, len) < 0) { |
| 35 | + if (connect(s, (struct sockaddr *) &sa, len) < 0) { |
36 | 36 | perror("connect"); |
37 | 37 | exit(8); |
38 | 38 | } |
39 | 39 | |
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) { |
43 | 54 | perror("write"); |
44 | 55 | exit(8); |
45 | 56 | } |
| 57 | + |
46 | 58 | exit(0); |
47 | 59 | } |