init and ls -l fixes

This commit is contained in:
Eric Andersen 1999-11-07 07:38:08 +00:00
parent dc6301e7ca
commit 07e5297ca7
5 changed files with 110 additions and 46 deletions

View File

@ -1,3 +1,11 @@
0.34
* ls -l now displays lnik names outside the current directory,
Patch thanks to Eric Delaunay
* init now properly handles sparc serial consoles and does a
better job of finding the real consol device rather than using
/dev/console which doesn't support job control. Patch also
thanks to Eric Delaunay.
0.33 0.33
* Fixed a bug where init could hang instead of rebooting. * Fixed a bug where init could hang instead of rebooting.
* Removed some debugging noise from init.c * Removed some debugging noise from init.c

View File

@ -206,7 +206,7 @@ static char append_char(mode_t mode)
** **
**/ **/
static void list_single(const char *name, struct stat *info) static void list_single(const char *name, struct stat *info, const char *fullname)
{ {
char scratch[PATH_MAX]; char scratch[PATH_MAX];
short len = strlen(name); short len = strlen(name);
@ -297,12 +297,12 @@ static void list_single(const char *name, struct stat *info)
wr(name, len); wr(name, len);
if (S_ISLNK(mode)) { if (S_ISLNK(mode)) {
wr(" -> ", 4); wr(" -> ", 4);
len = readlink(name, scratch, sizeof scratch); len = readlink(fullname, scratch, sizeof scratch);
if (len > 0) fwrite(scratch, 1, len, stdout); if (len > 0) fwrite(scratch, 1, len, stdout);
#ifdef FEATURE_FILETYPECHAR #ifdef FEATURE_FILETYPECHAR
/* show type of destination */ /* show type of destination */
if (opts & DISP_FTYPE) { if (opts & DISP_FTYPE) {
if (!stat(name, info)) { if (!stat(fullname, info)) {
append = append_char(info->st_mode); append = append_char(info->st_mode);
if (append) if (append)
fputc(append, stdout); fputc(append, stdout);
@ -372,7 +372,7 @@ static int list_item(const char *name)
if (!S_ISDIR(info.st_mode) || if (!S_ISDIR(info.st_mode) ||
(opts & DIR_NOLIST)) { (opts & DIR_NOLIST)) {
list_single(name, &info); list_single(name, &info, name);
return 0; return 0;
} }
@ -424,7 +424,7 @@ static int list_item(const char *name)
strcpy(fnend, entry->d_name); strcpy(fnend, entry->d_name);
if (lstat(fullname, &info)) if (lstat(fullname, &info))
goto direrr; /* (shouldn't fail) */ goto direrr; /* (shouldn't fail) */
list_single(entry->d_name, &info); list_single(entry->d_name, &info, fullname);
} }
closedir(dir); closedir(dir);
return 0; return 0;

64
init.c
View File

@ -88,8 +88,14 @@ void message(int device, char *fmt, ...)
/* Take full control of the log tty, and never close it. /* Take full control of the log tty, and never close it.
* It's mine, all mine! Muhahahaha! */ * It's mine, all mine! Muhahahaha! */
if (log_fd==-1) { if (log_fd < 0) {
if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) { if (log == NULL) {
/* don't even try to log, because there is no such console */
log_fd = -2;
/* log to main console instead */
device = CONSOLE;
}
else if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
log_fd=-1; log_fd=-1;
fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log); fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log);
fflush(stderr); fflush(stderr);
@ -97,7 +103,7 @@ void message(int device, char *fmt, ...)
} }
} }
if ( (device & LOG) && (log_fd != -1) ) { if ( (device & LOG) && (log_fd >= 0) ) {
va_start(arguments, fmt); va_start(arguments, fmt);
vdprintf(log_fd, fmt, arguments); vdprintf(log_fd, fmt, arguments);
va_end(arguments); va_end(arguments);
@ -180,25 +186,40 @@ static void console_init()
int fd; int fd;
int tried_devcons = 0; int tried_devcons = 0;
int tried_vtprimary = 0; int tried_vtprimary = 0;
struct serial_struct sr;
char *s; char *s;
if ((s = getenv("CONSOLE")) != NULL) { if ((s = getenv("CONSOLE")) != NULL) {
console = s; console = s;
/* Apparently the sparc does wierd things... */ }
#if defined (__sparc__) #if defined (__sparc__)
if (strncmp( s, "/dev/tty", 8 )==0) { /* sparc kernel supports console=tty[ab] parameter which is also
switch( s[8]) { * passed to init, so catch it here */
case 'a': else if ((s = getenv("console")) != NULL) {
s=SERIAL_CON0; /* remap tty[ab] to /dev/ttyS[01] */
break; if (strcmp( s, "ttya" )==0)
case 'b': console = SERIAL_CON0;
s=SERIAL_CON1; else if (strcmp( s, "ttyb" )==0)
} console = SERIAL_CON1;
} }
#endif #endif
} else { else {
console = VT_CONSOLE; struct vt_stat vt;
tried_devcons++; static char the_console[13];
console = the_console;
/* 2.2 kernels: identify the real console backend and try to use it */
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
/* this is a serial console */
snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line );
}
else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
/* this is linux virtual tty */
snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
} else {
console = VT_CONSOLE;
tried_devcons++;
}
} }
while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) { while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) {
@ -219,8 +240,15 @@ static void console_init()
if (fd < 0) if (fd < 0)
/* Perhaps we should panic here? */ /* Perhaps we should panic here? */
console = "/dev/null"; console = "/dev/null";
else else {
/* check for serial console and disable logging to tty3 & running a
* shell to tty2 */
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
log = NULL;
second_console = NULL;
}
close(fd); close(fd);
}
message(LOG, "console=%s\n", console ); message(LOG, "console=%s\n", console );
} }
@ -472,7 +500,7 @@ extern int init_main(int argc, char **argv)
if (pid1 == 0 && tty0_commands) { if (pid1 == 0 && tty0_commands) {
pid1 = run(tty0_commands, console, wait_for_enter); pid1 = run(tty0_commands, console, wait_for_enter);
} }
if (pid2 == 0 && tty1_commands) { if (pid2 == 0 && tty1_commands && second_console) {
pid2 = run(tty1_commands, second_console, TRUE); pid2 = run(tty1_commands, second_console, TRUE);
} }
wpid = wait(&status); wpid = wait(&status);

View File

@ -88,8 +88,14 @@ void message(int device, char *fmt, ...)
/* Take full control of the log tty, and never close it. /* Take full control of the log tty, and never close it.
* It's mine, all mine! Muhahahaha! */ * It's mine, all mine! Muhahahaha! */
if (log_fd==-1) { if (log_fd < 0) {
if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) { if (log == NULL) {
/* don't even try to log, because there is no such console */
log_fd = -2;
/* log to main console instead */
device = CONSOLE;
}
else if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
log_fd=-1; log_fd=-1;
fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log); fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log);
fflush(stderr); fflush(stderr);
@ -97,7 +103,7 @@ void message(int device, char *fmt, ...)
} }
} }
if ( (device & LOG) && (log_fd != -1) ) { if ( (device & LOG) && (log_fd >= 0) ) {
va_start(arguments, fmt); va_start(arguments, fmt);
vdprintf(log_fd, fmt, arguments); vdprintf(log_fd, fmt, arguments);
va_end(arguments); va_end(arguments);
@ -180,25 +186,40 @@ static void console_init()
int fd; int fd;
int tried_devcons = 0; int tried_devcons = 0;
int tried_vtprimary = 0; int tried_vtprimary = 0;
struct serial_struct sr;
char *s; char *s;
if ((s = getenv("CONSOLE")) != NULL) { if ((s = getenv("CONSOLE")) != NULL) {
console = s; console = s;
/* Apparently the sparc does wierd things... */ }
#if defined (__sparc__) #if defined (__sparc__)
if (strncmp( s, "/dev/tty", 8 )==0) { /* sparc kernel supports console=tty[ab] parameter which is also
switch( s[8]) { * passed to init, so catch it here */
case 'a': else if ((s = getenv("console")) != NULL) {
s=SERIAL_CON0; /* remap tty[ab] to /dev/ttyS[01] */
break; if (strcmp( s, "ttya" )==0)
case 'b': console = SERIAL_CON0;
s=SERIAL_CON1; else if (strcmp( s, "ttyb" )==0)
} console = SERIAL_CON1;
} }
#endif #endif
} else { else {
console = VT_CONSOLE; struct vt_stat vt;
tried_devcons++; static char the_console[13];
console = the_console;
/* 2.2 kernels: identify the real console backend and try to use it */
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
/* this is a serial console */
snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line );
}
else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
/* this is linux virtual tty */
snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
} else {
console = VT_CONSOLE;
tried_devcons++;
}
} }
while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) { while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) {
@ -219,8 +240,15 @@ static void console_init()
if (fd < 0) if (fd < 0)
/* Perhaps we should panic here? */ /* Perhaps we should panic here? */
console = "/dev/null"; console = "/dev/null";
else else {
/* check for serial console and disable logging to tty3 & running a
* shell to tty2 */
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
log = NULL;
second_console = NULL;
}
close(fd); close(fd);
}
message(LOG, "console=%s\n", console ); message(LOG, "console=%s\n", console );
} }
@ -472,7 +500,7 @@ extern int init_main(int argc, char **argv)
if (pid1 == 0 && tty0_commands) { if (pid1 == 0 && tty0_commands) {
pid1 = run(tty0_commands, console, wait_for_enter); pid1 = run(tty0_commands, console, wait_for_enter);
} }
if (pid2 == 0 && tty1_commands) { if (pid2 == 0 && tty1_commands && second_console) {
pid2 = run(tty1_commands, second_console, TRUE); pid2 = run(tty1_commands, second_console, TRUE);
} }
wpid = wait(&status); wpid = wait(&status);

10
ls.c
View File

@ -206,7 +206,7 @@ static char append_char(mode_t mode)
** **
**/ **/
static void list_single(const char *name, struct stat *info) static void list_single(const char *name, struct stat *info, const char *fullname)
{ {
char scratch[PATH_MAX]; char scratch[PATH_MAX];
short len = strlen(name); short len = strlen(name);
@ -297,12 +297,12 @@ static void list_single(const char *name, struct stat *info)
wr(name, len); wr(name, len);
if (S_ISLNK(mode)) { if (S_ISLNK(mode)) {
wr(" -> ", 4); wr(" -> ", 4);
len = readlink(name, scratch, sizeof scratch); len = readlink(fullname, scratch, sizeof scratch);
if (len > 0) fwrite(scratch, 1, len, stdout); if (len > 0) fwrite(scratch, 1, len, stdout);
#ifdef FEATURE_FILETYPECHAR #ifdef FEATURE_FILETYPECHAR
/* show type of destination */ /* show type of destination */
if (opts & DISP_FTYPE) { if (opts & DISP_FTYPE) {
if (!stat(name, info)) { if (!stat(fullname, info)) {
append = append_char(info->st_mode); append = append_char(info->st_mode);
if (append) if (append)
fputc(append, stdout); fputc(append, stdout);
@ -372,7 +372,7 @@ static int list_item(const char *name)
if (!S_ISDIR(info.st_mode) || if (!S_ISDIR(info.st_mode) ||
(opts & DIR_NOLIST)) { (opts & DIR_NOLIST)) {
list_single(name, &info); list_single(name, &info, name);
return 0; return 0;
} }
@ -424,7 +424,7 @@ static int list_item(const char *name)
strcpy(fnend, entry->d_name); strcpy(fnend, entry->d_name);
if (lstat(fullname, &info)) if (lstat(fullname, &info))
goto direrr; /* (shouldn't fail) */ goto direrr; /* (shouldn't fail) */
list_single(entry->d_name, &info); list_single(entry->d_name, &info, fullname);
} }
closedir(dir); closedir(dir);
return 0; return 0;