hyperhq / runv

Hypervisor-based Runtime for OCI
Apache License 2.0
826 stars 129 forks source link

Don't call os.Exit explicitly to avoid lost of logs #519

Closed WeiZhang555 closed 7 years ago

WeiZhang555 commented 7 years ago

Do not call os.Exit directly in codes, but call "return cli.NewExitError" instead, so that after the program terminated, glog can flush and no logs will be lost.

Signed-off-by: Zhang Wei zhangwei555@huawei.com

WeiZhang555 commented 7 years ago

The reason that this commit works is that in https://github.com/hyperhq/runv/blob/master/main.go#L144-L148 , there is a glog.Flush() to flush all the logs after the APP exits, but if we call os.Exit in middle directly, there's no way to flush all the logs, hence cached logs would be lost. With this modification, glog.Flush will always be called when program exits normally (except panic), and we could get all logs for debugging.