aboutsummaryrefslogtreecommitdiff
path: root/src/core/platform.h
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2016-12-13 22:41:35 -0800
committerGarrett D'Amore <garrett@damore.org>2016-12-13 22:41:35 -0800
commitec9f917101371baaae34ca10ae952392c2c2343d (patch)
tree9ad7b85748d4d70248c7e720e5e3045ef2d77f6b /src/core/platform.h
parent4919519754a0b5aee826add75273c291c33c4b5f (diff)
downloadnng-ec9f917101371baaae34ca10ae952392c2c2343d.tar.gz
nng-ec9f917101371baaae34ca10ae952392c2c2343d.tar.bz2
nng-ec9f917101371baaae34ca10ae952392c2c2343d.zip
More comments, and detection of fork-reentrancy. Much effort was spent
trying to come to a fork-safe solution, but ultimately we gave up.
Diffstat (limited to 'src/core/platform.h')
-rw-r--r--src/core/platform.h21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/core/platform.h b/src/core/platform.h
index e2d81139..f7af7c30 100644
--- a/src/core/platform.h
+++ b/src/core/platform.h
@@ -39,6 +39,23 @@
*/
/*
+ * A word about fork-safety: This library is *NOT* fork safe, in that
+ * functions may not be called in the child process without an intervening
+ * exec(). The library attempts to detect this situation, and crashes the
+ * process with an error message if it encounters it. (See nn_platform_init
+ * below.)
+ *
+ * Additionally, some file descriptors may leak across fork even to
+ * child processes. We make every reasonable effort to ensure that this
+ * does not occur, but on some platforms there are unavoidable race
+ * conditions between file creation and marking the file close-on-exec.
+ *
+ * Forkers should use posix_spawn() if possible, and as much as possible
+ * arrange for file close on exec by posix_spawn, or close the descriptors
+ * they do not need in the child.
+ */
+
+/*
* nni_abort crashes the system; it should do whatever is appropriate
* for abnormal programs on the platform, such as calling abort().
*/
@@ -155,7 +172,7 @@ uint64_t nni_clock(void);
void nni_usleep(uint64_t);
/*
- * nni_init is called to allow the platform the chance to
+ * nni_platform_init is called to allow the platform the chance to
* do any necessary initialization. This routine MUST be idempotent,
* and threadsafe, and will be called before any other API calls, and
* may be called at any point thereafter. It is permitted to return
@@ -170,6 +187,6 @@ int nni_platform_init(void);
* be called as the last thing executed in the library, and no other functions
* will be called until nni_platform_init is called.
*/
-void nni_fini(void);
+void nni_platform_fini(void);
#endif /* CORE_PLATFORM_H */