1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dir-watch-dnotify.c OS specific directory change notification for message bus
4 * Copyright (C) 2003 Red Hat, Inc.
6 * Licensed under the Academic Free License version 2.1
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <dbus/dbus-internals.h>
32 #include "dir-watch.h"
34 #define MAX_DIRS_TO_WATCH 128
36 /* use a static array to avoid handling OOM */
37 static int fds[MAX_DIRS_TO_WATCH];
38 static int num_fds = 0;
41 bus_watch_directory (const char *dir, void *userdata)
45 _dbus_assert (dir != NULL);
47 if (num_fds >= MAX_DIRS_TO_WATCH )
49 _dbus_warn ("Cannot watch config directory '%s'. Already watching %d directories\n", dir, MAX_DIRS_TO_WATCH);
53 fd = open (dir, O_RDONLY);
56 _dbus_warn ("Cannot open directory '%s'; error '%s'\n", dir, _dbus_strerror (errno));
60 if (fcntl (fd, F_NOTIFY, DN_DELETE|DN_RENAME|DN_MODIFY) == -1)
62 _dbus_warn ("Cannot setup D_NOTIFY for '%s' error '%s'\n", dir, _dbus_strerror (errno));
68 _dbus_verbose ("Added watch on config directory '%s'\n", dir);
75 bus_drop_all_directory_watches (void)
77 _dbus_verbose ("Dropping all watches on config directories\n");
81 for (i = 0; i < num_fds; i++)
83 if (close (fds[i]) != 0)
85 _dbus_verbose ("Error closing fd %d for config directory watch\n", fds[i]);