Reformatted init code to make if/while logic more clear.

Cleaned up some output from readbootlog.

Added -e flg to bootlogd. When -e is used, data saved
to the boot log file does not have escape characters
removed. This means colour and cursor movement codes
stay in the log file. The may then look nicer when
read with "less -R', but may appear cluttered or
out of alignment when viewed with other, plain-text tools.
This commit is contained in:
Jesse Smith 2019-08-11 22:10:45 -03:00
parent 362315a997
commit fa124114ae
4 changed files with 45 additions and 20 deletions

View File

@ -22,6 +22,7 @@ bootlogd \- record boot messages
.B /sbin/bootlogd
.RB [ \-c ]
.RB [ \-d ]
.RB [ \-e ]
.RB [ \-r ]
.RB [ \-s ]
.RB [ \-v ]
@ -34,6 +35,10 @@ the messages will be kept in memory until it is.
.SH OPTIONS
.IP \fB\-d\fP
Do not fork and run in the background.
.IP \fB\-e\fP
Print escape characters to the boot log file. This turns off filtering of
escape characters and allows tools like GNU Less to see and use colour control
characters (show the log in colour).
.IP \fB\-c\fP
Attempt to write to the logfile even if it does not yet exist.
Without this option,

View File

@ -340,7 +340,7 @@ dontuse:
/*
* Write data and make sure it's on disk.
*/
void writelog(FILE *fp, unsigned char *ptr, int len)
void writelog(FILE *fp, unsigned char *ptr, int len, int print_escape_characters)
{
int dosync = 0;
int i;
@ -363,7 +363,9 @@ void writelog(FILE *fp, unsigned char *ptr, int len)
/* remove escape sequences, but do it in a way that allows us to stop
* in the middle in case the string was cut off */
if (inside_esc == 1) {
if (! print_escape_characters)
{
if (inside_esc == 1) {
/* first '[' is special because if we encounter it again, it should be considered the final byte */
if (*ptr == '[') {
/* multi char sequence */
@ -376,7 +378,7 @@ void writelog(FILE *fp, unsigned char *ptr, int len)
}
inside_esc = 0;
}
} else if (inside_esc == 2) {
} else if (inside_esc == 2) {
switch (*ptr) {
case '0' ... '9': /* intermediate chars of escape sequence */
case ';':
@ -391,8 +393,8 @@ void writelog(FILE *fp, unsigned char *ptr, int len)
inside_esc = 0;
}
break;
}
} else {
}
} else {
switch (*ptr) {
case '\r':
ignore = 1;
@ -402,8 +404,8 @@ void writelog(FILE *fp, unsigned char *ptr, int len)
inside_esc = 1;
break;
}
}
}
} /* end of if we should filter escape characters */
if (!ignore) {
fwrite(ptr, sizeof(char), 1, fp);
@ -430,7 +432,7 @@ void writelog(FILE *fp, unsigned char *ptr, int len)
*/
void usage(void)
{
fprintf(stderr, "Usage: bootlogd [-v] [-r] [-d] [-s] [-c] [-p pidfile] [-l logfile]\n");
fprintf(stderr, "Usage: bootlogd [-v] [-r] [-d] [-e] [-s] [-c] [-p pidfile] [-l logfile]\n");
exit(1);
}
@ -490,14 +492,14 @@ int main(int argc, char **argv)
int considx;
struct real_cons cons[MAX_CONSOLES];
int num_consoles, consoles_left;
int print_escape_sequence = 0;
fp = NULL;
logfile = LOGFILE;
pidfile = NULL;
rotate = 0;
dontfork = 0;
while ((i = getopt(argc, argv, "cdsl:p:rv")) != EOF) switch(i) {
while ((i = getopt(argc, argv, "cdesl:p:rv")) != EOF) switch(i) {
case 'l':
logfile = optarg;
break;
@ -517,6 +519,9 @@ int main(int argc, char **argv)
case 'd':
dontfork = 1;
break;
case 'e':
print_escape_sequence = 1;
break;
case 's':
syncalot = 1;
break;
@ -678,8 +683,8 @@ int main(int argc, char **argv)
*/
if (--consoles_left <= 0) got_signal = 1;
break;
}
}
} /* end of while */
} /* end of going through all consoles */
/*
* Increment buffer position. Handle
@ -693,8 +698,8 @@ int main(int argc, char **argv)
inptr = ringbuf;
if (outptr >= endptr)
outptr = ringbuf;
}
}
} /* end of got data from read */
} /* end of checking select for new data */
/*
* Perhaps we need to open the logfile.
@ -714,8 +719,8 @@ int main(int argc, char **argv)
else
todo = endptr - outptr;
if (fp && todo)
writelog(fp, (unsigned char *)outptr, todo);
}
writelog(fp, (unsigned char *)outptr, todo, print_escape_sequence);
} /* end of while waiting for signal */
if (fp) {
if (!didnl) fputc('\n', fp);

View File

@ -2433,7 +2433,8 @@ void check_init_fifo(void)
}
/* Wait for data to appear, _if_ the pipe was opened. */
if (pipe_fd >= 0) while(!quit) {
if (pipe_fd >= 0) {
while(!quit) {
/* Do select, return on EINTR. */
FD_ZERO(&fds);
@ -2504,9 +2505,9 @@ void check_init_fifo(void)
default:
initlog(L_VB, "got unimplemented initrequest.");
break;
}
}
} /* end of switch */
} /* end of while loop not quitting */
} /* end of if the pipe is open */
/*
* We come here if the pipe couldn't be opened.
*/

View File

@ -58,6 +58,20 @@ int Clean_Line(char *source_line, char *output_line)
}
}
} /* done found character to scrub */
else if ( (a_letter == '?') && (source_line[source_index + 1] == '?') &&
(source_line[source_index + 2] == '7') )
{
source_index += 3;
output_line[target_index] = ' ';
target_index++;
}
else if ( (a_letter == '8') && (source_line[source_index + 1] == '?') &&
(source_line[source_index + 2] == '?') )
{
source_index += 3;
output_line[target_index] = ']';
target_index++;
}
else
{
output_line[target_index] = a_letter;