I’m traveling at the moment so i often find myself pulling my laptop out on the train where internet is patchy.
So I’ve found myself setting up more stuff to work locally.
Thats how I found myself trying to compile and run a local copy of the Overpass API for querying open street map data… on a Mac. I’m typing this on my phone from memory so will provide references and corrections later when back at my laptop. #OSM #overpass #overpassturbo #overpassapi #openstreetmap
First attempt to compile I get some errors saying things like “lseek64 not found did you mean lseek?” Some googling leads me to realise that I guess OSX just makes its file operation functions 64 bit by default and in fact the code base already has a compiler option to just #define all the *64 variants to be the same as their normal name. Good sign? This clears most of the errors.
There’s still one error about off64_t not being defined, eventually I find an open PR pointing out that #define off64_t off_t was omitted from the block of defines from earlier. Adding that in fixes it. In retrospect I should perhaps have taken this as a sign that the codebase isn’t tested on osx, would be fair enough! A couple times I’ve opened PRs to fix some trivial thing to make the project run on a Mac and had it closed with “we don’t support osx” which like I get that but if it’s a one line change c’mon! I commented on the PR to say it was a good one.
Ok it compiles now! I built the overpass db, and ran a rest query. My test data is a tiny cutout of Stoke Newington in London. Handily the test query looks for pubs and there are like 5 in my test data. Easy. However now there’s a weird issue, running the dispatcher worked the first time but refuses to work after that.
A bit of print debugging later I eventually track it down to a call to ftruncate on a file descriptor that came from shm_open, which means it’s an fd for a shared memory region. A bit more searching reveals that on osx, unlike unix, you’re only allowed to call truncate once _ever_ on a shared memory region. And since they persist that’s why I could only launch the dispatcher exactly one time. A stackoverflow comment suggests checking if the shm has size 0 and only calling truncate in that case. That seems to work for me but I can’t quite tell if there are instances where we might need to resize the shm region (for which it looks like you’d have to delete it with shm_unlink). The desired size for the shm is 81 bytes and is computed from some things but I’m too lazy right now to figure out the circumstances under which that number might change.
Anyway, it runs now, but I want to use the nice web interface offered by overpass turbo or ultra. For that I need the webserver and for that I apparently need to setup cgi in apache or nginx.
Tbh cgi scares me. And the ratio of config-required to how-much-I-care seems too high. I’m tempted to write a minimal python shim instead, is that crazier than setting up cgi? I don’t know… the devil you know I guess.