+#ifndef __FreeBSD__
+ if (global) {
+ ret = fchown(wait_shm_fd, 0, 0);
+ if (ret < 0) {
+ PERROR("fchown");
+ exit(EXIT_FAILURE);
+ }
+ /*
+ * If global session daemon, any application can
+ * register so the shm needs to be set in read-only mode
+ * for others.
+ */
+ mode &= ~S_IWOTH;
+ ret = fchmod(wait_shm_fd, mode);
+ if (ret < 0) {
+ PERROR("fchmod");
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ ret = fchown(wait_shm_fd, getuid(), getgid());
+ if (ret < 0) {
+ PERROR("fchown");
+ exit(EXIT_FAILURE);
+ }