vl: delay thread initialization after daemonization

Commit ac4119c (chardev: Use timer instead of bottom-half to postpone
open event, 2012-10-12) moved the alarm timer initialization to an earlier
point but failed to consider that it depends on qemu_init_main_loop.

Later, commit 1c53786 (vl: init main loop earlier, 2012-10-30) fixed
this, but left -daemonize in two different ways.  First, timers need to
be reinitialized after forking.  Second, the global mutex was being held
by the parent, and thus dropped after forking.

The first is now fixed using pthread_atfork.  For the second part,
make sure that the global mutex is not taken before daemonization,
and similarly delay qemu_thread_self.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2 files changed
tree: 3b57b04f25cdaf958add7c26d96a0a3e38ca74ab
  1. audio/
  2. block/
  3. bsd-user/
  4. default-configs/
  5. docs/
  6. fpu/
  7. fsdev/
  8. gdb-xml/
  9. hw/
  10. include/
  11. libcacard/
  12. linux-headers/
  13. linux-user/
  14. net/
  15. pc-bios/
  16. qapi/
  17. qga/
  18. QMP/
  19. qom/
  20. roms/
  21. scripts/
  22. slirp/
  23. sysconfigs/
  24. target-alpha/
  25. target-arm/
  26. target-cris/
  27. target-i386/
  28. target-lm32/
  29. target-m68k/
  30. target-microblaze/
  31. target-mips/
  32. target-openrisc/
  33. target-ppc/
  34. target-s390x/
  35. target-sh4/
  36. target-sparc/
  37. target-unicore32/
  38. target-xtensa/
  39. tcg/
  40. tests/
  41. trace/
  42. ui/
  43. .exrc
  44. .gitignore
  45. .gitmodules
  46. .mailmap
  47. a.out.h
  48. acl.c
  49. acl.h
  50. aes.c
  51. aes.h
  52. aio-posix.c
  53. aio-win32.c
  54. alpha-dis.c
  55. alpha.ld
  56. arch_init.c
  57. arch_init.h
  58. arm-dis.c
  59. arm.ld
  60. async.c
  61. balloon.c
  62. balloon.h
  63. bitmap.c
  64. bitmap.h
  65. bitops.c
  66. bitops.h
  67. block-migration.c
  68. block-migration.h
  69. block.c
  70. block.h
  71. block_int.h
  72. blockdev-nbd.c
  73. blockdev.c
  74. blockdev.h
  75. blockjob.c
  76. blockjob.h
  77. bswap.h
  78. bt-host.c
  79. bt-host.h
  80. bt-vhci.c
  81. buffered_file.c
  82. buffered_file.h
  83. cache-utils.c
  84. cache-utils.h
  85. Changelog
  86. cmd.c
  87. cmd.h
  88. CODING_STYLE
  89. compatfd.c
  90. compatfd.h
  91. compiler.h
  92. config.h
  93. configure
  94. console.c
  95. console.h
  96. COPYING
  97. COPYING.LIB
  98. coroutine-gthread.c
  99. coroutine-sigaltstack.c
  100. coroutine-ucontext.c
  101. coroutine-win32.c
  102. cpu-all.h
  103. cpu-common.h
  104. cpu-defs.h
  105. cpu-exec.c
  106. cpus.c
  107. cpus.h
  108. cputlb.c
  109. cputlb.h
  110. cris-dis.c
  111. cursor.c
  112. cursor_hidden.xpm
  113. cursor_left_ptr.xpm
  114. cutils.c
  115. def-helper.h
  116. device_tree.c
  117. device_tree.h
  118. dis-asm.h
  119. disas.c
  120. disas.h
  121. dma-helpers.c
  122. dma.h
  123. dump-stub.c
  124. dump.c
  125. dump.h
  126. elf.h
  127. envlist.c
  128. envlist.h
  129. error.c
  130. error.h
  131. event_notifier-posix.c
  132. event_notifier-win32.c
  133. event_notifier.h
  134. exec-all.h
  135. exec-memory.h
  136. exec.c
  137. gdbstub.c
  138. gdbstub.h
  139. gen-icount.h
  140. HACKING
  141. hmp-commands.hx
  142. hmp.c
  143. hmp.h
  144. host-utils.c
  145. host-utils.h
  146. hppa-dis.c
  147. hppa.ld
  148. hwaddr.h
  149. i386-dis.c
  150. i386.ld
  151. ia64-dis.c
  152. ia64.ld
  153. input.c
  154. int128.h
  155. iohandler.c
  156. ioport.c
  157. ioport.h
  158. iorange.h
  159. iov.c
  160. iov.h
  161. json-lexer.c
  162. json-lexer.h
  163. json-parser.c
  164. json-parser.h
  165. json-streamer.c
  166. json-streamer.h
  167. kvm-all.c
  168. kvm-stub.c
  169. kvm.h
  170. libfdt_env.h
  171. LICENSE
  172. lm32-dis.c
  173. m68k-dis.c
  174. m68k.ld
  175. main-loop.c
  176. main-loop.h
  177. MAINTAINERS
  178. Makefile
  179. Makefile.dis
  180. Makefile.objs
  181. Makefile.target
  182. Makefile.user
  183. memory-internal.h
  184. memory.c
  185. memory.h
  186. memory_mapping-stub.c
  187. memory_mapping.c
  188. memory_mapping.h
  189. microblaze-dis.c
  190. migration-exec.c
  191. migration-fd.c
  192. migration-tcp.c
  193. migration-unix.c
  194. migration.c
  195. migration.h
  196. mips-dis.c
  197. mips.ld
  198. module.c
  199. module.h
  200. monitor.c
  201. monitor.h
  202. nbd.c
  203. nbd.h
  204. net.c
  205. net.h
  206. notify.c
  207. notify.h
  208. os-posix.c
  209. os-win32.c
  210. osdep.c
  211. osdep.h
  212. oslib-posix.c
  213. oslib-win32.c
  214. page_cache.c
  215. path.c
  216. pci-ids.txt
  217. pflib.c
  218. pflib.h
  219. poison.h
  220. ppc-dis.c
  221. ppc.ld
  222. ppc64.ld
  223. qapi-schema-guest.json
  224. qapi-schema-test.json
  225. qapi-schema.json
  226. qbool.c
  227. qbool.h
  228. qdict-test-data.txt
  229. qdict.c
  230. qdict.h
  231. qemu-aio.h
  232. qemu-barrier.h
  233. qemu-bridge-helper.c
  234. qemu-char.c
  235. qemu-char.h
  236. qemu-common.h
  237. qemu-config.c
  238. qemu-config.h
  239. qemu-coroutine-int.h
  240. qemu-coroutine-io.c
  241. qemu-coroutine-lock.c
  242. qemu-coroutine-sleep.c
  243. qemu-coroutine.c
  244. qemu-coroutine.h
  245. qemu-doc.texi
  246. qemu-error.c
  247. qemu-error.h
  248. qemu-file.h
  249. qemu-ga.c
  250. qemu-img-cmds.hx
  251. qemu-img.c
  252. qemu-img.texi
  253. qemu-io.c
  254. qemu-lock.h
  255. qemu-log.c
  256. qemu-log.h
  257. qemu-nbd.c
  258. qemu-nbd.texi
  259. qemu-objects.h
  260. qemu-option-internal.h
  261. qemu-option.c
  262. qemu-option.h
  263. qemu-options-wrapper.h
  264. qemu-options.h
  265. qemu-options.hx
  266. qemu-os-posix.h
  267. qemu-os-win32.h
  268. qemu-pixman.c
  269. qemu-pixman.h
  270. qemu-progress.c
  271. qemu-queue.h
  272. qemu-seccomp.c
  273. qemu-seccomp.h
  274. qemu-sockets.c
  275. qemu-tech.texi
  276. qemu-thread-posix.c
  277. qemu-thread-posix.h
  278. qemu-thread-win32.c
  279. qemu-thread-win32.h
  280. qemu-thread.h
  281. qemu-timer-common.c
  282. qemu-timer.c
  283. qemu-timer.h
  284. qemu-tls.h
  285. qemu-tool.c
  286. qemu-user.c
  287. qemu-x509.h
  288. qemu-xattr.h
  289. qemu.sasl
  290. qemu_socket.h
  291. qerror.c
  292. qerror.h
  293. qfloat.c
  294. qfloat.h
  295. qint.c
  296. qint.h
  297. qjson.c
  298. qjson.h
  299. qlist.c
  300. qlist.h
  301. qmp-commands.hx
  302. qmp.c
  303. qobject.h
  304. qstring.c
  305. qstring.h
  306. qtest.c
  307. qtest.h
  308. range.h
  309. readline.c
  310. readline.h
  311. README
  312. rules.mak
  313. s390-dis.c
  314. s390.ld
  315. savevm.c
  316. sh4-dis.c
  317. softmmu-semi.h
  318. softmmu_defs.h
  319. softmmu_exec.h
  320. softmmu_header.h
  321. softmmu_template.h
  322. sparc-dis.c
  323. sparc.ld
  324. sparc64.ld
  325. spice-qemu-char.c
  326. sysemu.h
  327. tcg-runtime.c
  328. tci-dis.c
  329. tci.c
  330. thread-pool.c
  331. thread-pool.h
  332. thunk.c
  333. thunk.h
  334. TODO
  335. trace-events
  336. translate-all.c
  337. uboot_image.h
  338. uri.c
  339. uri.h
  340. user-exec.c
  341. VERSION
  342. version.rc
  343. vgafont.h
  344. vl.c
  345. vmstate.h
  346. x86_64.ld
  347. xen-all.c
  348. xen-mapcache.c
  349. xen-mapcache.h
  350. xen-stub.c