um: Output messages to stderr and support quiet option
v3 cover um: Output messages to stderr and support quiet option
Hello,
Here is version 3 of um-quiet series. In this version I just fixed some printf format issues.
V2 is here.
https://lkml.org/lkml/2017/5/8/35
This series fixes some boot time printf output to stderr by adding os_info() and os_warn(). The information-level messages via os_info() are suppressed when "quiet" kernel option is specified.
Also the last one allows user to pass "console=" option to kernel.
Note that the output of --help and --version are still sent to stdout since they are intentionally shown by the user.
Changes from v2:
- Cast rlim_min/max to unsigned long long explicitly for avoiding printf-format warning.
- Fix printf format in physmem.c so that it matches the type of arguments.
Thank you,
---
Masami Hiramatsu (6):
um: Use printk instead of printf in make_uml_dir
um: Add os_info() for pre-boot information messages
um: Use os_info for the messages on normal path
um: Add os_warn() for pre-boot warning/error messages
um: Use os_warn to print out pre-boot warning/error messages
um: console: Ignore console= option
arch/um/drivers/stdio_console.c | 3 +++ arch/um/include/shared/os.h | 4 ++++ arch/um/kernel/physmem.c | 10 +++++----- arch/um/kernel/um_arch.c | 16 +++++++++------- arch/um/kernel/umid.c | 4 ++-- arch/um/os-Linux/execvp.c | 2 +- arch/um/os-Linux/main.c | 9 ++++----- arch/um/os-Linux/mem.c | 28 ++++++++++++++-------------- arch/um/os-Linux/start_up.c | 28 +++++++++++++++------------- arch/um/os-Linux/umid.c | 19 +++++++++++-------- arch/um/os-Linux/util.c | 34 ++++++++++++++++++++++++++++++++++ 11 files changed, 102 insertions(+), 55 deletions(-)
--
Masami Hiramatsu <[email protected]>
PATCH v3 1/6 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.
---
Changes in v2:
- Use "%s", __func__ according to checkpatches.pl
--- arch/um/os-Linux/umid.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
arch/um/os-Linux/umid.c +7 -4
@@ -35,8 +35,9 @@ static int __init make_uml_dir(void) err = -ENOENT ;if (home ==NULL ) { -printk (UM_KERN_ERR "make_uml_dir : no value in " -"environment for $HOME\n" ); +printk (UM_KERN_ERR +"%s: no value in environment for $HOME\n" , + __func__); goto err; }strlcpy (dir, home,sizeof (dir));
@@ -50,13 +51,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 "%s : malloc failed, errno = %d\n" , + __func__, 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; }
PATCH v3 2/6 um: Add os_info() for pre-boot information messages
In reply to Masami HiramatsuAdd os_info() for printing out pre-boot information level messages in stderr. The messages via os_info() are suppressed by "quiet" kernel command line.
--- arch/um/include/shared/os.h | 2 ++ arch/um/os-Linux/util.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
arch/um/include/shared/os.h +2 -0
@@ -242,6 +242,8 @@ 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 os_info (const char *fmt, ...) + __attribute__ ((format (printf,1 ,2 )));/* time.c */ extern void os_idle_sleep (unsigned long long nsecs);
arch/um/os-Linux/util.c +25 -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)
@@ -152,3 +153,27 @@ void um_early_printk(const char *s, unsigned int n) {printf ("%.*s" , n, s); } + +static int quiet_info; + +static int __init quiet_cmd_param (char *str,int *add) +{ + quiet_info =1 ; +return 0 ; +} + +__uml_setup ("quiet" , quiet_cmd_param, +"quiet\n" +" Turns off information messages during boot.\n\n" ); + +void os_info (const char *fmt, ...) +{ +va_list list; + +if (quiet_info) +return ; + +va_start (list, fmt); +vfprintf (stderr, fmt, list); +va_end (list); +}
PATCH v3 3/6 um: Use os_info for the messages on normal path
In reply to Masami HiramatsuUse os_info() for printing out the messages on the normal execution path.
---
Changes in v3:
- Cast rlim_min/max to unsigned long long explicitly for avoiding printf-format warning.
--- arch/um/kernel/um_arch.c | 8 ++++---- arch/um/os-Linux/main.c | 3 +-- arch/um/os-Linux/mem.c | 18 +++++++++--------- arch/um/os-Linux/start_up.c | 26 ++++++++++++++------------ 4 files changed, 28 insertions(+), 27 deletions(-)
arch/um/kernel/um_arch.c +4 -4
@@ -289,8 +289,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); +os_info ("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 +330,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); +os_info ("Kernel virtual memory size shrunk to %lu bytes\n" , + virtmem_size);os_flush_stdout ();
arch/um/os-Linux/main.c +1 -2
@@ -184,14 +184,13 @@ int __init main(int argc, char **argv, char **envp)*/ unblock_signals (); +os_info ("\n" );/* Reboot */ if (ret) { -printf ("\n" );execvp (new_argv[0 ], new_argv);perror ("Failed to exec kernel" ); ret =1 ; } -printf ("\n" );return uml_exitcode; }
arch/um/os-Linux/mem.c +9 -9
@@ -25,13 +25,13 @@ static int __init check_tmpfs(const char *dir) {struct statfs st; -printf ("Checking if %s is on tmpfs..." , dir); +os_info ("Checking if %s is on tmpfs..." , dir);if (statfs (dir, &st) <0 ) { -printf ("%s\n" ,strerror (errno)); +os_info ("%s\n" ,strerror (errno)); }else if (st.f_type !=TMPFS_MAGIC ) { -printf ("no\n" ); +os_info ("no\n" ); }else { -printf ("OK\n" ); +os_info ("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..." ); +os_info ("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); +os_info ("%s\n" , dir);if (check_tmpfs (dir) >=0 ) goto done;else goto warn; } } -printf ("none found\n" ); +os_info ("none found\n" );for (i =0 ; tmpfs_dirs[i]; i++) { dir = tmpfs_dirs[i];
@@ -194,7 +194,7 @@ 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); +os_info ("Checking PROT_EXEC mmap in %s..." , tempdir);if (addr ==MAP_FAILED ) { err = errno;printf ("%s\n" ,strerror (err));
@@ -203,7 +203,7 @@ void __init check_tmpexec(void)printf ("%s must be not mounted noexec\n" , tempdir);exit (1 ); } -printf ("OK\n" ); +os_info ("OK\n" );munmap (addr,UM_KERN_PAGE_SIZE );close (fd);
arch/um/os-Linux/start_up.c +14 -12
@@ -166,7 +166,7 @@ static void __init check_sysemu(void)unsigned long regs[MAX_REG_NR ];int pid, n, status, count=0 ; -non_fatal ("Checking syscall emulation patch for ptrace..." ); +os_info ("Checking syscall emulation patch for ptrace..." ); sysemu_supported =0 ; pid =start_ptraced_child ();
@@ -199,10 +199,10 @@ static void __init check_sysemu(void) goto fail_stopped; sysemu_supported =1 ; -non_fatal ("OK\n" ); +os_info ("OK\n" );set_using_sysemu (!force_sysemu_disabled); -non_fatal ("Checking advanced syscall emulation patch for ptrace..." ); +os_info ("Checking advanced syscall emulation patch for ptrace..." ); pid =start_ptraced_child (); if ((ptrace(PTRACE_OLDSETOPTIONS, pid, 0,
@@ -244,7 +244,7 @@ static void __init check_sysemu(void) goto fail_stopped; sysemu_supported =2 ; -non_fatal ("OK\n" ); +os_info ("OK\n" );if (!force_sysemu_disabled)set_using_sysemu (sysemu_supported);
@@ -260,7 +260,7 @@ static void __init check_ptrace(void) {int pid, syscall, n, status; -non_fatal ("Checking that ptrace can change system call numbers..." ); +os_info ("Checking that ptrace can change system call numbers..." ); pid =start_ptraced_child (); if ((ptrace(PTRACE_OLDSETOPTIONS, pid, 0,
@@ -292,7 +292,7 @@ static void __init check_ptrace(void) } }stop_ptraced_child (pid,0 ,1 ); -non_fatal ("OK\n" ); +os_info ("OK\n" );check_sysemu (); }
@@ -308,15 +308,17 @@ static void __init check_coredump_limit(void)return ; } -printf ("Core dump limits :\n\tsoft - " ); +os_info ("Core dump limits :\n\tsoft - " );if (lim.rlim_cur ==RLIM_INFINITY ) -printf ("NONE\n" ); -else printf ("%lu\n" , lim.rlim_cur); +os_info ("NONE\n" ); +else +os_info ("%llu\n" , (unsigned long long )lim.rlim_cur); -printf ("\thard - " ); +os_info ("\thard - " );if (lim.rlim_max ==RLIM_INFINITY ) -printf ("NONE\n" ); -else printf ("%lu\n" , lim.rlim_max); +os_info ("NONE\n" ); +else +os_info ("%llu\n" , (unsigned long long )lim.rlim_max); }void __init os_early_checks (void )
PATCH v3 4/6 um: Add os_warn() for pre-boot warning/error messages
In reply to Masami HiramatsuAdd os_warn() for printing out pre-boot warning/error messages in stderr. The messages via os_warn() are not suppressed by quiet option.
--- arch/um/include/shared/os.h | 2 ++ arch/um/os-Linux/util.c | 9 +++++++++ 2 files changed, 11 insertions(+)
arch/um/include/shared/os.h +2 -0
@@ -244,6 +244,8 @@ extern void um_early_printk(const char *s, unsigned int n);extern void os_fix_helper_signals (void );extern void os_info (const char *fmt, ...) __attribute__ ((format (printf,1 ,2 ))); +extern void os_warn (const char *fmt, ...) + __attribute__ ((format (printf,1 ,2 )));/* time.c */ extern void os_idle_sleep (unsigned long long nsecs);
arch/um/os-Linux/util.c +9 -0
@@ -177,3 +177,12 @@ void os_info(const char *fmt, ...)vfprintf (stderr, fmt, list);va_end (list); } + +void os_warn (const char *fmt, ...) +{ +va_list list; + +va_start (list, fmt); +vfprintf (stderr, fmt, list); +va_end (list); +}
PATCH v3 5/6 um: Use os_warn to print out pre-boot warning/error messages
In reply to Masami HiramatsuUse os_warn() instead of printf/fprintf to print out pre-boot warning/error messages to stderr. Note that the help message and version message are kept to print out to stdout, because user explicitly specifies those options to get such information.
---
Changes in v3:
- Fix printf format in physmem.c so that it matches the type of arguments.
--- arch/um/kernel/physmem.c | 10 +++++----- arch/um/kernel/um_arch.c | 8 +++++--- arch/um/kernel/umid.c | 4 ++-- arch/um/os-Linux/execvp.c | 2 +- arch/um/os-Linux/main.c | 6 +++--- arch/um/os-Linux/mem.c | 10 +++++----- arch/um/os-Linux/start_up.c | 2 +- arch/um/os-Linux/umid.c | 8 ++++---- 8 files changed, 26 insertions(+), 24 deletions(-)
arch/um/kernel/physmem.c +5 -5
@@ -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); +os_warn ("Too few physical memory! Needed=%lu, given=%lu\n" , + offset, len);exit (1 ); }
@@ -99,9 +99,9 @@ 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, - (void *) uml_reserved, err); +os_warn ("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 +5 -3
@@ -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" ); +os_warn ("add_arg: Too many command line arguments!\n" );exit (1 ); }if (strlen (command_line) >0 )
@@ -126,6 +126,7 @@ static const char *usage_string =static int __init uml_version_setup (char *line,int *add) { +/* Explicitly use printf() to show version in stdout */ 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" ); +os_warn ("'debug' is not necessary to gdb UML in skas mode - run\n" ); +os_warn ("'gdb linux'\n" );return 0 ; }
@@ -171,6 +172,7 @@ static int __init Usage(char *line, int *add)printf (usage_string,init_utsname ()->release); p = &__uml_help_start; +/* Explicitly use printf() to show help in stdout */ while (p < &__uml_help_end) {printf ("%s" , *p); p++;
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" ); +os_warn ("umid already set\n" );return 0 ; } *add =0 ; err =set_umid (name);if (err == -EEXIST ) -printf ("umid '%s' already in use\n" , name); +os_warn ("umid '%s' already in use\n" , name);else if (!err) umid_inited =1 ;
arch/um/os-Linux/execvp.c +1 -1
@@ -136,7 +136,7 @@ int main(int argc, char**argv)int ret; argc--;if (!argc) { -fprintf (stderr,"Not enough arguments\n" ); +os_warn ("Not enough arguments\n" );return 1 ; } argv++;
arch/um/os-Linux/main.c +3 -3
@@ -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); +os_warn ("failed to install handler for signal %d " +"- errno = %d\n" , sig, errno);exit (1 ); } }
@@ -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); +os_warn ("deactivate_all_fds failed, errno = %d\n" , -err);/* * Let any pending signals fire now. This ensures
arch/um/os-Linux/mem.c +5 -5
@@ -82,7 +82,7 @@ static char * __init choose_tempdir(void) dir = fallback_dir; warn: -printf ("Warning: tempdir %s is not on tmpfs\n" , dir); +os_warn ("Warning: tempdir %s is not on tmpfs\n" , dir); done:/* Make a copy since getenv results may not remain valid forever. */ return strdup (dir);
@@ -100,7 +100,7 @@ static int __init make_tempfile(const char *template)if (tempdir ==NULL ) { tempdir =choose_tempdir ();if (tempdir ==NULL ) { -fprintf (stderr,"Failed to choose tempdir: %s\n" , +os_warn ("Failed to choose tempdir: %s\n" ,strerror (errno));return -1 ; }
@@ -125,7 +125,7 @@ static int __init make_tempfile(const char *template)strcat (tempname, template); fd =mkstemp (tempname);if (fd <0 ) { -fprintf (stderr,"open - cannot create %s: %s\n" , tempname, +os_warn ("open - cannot create %s: %s\n" , tempname,strerror (errno)); goto out; }
@@ -197,10 +197,10 @@ void __init check_tmpexec(void)os_info ("Checking PROT_EXEC mmap in %s..." , tempdir);if (addr ==MAP_FAILED ) { err = errno; -printf ("%s\n" ,strerror (err)); +os_warn ("%s\n" ,strerror (err));close (fd);if (err ==EPERM ) -printf ("%s must be not mounted noexec\n" , tempdir); +os_warn ("%s must be not mounted noexec\n" , tempdir);exit (1 ); }os_info ("OK\n" );
arch/um/os-Linux/start_up.c +1 -1
@@ -351,7 +351,7 @@ int __init parse_iomem(char *str, int *add) driver = str; file =strchr (str,',' );if (file ==NULL ) { -fprintf (stderr,"parse_iomem : failed to parse iomem\n" ); +os_warn ("parse_iomem : failed to parse iomem\n" ); goto out; } *file ='\0' ;
arch/um/os-Linux/umid.c +4 -4
@@ -354,7 +354,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" ); +os_warn ("uml_dir can't be an empty string\n" );return 0 ; }
@@ -365,7 +365,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); +os_warn ("Failed to malloc uml_dir - error = %d\n" , errno);/* * Return 0 here because do_initcalls doesn't look at
@@ -390,8 +390,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); +os_warn ("%s - remove_files_and_dir failed with err = %d\n" , + __func__, err); }__uml_exitcall (remove_umid_dir);
PATCH v3 6/6 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 ))/* console= option specifies tty */ +return 0 ; +line_setup (vt_conf,MAX_TTYS , &def_conf, str,"console" );return 1 ; }
Masami,
Quoted 30 lines · Masami Hiramatsu
Hello,
Here is version 3 of um-quiet series. In this version I just fixed some printf format issues.
V2 is here.
https://lkml.org/lkml/2017/5/8/35
This series fixes some boot time printf output to stderr by adding
os_info()andos_warn(). The information-level messages viaos_info()are suppressed when "quiet" kernel option is specified.
Also the last one allows user to pass "console=" option to kernel.Note that the output of --help and --version are still sent to stdout since they are intentionally shown by the user.
Changes from v2:
- Cast rlim_min/max to unsigned long long explicitly for avoiding printf-format warning.
- Fix printf format inphysmem.cso that it matches the type of arguments.Thank you,
---
Quoted 9 lines
Masami Hiramatsu (6):
um: Use printk instead of printf inmake_uml_dir
um: Addos_info()for pre-boot information messages
um: Useos_infofor the messages on normal path
um: Addos_warn()for pre-boot warning/error messages
um: Useos_warnto print out pre-boot warning/error messages
um: console: Ignore console= option
Series applied. Thanks!
Signature · 2 lines
Thanks, //richard