diff --git a/phc2sys.c b/phc2sys.c index c0b7b3d..64bdf26 100644 --- a/phc2sys.c +++ b/phc2sys.c @@ -341,7 +341,7 @@ static void clock_reinit(struct node *node, struct clock *clock, int new_state) if (clkid == CLOCK_INVALID) return; - phc_close(clock->clkid); + posix_clock_close(clock->clkid); clock->clkid = clkid; clock->phc_index = phc_index; diff --git a/phc_ctl.c b/phc_ctl.c index e55af59..149ee9e 100644 --- a/phc_ctl.c +++ b/phc_ctl.c @@ -531,6 +531,7 @@ int main(int argc, char *argv[]) /* pass the remaining arguments to the run_cmds loop */ result = run_cmds(clkid, cmdc, cmdv); + posix_clock_close(clkid); if (result < -1) { /* show usage when command fails */ usage(progname); diff --git a/util.c b/util.c index 43d6224..296dd59 100644 --- a/util.c +++ b/util.c @@ -190,6 +190,14 @@ char *portaddr2str(struct PortAddress *addr) return buf; } +void posix_clock_close(clockid_t clock) +{ + if (clock == CLOCK_REALTIME) { + return; + } + phc_close(clock); +} + clockid_t posix_clock_open(const char *device, int *phc_index) { struct sk_ts_info ts_info; diff --git a/util.h b/util.h index 11e0935..6e104ea 100644 --- a/util.h +++ b/util.h @@ -110,6 +110,12 @@ char *pid2str(struct PortIdentity *id); char *portaddr2str(struct PortAddress *addr); +/** + * Closes a dynamic posix clock. + * @param clock A clock ID obtained via posix_clock_close(). + */ +void posix_clock_close(clockid_t clock); + /** * Opens a dynamic posix clock by name. * @param device The PHC character device or network interface to open.