Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpine linux (musl libc) fixes #557

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
17 changes: 16 additions & 1 deletion open-vm-tools/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@ AC_CHECK_FUNCS(

AC_CHECK_FUNCS([ecvt])
AC_CHECK_FUNCS([fcvt])
AC_CHECK_FUNCS([getifaddrs getauxval issetugid __secure_getenv])

AC_CHECK_FUNC([mkdtemp], [have_mkdtemp=yes])

Expand Down Expand Up @@ -1378,10 +1379,13 @@ fi
###

AC_CHECK_HEADERS([crypt.h])
AC_CHECK_HEADERS([ifaddrs.h])
AC_CHECK_HEADERS([inttypes.h])
AC_CHECK_HEADERS([stdint.h])
AC_CHECK_HEADERS([stdlib.h])
AC_CHECK_HEADERS([wchar.h])
AC_CHECK_HEADERS([net/if.h])
AC_CHECK_HEADERS([sys/auxv.h])
AC_CHECK_HEADERS([sys/inttypes.h])
AC_CHECK_HEADERS([sys/io.h])
AC_CHECK_HEADERS([sys/param.h]) # Required to make the sys/user.h check work correctly on FreeBSD
Expand Down Expand Up @@ -1441,6 +1445,7 @@ AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_CHECK_MEMBERS([struct stat.st_rdev])
AC_CHECK_MEMBERS([struct timespec.tv_sec],[],[],[[#include <time.h>]])
AC_HEADER_TIME
AC_STRUCT_TM
AC_C_VOLATILE
Expand All @@ -1451,7 +1456,17 @@ AC_C_VOLATILE

### General flags / actions
CFLAGS="$CFLAGS -Wall"
CFLAGS="$CFLAGS -Werror"
AC_ARG_ENABLE(
werror,
AS_HELP_STRING(
[--disable-werror],
[disable compilation with -Werror]),
[enable_werror="$enableval"],
[enable_werror="yes"])

if test "$enable_werror" = "yes"; then
CFLAGS="$CFLAGS -Werror"
fi

# -Wno-unknown-pragmas is due to gcc not understanding '#pragma ident'
# in Xlib.h on OpenSolaris.
Expand Down
2 changes: 1 addition & 1 deletion open-vm-tools/lib/asyncsocket/asyncsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
#include "random.h"
#include "asyncsocket.h"
#include "asyncSocketBase.h"
#include "poll.h"
#include "vm_poll.h"
#include "log.h"
#include "err.h"
#include "hostinfo.h"
Expand Down
8 changes: 5 additions & 3 deletions open-vm-tools/lib/err/errPosix.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ ErrErrno2String(Err_Number errorNumber, // IN
{
char *p;

#if defined(__linux__) && !defined(__ANDROID__)
#if defined(__GLIBC__)
p = strerror_r(errorNumber, buf, bufSize);
#else
p = strerror(errorNumber);
#endif
if (strerror_r(errorNumber, buf, bufSize) != 0)
snprintf(buf, bufSize, "unknown error %i", errorNumber);
p = buf;
#endif /* defined __GLIBC__ */
ASSERT(p != NULL);
return p;
}
2 changes: 1 addition & 1 deletion open-vm-tools/lib/file/fileIOPosix.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static AlignedPool alignedPool;
* are not available in any header file.
*/

#if defined(__linux__) && !defined(__ANDROID__)
#if defined(__linux__) && defined(__GLIBC__)
#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
/*
* We want preadv/pwritev. But due to FOB=64, the symbols are -64.
Expand Down
2 changes: 1 addition & 1 deletion open-vm-tools/lib/hgfsServer/hgfsServer.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include "hgfsDirNotify.h"
#include "hgfsThreadpool.h"
#include "userlock.h"
#include "poll.h"
#include "vm_poll.h"
#include "mutexRankLib.h"
#include "vm_basic_asm.h"
#include "unicodeOperations.h"
Expand Down
8 changes: 5 additions & 3 deletions open-vm-tools/lib/hgfsServer/hgfsServerLinux.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ typedef struct DirectoryEntry {
#endif

/*
* ALLPERMS (mode 07777) and ACCESSPERMS (mode 0777) are not defined in the
* Solaris version of <sys/stat.h>.
* ALLPERMS (mode 07777) and ACCESSPERMS (mode 0777) are not specified in
* POSIX.
*/
#ifdef sun
#ifndef ACCESSPERMS
# define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO)
#endif
#ifndef ALLPERMS
# define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)
#endif

Expand Down
2 changes: 1 addition & 1 deletion open-vm-tools/lib/include/asyncsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ typedef struct AsyncSocket AsyncSocket;
* Or the client can specify its favorite poll class and locking behavior.
* Use of IVmdbPoll is only supported for regular sockets and for Attach.
*/
#include "poll.h"
#include "vm_poll.h"
struct IVmdbPoll;
typedef struct AsyncSocketPollParams {
int flags; /* Default 0, only POLL_FLAG_NO_BULL is valid */
Expand Down
1 change: 1 addition & 0 deletions open-vm-tools/lib/include/guest_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ Bool Gos_InSetArray(uint32 gos, const uint32 *set);
/* Linux */
#define STR_OS_ALMA_LINUX "almaLinux"
#define STR_OS_AMAZON_LINUX "amazonlinux"
#define STR_OS_ALPINE "Alpine"
#define STR_OS_ANNVIX "Annvix"
#define STR_OS_ARCH "Arch"
#define STR_OS_ARKLINUX "Arklinux"
Expand Down
8 changes: 1 addition & 7 deletions open-vm-tools/lib/include/hgfsUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@
# include <time.h>
# endif
# include "vm_basic_types.h"
# if !defined _STRUCT_TIMESPEC && \
!defined _TIMESPEC_DECLARED && \
!defined __timespec_defined && \
!defined sun && \
!defined __FreeBSD__ && \
!__APPLE__ && \
!defined _WIN32
# if !defined HAVE_STRUCT_TIMESPEC_TV_SEC
struct timespec {
time_t tv_sec;
long tv_nsec;
Expand Down
2 changes: 1 addition & 1 deletion open-vm-tools/lib/include/pollImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#define INCLUDE_ALLOW_USERLEVEL
#include "includeCheck.h"

#include "poll.h"
#include "vm_poll.h"
#include "vm_basic_asm.h"

#if defined(__cplusplus)
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions open-vm-tools/lib/misc/hostinfoPosix.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ typedef struct {

static const DistroInfo distroArray[] = {
{ "ALT", "/etc/altlinux-release" },
{ "Alpine", "/etc/alpine-release" },
{ "Annvix", "/etc/annvix-release" },
{ "Arch", "/etc/arch-release" },
{ "Arklinux", "/etc/arklinux-release" },
Expand Down Expand Up @@ -1254,6 +1255,7 @@ HostinfoSetSuseShortName(const ShortNameSet *entry, // IN:
static const ShortNameSet shortNameArray[] = {
/* Long distro name Short distro name Short name set function */
{ "almalinux", STR_OS_ALMA_LINUX, HostinfoGenericSetShortName },
{ "alpine", STR_OS_ALPINE, HostinfoGenericSetShortName},
{ "amazon", NULL, HostinfoSetAmazonShortName },
{ "annvix", STR_OS_ANNVIX, HostinfoGenericSetShortName },
{ "arch", STR_OS_ARCH, HostinfoGenericSetShortName },
Expand Down
30 changes: 14 additions & 16 deletions open-vm-tools/lib/misc/idLinux.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@
#include <sys/syscall.h>
#include <string.h>
#include <unistd.h>
#ifdef __linux__
#if defined(__GLIBC__) && \
(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16))
#ifdef HAVE_SYS_AUXV_H
#include <sys/auxv.h>
#endif
#endif
#ifdef __APPLE__
#include <sys/socket.h>
#include <TargetConditionals.h>
Expand Down Expand Up @@ -1025,31 +1022,32 @@ Id_EndSuperUser(uid_t uid) // IN:
static Bool
IdIsSetUGid(void)
{
#if defined(__ANDROID__)
/* Android does not have a secure_getenv, so be conservative. */
return TRUE;
#else
/*
* We use __secure_getenv, which returns NULL if the binary is
* setuid or setgid. Alternatives include,
* setuid or setgid, when issetugid or getauxval(AT_SECURE) is not
* available. Alternatives include,
*
* a) getauxval(AT_SECURE); not available until glibc 2.16.
* b) __libc_enable_secure; may not be exported.
* a) issetugid(); not (yet?) available in glibc.
* b) getauxval(AT_SECURE); not available until glibc 2.16.
* c) __libc_enable_secure; may not be exported.
*
* Use (a) when we are based on glibc 2.16, or newer.
* Use (b) when we are based on glibc 2.16, or newer.
*/

#if defined(__GLIBC__) && \
(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16))
#if HAVE_ISSETUGID
return issetugid();
#elif HAVE_GETAUXVAL
return getauxval(AT_SECURE) != 0;
#else
#elif HAVE___SECURE_GETENV
static const char envName[] = "VMW_SETUGID_TEST";

if (setenv(envName, "1", TRUE) == -1) {
return TRUE; /* Conservative */
}
return __secure_getenv(envName) == NULL;
#endif
#else
/* Android does not have a secure_getenv, so be conservative. */
return TRUE;
#endif
}
#endif
Expand Down
11 changes: 6 additions & 5 deletions open-vm-tools/lib/nicInfo/nicInfoPosix.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@
#include <sys/stat.h>
#include <errno.h>
#include <limits.h>
#if defined(__FreeBSD__) || defined(__APPLE__)
#if HAVE_SYS_SYSCTL_H
# include <sys/sysctl.h>
#endif
#if HAVE_IFADDRS_H
# include <ifaddrs.h>
#endif
#if HAVE_NET_IF_H
# include <net/if.h>
#endif
#ifndef NO_DNET
Expand Down Expand Up @@ -499,10 +503,7 @@ GuestInfoGetNicInfo(unsigned int maxIPv4Routes,
*
******************************************************************************
*/
#if defined(__FreeBSD__) || \
defined(__APPLE__) || \
defined(USERWORLD) || \
(defined(__linux__) && defined(NO_DNET))
#if defined(NO_DNET) && defined(HAVE_GETIFADDRS)

char *
GuestInfoGetPrimaryIP(void)
Expand Down
2 changes: 1 addition & 1 deletion open-vm-tools/lib/rpcIn/rpcin.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

#if defined(VMTOOLS_USE_VSOCKET)
# include <glib.h>
# include "poll.h"
# include "vm_poll.h"
# include "asyncsocket.h"
# include "vmci_defs.h"
#include "dataMap.h"
Expand Down
3 changes: 1 addition & 2 deletions open-vm-tools/services/plugins/dndcp/dnd/dndLinux.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

#define DND_ROOTDIR_PERMS (S_IRWXU | S_IRWXG | S_IRWXO)
#define DND_STAGINGDIR_PERMS (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
#ifdef sun
#ifndef ACCESSPERMS
#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO)
#endif
#ifdef __ANDROID__
Expand All @@ -62,7 +62,6 @@
*/
#define NO_SETMNTENT
#define NO_ENDMNTENT
#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO)
#endif


Expand Down
2 changes: 1 addition & 1 deletion open-vm-tools/services/plugins/vix/vixTools.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#include <unistd.h>
#endif

#if defined(sun) || defined(__FreeBSD__) || defined(__APPLE__)
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion open-vm-tools/vgauth/common/VGAuthLog.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ LogErrorPosixCodeV(int code,
g_vsnprintf(buf, sizeof buf, fmt, args);
buf[sizeof buf - 1] = '\0';

#ifdef sun
#if !defined(__GLIBC__)
strerror_r(code, errMsg, sizeof errMsg);
g_warning("[function %s, file %s, line %d], %s, [errno = %d], %s\n",
func, file, line, buf, code, errMsg);
Expand Down
12 changes: 6 additions & 6 deletions open-vm-tools/vmhgfs-fuse/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ static int
HgfsDoRead(HgfsHandle handle, // IN: Handle for this file
char *buf, // OUT: Buffer to copy data into
size_t count, // IN: Number of bytes to read
loff_t offset) // IN: Offset at which to read
off64_t offset) // IN: Offset at which to read
{
HgfsReq *req;
HgfsOp opUsed;
Expand Down Expand Up @@ -708,11 +708,11 @@ ssize_t
HgfsRead(struct fuse_file_info *fi, // IN: File info struct
char *buf, // OUT: User buffer to copy data into
size_t count, // IN: Number of bytes to read
loff_t offset) // IN: Offset at which to read
off64_t offset) // IN: Offset at which to read
{
int result = 0;
char *buffer = buf;
loff_t curOffset = offset;
off64_t curOffset = offset;
size_t nextCount, remainingCount = count;
uint32 maxIOSize = HgfsMaxIOSize();

Expand Down Expand Up @@ -769,7 +769,7 @@ static int
HgfsDoWrite(HgfsHandle handle, // IN: Handle for the file
const char *buf, // IN: Buffer containing data
size_t count, // IN: Number of bytes to write
loff_t offset) // IN: Offset to begin writing at
off64_t offset) // IN: Offset to begin writing at
{
HgfsReq *req;
int result = 0;
Expand Down Expand Up @@ -893,11 +893,11 @@ ssize_t
HgfsWrite(struct fuse_file_info *fi, // IN: File info structure
const char *buf, // OUT: User buffer to copy data into
size_t count, // IN: Number of bytes to read
loff_t offset) // IN: Offset at which to read
off64_t offset) // IN: Offset at which to read
{
int result;
const char *buffer = buf;
loff_t curOffset = offset;
off64_t curOffset = offset;
size_t nextCount, remainingCount = count;
ssize_t bytesWritten = 0;
uint32 maxIOSize = HgfsMaxIOSize();
Expand Down
2 changes: 1 addition & 1 deletion open-vm-tools/vmhgfs-fuse/fsutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ HgfsStatusConvertToLinux(HgfsStatus hgfsStatus) // IN: Status code to convert
unsigned long
HgfsCalcBlockSize(uint64 tsize)
{
loff_t used = (tsize + 511) >> 9;
off64_t used = (tsize + 511) >> 9;
return (used > ULONG_MAX) ? ULONG_MAX : used;
}

Expand Down
8 changes: 2 additions & 6 deletions open-vm-tools/vmhgfs-fuse/fsutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
#include "hgfsProto.h"
#include <fuse.h>

#if defined(__FreeBSD__) || defined(__SOLARIS__) || defined(__APPLE__)
typedef long long loff_t;
#endif

/*
* Struct used to pass around attributes.
* These aren't just the attributes seen in HgfsAttr[V2]; we add a filename
Expand Down Expand Up @@ -73,7 +69,7 @@ ssize_t
HgfsWrite(struct fuse_file_info *fi,
const char *buf,
size_t count,
loff_t offset);
off64_t offset);

int
HgfsRename(const char* from, const char* to);
Expand All @@ -93,7 +89,7 @@ ssize_t
HgfsRead(struct fuse_file_info *fi,
char *buf,
size_t count,
loff_t offset);
off64_t offset);

int
HgfsSetattr(const char* path,
Expand Down