mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
lib: introduce guestfs_int_make_pid_path()
Introduce a small function for creating pathnames for PID files. guestfs_int_make_pid_path() is something of an amalgamation of guestfs_int_make_temp_path() [1] and guestfs_int_create_socketname() [2]: - it creates a pathname under sockdir, like [2], - it uses the handle's unique counter, like [1], - it takes a name like both [1] and [2], but the name is not size-limited like in [2], plus we hardcode the suffix from [1] as ".pid". Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2184967 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Richard W.M. Jones <rjones@redhat.com> Message-Id: <20230714132213.96616-7-lersek@redhat.com>
This commit is contained in:
@@ -669,6 +669,7 @@ extern int guestfs_int_lazy_make_tmpdir (guestfs_h *g);
|
||||
extern int guestfs_int_lazy_make_sockdir (guestfs_h *g);
|
||||
extern char *guestfs_int_make_temp_path (guestfs_h *g, const char *name, const char *extension);
|
||||
extern int guestfs_int_create_socketname (guestfs_h *g, const char *filename, char (*sockname)[UNIX_PATH_MAX]);
|
||||
extern char *guestfs_int_make_pid_path (guestfs_h *g, const char *name);
|
||||
extern char *guestfs_int_lazy_make_supermin_appliance_dir (guestfs_h *g);
|
||||
extern void guestfs_int_remove_tmpdir (guestfs_h *g);
|
||||
extern void guestfs_int_remove_sockdir (guestfs_h *g);
|
||||
|
||||
@@ -279,6 +279,21 @@ guestfs_int_create_socketname (guestfs_h *g, const char *filename,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate unique paths for PID files.
|
||||
*
|
||||
* Returns a unique path or NULL on error. On success, the pathname points
|
||||
* under sockdir and not tmpdir; daemons that write PID files after dropping
|
||||
* privileges may not have access to tmpdir.
|
||||
*/
|
||||
char *
|
||||
guestfs_int_make_pid_path (guestfs_h *g, const char *name)
|
||||
{
|
||||
if (guestfs_int_lazy_make_sockdir (g) < 0)
|
||||
return NULL;
|
||||
return safe_asprintf (g, "%s/%s%d.pid", g->sockdir, name, ++g->unique);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the supermin appliance directory under cachedir, if it does
|
||||
* not exist.
|
||||
|
||||
Reference in New Issue
Block a user