rktio: adjust Mac OS setenv
workaround
A `setenv` bug appears to be fixed as of Sierra, so only use the workaround for earlier versions.
This commit is contained in:
parent
b538d03d5a
commit
0de27b6ce9
|
@ -95,6 +95,7 @@ int rktio_setenv(rktio_t *rktio, const char *name, const char *val)
|
||||||
#ifdef SETENV_DROPS_LEADING_EQUAL_SIGN
|
#ifdef SETENV_DROPS_LEADING_EQUAL_SIGN
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
|
|
||||||
|
if (rktio->macos_kernel_version < 16) {
|
||||||
if (val[0] == '=') {
|
if (val[0] == '=') {
|
||||||
intptr_t len = strlen(val);
|
intptr_t len = strlen(val);
|
||||||
tmp = malloc(len + 2);
|
tmp = malloc(len + 2);
|
||||||
|
@ -102,6 +103,7 @@ int rktio_setenv(rktio_t *rktio, const char *name, const char *val)
|
||||||
tmp[0] = '=';
|
tmp[0] = '=';
|
||||||
val = tmp;
|
val = tmp;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
r = setenv(name, val, 1);
|
r = setenv(name, val, 1);
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
#include "rktio_private.h"
|
#include "rktio_private.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifdef OS_X
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <sys/sysctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
rktio_t *rktio_init(void)
|
rktio_t *rktio_init(void)
|
||||||
{
|
{
|
||||||
|
@ -33,6 +37,27 @@ rktio_t *rktio_init(void)
|
||||||
|
|
||||||
rktio_syslog_init(rktio);
|
rktio_syslog_init(rktio);
|
||||||
|
|
||||||
|
#ifdef OS_X
|
||||||
|
{
|
||||||
|
int a[2], i, k = 0;
|
||||||
|
size_t len;
|
||||||
|
char *vers;
|
||||||
|
|
||||||
|
a[0] = CTL_KERN;
|
||||||
|
a[1] = KERN_OSRELEASE;
|
||||||
|
sysctl(a, 2, NULL, &len, NULL, 0);
|
||||||
|
vers = malloc(len * sizeof(char));
|
||||||
|
sysctl(a, 2, vers, &len, NULL, 0);
|
||||||
|
|
||||||
|
for (i = 0; (i < len) && (vers[i] != '.'); i++)
|
||||||
|
k = (k * 10) + vers[i] - '0';
|
||||||
|
|
||||||
|
rktio->macos_kernel_version = k;
|
||||||
|
|
||||||
|
free(vers);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return rktio;
|
return rktio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,10 @@ struct rktio_t {
|
||||||
#ifdef SUPPORT_BACKGROUND_SLEEP_THREAD
|
#ifdef SUPPORT_BACKGROUND_SLEEP_THREAD
|
||||||
struct background_sleep_t *background;
|
struct background_sleep_t *background;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef OS_X
|
||||||
|
int macos_kernel_version; /* e.g., 10 => 10.6, 15 => 10.11 */
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/*========================================================================*/
|
/*========================================================================*/
|
||||||
|
|
|
@ -262,38 +262,22 @@ static int is_day_before(SYSTEMTIME *a, SYSTEMTIME *b)
|
||||||
|
|
||||||
#if defined(OS_X) && defined(__x86_64__)
|
#if defined(OS_X) && defined(__x86_64__)
|
||||||
/* work around a bug in localtime() in 10.6.8 */
|
/* work around a bug in localtime() in 10.6.8 */
|
||||||
# include <sys/param.h>
|
static int valid_time_range(rktio_t *rktio, intptr_t lnow)
|
||||||
# include <sys/sysctl.h>
|
|
||||||
static int VALID_TIME_RANGE(intptr_t lnow)
|
|
||||||
{
|
{
|
||||||
/* Fits in 32 bits? */
|
/* Fits in 32 bits? */
|
||||||
int ilnow = (int)lnow;
|
int ilnow = (int)lnow;
|
||||||
if (lnow == (intptr_t)ilnow)
|
if (lnow == (intptr_t)ilnow)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* 10.7 or later? */
|
if (rktio->macos_kernel_version == 10) {
|
||||||
{
|
|
||||||
int a[2];
|
|
||||||
size_t len;
|
|
||||||
char *vers;
|
|
||||||
|
|
||||||
a[0] = CTL_KERN;
|
|
||||||
a[1] = KERN_OSRELEASE;
|
|
||||||
sysctl(a, 2, NULL, &len, NULL, 0);
|
|
||||||
vers = malloc(len * sizeof(char));
|
|
||||||
sysctl(a, 2, vers, &len, NULL, 0);
|
|
||||||
|
|
||||||
if ((vers[0] == '1') && (vers[1] == '0') && (vers[2] == '.')) {
|
|
||||||
/* localtime() in 10.6.x (= 10.x at the kernel layer) doesn't seem
|
/* localtime() in 10.6.x (= 10.x at the kernel layer) doesn't seem
|
||||||
to work right with negative numbers that don't fit into 32 bits */
|
to work right with negative numbers that don't fit into 32 bits */
|
||||||
free(vers);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
free(vers);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
# define VALID_TIME_RANGE(lnow) valid_time_range(rktio, lnow)
|
||||||
#else
|
#else
|
||||||
|
|
||||||
# ifdef MIN_VALID_DATE_SECONDS
|
# ifdef MIN_VALID_DATE_SECONDS
|
||||||
|
|
Loading…
Reference in New Issue
Block a user