X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=utils%2Fstatd%2Fsm-notify.c;h=bb67c378e94839254bbb49ec093bef71dda11317;hb=ec637de16210c1c6fcb3a0df34d7889592f577dc;hp=bb6c2efa3f4e949191f4831757f7cf5e649eafa6;hpb=dda3455d8b96a7b078bc00c113e1af15ed421d5b;p=nfs-utils.git diff --git a/utils/statd/sm-notify.c b/utils/statd/sm-notify.c index bb6c2ef..bb67c37 100644 --- a/utils/statd/sm-notify.c +++ b/utils/statd/sm-notify.c @@ -86,7 +86,7 @@ static int addr_get_port(nsm_address *); static void addr_set_port(nsm_address *, int); static struct addrinfo *host_lookup(int, const char *); void nsm_log(int fac, const char *fmt, ...); -static int record_pid(); +static int record_pid(void); static void drop_privs(void); static void set_kernel_nsm_state(int state); @@ -215,7 +215,9 @@ notify(void) nsm_address local_addr; time_t failtime = 0; int sock = -1; + int retry_cnt = 0; + retry: sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { perror("socket"); @@ -248,7 +250,16 @@ notify(void) exit(1); } } else { - (void) bindresvport(sock, (struct sockaddr_in *) &local_addr); + struct servent *se; + struct sockaddr_in *sin = (struct sockaddr_in *)&local_addr; + (void) bindresvport(sock, sin); + /* try to avoid known ports */ + se = getservbyport(sin->sin_port, "udp"); + if (se && retry_cnt < 100) { + retry_cnt++; + close(sock); + goto retry; + } } if (opt_max_retry) @@ -719,7 +730,7 @@ nsm_log(int fac, const char *fmt, ...) * program exits. * If file already exists, fail. */ -static int record_pid() +static int record_pid(void) { char pid[20]; int fd;