I have developed a daemon program which can get all up interfaces and print their names and other properties. It works fine when my system is running, but failed to list these interfaces after restarting my device(this will cause my daemon auto-start). Below are useful informations for your reference.
Environment
device : jetson xavier nx
system : ubuntu 18.04 - aarch64
network : eth0 - AF_PACKET, AF_INET, AF_INET6
# eth0 with static ipv4 address 172.18.0.3
# and there are other interfaces not listed
Custom Service file
[Unit]
Description=test
Wants=network-online.target
After=network.target network-online.target
[Service]
type=forking
ExecStart=/opt/test
Restart=always
[Install]
WantedBy=multi-user.target
Get interfaces by getifaddrs
getifaddrs(&ifaddr);
for(struct ifaddrs *ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
{
// some needed valid checking codes here
printf("Found interfaces %-8s %d\n",ifa->ifa_name,ifa->ifa_addr->sa_family);
}
I expecting the result should contains eth0 2, means AF_INET, but I can only get eth0 17, means AF_PACKET.
I have tried following things respectively:
- solutions from this and other posts
- add
ExecStartPre=/bin/sleep 30before lineExecStart=/opt/testwithin service file
and the first doesn't work, the second works fine but I don't think it gets the root of the problem.
So, in short, what causes my daemon program not getting expected interface? How to correct it?
Please don't hesitate to ask for more information.
NetworkManager-wait-online.servicefrom link in my first try from my question.