The one user of the function, posix_clock_open(), simply open codes
the closing call to phc_close().  This patch provides a method to
balance closing and opening of a posix clock.  In addition, the
phc_ctl program never explicitly closed the opened clock, and so this
patch adds the missing call.

Signed-off-by: Richard Cochran <richardcoch...@gmail.com>
---
 phc2sys.c | 2 +-
 phc_ctl.c | 1 +
 util.c    | 8 ++++++++
 util.h    | 6 ++++++
 4 files changed, 16 insertions(+), 1 deletion(-)

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.
-- 
2.20.1



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to