udev-watch.c revision 9f6445e34a57c270f013c9416c123e56261553dd
/*
* Copyright (C) 2004-2012 Kay Sievers <kay@vrfy.org>
* Copyright (C) 2009 Canonical Ltd.
* Copyright (C) 2009 Scott James Remnant <scott@netsplit.com>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <dirent.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "udev.h"
static int inotify_fd = -1;
/* inotify descriptor, will be shared with rules directory;
* set to cloexec since we need our children to be able to add
* watches for us
*/
{
if (inotify_fd < 0)
log_error("inotify_init failed: %m");
return inotify_fd;
}
/* move any old watches directory out of the way, and then restore
* the watches
*/
{
if (inotify_fd < 0)
return;
log_error("unable to open old watches dir /run/udev/watch.old; old watches will not be restored: %m");
return;
}
char device[UTIL_PATH_SIZE];
struct udev_device *dev;
continue;
goto unlink;
goto unlink;
}
}
}
{
char filename[UTIL_PATH_SIZE];
int wd;
int r;
if (inotify_fd < 0)
return;
if (wd < 0) {
log_error("inotify_add_watch(%d, %s, %o) failed: %m",
return;
}
if (r < 0)
}
{
int wd;
char filename[UTIL_PATH_SIZE];
if (inotify_fd < 0)
return;
if (wd < 0)
return;
}
{
char filename[UTIL_PATH_SIZE];
char device[UTIL_NAME_SIZE];
if (inotify_fd < 0 || wd < 0)
return NULL;
return NULL;
}