qemu-e2k/util
Marc-André Lureau 9e6bdef224 util: add qemu_write_pidfile()
There are variants of qemu_create_pidfile() in qemu-pr-helper and
qemu-ga. Let's have a common implementation in libqemuutil.

The code is initially based from pr-helper write_pidfile(), with
various improvements and suggestions from Daniel Berrangé:

  QEMU will leave the pidfile existing on disk when it exits which
  initially made me think it avoids the deletion race. The app
  managing QEMU, however, may well delete the pidfile after it has
  seen QEMU exit, and even if the app locks the pidfile before
  deleting it, there is still a race.

  eg consider the following sequence

        QEMU 1        libvirtd        QEMU 2

  1.    lock(pidfile)

  2.    exit()

  3.                 open(pidfile)

  4.                 lock(pidfile)

  5.                                  open(pidfile)

  6.                 unlink(pidfile)

  7.                 close(pidfile)

  8.                                  lock(pidfile)

  IOW, at step 8 the new QEMU has successfully acquired the lock, but
  the pidfile no longer exists on disk because it was deleted after
  the original QEMU exited.

  While we could just say no external app should ever delete the
  pidfile, I don't think that is satisfactory as people don't read
  docs, and admins don't like stale pidfiles being left around on
  disk.

  To make this robust, I think we might want to copy libvirt's
  approach to pidfile acquisition which runs in a loop and checks that
  the file on disk /after/ acquiring the lock matches the file that
  was locked. Then we could in fact safely let QEMU delete its own
  pidfiles on clean exit..

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20180831145314.14736-2-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-10-02 18:47:55 +02:00
..
Makefile.objs util: add atomic64 2018-10-02 18:47:55 +02:00
acl.c Drop Emacs local variables lists redundant with .dir-locals.el 2016-07-12 16:19:16 +02:00
aio-posix.c aio-posix: do skip system call if ctx->notifier polling succeeds 2018-09-26 10:46:21 +08:00
aio-wait.c block: Use a single global AioWait 2018-09-25 15:50:15 +02:00
aio-win32.c aio: Do aio_notify_accept only during blocking aio_poll 2018-08-15 10:12:35 +08:00
aiocb.c block: move AioContext, QEMUTimer, main-loop to libqemuutil 2017-02-21 11:14:07 +00:00
async.c util/async: use qemu_aio_coroutine_enter in co_schedule_bh_cb 2018-09-25 15:50:15 +02:00
atomic64.c util: add atomic64 2018-10-02 18:47:55 +02:00
base64.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
bitmap.c bitmap: provide to_le/from_le helpers 2017-09-22 14:11:25 +02:00
bitops.c bitmap: remove BITOP_WORD() 2017-09-22 14:11:23 +02:00
buffer.c qemu-common: stop including qemu/host-utils.h from qemu-common.h 2016-05-19 16:42:28 +02:00
bufferiszero.c util: Introduce include/qemu/cpuid.h 2017-07-24 12:42:55 +01:00
cacheinfo.c util: add atomic64 2018-10-02 18:47:55 +02:00
compatfd.c cpus: remove ugly cast on sigbus_handler 2017-03-03 16:40:02 +01:00
coroutine-sigaltstack.c coroutine-sigaltstack: use helper for allocating stack memory 2016-09-29 14:13:39 +02:00
coroutine-ucontext.c build: try improve handling of clang warnings 2018-03-12 08:59:03 +01:00
coroutine-win32.c coroutine: add a macro for the coroutine stack size 2016-09-29 14:13:39 +02:00
crc32c.c util: Clean up includes 2016-02-04 17:01:04 +00:00
cutils.c cutils: Provide strchrnul 2018-06-29 12:32:10 +02:00
drm.c util: promote qemu_egl_rendernode_open() to libqemuutil 2018-08-27 10:51:44 +02:00
envlist.c util: Use g_malloc/g_free in envlist.c 2017-05-07 09:57:51 +03:00
error.c error: Implement the warn and free Error functions 2017-07-13 13:50:19 +02:00
event_notifier-posix.c Revert "qemu: add a cleanup callback function to EventNotifier" 2018-01-24 19:20:19 +02:00
event_notifier-win32.c Revert "qemu: add a cleanup callback function to EventNotifier" 2018-01-24 19:20:19 +02:00
fifo8.c migration: consolidate VMStateField.start 2017-02-13 17:27:13 +00:00
getauxval.c util: Clean up includes 2016-02-04 17:01:04 +00:00
hbitmap.c hbitmap: Add @advance param to hbitmap_iter_next() 2018-06-18 17:04:55 +02:00
hexdump.c util: Improved qemu_hexmap() to include an ascii dump of the buffer 2016-04-06 09:52:07 +08:00
host-utils.c host-utils: Implement unsigned quadword left/right shift and unit tests 2017-01-31 10:10:14 +11:00
id.c util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
iohandler.c block: move AioContext, QEMUTimer, main-loop to libqemuutil 2017-02-21 11:14:07 +00:00
iov.c util: Fix assertion in iov_copy() upon zero 'bytes' and non-zero 'offset' 2016-08-03 18:44:57 +02:00
iova-tree.c util: remove redundant include of glib.h and add osdep.h 2018-06-29 12:22:28 +01:00
keyval.c qobject: Replace qobject_incref/QINCREF qobject_decref/QDECREF 2018-05-04 08:27:53 +02:00
lockcnt.c qemu-thread: optimize QemuLockCnt with futexes on Linux 2017-01-16 13:25:18 +00:00
log.c tcg: Optionally log FPU state in TCG -d cpu logging 2018-05-15 14:58:44 +01:00
main-loop.c main-loop: drop spin_counter 2018-06-01 16:01:29 +01:00
memfd.c hostmem-memfd: add checks before adding hostmem-memfd & properties 2018-10-02 18:47:55 +02:00
mmap-alloc.c Make qemu_mempath_getpagesize() accept NULL 2018-04-27 18:05:22 +10:00
module.c module: Use QEMU_MODULE_DIR as a search path 2018-08-23 18:46:25 +02:00
notify.c util: Clean up includes 2016-02-04 17:01:04 +00:00
osdep.c glib: bump min required glib library version to 2.40 2018-06-29 12:22:28 +01:00
oslib-posix.c util: add qemu_write_pidfile() 2018-10-02 18:47:55 +02:00
oslib-win32.c util: add qemu_write_pidfile() 2018-10-02 18:47:55 +02:00
pagesize.c util: move qemu_real_host_page_size/mask to osdep.h 2017-10-10 09:45:00 -07:00
path.c util: Removed unneeded header from path.c 2017-03-14 13:26:37 +01:00
qdist.c qdist: return "(empty)" instead of NULL when printing an empty dist 2016-08-03 18:44:56 +02:00
qemu-config.c block: Add block-specific QDict header 2018-06-15 14:49:44 +02:00
qemu-coroutine-io.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
qemu-coroutine-lock.c coroutine: avoid co_queue_wakeup recursion 2018-03-27 13:05:28 +01:00
qemu-coroutine-sleep.c coroutine: simplify co_aio_sleep_ns() prototype 2017-12-19 09:25:27 +00:00
qemu-coroutine.c block: Add missing locking in bdrv_co_drain_bh_cb() 2018-09-25 15:50:15 +02:00
qemu-error.c qemu-error: add {error, warn}_report_once_cond 2018-09-24 17:13:07 +02:00
qemu-openpty.c util: Clean up includes 2016-02-04 17:01:04 +00:00
qemu-option.c opts: remove redundant check for NULL parameter 2018-07-17 16:24:50 +02:00
qemu-progress.c progress: Show current progress on SIGINFO 2017-04-28 18:48:11 +02:00
qemu-sockets.c sockets: allow SocketAddress 'fd' to reference numeric file descriptors 2018-03-13 18:06:06 +00:00
qemu-thread-common.h QemuMutex: support --enable-debug-mutex 2018-06-28 19:05:32 +02:00
qemu-thread-posix.c qemu-thread: introduce qemu-thread-common.h 2018-06-28 19:05:31 +02:00
qemu-thread-win32.c qsp: QEMU's Synchronization Profiler 2018-08-23 18:46:25 +02:00
qemu-timer-common.c util: Clean up includes 2016-02-04 17:01:04 +00:00
qemu-timer.c timer: remove replay clock probe in deadline calculation 2018-07-30 14:00:11 +02:00
qht.c qht: constify arguments to some internal functions 2018-09-26 08:55:54 -07:00
qsp.c qsp: use atomic64 accessors 2018-10-02 18:47:55 +02:00
range.c range: Replace internal representation of Range 2016-07-04 16:49:33 +03:00
rcu.c membarrier: introduce qemu/sys_membarrier.h 2018-03-12 16:12:47 +01:00
readline.c readline: don't free completions in readline_free() 2018-02-05 13:54:39 +01:00
stats64.c util/stats64: Fix min/max comparisons 2017-11-15 09:34:51 +01:00
sys_membarrier.c sys_membarrier: fix up include directives 2018-04-05 14:37:38 +02:00
systemd.c qemu-ga: obey LISTEN_PID when using systemd socket activation 2017-03-19 11:12:12 +01:00
thread-pool.c thread-pool: add missing qemu_bh_cancel in completion function 2017-03-17 12:54:21 +01:00
throttle.c throttle: Assert that bkt->max is valid in throttle_compute_wait() 2017-09-26 14:46:23 +02:00
timed-average.c Fix some typos found by codespell 2016-05-18 15:04:27 +03:00
trace-events aio-posix: compute timeout before polling 2018-09-26 10:46:21 +08:00
unicode.c json: Reject invalid UTF-8 sequences 2018-08-24 20:26:37 +02:00
uri.c cutils: Provide strchrnul 2018-06-29 12:32:10 +02:00
uuid.c util: add is_equal to UUID API 2017-12-20 22:01:24 +08:00
vfio-helpers.c replace functions which are only available in glib-2.24 2018-05-20 08:55:01 +03:00