Friday, July 5, 2019

This just gets worse and worse

More macos strangeness.
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, char** argv) {
    int pid = fork();

    if (pid == 0) {
        printf("child, errno: %d\n", errno);
        exit(0);
    } else {
        printf("parent, errno: %d\n", errno);
        exit(0);
    }
}

And here's the output under macos.
$ ./a.out 
parent, errno: 0
child, errno: 22
The fork man page doesn't even list "Invalid argument" as a possible errno value...

Sunday, June 23, 2019

MacOS/Darwin/Mach sleep weirdness

A system call to sleep returns 0 as it should, but set errno to 60 "ETIMEDOUT Operation timed out." which it really shouldn't, especially on a return of 0. https://pubs.opengroup.org/onlinepubs/009695399/functions/sleep.html states "No errors are defined." Here's some C proof.
#include <stdio.h>
#include <unistd.h>
#include <sys/errno.h>

int main(int argc, char **argv) {
    printf("this looks good: %d\n", sleep(1));
    printf("this does not: %d\n", errno);
}
And the output.
this looks good: 0
this does not: 60

Sunday, February 10, 2019

We're not in Kansas

I've been using the excellent MaxMind Geo IP database (https://www.maxmind.com) in a Python application (https://github.com/drsjb80/HPotter). Interestingly, when I look a MSU Denver's IP address:
 
$ python3
Python 3.7.1 (default, Nov 18 2018, 09:59:08)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import geoip2.database
>>> reader = geoip2.database.Reader('/usr/local/lib/python3.7/site-packages/_maxminddb_geolite2/GeoLite2-City.mmdb')
>>> reader.city('147.153.5.6').location
geoip2.records.Location(average_income=None, metro_code=None, time_zone=None, population_density=None, longitude=-97.822, postal_code=None, postal_confidence=None, accuracy_radius=5, latitude=37.751)


the lat/long says we're in Kansas, in the middle of a reservior acutally:
 Who knew?