um: Fix printf usage and support quiet option
cover um: Fix printf usage and support quiet option
Hello,
This series fixes some boot time printf output to stderr by default, and support "quiet" option to suppress non- fatal error (or warning) messages in user-mode-linux. Also the last one allows user to pass "console=" option to kernel.
Thank you,
---
Masami Hiramatsu (7):
um: Use printk instead of printf in make_uml_dir
um: Use non_fatal() in check_coredump_limit
um: Make non_fatal non-static for other files
um: Use non_fatal() for non-fatal information/warning messages
um: Print out fatal error in stderr
um: Suppress non-fatal messages when quiet
um: console: Ignore console= option
arch/um/drivers/stdio_console.c | 3 +++ arch/um/include/shared/os.h | 1 + arch/um/kernel/physmem.c | 8 ++++---- arch/um/kernel/um_arch.c | 16 +++++++++------- arch/um/kernel/umid.c | 4 ++-- arch/um/os-Linux/main.c | 10 +++++----- arch/um/os-Linux/mem.c | 24 ++++++++++++------------ arch/um/os-Linux/start_up.c | 23 ++++++++--------------- arch/um/os-Linux/umid.c | 14 ++++++++------ arch/um/os-Linux/util.c | 25 +++++++++++++++++++++++++ 10 files changed, 77 insertions(+), 51 deletions(-)
--
Masami Hiramatsu <[email protected]>
RFC PATCH 1/7 um: Use printk instead of printf in make_uml_dir
Since this function will be called after printk buffer initialized, use printk as other functions do.
--- arch/um/os-Linux/umid.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/um/os-Linux/umid.c +4 -2
@@ -50,13 +50,15 @@ static int __init make_uml_dir(void) err = -ENOMEM ; uml_dir =malloc (strlen (dir) +1 );if (uml_dir ==NULL ) { -printf ("make_uml_dir : malloc failed, errno = %d\n" , errno); +printk (UM_KERN_ERR "make_uml_dir : malloc failed, " +"errno = %d\n" , errno); goto err; }strcpy (uml_dir, dir);if ((mkdir (uml_dir,0777 ) <0 ) && (errno !=EEXIST )) { -printf ("Failed to mkdir '%s': %s\n" , uml_dir,strerror (errno)); +printk (UM_KERN_ERR "Failed to mkdir '%s': %s\n" , + uml_dir,strerror (errno)); err = -errno; goto err_free; }
RFC PATCH 2/7 um: Use non_fatal() in check_coredump_limit
In reply to Masami HiramatsuUse non_fatal() instead of printf in check_coredump_limit().
--- arch/um/os-Linux/start_up.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
arch/um/os-Linux/start_up.c +8 -6
@@ -308,15 +308,17 @@ static void __init check_coredump_limit(void)return ; } -printf ("Core dump limits :\n\tsoft - " ); +non_fatal ("Core dump limits :\n\tsoft - " );if (lim.rlim_cur ==RLIM_INFINITY ) -printf ("NONE\n" ); -else printf ("%lu\n" , lim.rlim_cur); +non_fatal ("NONE\n" ); +else +non_fatal ("%lu\n" , lim.rlim_cur); -printf ("\thard - " ); +non_fatal ("\thard - " );if (lim.rlim_max ==RLIM_INFINITY ) -printf ("NONE\n" ); -else printf ("%lu\n" , lim.rlim_max); +non_fatal ("NONE\n" ); +else +non_fatal ("%lu\n" , lim.rlim_max); }void __init os_early_checks (void )
RFC PATCH 3/7 um: Make non_fatal non-static for other files
In reply to Masami HiramatsuMove non_fatal() to util.c and make it global so that it can be used from other files.
--- arch/um/include/shared/os.h | 1 + arch/um/os-Linux/start_up.c | 9 --------- arch/um/os-Linux/util.c | 9 +++++++++ 3 files changed, 10 insertions(+), 9 deletions(-)
arch/um/include/shared/os.h +1 -0
@@ -242,6 +242,7 @@ extern void setup_hostinfo(char *buf, int len);extern void os_dump_core (void ) __attribute__ ((noreturn));extern void um_early_printk (const char *s,unsigned int n);extern void os_fix_helper_signals (void ); +extern void non_fatal (const char *fmt, ...);/* time.c */ extern void os_idle_sleep (unsigned long long nsecs);
arch/um/os-Linux/start_up.c +0 -9
@@ -81,15 +81,6 @@ static void fatal(char *fmt, ...)exit (1 ); } -static void non_fatal (char *fmt, ...) -{ -va_list list; - -va_start (list, fmt); -vfprintf (stderr, fmt, list); -va_end (list); -} -static int start_ptraced_child (void ) {int pid, n, status;
arch/um/os-Linux/util.c +9 -0
@@ -152,3 +152,12 @@ void um_early_printk(const char *s, unsigned int n) {printf ("%.*s" , n, s); } + +void non_fatal (const char *fmt, ...) +{ +va_list list; + +va_start (list, fmt); +vfprintf (stderr, fmt, list); +va_end (list); +}
RFC PATCH 4/7 um: Use non_fatal() for non-fatal information/warning messages
In reply to Masami HiramatsuUse non_fatal() for non-fatal information or warning messages instead of printf(). This also changes these messages output to stderr.
--- arch/um/kernel/um_arch.c | 14 ++++++++------ arch/um/kernel/umid.c | 4 ++-- arch/um/os-Linux/main.c | 6 +++--- arch/um/os-Linux/mem.c | 24 ++++++++++++------------ arch/um/os-Linux/umid.c | 8 ++++---- 5 files changed, 29 insertions(+), 27 deletions(-)
arch/um/kernel/um_arch.c +8 -6
@@ -126,6 +126,7 @@ static const char *usage_string =static int __init uml_version_setup (char *line,int *add) { +/* Version is shown when user intended to see it, not an error */ printf ("%s\n" ,init_utsname ()->release);exit (0 );
@@ -154,8 +155,8 @@ __uml_setup("root=", uml_root_setup,static int __init no_skas_debug_setup (char *line,int *add) { -printf ("'debug' is not necessary to gdb UML in skas mode - run \n" ); -printf ("'gdb linux'\n" ); +non_fatal ("'debug' is not necessary to gdb UML in skas mode - run\n" ); +non_fatal ("'gdb linux'\n" );return 0 ; }
@@ -169,6 +170,7 @@ static int __init Usage(char *line, int *add) {const char **p; +/* Usage is usually shown when user intended to see it, not an error */ printf (usage_string,init_utsname ()->release); p = &__uml_help_start;while (p < &__uml_help_end) {
@@ -289,8 +291,8 @@ int __init linux_main(int argc, char **argv) diff =UML_ROUND_UP (brk_start) -UML_ROUND_UP (&_end);if (diff >1024 *1024 ) { -printf ("Adding %ld bytes to physical memory to account for " -"exec-shield gap\n" , diff); +non_fatal ("Adding %ld bytes to physical memory to account for " +"exec-shield gap\n" , diff); physmem_size +=UML_ROUND_UP (brk_start) -UML_ROUND_UP (&_end); }
@@ -330,8 +332,8 @@ int __init linux_main(int argc, char **argv) end_vm = start_vm + virtmem_size;if (virtmem_size < physmem_size) -printf ("Kernel virtual memory size shrunk to %lu bytes\n" , - virtmem_size); +non_fatal ("Kernel virtual memory size shrunk to %lu bytes\n" , + virtmem_size);os_flush_stdout ();
arch/um/kernel/umid.c +2 -2
@@ -16,14 +16,14 @@ static int __init set_umid_arg(char *name, int *add)int err;if (umid_inited) { -printf ("umid already set\n" ); +non_fatal ("umid already set\n" );return 0 ; } *add =0 ; err =set_umid (name);if (err == -EEXIST ) -printf ("umid '%s' already in use\n" , name); +non_fatal ("umid '%s' already in use\n" , name);else if (!err) umid_inited =1 ;
arch/um/os-Linux/main.c +3 -3
@@ -175,7 +175,7 @@ int __init main(int argc, char **argv, char **envp)/* disable SIGIO for the fds and set SIGIO to be ignored */ err =deactivate_all_fds ();if (err) -printf ("deactivate_all_fds failed, errno = %d\n" , -err); +non_fatal ("deactivate_all_fds failed, errno = %d\n" , -err);/* * Let any pending signals fire now. This ensures
@@ -186,12 +186,12 @@ int __init main(int argc, char **argv, char **envp)/* Reboot */ if (ret) { -printf ("\n" ); +non_fatal ("\n" );execvp (new_argv[0 ], new_argv);perror ("Failed to exec kernel" ); ret =1 ; } -printf ("\n" ); +non_fatal ("\n" );return uml_exitcode; }
arch/um/os-Linux/mem.c +12 -12
@@ -25,13 +25,13 @@ static int __init check_tmpfs(const char *dir) {struct statfs st; -printf ("Checking if %s is on tmpfs..." , dir); +non_fatal ("Checking if %s is on tmpfs..." , dir);if (statfs (dir, &st) <0 ) { -printf ("%s\n" ,strerror (errno)); +non_fatal ("%s\n" ,strerror (errno)); }else if (st.f_type !=TMPFS_MAGIC ) { -printf ("no\n" ); +non_fatal ("no\n" ); }else { -printf ("OK\n" ); +non_fatal ("OK\n" );return 0 ; }return -1 ;
@@ -61,18 +61,18 @@ static char * __init choose_tempdir(void)int i;const char *dir; -printf ("Checking environment variables for a tempdir..." ); +non_fatal ("Checking environment variables for a tempdir..." );for (i =0 ; vars[i]; i++) { dir =getenv (vars[i]);if ((dir !=NULL ) && (*dir !='\0' )) { -printf ("%s\n" , dir); +non_fatal ("%s\n" , dir);if (check_tmpfs (dir) >=0 ) goto done;else goto warn; } } -printf ("none found\n" ); +non_fatal ("none found\n" );for (i =0 ; tmpfs_dirs[i]; i++) { dir = tmpfs_dirs[i];
@@ -82,7 +82,7 @@ static char * __init choose_tempdir(void) dir = fallback_dir; warn: -printf ("Warning: tempdir %s is not on tmpfs\n" , dir); +non_fatal ("Warning: tempdir %s is not on tmpfs\n" , dir); done:/* Make a copy since getenv results may not remain valid forever. */ return strdup (dir);
@@ -194,16 +194,16 @@ void __init check_tmpexec(void) addr =mmap (NULL ,UM_KERN_PAGE_SIZE ,PROT_READ |PROT_WRITE |PROT_EXEC ,MAP_PRIVATE , fd,0 ); -printf ("Checking PROT_EXEC mmap in %s..." , tempdir); +non_fatal ("Checking PROT_EXEC mmap in %s..." , tempdir);if (addr ==MAP_FAILED ) { err = errno; -printf ("%s\n" ,strerror (err)); +non_fatal ("%s\n" ,strerror (err));close (fd);if (err ==EPERM ) -printf ("%s must be not mounted noexec\n" , tempdir); +non_fatal ("%s must be not mounted noexec\n" , tempdir);exit (1 ); } -printf ("OK\n" ); +non_fatal ("OK\n" );munmap (addr,UM_KERN_PAGE_SIZE );close (fd);
arch/um/os-Linux/umid.c +4 -4
@@ -353,7 +353,7 @@ char *get_umid(void)static int __init set_uml_dir (char *name,int *add) {if (*name =='\0' ) { -printf ("uml_dir can't be an empty string\n" ); +non_fatal ("uml_dir can't be an empty string\n" );return 0 ; }
@@ -364,7 +364,7 @@ static int __init set_uml_dir(char *name, int *add) uml_dir =malloc (strlen (name) +2 );if (uml_dir ==NULL ) { -printf ("Failed to malloc uml_dir - error = %d\n" , errno); +non_fatal ("Failed to malloc uml_dir - error = %d\n" , errno);/* * Return 0 here because do_initcalls doesn't look at
@@ -389,8 +389,8 @@ static void remove_umid_dir(void)sprintf (dir,"%s%s" , uml_dir, umid); err =remove_files_and_dir (dir);if (err) -printf ("remove_umid_dir - remove_files_and_dir failed with " -"err = %d\n" , err); +non_fatal ("remove_umid_dir - remove_files_and_dir failed with " +"err = %d\n" , err); }__uml_exitcall (remove_umid_dir);
RFC PATCH 5/7 um: Print out fatal error in stderr
In reply to Masami HiramatsuPrint out fatal error in stderr as same as fatal() does.
--- arch/um/kernel/physmem.c | 8 ++++---- arch/um/kernel/um_arch.c | 2 +- arch/um/os-Linux/main.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-)
arch/um/kernel/physmem.c +4 -4
@@ -89,8 +89,8 @@ void __init setup_physmem(unsigned long start, unsigned long reserve_end, offset = uml_reserved - uml_physmem; map_size = len - offset;if (map_size <=0 ) { -printf ("Too few physical memory! Needed=%d, given=%d\n" , - offset, len); +fprintf (stderr,"Too few physical memory! Needed=%d, " +"given=%d\n" , offset, len);exit (1 ); }
@@ -99,8 +99,8 @@ void __init setup_physmem(unsigned long start, unsigned long reserve_end, err =os_map_memory ((void *) uml_reserved, physmem_fd, offset, map_size,1 ,1 ,1 );if (err <0 ) { -printf ("setup_physmem - mapping %ld bytes of memory at 0x%p " -"failed - errno = %d\n" , map_size, +fprintf (stderr,"setup_physmem - mapping %ld bytes of memory " +"at 0x%p failed - errno = %d\n" , map_size, (void *) uml_reserved, err);exit (1 ); }
arch/um/kernel/um_arch.c +1 -1
@@ -34,7 +34,7 @@ static char __initdata command_line[COMMAND_LINE_SIZE] = { 0 };static void __init add_arg (char *arg) {if (strlen (command_line) +strlen (arg) +1 >COMMAND_LINE_SIZE ) { -printf ("add_arg: Too many command line arguments!\n" ); +fprintf (stderr,"add_arg: Too many command line arguments!\n" );exit (1 ); }if (strlen (command_line) >0 )
arch/um/os-Linux/main.c +2 -2
@@ -74,8 +74,8 @@ static void install_fatal_handler(int sig) action.sa_restorer =NULL ; action.sa_handler = last_ditch_exit;if (sigaction (sig, &action,NULL ) <0 ) { -printf ("failed to install handler for signal %d - errno = %d\n" , - sig, errno); +fprintf (stderr,"failed to install handler for signal %d " +"- errno = %d\n" , sig, errno);exit (1 ); } }
Re: [RFC PATCH 5/7] um: Print out fatal error in stderr
Quoted 14 lines · On Fri, 28 Apr 2017 19:25:39 +0900 Masami Hiramatsu <[email protected]> wrote:
Print out fatal error in stderr as same as
fatal()does.Signed-off-by Masami Hiramatsu <[email protected]>--- arch/um/kernel/physmem.c | 8 ++++---- arch/um/kernel/um_arch.c | 2 +- arch/um/os-Linux/main.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-)arch/um/kernel/physmem.c +0
-0
arch/um/kernel/physmem.c void __init setup_physmem(unsigned long start, unsigned long reserve_end, · line 93
Quoted 7 lines
arch/um/kernel/physmem.c +2
-2@@ -89,8 +89,8 @@ void __init setup_physmem(unsigned long start, unsigned long reserve_end, offset = uml_reserved - uml_physmem; map_size = len - offset;if (map_size <=0 ) { -printf ("Too few physical memory! Needed=%d, given=%d\n" , - offset, len); +fprintf (stderr,"Too few physical memory! Needed=%d, " +"given=%d\n" , offset, len);
Oops, I've missed to include something for using fprintf here. Anyway, I think we need something like um_fatal() for handling these errors.
I'll resend v2.
Thanks,
Quoted 43 lines
arch/um/kernel/physmem.c +2
-2exit (1 ); }@@ -99,8 +99,8 @@ void __init setup_physmem(unsigned long start, unsigned long reserve_end, err =os_map_memory ((void *) uml_reserved, physmem_fd, offset, map_size,1 ,1 ,1 );if (err <0 ) { -printf ("setup_physmem - mapping %ld bytes of memory at 0x%p " -"failed - errno = %d\n" , map_size, +fprintf (stderr,"setup_physmem - mapping %ld bytes of memory " +"at 0x%p failed - errno = %d\n" , map_size, (void *) uml_reserved, err);exit (1 ); }arch/um/kernel/um_arch.c +1
-1@@ -34,7 +34,7 @@ static char __initdata command_line[COMMAND_LINE_SIZE] = { 0 };static void __init add_arg (char *arg) {if (strlen (command_line) +strlen (arg) +1 >COMMAND_LINE_SIZE ) { -printf ("add_arg: Too many command line arguments!\n" ); +fprintf (stderr,"add_arg: Too many command line arguments!\n" );exit (1 ); }if (strlen (command_line) >0 )arch/um/os-Linux/main.c +2
-2@@ -74,8 +74,8 @@ static void install_fatal_handler(int sig) action.sa_restorer =NULL ; action.sa_handler = last_ditch_exit;if (sigaction (sig, &action,NULL ) <0 ) { -printf ("failed to install handler for signal %d - errno = %d\n" , - sig, errno); +fprintf (stderr,"failed to install handler for signal %d " +"- errno = %d\n" , sig, errno);exit (1 ); } }
Signature · 1 line
Masami Hiramatsu <[email protected]>
RFC PATCH 6/7 um: Suppress non-fatal messages when quiet
In reply to Masami HiramatsuSuppress non-fatal boot messages when "quiet" kernel parameter is given.
--- arch/um/os-Linux/util.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/um/os-Linux/util.c +16 -0
@@ -13,6 +13,7 @@#include <wait.h> #include <sys/mman.h> #include <sys/utsname.h> +#include <init.h> #include <os.h> void stack_protections (unsigned long address)
@@ -153,10 +154,25 @@ void um_early_printk(const char *s, unsigned int n)printf ("%.*s" , n, s); } +static int quiet_non_fatal; + +static int __init quiet_cmd_param (char *str,int *add) +{ + quiet_non_fatal =1 ; +return 0 ; +} + +__uml_setup ("quiet" , quiet_cmd_param, +"quiet\n" +" Turns off non-fatal message during boot.\n\n" ); +void non_fatal (const char *fmt, ...) {va_list list; +if (quiet_non_fatal) +return ; +va_start (list, fmt);vfprintf (stderr, fmt, list);va_end (list);
RFC PATCH 7/7 um: console: Ignore console= option
In reply to Masami HiramatsuIgnore linux kernel's console= option at uml's console option handler. Since uml's con= option is only for setting up new console, and Linux kernel's console= option specify to which console kernel output its message, we can use both option for different purpose.
--- arch/um/drivers/stdio_console.c | 3 +++ 1 file changed, 3 insertions(+)
arch/um/drivers/stdio_console.c +3 -0
@@ -192,6 +192,9 @@ __uml_exitcall(console_exit);static int console_chan_setup (char *str) { +if (!strncmp (str,"sole=" ,5 ))/* This may passed to tty */ +return 0 ; +line_setup (vt_conf,MAX_TTYS , &def_conf, str,"console" );return 1 ; }