Set timeout threshold for alibaba ecs identification to avoid hanging.
authorWeisson <hanxiaobupt@bupt.cn>
Fri, 14 Jun 2024 11:30:01 +0000 (19:30 +0800)
committerRichard W.M. Jones <rjones@redhat.com>
Mon, 24 Jun 2024 17:01:34 +0000 (18:01 +0100)
commit1f0682ca1b24565ec95796a0fa0774793eafaed7
tree8a8e22ee057f1e61738efec8344b5f5a28a9bcca
parent94773022f76f994d7a9b37f59ba978bd28f30d1d
Set timeout threshold for alibaba ecs identification to avoid hanging.

On Alibaba ECS/EBM, virt-what used to run this tricky shell command:
```
( { echo -e "GET /latest/meta-datainstance/instance-type HTTP/1.0\r\nHost: 100.100.100.200\r\n\r" >&3; grep -sq 'ebm' <&3 ; } 3<> /dev/tcp/100.100.100.200/80 ) 2>/dev/null
```
which means the host fetches metadata and identifies its flavor.

However, the remote server '100.100.100.200' is accessible only within
Alibaba Cloud network, which keeps those hosts, not in that condition
mentioned above, hanging until syscall 'connect' timeout and get interrupted
by kernel, or even worse, hanging forever.

This commit set 1 second timeout at most for meta-data fetching process
to avoid that kind of hanging.

Signed-off-by: Weisson <hanxiaobupt@bupt.cn>
tests/alibaba-cloud-arm/sbin/timeout [new file with mode: 0755]
tests/alibaba-cloud-x86/sbin/timeout [new file with mode: 0755]
virt-what.in