mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
src: conditionalize use of chown & stat constants
chown and some stat constants are not available on the Windows platform. Reviewed-by: Pavel Hrdina <phrdina@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
6dd8913207
commit
a464220430
@ -710,7 +710,11 @@ virSecurityDACSetOwnershipInternal(const virSecurityDACData *priv,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
rc = ENOSYS;
|
||||||
|
#else /* !WIN32 */
|
||||||
rc = chown(path, uid, gid);
|
rc = chown(path, uid, gid);
|
||||||
|
#endif /* !WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
@ -79,6 +79,9 @@
|
|||||||
|
|
||||||
VIR_LOG_INIT("storage.storage_util");
|
VIR_LOG_INIT("storage.storage_util");
|
||||||
|
|
||||||
|
#ifndef S_IRWXUGO
|
||||||
|
# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* virStorageBackendNamespaceInit:
|
/* virStorageBackendNamespaceInit:
|
||||||
* @poolType: virStoragePoolType
|
* @poolType: virStoragePoolType
|
||||||
|
@ -95,6 +95,17 @@
|
|||||||
|
|
||||||
VIR_LOG_INIT("util.file");
|
VIR_LOG_INIT("util.file");
|
||||||
|
|
||||||
|
#ifndef S_ISUID
|
||||||
|
# define S_ISUID 04000
|
||||||
|
#endif
|
||||||
|
#ifndef S_ISGID
|
||||||
|
# define S_ISGID 02000
|
||||||
|
#endif
|
||||||
|
#ifndef S_ISVTX
|
||||||
|
# define S_ISVTX 01000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef O_DIRECT
|
#ifndef O_DIRECT
|
||||||
# define O_DIRECT 0
|
# define O_DIRECT 0
|
||||||
#endif
|
#endif
|
||||||
@ -314,7 +325,7 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned int flags)
|
|||||||
virFileWrapperFdFree(ret);
|
virFileWrapperFdFree(ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#else
|
#else /* WIN32 */
|
||||||
virFileWrapperFdPtr
|
virFileWrapperFdPtr
|
||||||
virFileWrapperFdNew(int *fd G_GNUC_UNUSED,
|
virFileWrapperFdNew(int *fd G_GNUC_UNUSED,
|
||||||
const char *name G_GNUC_UNUSED,
|
const char *name G_GNUC_UNUSED,
|
||||||
@ -324,7 +335,7 @@ virFileWrapperFdNew(int *fd G_GNUC_UNUSED,
|
|||||||
_("virFileWrapperFd unsupported on this platform"));
|
_("virFileWrapperFd unsupported on this platform"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* WIN32 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virFileWrapperFdClose:
|
* virFileWrapperFdClose:
|
||||||
@ -479,7 +490,7 @@ int virFileFlock(int fd, bool lock, bool shared)
|
|||||||
return flock(fd, LOCK_UN);
|
return flock(fd, LOCK_UN);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else /* WIN32 */
|
||||||
|
|
||||||
int virFileLock(int fd G_GNUC_UNUSED,
|
int virFileLock(int fd G_GNUC_UNUSED,
|
||||||
bool shared G_GNUC_UNUSED,
|
bool shared G_GNUC_UNUSED,
|
||||||
@ -507,7 +518,7 @@ int virFileFlock(int fd G_GNUC_UNUSED,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif /* WIN32 */
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -1581,10 +1592,12 @@ virFileResolveLinkHelper(const char *linkpath,
|
|||||||
if (g_lstat(linkpath, &st) < 0)
|
if (g_lstat(linkpath, &st) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
if (!S_ISLNK(st.st_mode)) {
|
if (!S_ISLNK(st.st_mode)) {
|
||||||
*resultpath = g_strdup(linkpath);
|
*resultpath = g_strdup(linkpath);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif /* WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
*resultpath = virFileCanonicalizePath(linkpath);
|
*resultpath = virFileCanonicalizePath(linkpath);
|
||||||
@ -1630,10 +1643,17 @@ virFileIsLink(const char *linkpath)
|
|||||||
{
|
{
|
||||||
GStatBuf st;
|
GStatBuf st;
|
||||||
|
|
||||||
|
/* Still do this on Windows so we report
|
||||||
|
* errors like ENOENT, etc
|
||||||
|
*/
|
||||||
if (g_lstat(linkpath, &st) < 0)
|
if (g_lstat(linkpath, &st) < 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
return S_ISLNK(st.st_mode) != 0;
|
return S_ISLNK(st.st_mode) != 0;
|
||||||
|
#else /* WIN32 */
|
||||||
|
return 0;
|
||||||
|
#endif /* WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2615,6 +2635,7 @@ virDirCreateNoFork(const char *path,
|
|||||||
virReportSystemError(errno, _("stat of '%s' failed"), path);
|
virReportSystemError(errno, _("stat of '%s' failed"), path);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
# ifndef WIN32
|
||||||
if (((uid != (uid_t) -1 && st.st_uid != uid) ||
|
if (((uid != (uid_t) -1 && st.st_uid != uid) ||
|
||||||
(gid != (gid_t) -1 && st.st_gid != gid))
|
(gid != (gid_t) -1 && st.st_gid != gid))
|
||||||
&& (chown(path, uid, gid) < 0)) {
|
&& (chown(path, uid, gid) < 0)) {
|
||||||
@ -2623,6 +2644,7 @@ virDirCreateNoFork(const char *path,
|
|||||||
path, (unsigned int) uid, (unsigned int) gid);
|
path, (unsigned int) uid, (unsigned int) gid);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
# endif /* !WIN32 */
|
||||||
if (mode != (mode_t) -1 && chmod(path, mode) < 0) {
|
if (mode != (mode_t) -1 && chmod(path, mode) < 0) {
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
@ -2959,6 +2981,7 @@ void virDirClose(DIR **dirp)
|
|||||||
*
|
*
|
||||||
* Returns -1 on error, with error already reported, 0 on success.
|
* Returns -1 on error, with error already reported, 0 on success.
|
||||||
*/
|
*/
|
||||||
|
#ifndef WIN32
|
||||||
int virFileChownFiles(const char *name,
|
int virFileChownFiles(const char *name,
|
||||||
uid_t uid,
|
uid_t uid,
|
||||||
gid_t gid)
|
gid_t gid)
|
||||||
@ -2999,6 +3022,19 @@ int virFileChownFiles(const char *name,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else /* WIN32 */
|
||||||
|
|
||||||
|
int virFileChownFiles(const char *name,
|
||||||
|
uid_t uid,
|
||||||
|
gid_t gid)
|
||||||
|
{
|
||||||
|
virReportSystemError(ENOSYS,
|
||||||
|
_("cannot chown '%s' to (%u, %u)"),
|
||||||
|
name, (unsigned int) uid,
|
||||||
|
(unsigned int) gid);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif /* WIN32 */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virFileMakePathHelper(char *path, mode_t mode)
|
virFileMakePathHelper(char *path, mode_t mode)
|
||||||
|
Loading…
Reference in New Issue
Block a user