qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/7] util: Introduce qemu_get_runtime_dir()
@ 2024-07-16  7:27 Akihiko Odaki
  2024-07-16  7:27 ` [PATCH v4 1/7] " Akihiko Odaki
                   ` (9 more replies)
  0 siblings, 10 replies; 22+ messages in thread
From: Akihiko Odaki @ 2024-07-16  7:27 UTC (permalink / raw)
  To: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
	Konstantin Kostiuk, Michael Roth, Paolo Bonzini, Fam Zheng,
	Dr . David Alan Gilbert, Stefan Hajnoczi, Gerd Hoffmann,
	Stefan Weil, Yan Vugenfirer, Akihiko Odaki

qemu_get_runtime_dir() returns a dynamically allocated directory path
that is appropriate for storing runtime files. It corresponds to "run"
directory in Unix.

With a tree-wide search, it was found that there are several cases
where such a functionality is implemented so let's have one as a common
utlity function.

A notable feature of qemu_get_runtime_dir() is that it uses
$XDG_RUNTIME_DIR if available. While the function is often called by
executables which requires root privileges, it is still possible that
they are called from a user without privilege to write the system
runtime directory. In fact, I decided to write this patch when I ran
virtiofsd in a Linux namespace created by a normal user and realized
it tries to write the system runtime directory, not writable in this
case. $XDG_RUNTIME_DIR should provide a writable directory in such
cases.

This function does not use qemu_get_local_state_dir() or its logic
for Windows. Actually the implementation of qemu_get_local_state_dir()
for Windows seems not right as it calls g_get_system_data_dirs(),
which refers to $XDG_DATA_DIRS. In Unix terminology, it is basically
"/usr/share", not "/var", which qemu_get_local_state_dir() is intended
to provide. Instead, this function try to use the following in order:
- $XDG_RUNTIME_DIR
- LocalAppData folder
- get_relocated_path(CONFIG_QEMU_LOCALSTATEDIR "/run")

This function does not use g_get_user_runtime_dir() either as it
falls back to g_get_user_cache_dir() when $XDG_DATA_DIRS is not
available. In the case, we rather use:
get_relocated_path(CONFIG_QEMU_LOCALSTATEDIR "/run")

V2 -> V3:
  Rebase to the current master.
  Dropped patch "qga: Remove platform GUID definitions" since it is
  irrelevant.

V1 -> V2:
  Rebased to the current master since Patchew complains.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
Changes in v4:
- Rebased.
- Link to v3: https://lore.kernel.org/r/20230921075425.16738-1-akihiko.odaki@daynix.com

---
Akihiko Odaki (7):
      util: Introduce qemu_get_runtime_dir()
      ivshmem-server: Use qemu_get_runtime_dir()
      qga: Use qemu_get_runtime_dir()
      scsi: Use qemu_get_runtime_dir()
      module: Use qemu_get_runtime_dir()
      util: Remove qemu_get_local_state_dir()
      spice-app: Use qemu_get_runtime_dir()

 include/qemu/osdep.h          | 10 +++++++---
 contrib/ivshmem-server/main.c | 20 ++++++++++++++++----
 qga/main.c                    |  9 ++++-----
 scsi/qemu-pr-helper.c         |  6 +++---
 ui/spice-app.c                |  4 ++--
 util/module.c                 |  3 ++-
 util/oslib-posix.c            |  9 +++++++--
 util/oslib-win32.c            | 24 ++++++++++++++++++++----
 8 files changed, 61 insertions(+), 24 deletions(-)
---
base-commit: f2cb4026fccfe073f84a4b440e41d3ed0c3134f6
change-id: 20240218-run-6f0d91ec7439

Best regards,
-- 
Akihiko Odaki <akihiko.odaki@daynix.com>



^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2025-01-11  5:15 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-16  7:27 [PATCH v4 0/7] util: Introduce qemu_get_runtime_dir() Akihiko Odaki
2024-07-16  7:27 ` [PATCH v4 1/7] " Akihiko Odaki
2024-07-16  9:53   ` Daniel P. Berrangé
2024-07-16 10:52     ` Akihiko Odaki
2024-07-16 10:54       ` Daniel P. Berrangé
2024-07-16 11:27         ` Akihiko Odaki
2024-07-16  7:27 ` [PATCH v4 2/7] ivshmem-server: Use qemu_get_runtime_dir() Akihiko Odaki
2024-07-16  7:27 ` [PATCH v4 3/7] qga: " Akihiko Odaki
2024-07-16  7:27 ` [PATCH v4 4/7] scsi: " Akihiko Odaki
2024-07-16  7:27 ` [PATCH v4 5/7] module: " Akihiko Odaki
2024-07-16  7:27 ` [PATCH v4 6/7] util: Remove qemu_get_local_state_dir() Akihiko Odaki
2024-07-16  7:27 ` [PATCH v4 7/7] spice-app: Use qemu_get_runtime_dir() Akihiko Odaki
2024-07-16  8:06 ` [PATCH v4 0/7] util: Introduce qemu_get_runtime_dir() Michael Tokarev
2024-07-16  9:32   ` Akihiko Odaki
2024-07-16  9:41     ` Michael Tokarev
2024-07-16  9:56   ` Daniel P. Berrangé
2024-07-16 10:43     ` Paolo Bonzini
2024-07-16 12:45       ` Akihiko Odaki
2024-07-16 13:29         ` Paolo Bonzini
2024-07-16 13:35           ` Akihiko Odaki
2024-07-16  8:45 ` Paolo Bonzini
2025-01-11  5:15 ` Akihiko Odaki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).