2 * Copyright (C) 2009 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <sys/inotify.h>
31 #include <apr_general.h>
33 #include "hostinfod.h"
35 int sockets_inotify_fd = -1;
38 monitor_socket_dir (void)
43 error ("no socket directory was configured - see hostinfo(8)");
47 if (stat (socket_dir, &statbuf) == -1) {
48 perrorf ("%s (socket directory): does not exist or is not accessible",
52 if (!S_ISDIR (statbuf.st_mode)) {
53 error ("%s (socket directory): not a directory", socket_dir);
57 #ifdef HAVE_INOTIFY_INIT1
58 sockets_inotify_fd = inotify_init1 (IN_NONBLOCK | IN_CLOEXEC);
59 if (sockets_inotify_fd == -1) {
60 perrorf ("inotify_init");
64 sockets_inotify_fd = inotify_init ();
65 if (sockets_inotify_fd == -1) {
66 perrorf ("inotify_init");
69 if (fcntl (sockets_inotify_fd, F_SETFL, O_NONBLOCK) == -1) {
70 perrorf ("fcntl: O_NONBLOCK");
73 if (fcntl (sockets_inotify_fd, F_SETFD, FD_CLOEXEC) == -1) {
74 perrorf ("fcntl: FD_CLOEXEC");
79 if (inotify_add_watch (sockets_inotify_fd, socket_dir,
80 IN_CREATE|IN_DELETE|IN_MOVE) == -1) {
81 perrorf ("inotify_add_watch: %s", socket_dir);
85 debug ("inotify of %s successful, fd = %d",
86 socket_dir, sockets_inotify_fd);