Skip to content
Snippets Groups Projects
  • Nadav Har'El's avatar
    082ff373
    Fix crash on malformed command line · 082ff373
    Nadav Har'El authored
    
    Before this patch, OSv crashes or continuously reboots when given unknown
    command line paramters, e.g.,
    
            scripts/run.py -c1 -e "--help --z a"
    
    With this patch, it says, as expected that the "--z" option is not
    recognized, and displays the list of known options:
    
        unrecognised option '--z'
        OSv options:
          --help                show help text
          --trace arg           tracepoints to enable
          --trace-backtrace     log backtraces in the tracepoint log
          --leak                start leak detector after boot
          --nomount             don't mount the file system
          --noshutdown          continue running after main() returns
          --env arg             set Unix-like environment variable (putenv())
          --cwd arg             set current working directory
        Aborted
    
    The problem was that to parse the command line options, we used Boost,
    which throws an exception when an unrecognized option is seen. We need
    to catch this exception, and show a message accordingly.
    
    But before this patch, C++ exceptions did not work correctly during this
    stage of the boot process, because exceptions use elf::program(), and we
    only set it up later. So this patch moves the setup of the elf::program()
    object earlier in the boot, to the beginning of main_cont().
    
    Now we'll be able to use C++ exceptions throughout main_cont(), not just
    in command line parsing.
    
    This patch also removes the unused "filesystem" paramter of
    elf::program(), rather than move the initializion of this empty object
    as well.
    
    Fixes #103.
    
    Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
    Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
    082ff373
    History
    Fix crash on malformed command line
    Nadav Har'El authored
    
    Before this patch, OSv crashes or continuously reboots when given unknown
    command line paramters, e.g.,
    
            scripts/run.py -c1 -e "--help --z a"
    
    With this patch, it says, as expected that the "--z" option is not
    recognized, and displays the list of known options:
    
        unrecognised option '--z'
        OSv options:
          --help                show help text
          --trace arg           tracepoints to enable
          --trace-backtrace     log backtraces in the tracepoint log
          --leak                start leak detector after boot
          --nomount             don't mount the file system
          --noshutdown          continue running after main() returns
          --env arg             set Unix-like environment variable (putenv())
          --cwd arg             set current working directory
        Aborted
    
    The problem was that to parse the command line options, we used Boost,
    which throws an exception when an unrecognized option is seen. We need
    to catch this exception, and show a message accordingly.
    
    But before this patch, C++ exceptions did not work correctly during this
    stage of the boot process, because exceptions use elf::program(), and we
    only set it up later. So this patch moves the setup of the elf::program()
    object earlier in the boot, to the beginning of main_cont().
    
    Now we'll be able to use C++ exceptions throughout main_cont(), not just
    in command line parsing.
    
    This patch also removes the unused "filesystem" paramter of
    elf::program(), rather than move the initializion of this empty object
    as well.
    
    Fixes #103.
    
    Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
    Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>