Set umask at start

umask setting can be too strict so set to a sensible value.
This fix some problem creating core files after setuid.
Compute buffer required for state file

Avoid using constants that could lead to future overflows.
Use fchown instead of chown

This reduce race conditions and can decrease disk operations.
Make some variable static const

This maximize memory sharing and help to reduce attach surface.
Reduce permissions for core and statefile

These files can contain sensitive information if use write something
like password on the screen.
Make some data and functions static

This allow compiler to better optimize code and reduce name pollution.
Do not compile debug code if not necessary

Some functions in console.c was used only for debug.
However the purpose of these function is just to write some stuff
but if DEBUG_CONSOLE is not enabled they end up doing nothing and
just wasting code.
Remove unused field.
Do not allocate a new environment array

The environment array is already writable so there is no need to copy it.
Avoid useless memset calls

Use qemu_mallocz to reset memory instead of allocating and then zeroing
manually.
Clean statefile file if present

Avoid to keep empty statefile and allow removing directory.
Allocate vncterm on the stack

There is no need to use dynamic memory.
Do not call connect_pty in read_xs_watch

Setting pty_path is enough to get the pty opened.
Cleanup old commented out code
Fix missing break

Specifying -V caused text terminal to be enabled.
Allocate display_state and text_display_state in the stack

Use same allocation used for vncterm variable.