vl.c: move pidfile creation up
PATCH 1/1 vl.c: move pidfile creation up
With current code, pid file is open after various sockets, chardevs, fsdevs and the like. This causes interesting effects, for example when monitor is a unix-socket, and another qemu instance is already running, new qemu first "damages" the socket and next complain that it can't acquire the pid file and exits, making running qemu unreachable.
Move pid file creation a bit earlier.
--- vl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
vl.c +5 -5
@@ -4305,6 +4305,11 @@ int main(int argc, char **argv, char **envp)exit (1 ); } +if (pid_file &&qemu_create_pidfile (pid_file) !=0 ) { +error_report ("could not acquire pid file: %s" ,strerror (errno)); +exit (1 ); + } +page_size_init ();socket_init ();
@@ -4326,11 +4331,6 @@ int main(int argc, char **argv, char **envp) }#endif -if (pid_file &&qemu_create_pidfile (pid_file) !=0 ) { -error_report ("could not acquire pid file: %s" ,strerror (errno)); -exit (1 ); - } -if (qemu_opts_foreach (qemu_find_opts ("device" ), device_help_func,NULL ,NULL )) {exit (0 );
Signature · 1 line
2.1.4
Quoted 9 lines · Michael Tokarev
With current code, pid file is open after various sockets, chardevs, fsdevs and the like. This causes interesting effects, for example when monitor is a unix-socket, and another qemu instance is already running, new qemu first "damages" the socket and next complain that it can't acquire the pid file and exits, making running qemu unreachable.
Move pid file creation a bit earlier.
Makes sense, but ...
Quoted 11 lines
Signed-off-by Michael Tokarev <[email protected]>--- vl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)vl.c +0
-0@@ -4305,6 +4305,11 @@ int main(int argc, char **argv, char **envp)exit (1 );
vl.c int main(int argc, char **argv, char **envp) · line 4315
Quoted 10 lines
vl.c +5
-0} +if (pid_file &&qemu_create_pidfile (pid_file) !=0 ) { +error_report ("could not acquire pid file: %s" ,strerror (errno)); +exit (1 ); + } +page_size_init ();socket_init ();
... is this early enough? For instance, we clobber the log file another 200 lines further up.
A "don't clobber anything externally visible before this spot" comment could be useful.
Quoted 12 lines
vl.c +0
-5@@ -4326,11 +4331,6 @@ int main(int argc, char **argv, char **envp) }#endif -if (pid_file &&qemu_create_pidfile (pid_file) !=0 ) { -error_report ("could not acquire pid file: %s" ,strerror (errno)); -exit (1 ); - } -if (qemu_opts_foreach (qemu_find_opts ("device" ), device_help_func,NULL ,NULL )) {exit (0 );
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Michael Tokarev
With current code, pid file is open after various sockets, chardevs, fsdevs and the like. This causes interesting effects, for example when monitor is a unix-socket, and another qemu instance is already running, new qemu first "damages" the socket and next complain that it can't acquire the pid file and exits, making running qemu unreachable.
..
Quoted 2 lines
... is this early enough? For instance, we clobber the log file another 200 lines further up.
Yeah, you're right. There's also some tracing initing in there and other potentially interesting stuff.
I moved the pid file creation right after the os_daemonize() call. Before this point we don't even know our pid.
Quoted 2 lines
A "don't clobber anything externally visible before this spot" comment could be useful.
Hopefully this is "early enough" to not need this comment :)
Thanks,
/mjt