- Due to #3167 fix, sometimes get node unexpected reboot due to
transportd fail to monitor dtmd. This is timming issue if dtmd
create pid file with 0640 then chown to opensaf user. Then transportd
see pid file right after created but fail to read it.
- Keep old permissions, only change permissions after chown done.
Also retry open fifo file if no such file error.
---
 src/base/daemon.c   | 6 ++++--
 src/nid/nodeinit.cc | 3 ++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/base/daemon.c b/src/base/daemon.c
index 62b6a7311..48a0665f2 100644
--- a/src/base/daemon.c
+++ b/src/base/daemon.c
@@ -102,7 +102,7 @@ static int __create_pidfile(const char *pidfile)
                syslog(LOG_WARNING,"truncation occurred writing pid file: %s", 
pidfiletmp);
 
        /* open the file and associate a stream with it */
-       if (((fd = open(pidfiletmp, O_RDWR | O_CREAT, 0640)) == -1) ||
+       if (((fd = open(pidfiletmp, O_RDWR | O_CREAT, 0644)) == -1) ||
            ((file = fdopen(fd, "r+")) == NULL)) {
                syslog(LOG_ERR, "open failed, pidfiletmp=%s, errno=%s",
                       pidfiletmp, strerror(errno));
@@ -169,7 +169,7 @@ static void create_fifofile(const char *fifofile)
 
        mask = umask(0);
 
-       if (mkfifo(fifofile, 0660) == -1) {
+       if (mkfifo(fifofile, 0666) == -1) {
                syslog(LOG_ERR, "mkfifo failed: %s %s", fifofile,
                                strerror(errno));
                umask(mask);
@@ -469,7 +469,9 @@ void daemonize(int argc, char *argv[])
                        }
                        if ((pw->pw_uid > 0) && (pw->pw_gid > 0)) {
                                assert(chown(fifo_file, pw->pw_uid, pw->pw_gid) 
== 0);
+                               assert(chmod(fifo_file, 0660) == 0);
                                assert(chown(__pidfile, pw->pw_uid, pw->pw_gid) 
== 0);
+                               assert(chmod(__pidfile, 0640) == 0);
                        }
                        if ((pw->pw_gid > 0) && (setgid(pw->pw_gid) < 0)) {
                                syslog(LOG_ERR, "setgid failed, gid=%d (%s)",
diff --git a/src/nid/nodeinit.cc b/src/nid/nodeinit.cc
index 9757dca24..d5b4eb20a 100644
--- a/src/nid/nodeinit.cc
+++ b/src/nid/nodeinit.cc
@@ -1438,7 +1438,8 @@ int handle_data_request(struct pollfd *fds, const 
std::string &nid_name) {
         }
         fifo_fd = open(fifo_file.c_str(), O_WRONLY | O_NONBLOCK);
       } while ((fifo_fd == -1) &&
-               (retry_cnt++ < 50 && (errno == EINTR || errno == ENXIO)));
+               (retry_cnt++ < 50 &&
+                (errno == EINTR || errno == ENXIO || errno == ENOENT)));
 
       if (fifo_fd == -1) {
         LOG_ER("Failed to open %s, error: %s", fifo_file.c_str(),
-- 
2.17.1



_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to