Mercurial > hg > aboriginal
annotate sources/toys/unique-port.sh @ 1682:64316ca2bc9b
Remove redundant list assignment in ccwrap that screws up ordering and puts the -L entries in the wrong order.
author | Rob Landley <rob@landley.net> |
---|---|
date | Fri, 05 Sep 2014 23:54:01 -0500 |
parents | 1cdd44f2bac2 |
children |
rev | line source |
---|---|
972 | 1 unique_port() |
2 { | |
1072
94b0b4ef1157
Add native-build.sh to system-image (it takes only one argument now, the build control system image file). Make system-image.sh script processing understand an INCLUDE syntax to insert unique-port, and trim the unique-port comment to something less distracting.
Rob Landley <rob@landley.net>
parents:
972
diff
changeset
|
3 # Try to find an unused port number for each running instance of the program. |
972 | 4 |
5 START=8192 | |
6 RANGE=$[$(awk '{print $1}' /proc/sys/net/ipv4/ip_local_port_range)-$START] | |
1196
1cdd44f2bac2
If some clever sysadmin claimed 1024-65535 for local ports, punt.
Rob Landley <rob@landley.net>
parents:
1072
diff
changeset
|
7 if [ $RANGE -lt 8 ] |
972 | 8 then |
9 START=$[$(awk '{print $2}' /proc/sys/net/ipv4/ip_local_port_range)] | |
10 RANGE=$[65535-$START] | |
1196
1cdd44f2bac2
If some clever sysadmin claimed 1024-65535 for local ports, punt.
Rob Landley <rob@landley.net>
parents:
1072
diff
changeset
|
11 if [ $RANGE -lt 8 ] |
1cdd44f2bac2
If some clever sysadmin claimed 1024-65535 for local ports, punt.
Rob Landley <rob@landley.net>
parents:
1072
diff
changeset
|
12 then |
1cdd44f2bac2
If some clever sysadmin claimed 1024-65535 for local ports, punt.
Rob Landley <rob@landley.net>
parents:
1072
diff
changeset
|
13 START=16384 |
1cdd44f2bac2
If some clever sysadmin claimed 1024-65535 for local ports, punt.
Rob Landley <rob@landley.net>
parents:
1072
diff
changeset
|
14 RANGE=32768 |
1cdd44f2bac2
If some clever sysadmin claimed 1024-65535 for local ports, punt.
Rob Landley <rob@landley.net>
parents:
1072
diff
changeset
|
15 fi |
972 | 16 fi |
17 echo $[($$%$RANGE)+$START] | |
18 } |