Tag Archives: os x
Building Bitcoin Core on OS X with Errors, Warnings and Solutions
Here we talk about how to build Bitcoin Core on OS X with some error messages and their solutions.
First, we assume the Xcode command line tools and MacPorts are installed. We also assume Bitcoin Core has been cloned with git.
Continue reading Building Bitcoin Core on OS X with Errors, Warnings and Solutions
Setting up Perforce Helix Core Service on OS X High Sierra
Here is a guide about how to start Perforce Helix Core as a global daemon on OS X High Sierra, running under a separate user called perforce. By the nature of this guide, some of it applies directly to my own system; readers are expected to identify those instances and change appropriately.
First, we download the p4d and p4 executable files. Some people may prefer the visual client, but this guide is focused on the command line.
Then we install the binaries into /usr/local/sbin
and /usr/local/bin
, respectively.
Install the server binary.
sudo mkdir -p /usr/local/sbin sudo cp p4d /usr/local/sbin sudo chown root:wheel /usr/local/sbin/p4d sudo chmod 555 /usr/local/sbin/p4d
And install the client binary.
sudo mkdir -p /usrl/local/bin sudo cp p4 /usr/local/bin/ sudo chown root:wheel /usr/local/bin/p4 sudo chmod 555 /usr/local/bin/p4
We’ll create a group and user called perforce, and store the version control database in /usr/local/var/perforce
with the log in /usr/local/var/log/p4d.log
.
Here I’ve carefully chosen the unique id 268
for both the group and user because it’s free on my system. To see all group ids in use on a system, this one liner can be used,
for f in `dscl . -list /Groups`; do dscl . -read /Groups/$f; \ done | grep PrimaryGroupID | sort -k2 -n
and to see all the user ids, this one liner can be used.
for f in `dscl . -list /Users`; do dscl . -read /Users/$f; \ done | grep UniqueID | sort -k2 -n
We create the group with
sudo dscl . -create /Groups/perforce sudo dscl . -create /Groups/perforce PrimaryGroupID 268 sudo dscl . -create /Groups/perforce Password '*'
and then we create the user with
sudo dscl . -create /Users/perforce sudo dscl . -create /Users/perforce UniqueID 268 sudo dscl . -create /Users/perforce UserShell /usr/bin/false sudo dscl . -create /Users/perforce RealName 'Perforce Server' sudo dscl . -create /Users/perforce NFSHomeDirectory /usr/local/var/perforce sudo dscl . -create /Users/perforce PrimaryGroupID 268 sudo dscl . -create /Users/perforce Password '*'
Then we create the log file and database directory
sudo mkdir -p /usr/local/var/log sudo touch /usr/local/var/log/p4d.log sudo mkdir -p /usr/local/var/perforce
and set the ownership to the new user and group.
sudo chown perforce:perforce /usr/local/var/perforce sudo chown perforce:perforce /usr/local/var/log/p4d.log
Then we create the launch daemon description file.
sudo nano /Library/LaunchDaemons/com.perforce.plist
and add the following.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Debug</key> <false/> <key>Label</key> <string>com.perforce</string> <key>OnDemand</key> <false/> <key>Program</key> <string>/usr/local/sbin/p4d</string> <key>ProgramArguments</key> <array> <string>/usr/local/sbin/p4d</string> </array> <key>EnvironmentVariables</key> <dict> <key>P4LOG</key> <string>/usr/local/var/log/p4d.log</string> <key>P4PORT</key> <string>1666</string> <key>P4ROOT</key> <string>/usr/local/var/perforce/</string> <key>P4NAME</key> <string>Shinka</string> <key>P4DESCRIPTION</key> <string>Myrkraverk's Perforce</string> </dict> <key>RunAtLoad</key> <true/> <key>ServiceDescription</key> <string>Launches Perforce Server</string> <key>StartInterval</key> <integer>180</integer> <key>KeepAlive</key> <true/> <key>UserName</key> <string>perforce</string> <key>GroupName<key> <string>perforce</string> </dict> </plist> And finally, start the Helix Core service with sudo launchctl load /Library/LaunchDaemons/com.perforce.plist
we then issue
p4 set P4PORT=localhost:1666
and we test it with
p4 help
which outputs at the end
Server 2018.1/1637071.
so we know it's all working.
The steps to properly set up Helix Core with p4 protect
and so forth are left out of this guide; please see the administration guide from Perforce.
To use SSL for the connection, the P4PORT should start with ssl:
.
Compiling Sysbench on OS X Yosemite or Later
These instructions are applicable after cloning the git repository and generating the autoconfigure scripts.
git clone 'https://github.com/akopytov/sysbench.git' sysbench cd sysbench ./autogen.sh
In order to build Sysbench1 with PostgreSQL and MariaDB support, you need to make sure both mysql_config
and pg_config
are in your path.
I use Zsh, so this is my way of doing it, when both Postgres and MariaDB have been installed with MacPorts.
path=( /opt/local/lib/mariadb-10.1/bin /opt/local/lib/postgresql96/bin $path )
Then run
./configure --with-pgsql --with-mysql --prefix=/path/of/your/choice
You are likely to get an error like
ld: library not found for -lgcc_s.10.4
if you do not also
export MACOSX_DEPLOYMENT_TARGET=10.10
before running make
, while building the bundled LuaJit. This is documented in their installation instructions.
Of course, this isn’t taken care of by the wrapper Autotools, nor is there a configure flag to set this.
An alternative might be --with-system-luajit
but that depends on your situation.
Then you finish it off with make install
. Happy benchmarking.
1 I hope I’m linking to the right git repository.
The Case of the Apparent NSS Memory Corruption
This is a story of my encounter with an apparent memory corruption issue in the Netscape Security Services library.
The source I’m discussing can be found on Github.
Usually, when I try to get acquainted with a new API, I start to write simple program, one API call by call, which I compile and run after each step.
Imagine my surprise, when after adding the following function call (the only thing I added)
PK11_FindKeyByAnyCert( certificate, passwd );
I got this memory corruption error.
dblfree(56630,0x7fff73f61300) malloc: *** error for object 0x7fd39250ce70: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug zsh: abort ./dblfree
The above error is taken from my minimal example of the problem, not the actual program I was working on at the time. The only difference is the name of the binary and the hex numbers.
So what is happening here? I didn’t know. And to find out, it’s really important to use the right tool for the job.
So the first thing I did was to instrument my code with the built-in OS X tools, instruments(1). That didn’t tell me much; either because it doesn’t help in this particular instance, or that I just don’t know how to use it.
I will make a note that some people suggested Valgrind. I didn’t go that way because the problem seems to be adequately described with the Clang Address Sanitizer.
Continue reading The Case of the Apparent NSS Memory Corruption
When Dtrace Fails – Spectacularly
So, I’ve been spending some time looking at Dtrace today. At first, I created a proof of concept on OS X, and then went on to try it in production on FreeBSD.
No such luck. After several hours of trying to figure out what the heck was going wrong, I tried the following experiment, on OS X.
% uname -a Darwin foo 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep 1 21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64 % cat hello.c #include <stdio.h> int main(int argc, char *argv[]) { printf( "Hello\n" ); return 0; } % dtrace -n 'pid$target::main:entry{printf("%#p\n",uregs[R_RBP]);}' -c ./hello dtrace: description 'pid$target::main:entry' matched 1 probe Hello dtrace: pid 9224 has exited CPU ID FUNCTION:NAME 0 67470 main:entry 0x7fff583c1c20
And then again on FreeBSD.
% uname -a FreeBSD bar 10.2-RELEASE FreeBSD 10.2-RELEASE #0 r286666: Wed Aug 12 15:26:37 UTC 2015 root@releng1.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64 % cat hello.c #include <stdio.h> int main(int argc, char *argv[]) { printf( "Hello\n" ); return 0; } % dtrace -n 'pid$target::main:entry{printf("%#p\n",uregs[R_RBP]);}' -c ./hello dtrace: description 'pid$target::main:entry' matched 1 probe Hello dtrace: pid 84313 has exited CPU ID FUNCTION:NAME 2 54008 main:entry 0
As you can see, the printed value of the %rbp register is zero on FreeBSD. In my experiments, trying to read that register always yields zero. Similarly, I do not trust it for other registers.
This seems to be a bug in FreeBSD’s Dtrace. At the time of this writing, I have not tried it on recent Illumos.