Close client UDS transport before exit.

In pmc and phc2sys handle terminating signals and close the UDS
transport before exit to remove the sockets in /var/run.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
master
Miroslav Lichvar 2014-07-08 16:14:21 +02:00 committed by Richard Cochran
parent ca637b2067
commit 30841a6849
2 changed files with 27 additions and 13 deletions

View File

@ -526,7 +526,7 @@ static int do_pps_loop(struct node *node, struct clock *clock, int fd)
enable_pps_output(node->master->clkid);
}
while (1) {
while (is_running()) {
if (!read_pps(fd, &pps_offset, &pps_ts)) {
continue;
}
@ -570,7 +570,7 @@ static int do_loop(struct node *node, int subscriptions)
interval.tv_sec = node->phc_interval;
interval.tv_nsec = (node->phc_interval - interval.tv_sec) * 1e9;
while (1) {
while (is_running()) {
clock_nanosleep(CLOCK_MONOTONIC, 0, &interval, NULL);
if (update_pmc(node, subscriptions) < 0)
continue;
@ -611,7 +611,7 @@ static int do_loop(struct node *node, int subscriptions)
update_clock(node, clock, offset, ts, delay);
}
}
return 0; /* unreachable */
return 0;
}
static int check_clock_identity(struct node *node, struct ptp_message *msg)
@ -1187,6 +1187,8 @@ int main(int argc, char *argv[])
.kernel_leap = 1,
};
handle_term_signals();
configured_pi_kp = KP;
configured_pi_ki = KI;
@ -1349,7 +1351,8 @@ int main(int argc, char *argv[])
return -1;
if (auto_init_ports(&node, rt) < 0)
return -1;
return do_loop(&node, 1);
r = do_loop(&node, 1);
goto end;
}
src = clock_add(&node, src_name);
@ -1377,14 +1380,16 @@ int main(int argc, char *argv[])
goto bad_usage;
}
r = -1;
if (wait_sync) {
if (init_pmc(&node, domain_number))
return -1;
goto end;
while (1) {
while (is_running()) {
r = run_pmc_wait_sync(&node, 1000);
if (r < 0)
return -1;
goto end;
if (r > 0)
break;
else
@ -1395,7 +1400,7 @@ int main(int argc, char *argv[])
r = run_pmc_get_utc_offset(&node, 1000);
if (r <= 0) {
pr_err("failed to get UTC offset");
return -1;
goto end;
}
}
@ -1409,11 +1414,16 @@ int main(int argc, char *argv[])
/* only one destination clock allowed with PPS until we
* implement a mean to specify PTP port to PPS mapping */
servo_sync_interval(dst->servo, 1.0);
return do_pps_loop(&node, dst, pps_fd);
r = do_pps_loop(&node, dst, pps_fd);
} else {
r = do_loop(&node, 0);
}
return do_loop(&node, 0);
end:
if (node.pmc)
close_pmc(&node);
return r;
bad_usage:
usage(progname);
return -1;

10
pmc.c
View File

@ -714,6 +714,7 @@ int main(int argc, char *argv[])
const char *iface_name = NULL;
char *progname;
int c, cnt, length, tmo = -1, batch_mode = 0, zero_datalen = 0;
int ret = 0;
char line[1024], *command = NULL;
enum transport_type transport_type = TRANS_UDP_IPV4;
UInteger8 boundary_hops = 1, domain_number = 0, transport_specific = 0;
@ -721,6 +722,8 @@ int main(int argc, char *argv[])
#define N_FD 2
struct pollfd pollfd[N_FD];
handle_term_signals();
/* Process the command line arguments. */
progname = strrchr(argv[0], '/');
progname = progname ? 1+progname : argv[0];
@ -798,7 +801,7 @@ int main(int argc, char *argv[])
pollfd[0].fd = batch_mode ? -1 : STDIN_FILENO;
pollfd[1].fd = pmc_get_transport_fd(pmc);
while (1) {
while (is_running()) {
if (batch_mode && !command) {
if (optind < argc) {
command = argv[optind++];
@ -823,7 +826,8 @@ int main(int argc, char *argv[])
continue;
} else {
pr_emerg("poll failed");
return -1;
ret = -1;
break;
}
} else if (!cnt) {
break;
@ -866,5 +870,5 @@ int main(int argc, char *argv[])
pmc_destroy(pmc);
msg_cleanup();
return 0;
return ret;
}