• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

man/H03-May-2022-215172

.gitignoreH A D08-Dec-20148 32

MakefileH A D08-Dec-2014953 4928

README.mdH A D08-Dec-20142.1 KiB8548

main.cH A D08-Dec-20149.6 KiB319235

test_odoH A D08-Dec-2014408 2415

types.hH A D08-Dec-20141 KiB4536

README.md

1odo - an atomic odometer for the command line
2
3# Atomic Odometer? What?
4
5odo atomically updates a count in a file, which will be created if not
6present. The count is text-formatted (e.g. "00012345\n"), and will be
7accurately incremented or reset even when multiple processes attempt to
8change the counter at the same time. (It uses [memory mapping and atomic
9compare-and-swap operations][1] to eliminate race conditions.)
10
11[1]: https://spin.atomicobject.com/2014/11/24/odo-atomic-counters-from-the-command-line/
12
13
14## Use cases
15
16This could be used to track some intermittent event, like services being
17restarted. (This was the [original inspiration][2].) Since the counter
18is just a number in a text file, it's easy to compose odo with other
19tools.
20
21[2]: https://twitter.com/nrr/status/529016501421240322
22
23
24## Dependencies
25
26odo depends on atomic compare-and-swap functionality (e.g.
27`__sync_bool_compare_and_swap`), which is available on most common
28platforms. The build is currently tested on Linux, OpenBSD, and OSX on
29x86 and x86-64 systems, as well as on a Raspberry Pi (32-bit ARM).
30
31If the gcc-specific feature defines in `types.h` are not recognized by
32your C99 compiler, you may need to set `COUNTER_SIZE` in the Makefile
33yourself: `-DCOUNTER_SIZE=4` for 32-bit systems and `-DCOUNTER_SIZE=8`
34for 64-bit systems.
35
36
37## Getting started
38
39To build it, just type:
40
41    $ make
42
43To install it:
44
45    $ make install
46
47To run the tests:
48
49    $ make test
50
51
52## Example Use
53
54This atomically increments a counter in /log/restarts. If the counter
55file does not exist, it is created as 0 and incremented to 1.
56
57    $ odo /log/restarts
58
59Same, but print the updated count:
60
61    $ odo -p /log/restarts
62
63Reset the count to 0:
64
65    $ ./odo -r /log/restarts
66
67Set the count to a number (for testing notifications, perhaps):
68
69    $ ./odo -s 12345 /log/restarts
70
71Print the current counter value without incrementing:
72
73    $ ./odo -c /log/restarts
74
75Print usage / help:
76
77    $ ./odo -h
78
79
80## Note
81
82odo's atomicity is only as reliable as the underlying filesystem's.
83Inconsistencies may still occur if used on a non-local filesystems
84such as nfs.
85