-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGOOD_PRACTICES
More file actions
51 lines (44 loc) · 2.19 KB
/
GOOD_PRACTICES
File metadata and controls
51 lines (44 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
1) respect shared/exclusive locks
---------------------------------
See README on '## LOCKING ##' to see how it works. Generally speaking, you
do *not* need to use locks if you
- use only one connection (or session creation + one additional connection)
- use only the default server port
- don't spawn additional children
- don't connect/sendto anywhere
- don't start listening on any ports
- don't execute any external commands (see spawning children above)
This means that ie. calling 'myaddr' or 'noop' without a shared lock is fine,
because it obeys the rules above and gives no additional overhead over what the
'lock' command would do - that's the borderline.
If you can do less or equal amount of system invasion than the 'lock' command
would, you don't need to use locking.
For anything complex (listening/sending/cmd execution/..), use shared locks.
Usage of sessions is encouraged as you don't need to lock on every command.
When you need exclusive access, use exclusive locks. Remember to unlock or
degrade your lock back to shared, especially with sessions as sessions don't
exit (unlock) when send_ns returns (!!!). The best option is to specify
unlock/degradation on the same cmdline part as the exclusive lock, meaning that
even if the test dies completely, the rest of the cmdline part still gets run
and the server is unlocked.
If you can, use the 'timeout' cmd after the 'lock' cmd to minimize the amount
of time spent with exclusive access if anything hangs up.
Also, always try to reduce the amount of time you need to spend while having
exclusive access as others need to use the server as well.
Ie.
# start a session
s=$(send_ns -S remote)
# get shared lock
send_ns -s $s remote "lock,sh"
# run cmd1 and cmd2 under shared lock
send_ns -s $s remote "cmd1;cmd2"
# run cmd3 under exclusive lock
send_ns -s $s remote "lock,ex;cmd3;lock,sh"
# run dangerous cmd4 (may hang) under another exclusive lock
send_ns -s $s remote "lock,ex;timeout,60;cmd3;timeout;lock,sh"
# run cmd5 under shared lock
send_ns -s $s remote "cmd4"
# end the session
send_ns -s $s -E remote
# (alternatively, from a cleanup script) kill the session
send_ns -s $s -K remote