Skip to content

Commit

Permalink
Close client UDS transport before exit.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mlichvar authored and richardcochran committed Sep 21, 2014
1 parent ca637b2 commit 30841a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
30 changes: 20 additions & 10 deletions phc2sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1187,6 +1187,8 @@ int main(int argc, char *argv[])
.kernel_leap = 1,
};

handle_term_signals();

configured_pi_kp = KP;
configured_pi_ki = KI;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
}

Expand All @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions pmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,13 +714,16 @@ 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;
struct ptp_message *msg;
#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];
Expand Down Expand Up @@ -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++];
Expand All @@ -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;
Expand Down Expand Up @@ -866,5 +870,5 @@ int main(int argc, char *argv[])

pmc_destroy(pmc);
msg_cleanup();
return 0;
return ret;
}

0 comments on commit 30841a6

Please sign in to comment.