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
|
@ -94,13 +94,15 @@ int rktio_setenv(rktio_t *rktio, const char *name, const char *val)
|
|||
int r;
|
||||
#ifdef SETENV_DROPS_LEADING_EQUAL_SIGN
|
||||
char *tmp = NULL;
|
||||
|
||||
if (val[0] == '=') {
|
||||
intptr_t len = strlen(val);
|
||||
tmp = malloc(len + 2);
|
||||
memcpy(tmp + 1, val, len + 1);
|
||||
tmp[0] = '=';
|
||||
val = tmp;
|
||||
|
||||
if (rktio->macos_kernel_version < 16) {
|
||||
if (val[0] == '=') {
|
||||
intptr_t len = strlen(val);
|
||||
tmp = malloc(len + 2);
|
||||
memcpy(tmp + 1, val, len + 1);
|
||||
tmp[0] = '=';
|
||||
val = tmp;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
#include "rktio_private.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef OS_X
|
||||
# include <sys/types.h>
|
||||
# include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
rktio_t *rktio_init(void)
|
||||
{
|
||||
|
@ -33,6 +37,27 @@ rktio_t *rktio_init(void)
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -116,6 +116,10 @@ struct rktio_t {
|
|||
#ifdef SUPPORT_BACKGROUND_SLEEP_THREAD
|
||||
struct background_sleep_t *background;
|
||||
#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__)
|
||||
/* work around a bug in localtime() in 10.6.8 */
|
||||
# include <sys/param.h>
|
||||
# include <sys/sysctl.h>
|
||||
static int VALID_TIME_RANGE(intptr_t lnow)
|
||||
static int valid_time_range(rktio_t *rktio, intptr_t lnow)
|
||||
{
|
||||
/* Fits in 32 bits? */
|
||||
int ilnow = (int)lnow;
|
||||
if (lnow == (intptr_t)ilnow)
|
||||
return 1;
|
||||
|
||||
/* 10.7 or later? */
|
||||
{
|
||||
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
|
||||
to work right with negative numbers that don't fit into 32 bits */
|
||||
free(vers);
|
||||
return 0;
|
||||
}
|
||||
free(vers);
|
||||
if (rktio->macos_kernel_version == 10) {
|
||||
/* 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 */
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
# define VALID_TIME_RANGE(lnow) valid_time_range(rktio, lnow)
|
||||
#else
|
||||
|
||||
# ifdef MIN_VALID_DATE_SECONDS
|
||||
|
|
Loading…
Reference in New Issue
Block a user