1* Hacking Memcached
2
3* Prerequisites
4
5 - autoconf
6 - automake
7 - autotools
8 - libevent
9
10* Getting Started
11
12After checking out a git repository, you must first run autogen.sh
13once in order to create the configure script.
14
15Next, run the configure script and start doing builds.
16
17IE:
18    ./autogen.sh && ./configure && make && make test
19
20* Setting up Git
21
22Though not required, there are a couple of things you can add to git
23to help development.
24
25** Pre Commit Hook
26
27The pre-commit hook can be used to ensure that your tree passes tests
28before allowing a commit.  To do so, add the following to
29.git/hooks/pre-commit (which must be executable):
30
31    #!/bin/sh
32    make test
33
34** Post Commit Hook
35
36Because the version number changes on each commit, it's good to use a
37post commit hook to update the version number after each commit so as
38to keep the reporting accurate.  To do so, add the following to
39.git/hooks/post-commit (which must be executable)
40
41    #!/bin/sh
42    ./version.sh
43
44** Running memcached in gdb for tests.
45
46By default `make test` will spawn a memcached daemon for each test.
47This doesn't let you easily drop into gdb or run verbosely.
48
49If you export the environment variable
50T_MEMD_USE_DAEMON="127.0.0.1:11211" the tests will use an existing
51daemon at that address.
52
53* Debugging seccomp issues
54
55If new functionality fails when built with seccomp / drop privileges
56support, it can be debugged in one of two ways:
57
58Run the memcached via strace. For example:
59
60    strace -o /tmp/memcache.strace -f -- ./memcached
61    less /tmp/memcache.strace
62
63And look for calls which failed due to access restriction. They will
64show up with result: "-1 (errno 13)". Then add them to linux_priv.c.
65
66Alternatively, change the definition in linux_priv.c to:
67
68    #define DENY_ACTION SCMP_ACT_TRAP
69
70and the process will crash with a coredump on all policy violations.
71In strace output those can be seen as:
72
73    SIGSYS {si_signo=SIGSYS, si_code=SYS_SECCOMP,
74    si_call_addr=0x358a443454d, si_syscall=__NR_write,
75    si_arch=AUDIT_ARCH_X86_64} ---
76
77In that output, the si_syscall shows which operation has been
78blocked. In this case that's `write()`.
79
80* Sending patches
81
82See current instructions at https://github.com/memcached/memcached/wiki/DevelopmentRepos
83