summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-11-07 07:38:08 +0000
committerEric Andersen <andersen@codepoet.org>1999-11-07 07:38:08 +0000
commit07e5297ca7707d2fd56ab2fa8e1ea0c9805035e3 (patch)
tree67473f996e985a255afbb8d20cb1583fe09f0b14
parentdc6301e7ca26457e413f1dfc88fca4d19e775970 (diff)
downloadbusybox-w32-07e5297ca7707d2fd56ab2fa8e1ea0c9805035e3.tar.gz
busybox-w32-07e5297ca7707d2fd56ab2fa8e1ea0c9805035e3.tar.bz2
busybox-w32-07e5297ca7707d2fd56ab2fa8e1ea0c9805035e3.zip
init and ls -l fixes
-rw-r--r--Changelog8
-rw-r--r--coreutils/ls.c10
-rw-r--r--init.c64
-rw-r--r--init/init.c64
-rw-r--r--ls.c10
5 files changed, 110 insertions, 46 deletions
diff --git a/Changelog b/Changelog
index 5957414d1..1dd93c3c7 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,11 @@
10.34
2 * ls -l now displays lnik names outside the current directory,
3 Patch thanks to Eric Delaunay
4 * init now properly handles sparc serial consoles and does a
5 better job of finding the real consol device rather than using
6 /dev/console which doesn't support job control. Patch also
7 thanks to Eric Delaunay.
8
10.33 90.33
2 * Fixed a bug where init could hang instead of rebooting. 10 * Fixed a bug where init could hang instead of rebooting.
3 * Removed some debugging noise from init.c 11 * Removed some debugging noise from init.c
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 0cde1960f..4eb486f87 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -206,7 +206,7 @@ static char append_char(mode_t mode)
206 ** 206 **
207 **/ 207 **/
208 208
209static void list_single(const char *name, struct stat *info) 209static void list_single(const char *name, struct stat *info, const char *fullname)
210{ 210{
211 char scratch[PATH_MAX]; 211 char scratch[PATH_MAX];
212 short len = strlen(name); 212 short len = strlen(name);
@@ -297,12 +297,12 @@ static void list_single(const char *name, struct stat *info)
297 wr(name, len); 297 wr(name, len);
298 if (S_ISLNK(mode)) { 298 if (S_ISLNK(mode)) {
299 wr(" -> ", 4); 299 wr(" -> ", 4);
300 len = readlink(name, scratch, sizeof scratch); 300 len = readlink(fullname, scratch, sizeof scratch);
301 if (len > 0) fwrite(scratch, 1, len, stdout); 301 if (len > 0) fwrite(scratch, 1, len, stdout);
302#ifdef FEATURE_FILETYPECHAR 302#ifdef FEATURE_FILETYPECHAR
303 /* show type of destination */ 303 /* show type of destination */
304 if (opts & DISP_FTYPE) { 304 if (opts & DISP_FTYPE) {
305 if (!stat(name, info)) { 305 if (!stat(fullname, info)) {
306 append = append_char(info->st_mode); 306 append = append_char(info->st_mode);
307 if (append) 307 if (append)
308 fputc(append, stdout); 308 fputc(append, stdout);
@@ -372,7 +372,7 @@ static int list_item(const char *name)
372 372
373 if (!S_ISDIR(info.st_mode) || 373 if (!S_ISDIR(info.st_mode) ||
374 (opts & DIR_NOLIST)) { 374 (opts & DIR_NOLIST)) {
375 list_single(name, &info); 375 list_single(name, &info, name);
376 return 0; 376 return 0;
377 } 377 }
378 378
@@ -424,7 +424,7 @@ static int list_item(const char *name)
424 strcpy(fnend, entry->d_name); 424 strcpy(fnend, entry->d_name);
425 if (lstat(fullname, &info)) 425 if (lstat(fullname, &info))
426 goto direrr; /* (shouldn't fail) */ 426 goto direrr; /* (shouldn't fail) */
427 list_single(entry->d_name, &info); 427 list_single(entry->d_name, &info, fullname);
428 } 428 }
429 closedir(dir); 429 closedir(dir);
430 return 0; 430 return 0;
diff --git a/init.c b/init.c
index bf97fe5d6..707b1916f 100644
--- a/init.c
+++ b/init.c
@@ -88,8 +88,14 @@ void message(int device, char *fmt, ...)
88 88
89 /* Take full control of the log tty, and never close it. 89 /* Take full control of the log tty, and never close it.
90 * It's mine, all mine! Muhahahaha! */ 90 * It's mine, all mine! Muhahahaha! */
91 if (log_fd==-1) { 91 if (log_fd < 0) {
92 if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) { 92 if (log == NULL) {
93 /* don't even try to log, because there is no such console */
94 log_fd = -2;
95 /* log to main console instead */
96 device = CONSOLE;
97 }
98 else if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
93 log_fd=-1; 99 log_fd=-1;
94 fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log); 100 fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log);
95 fflush(stderr); 101 fflush(stderr);
@@ -97,7 +103,7 @@ void message(int device, char *fmt, ...)
97 } 103 }
98 } 104 }
99 105
100 if ( (device & LOG) && (log_fd != -1) ) { 106 if ( (device & LOG) && (log_fd >= 0) ) {
101 va_start(arguments, fmt); 107 va_start(arguments, fmt);
102 vdprintf(log_fd, fmt, arguments); 108 vdprintf(log_fd, fmt, arguments);
103 va_end(arguments); 109 va_end(arguments);
@@ -180,25 +186,40 @@ static void console_init()
180 int fd; 186 int fd;
181 int tried_devcons = 0; 187 int tried_devcons = 0;
182 int tried_vtprimary = 0; 188 int tried_vtprimary = 0;
189 struct serial_struct sr;
183 char *s; 190 char *s;
184 191
185 if ((s = getenv("CONSOLE")) != NULL) { 192 if ((s = getenv("CONSOLE")) != NULL) {
186 console = s; 193 console = s;
187/* Apparently the sparc does wierd things... */ 194 }
188#if defined (__sparc__) 195#if defined (__sparc__)
189 if (strncmp( s, "/dev/tty", 8 )==0) { 196 /* sparc kernel supports console=tty[ab] parameter which is also
190 switch( s[8]) { 197 * passed to init, so catch it here */
191 case 'a': 198 else if ((s = getenv("console")) != NULL) {
192 s=SERIAL_CON0; 199 /* remap tty[ab] to /dev/ttyS[01] */
193 break; 200 if (strcmp( s, "ttya" )==0)
194 case 'b': 201 console = SERIAL_CON0;
195 s=SERIAL_CON1; 202 else if (strcmp( s, "ttyb" )==0)
196 } 203 console = SERIAL_CON1;
197 } 204 }
198#endif 205#endif
199 } else { 206 else {
200 console = VT_CONSOLE; 207 struct vt_stat vt;
201 tried_devcons++; 208 static char the_console[13];
209
210 console = the_console;
211 /* 2.2 kernels: identify the real console backend and try to use it */
212 if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
213 /* this is a serial console */
214 snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line );
215 }
216 else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
217 /* this is linux virtual tty */
218 snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
219 } else {
220 console = VT_CONSOLE;
221 tried_devcons++;
222 }
202 } 223 }
203 224
204 while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) { 225 while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) {
@@ -219,8 +240,15 @@ static void console_init()
219 if (fd < 0) 240 if (fd < 0)
220 /* Perhaps we should panic here? */ 241 /* Perhaps we should panic here? */
221 console = "/dev/null"; 242 console = "/dev/null";
222 else 243 else {
244 /* check for serial console and disable logging to tty3 & running a
245 * shell to tty2 */
246 if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
247 log = NULL;
248 second_console = NULL;
249 }
223 close(fd); 250 close(fd);
251 }
224 message(LOG, "console=%s\n", console ); 252 message(LOG, "console=%s\n", console );
225} 253}
226 254
@@ -472,7 +500,7 @@ extern int init_main(int argc, char **argv)
472 if (pid1 == 0 && tty0_commands) { 500 if (pid1 == 0 && tty0_commands) {
473 pid1 = run(tty0_commands, console, wait_for_enter); 501 pid1 = run(tty0_commands, console, wait_for_enter);
474 } 502 }
475 if (pid2 == 0 && tty1_commands) { 503 if (pid2 == 0 && tty1_commands && second_console) {
476 pid2 = run(tty1_commands, second_console, TRUE); 504 pid2 = run(tty1_commands, second_console, TRUE);
477 } 505 }
478 wpid = wait(&status); 506 wpid = wait(&status);
diff --git a/init/init.c b/init/init.c
index bf97fe5d6..707b1916f 100644
--- a/init/init.c
+++ b/init/init.c
@@ -88,8 +88,14 @@ void message(int device, char *fmt, ...)
88 88
89 /* Take full control of the log tty, and never close it. 89 /* Take full control of the log tty, and never close it.
90 * It's mine, all mine! Muhahahaha! */ 90 * It's mine, all mine! Muhahahaha! */
91 if (log_fd==-1) { 91 if (log_fd < 0) {
92 if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) { 92 if (log == NULL) {
93 /* don't even try to log, because there is no such console */
94 log_fd = -2;
95 /* log to main console instead */
96 device = CONSOLE;
97 }
98 else if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
93 log_fd=-1; 99 log_fd=-1;
94 fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log); 100 fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log);
95 fflush(stderr); 101 fflush(stderr);
@@ -97,7 +103,7 @@ void message(int device, char *fmt, ...)
97 } 103 }
98 } 104 }
99 105
100 if ( (device & LOG) && (log_fd != -1) ) { 106 if ( (device & LOG) && (log_fd >= 0) ) {
101 va_start(arguments, fmt); 107 va_start(arguments, fmt);
102 vdprintf(log_fd, fmt, arguments); 108 vdprintf(log_fd, fmt, arguments);
103 va_end(arguments); 109 va_end(arguments);
@@ -180,25 +186,40 @@ static void console_init()
180 int fd; 186 int fd;
181 int tried_devcons = 0; 187 int tried_devcons = 0;
182 int tried_vtprimary = 0; 188 int tried_vtprimary = 0;
189 struct serial_struct sr;
183 char *s; 190 char *s;
184 191
185 if ((s = getenv("CONSOLE")) != NULL) { 192 if ((s = getenv("CONSOLE")) != NULL) {
186 console = s; 193 console = s;
187/* Apparently the sparc does wierd things... */ 194 }
188#if defined (__sparc__) 195#if defined (__sparc__)
189 if (strncmp( s, "/dev/tty", 8 )==0) { 196 /* sparc kernel supports console=tty[ab] parameter which is also
190 switch( s[8]) { 197 * passed to init, so catch it here */
191 case 'a': 198 else if ((s = getenv("console")) != NULL) {
192 s=SERIAL_CON0; 199 /* remap tty[ab] to /dev/ttyS[01] */
193 break; 200 if (strcmp( s, "ttya" )==0)
194 case 'b': 201 console = SERIAL_CON0;
195 s=SERIAL_CON1; 202 else if (strcmp( s, "ttyb" )==0)
196 } 203 console = SERIAL_CON1;
197 } 204 }
198#endif 205#endif
199 } else { 206 else {
200 console = VT_CONSOLE; 207 struct vt_stat vt;
201 tried_devcons++; 208 static char the_console[13];
209
210 console = the_console;
211 /* 2.2 kernels: identify the real console backend and try to use it */
212 if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
213 /* this is a serial console */
214 snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line );
215 }
216 else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
217 /* this is linux virtual tty */
218 snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
219 } else {
220 console = VT_CONSOLE;
221 tried_devcons++;
222 }
202 } 223 }
203 224
204 while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) { 225 while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) {
@@ -219,8 +240,15 @@ static void console_init()
219 if (fd < 0) 240 if (fd < 0)
220 /* Perhaps we should panic here? */ 241 /* Perhaps we should panic here? */
221 console = "/dev/null"; 242 console = "/dev/null";
222 else 243 else {
244 /* check for serial console and disable logging to tty3 & running a
245 * shell to tty2 */
246 if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
247 log = NULL;
248 second_console = NULL;
249 }
223 close(fd); 250 close(fd);
251 }
224 message(LOG, "console=%s\n", console ); 252 message(LOG, "console=%s\n", console );
225} 253}
226 254
@@ -472,7 +500,7 @@ extern int init_main(int argc, char **argv)
472 if (pid1 == 0 && tty0_commands) { 500 if (pid1 == 0 && tty0_commands) {
473 pid1 = run(tty0_commands, console, wait_for_enter); 501 pid1 = run(tty0_commands, console, wait_for_enter);
474 } 502 }
475 if (pid2 == 0 && tty1_commands) { 503 if (pid2 == 0 && tty1_commands && second_console) {
476 pid2 = run(tty1_commands, second_console, TRUE); 504 pid2 = run(tty1_commands, second_console, TRUE);
477 } 505 }
478 wpid = wait(&status); 506 wpid = wait(&status);
diff --git a/ls.c b/ls.c
index 0cde1960f..4eb486f87 100644
--- a/ls.c
+++ b/ls.c
@@ -206,7 +206,7 @@ static char append_char(mode_t mode)
206 ** 206 **
207 **/ 207 **/
208 208
209static void list_single(const char *name, struct stat *info) 209static void list_single(const char *name, struct stat *info, const char *fullname)
210{ 210{
211 char scratch[PATH_MAX]; 211 char scratch[PATH_MAX];
212 short len = strlen(name); 212 short len = strlen(name);
@@ -297,12 +297,12 @@ static void list_single(const char *name, struct stat *info)
297 wr(name, len); 297 wr(name, len);
298 if (S_ISLNK(mode)) { 298 if (S_ISLNK(mode)) {
299 wr(" -> ", 4); 299 wr(" -> ", 4);
300 len = readlink(name, scratch, sizeof scratch); 300 len = readlink(fullname, scratch, sizeof scratch);
301 if (len > 0) fwrite(scratch, 1, len, stdout); 301 if (len > 0) fwrite(scratch, 1, len, stdout);
302#ifdef FEATURE_FILETYPECHAR 302#ifdef FEATURE_FILETYPECHAR
303 /* show type of destination */ 303 /* show type of destination */
304 if (opts & DISP_FTYPE) { 304 if (opts & DISP_FTYPE) {
305 if (!stat(name, info)) { 305 if (!stat(fullname, info)) {
306 append = append_char(info->st_mode); 306 append = append_char(info->st_mode);
307 if (append) 307 if (append)
308 fputc(append, stdout); 308 fputc(append, stdout);
@@ -372,7 +372,7 @@ static int list_item(const char *name)
372 372
373 if (!S_ISDIR(info.st_mode) || 373 if (!S_ISDIR(info.st_mode) ||
374 (opts & DIR_NOLIST)) { 374 (opts & DIR_NOLIST)) {
375 list_single(name, &info); 375 list_single(name, &info, name);
376 return 0; 376 return 0;
377 } 377 }
378 378
@@ -424,7 +424,7 @@ static int list_item(const char *name)
424 strcpy(fnend, entry->d_name); 424 strcpy(fnend, entry->d_name);
425 if (lstat(fullname, &info)) 425 if (lstat(fullname, &info))
426 goto direrr; /* (shouldn't fail) */ 426 goto direrr; /* (shouldn't fail) */
427 list_single(entry->d_name, &info); 427 list_single(entry->d_name, &info, fullname);
428 } 428 }
429 closedir(dir); 429 closedir(dir);
430 return 0; 430 return 0;