ttymsg.c (7111b0acefc667e94cbfbcfc422e74791a80acbd) | ttymsg.c (6a20d55a591484ce93ad7002606c9ca4dbbd7ebb) |
---|---|
1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 45 unchanged lines hidden (view full) --- 54/* 55 * Display the contents of a uio structure on a terminal. Used by wall(1), 56 * syslogd(8), and talkd(8). Forks and finishes in child if write would block, 57 * waiting up to tmout seconds. Returns pointer to error string on unexpected 58 * error; string is not newline-terminated. Various "normal" errors are 59 * ignored (exclusive-use, lack of permission, etc.). 60 */ 61char * | 1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 45 unchanged lines hidden (view full) --- 54/* 55 * Display the contents of a uio structure on a terminal. Used by wall(1), 56 * syslogd(8), and talkd(8). Forks and finishes in child if write would block, 57 * waiting up to tmout seconds. Returns pointer to error string on unexpected 58 * error; string is not newline-terminated. Various "normal" errors are 59 * ignored (exclusive-use, lack of permission, etc.). 60 */ 61char * |
62ttymsg(iov, iovcnt, line, tmout) 63 struct iovec *iov; 64 int iovcnt; 65 char *line; 66 int tmout; | 62ttymsg(struct iovec *iov, int iovcnt, const char *line, int tmout) |
67{ | 63{ |
64 struct iovec localiov[7]; 65 int cnt, fd, left, wret; |
|
68 static char device[MAXNAMLEN] = _PATH_DEV; 69 static char errbuf[1024]; | 66 static char device[MAXNAMLEN] = _PATH_DEV; 67 static char errbuf[1024]; |
70 register int cnt, fd, left, wret; 71 struct iovec localiov[7]; 72 int forked = 0; | 68 int forked; |
73 | 69 |
70 forked = 0; |
|
74 if (iovcnt > sizeof(localiov) / sizeof(localiov[0])) 75 return ("too many iov's (change code in wall/ttymsg.c)"); 76 | 71 if (iovcnt > sizeof(localiov) / sizeof(localiov[0])) 72 return ("too many iov's (change code in wall/ttymsg.c)"); 73 |
77 (void) strcpy(device + sizeof(_PATH_DEV) - 1, line); | 74 strlcat(device, line, sizeof(device)); |
78 if (strchr(device + sizeof(_PATH_DEV) - 1, '/')) { 79 /* A slash is an attempt to break security... */ | 75 if (strchr(device + sizeof(_PATH_DEV) - 1, '/')) { 76 /* A slash is an attempt to break security... */ |
80 (void) snprintf(errbuf, sizeof(errbuf), "'/' in \"%s\"", 81 device); | 77 (void) snprintf(errbuf, sizeof(errbuf), 78 "Too many '/' in \"%s\"", device); |
82 return (errbuf); 83 } 84 85 /* 86 * open will fail on slip lines or exclusive-use lines 87 * if not running as root; not an error. 88 */ 89 if ((fd = open(device, O_WRONLY|O_NONBLOCK, 0)) < 0) { 90 if (errno == EBUSY || errno == EACCES) 91 return (NULL); | 79 return (errbuf); 80 } 81 82 /* 83 * open will fail on slip lines or exclusive-use lines 84 * if not running as root; not an error. 85 */ 86 if ((fd = open(device, O_WRONLY|O_NONBLOCK, 0)) < 0) { 87 if (errno == EBUSY || errno == EACCES) 88 return (NULL); |
92 (void) snprintf(errbuf, sizeof(errbuf), 93 "%s: %s", device, strerror(errno)); | 89 (void) snprintf(errbuf, sizeof(errbuf), "%s: %s", device, 90 strerror(errno)); |
94 return (errbuf); 95 } 96 97 for (cnt = left = 0; cnt < iovcnt; ++cnt) 98 left += iov[cnt].iov_len; 99 100 for (;;) { 101 wret = writev(fd, iov, iovcnt); 102 if (wret >= left) 103 break; 104 if (wret >= 0) { 105 left -= wret; 106 if (iov != localiov) { | 91 return (errbuf); 92 } 93 94 for (cnt = left = 0; cnt < iovcnt; ++cnt) 95 left += iov[cnt].iov_len; 96 97 for (;;) { 98 wret = writev(fd, iov, iovcnt); 99 if (wret >= left) 100 break; 101 if (wret >= 0) { 102 left -= wret; 103 if (iov != localiov) { |
107 bcopy(iov, localiov, | 104 bcopy(iov, localiov, |
108 iovcnt * sizeof(struct iovec)); 109 iov = localiov; 110 } 111 for (cnt = 0; wret >= iov->iov_len; ++cnt) { 112 wret -= iov->iov_len; 113 ++iov; 114 --iovcnt; 115 } --- 52 unchanged lines hidden --- | 105 iovcnt * sizeof(struct iovec)); 106 iov = localiov; 107 } 108 for (cnt = 0; wret >= iov->iov_len; ++cnt) { 109 wret -= iov->iov_len; 110 ++iov; 111 --iovcnt; 112 } --- 52 unchanged lines hidden --- |