virfile: Modernize definition of virFileOpenForked/virFileOpenForceOwnerMode/virFileOpenAs

Declare one argument per line and one variable per line and use boolean
operators at the end of the line rather than at the beginning.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Peter Krempa 2024-05-22 17:30:50 +02:00
parent cb78302a51
commit f2648fca1a

View File

@ -2330,8 +2330,12 @@ virFileAccessibleAs(const char *path, int mode,
* opened as "fd" if it's not correct AND the flags say it should be * opened as "fd" if it's not correct AND the flags say it should be
* forced. */ * forced. */
static int static int
virFileOpenForceOwnerMode(const char *path, int fd, mode_t mode, virFileOpenForceOwnerMode(const char *path,
uid_t uid, gid_t gid, unsigned int flags) int fd,
mode_t mode,
uid_t uid,
gid_t gid,
unsigned int flags)
{ {
int ret = 0; int ret = 0;
struct stat st; struct stat st;
@ -2381,11 +2385,16 @@ virFileOpenForceOwnerMode(const char *path, int fd, mode_t mode,
* buildVol backend function expects the file to be deleted on error. * buildVol backend function expects the file to be deleted on error.
*/ */
static int static int
virFileOpenForked(const char *path, int openflags, mode_t mode, virFileOpenForked(const char *path,
uid_t uid, gid_t gid, unsigned int flags) int openflags,
mode_t mode,
uid_t uid,
gid_t gid,
unsigned int flags)
{ {
pid_t pid; pid_t pid;
int status = 0, ret = 0; int status = 0;
int ret = 0;
int recvfd_errno = 0; int recvfd_errno = 0;
int fd = -1; int fd = -1;
int pair[2] = { -1, -1 }; int pair[2] = { -1, -1 };
@ -2546,10 +2555,15 @@ virFileOpenForked(const char *path, int openflags, mode_t mode,
* expects the file to be deleted on error. * expects the file to be deleted on error.
*/ */
int int
virFileOpenAs(const char *path, int openflags, mode_t mode, virFileOpenAs(const char *path,
uid_t uid, gid_t gid, unsigned int flags) int openflags,
mode_t mode,
uid_t uid,
gid_t gid,
unsigned int flags)
{ {
int ret = 0, fd = -1; int ret = 0;
int fd = -1;
bool created = false; bool created = false;
/* allow using -1 to mean "current value" */ /* allow using -1 to mean "current value" */
@ -2563,9 +2577,9 @@ virFileOpenAs(const char *path, int openflags, mode_t mode,
if (!(flags & (VIR_FILE_OPEN_NOFORK|VIR_FILE_OPEN_FORK))) if (!(flags & (VIR_FILE_OPEN_NOFORK|VIR_FILE_OPEN_FORK)))
flags |= VIR_FILE_OPEN_NOFORK|VIR_FILE_OPEN_FORK; flags |= VIR_FILE_OPEN_NOFORK|VIR_FILE_OPEN_FORK;
if ((flags & VIR_FILE_OPEN_NOFORK) if ((flags & VIR_FILE_OPEN_NOFORK) ||
|| (geteuid() != 0) (geteuid() != 0) ||
|| ((uid == 0) && (gid == 0))) { ((uid == 0) && (gid == 0))) {
if ((fd = open(path, openflags, mode)) < 0) { if ((fd = open(path, openflags, mode)) < 0) {
ret = -errno; ret = -errno;