few random readability enhansements. No code changes

This commit is contained in:
Denis Vlasenko 2006-09-08 17:31:55 +00:00
parent 9a9edf200b
commit bd8f43dbab
3 changed files with 10 additions and 8 deletions

View File

@ -514,8 +514,8 @@ int stty_main(int argc, char **argv)
device_name = file_name; device_name = file_name;
fclose(stdin); fclose(stdin);
xopen(device_name, O_RDONLY | O_NONBLOCK); xopen(device_name, O_RDONLY | O_NONBLOCK);
if ((fdflags = fcntl(STDIN_FILENO, F_GETFL)) == -1 fdflags = fcntl(STDIN_FILENO, F_GETFL);
|| fcntl(STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0) if (fdflags == -1 || fcntl(STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
perror_on_device("%s: couldn't reset non-blocking mode"); perror_on_device("%s: couldn't reset non-blocking mode");
} else { } else {
device_name = bb_msg_standard_input; device_name = bb_msg_standard_input;

View File

@ -20,6 +20,7 @@ int device_open(const char *device, int mode)
m = mode | O_NONBLOCK; m = mode | O_NONBLOCK;
/* Retry up to 5 times */ /* Retry up to 5 times */
/* TODO: explain why it can't be considered insane */
for (f = 0; f < 5; f++) for (f = 0; f < 5; f++)
if ((fd = open(device, m, 0600)) >= 0) if ((fd = open(device, m, 0600)) >= 0)
break; break;

View File

@ -277,9 +277,9 @@ static void message(char *fmt, ...)
} else } else
#endif #endif
if ((fd = device_open(logFilePath, fd = device_open(logFilePath, O_WRONLY | O_CREAT
O_WRONLY | O_CREAT | O_NOCTTY | O_APPEND | | O_NOCTTY | O_APPEND | O_NONBLOCK);
O_NONBLOCK)) >= 0) { if (fd >= 0) {
fl.l_type = F_WRLCK; fl.l_type = F_WRLCK;
fcntl(fd, F_SETLKW, &fl); fcntl(fd, F_SETLKW, &fl);
@ -291,7 +291,8 @@ static void message(char *fmt, ...)
&& (lseek(fd,0,SEEK_END) > logFileSize) ) { && (lseek(fd,0,SEEK_END) > logFileSize) ) {
if(logFileRotate > 0) { if(logFileRotate > 0) {
int i; int i;
char oldFile[(strlen(logFilePath)+4)], newFile[(strlen(logFilePath)+4)]; char oldFile[(strlen(logFilePath)+4)];
char newFile[(strlen(logFilePath)+4)];
for(i=logFileRotate-1;i>0;i--) { for(i=logFileRotate-1;i>0;i--) {
sprintf(oldFile, "%s.%d", logFilePath, i-1); sprintf(oldFile, "%s.%d", logFilePath, i-1);
sprintf(newFile, "%s.%d", logFilePath, i); sprintf(newFile, "%s.%d", logFilePath, i);
@ -321,8 +322,8 @@ static void message(char *fmt, ...)
close(fd); close(fd);
} else { } else {
/* Always send console messages to /dev/console so people will see them. */ /* Always send console messages to /dev/console so people will see them. */
if ((fd = device_open(_PATH_CONSOLE, fd = device_open(_PATH_CONSOLE, O_WRONLY | O_NOCTTY | O_NONBLOCK);
O_WRONLY | O_NOCTTY | O_NONBLOCK)) >= 0) { if (fd >= 0) {
va_start(arguments, fmt); va_start(arguments, fmt);
vdprintf(fd, fmt, arguments); vdprintf(fd, fmt, arguments);
va_end(arguments); va_end(arguments);