mirror of
https://github.com/systemd/systemd.git
synced 2024-12-25 01:34:28 +03:00
libudev: do not use any udev source file
This commit is contained in:
parent
b2946df419
commit
3eb46ec6dd
@ -31,7 +31,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "../../udev/list.h"
|
#include "../../udev/lib/list.h"
|
||||||
|
|
||||||
#define TMPFILE UDEV_PREFIX "/dev/.udev/collect"
|
#define TMPFILE UDEV_PREFIX "/dev/.udev/collect"
|
||||||
#define BUFSIZE 16
|
#define BUFSIZE 16
|
||||||
|
@ -16,8 +16,6 @@ AM_CPPFLAGS = \
|
|||||||
common_ldadd =
|
common_ldadd =
|
||||||
|
|
||||||
common_files = \
|
common_files = \
|
||||||
list.h \
|
|
||||||
logging.h \
|
|
||||||
udev.h \
|
udev.h \
|
||||||
udev_rules.h \
|
udev_rules.h \
|
||||||
udev_sysdeps.h \
|
udev_sysdeps.h \
|
||||||
@ -32,6 +30,7 @@ common_files = \
|
|||||||
udev_utils.c \
|
udev_utils.c \
|
||||||
udev_utils_file.c \
|
udev_utils_file.c \
|
||||||
udev_utils_string.c \
|
udev_utils_string.c \
|
||||||
|
lib/list.h \
|
||||||
lib/libudev.h \
|
lib/libudev.h \
|
||||||
lib/libudev-private.h \
|
lib/libudev-private.h \
|
||||||
lib/libudev.c \
|
lib/libudev.c \
|
||||||
|
@ -28,9 +28,7 @@ libudev_la_SOURCES =\
|
|||||||
libudev-enumerate.c \
|
libudev-enumerate.c \
|
||||||
libudev-ctrl.c \
|
libudev-ctrl.c \
|
||||||
libudev-monitor.c \
|
libudev-monitor.c \
|
||||||
../list.h \
|
list.h
|
||||||
../udev.h \
|
|
||||||
../udev_sysdeps.c
|
|
||||||
|
|
||||||
libudev_la_LDFLAGS = \
|
libudev_la_LDFLAGS = \
|
||||||
-version-info $(LIBUDEV_LT_CURRENT):$(LIBUDEV_LT_REVISION):$(LIBUDEV_LT_AGE) \
|
-version-info $(LIBUDEV_LT_CURRENT):$(LIBUDEV_LT_REVISION):$(LIBUDEV_LT_AGE) \
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
|
||||||
#include "../udev.h"
|
|
||||||
#include "libudev.h"
|
#include "libudev.h"
|
||||||
#include "libudev-private.h"
|
#include "libudev-private.h"
|
||||||
|
|
||||||
@ -155,7 +154,7 @@ static int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int
|
|||||||
ctrl_msg.type = type;
|
ctrl_msg.type = type;
|
||||||
|
|
||||||
if (buf != NULL)
|
if (buf != NULL)
|
||||||
strlcpy(ctrl_msg.buf, buf, sizeof(ctrl_msg.buf));
|
util_strlcpy(ctrl_msg.buf, buf, sizeof(ctrl_msg.buf));
|
||||||
else
|
else
|
||||||
ctrl_msg.intval = intval;
|
ctrl_msg.intval = intval;
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
|
|
||||||
#include "libudev.h"
|
#include "libudev.h"
|
||||||
#include "libudev-private.h"
|
#include "libudev-private.h"
|
||||||
#include "../udev.h"
|
|
||||||
|
|
||||||
struct udev_device {
|
struct udev_device {
|
||||||
int refcount;
|
int refcount;
|
||||||
@ -58,17 +57,17 @@ static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *f
|
|||||||
size_t start;
|
size_t start;
|
||||||
|
|
||||||
/* translate to location of db file */
|
/* translate to location of db file */
|
||||||
strlcpy(filename, udev_get_dev_path(udev), len);
|
util_strlcpy(filename, udev_get_dev_path(udev), len);
|
||||||
start = strlcat(filename, "/.udev/db/", len);
|
start = util_strlcat(filename, "/.udev/db/", len);
|
||||||
strlcat(filename, devpath, len);
|
util_strlcat(filename, devpath, len);
|
||||||
return util_path_encode(&filename[start], len - start);
|
return util_path_encode(&filename[start], len - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int device_read_db(struct udev_device *udev_device)
|
static int device_read_db(struct udev_device *udev_device)
|
||||||
{
|
{
|
||||||
struct stat stats;
|
struct stat stats;
|
||||||
char filename[PATH_SIZE];
|
char filename[UTIL_PATH_SIZE];
|
||||||
char line[PATH_SIZE];
|
char line[UTIL_LINE_SIZE];
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
@ -79,7 +78,7 @@ static int device_read_db(struct udev_device *udev_device)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ((stats.st_mode & S_IFMT) == S_IFLNK) {
|
if ((stats.st_mode & S_IFMT) == S_IFLNK) {
|
||||||
char target[NAME_SIZE];
|
char target[UTIL_PATH_SIZE];
|
||||||
int target_len;
|
int target_len;
|
||||||
|
|
||||||
info(udev_device->udev, "found a symlink as db file\n");
|
info(udev_device->udev, "found a symlink as db file\n");
|
||||||
@ -121,9 +120,9 @@ static int device_read_db(struct udev_device *udev_device)
|
|||||||
device_set_devnum(udev_device, makedev(maj, min));
|
device_set_devnum(udev_device, makedev(maj, min));
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
strlcpy(filename, udev_get_dev_path(udev_device->udev), sizeof(filename));
|
util_strlcpy(filename, udev_get_dev_path(udev_device->udev), sizeof(filename));
|
||||||
strlcat(filename, "/", sizeof(filename));
|
util_strlcat(filename, "/", sizeof(filename));
|
||||||
strlcat(filename, val, sizeof(filename));
|
util_strlcat(filename, val, sizeof(filename));
|
||||||
device_add_devlink(udev_device, filename);
|
device_add_devlink(udev_device, filename);
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
@ -183,7 +182,7 @@ struct udev_device *device_init(struct udev *udev)
|
|||||||
**/
|
**/
|
||||||
struct udev_device *udev_device_new_from_devpath(struct udev *udev, const char *devpath)
|
struct udev_device *udev_device_new_from_devpath(struct udev *udev, const char *devpath)
|
||||||
{
|
{
|
||||||
char path[PATH_SIZE];
|
char path[UTIL_PATH_SIZE];
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
struct udev_device *udev_device;
|
struct udev_device *udev_device;
|
||||||
|
|
||||||
@ -192,8 +191,8 @@ struct udev_device *udev_device_new_from_devpath(struct udev *udev, const char *
|
|||||||
if (devpath == NULL)
|
if (devpath == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
strlcpy(path, udev_get_sys_path(udev), sizeof(path));
|
util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
|
||||||
strlcat(path, devpath, sizeof(path));
|
util_strlcat(path, devpath, sizeof(path));
|
||||||
if (stat(path, &statbuf) != 0)
|
if (stat(path, &statbuf) != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!S_ISDIR(statbuf.st_mode))
|
if (!S_ISDIR(statbuf.st_mode))
|
||||||
@ -204,7 +203,7 @@ struct udev_device *udev_device_new_from_devpath(struct udev *udev, const char *
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* resolve possible symlink to real path */
|
/* resolve possible symlink to real path */
|
||||||
strlcpy(path, devpath, sizeof(path));
|
util_strlcpy(path, devpath, sizeof(path));
|
||||||
util_resolve_sys_link(udev, path, sizeof(path));
|
util_resolve_sys_link(udev, path, sizeof(path));
|
||||||
device_set_devpath(udev_device, path);
|
device_set_devpath(udev_device, path);
|
||||||
info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device));
|
info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device));
|
||||||
@ -333,7 +332,7 @@ const char *udev_device_get_devname(struct udev_device *udev_device)
|
|||||||
**/
|
**/
|
||||||
const char *udev_device_get_subsystem(struct udev_device *udev_device)
|
const char *udev_device_get_subsystem(struct udev_device *udev_device)
|
||||||
{
|
{
|
||||||
char subsystem[NAME_SIZE];
|
char subsystem[UTIL_PATH_SIZE];
|
||||||
|
|
||||||
if (udev_device == NULL)
|
if (udev_device == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -363,7 +362,7 @@ int udev_device_get_devlinks(struct udev_device *udev_device,
|
|||||||
int (*cb)(struct udev_device *udev_device, const char *value, void *data),
|
int (*cb)(struct udev_device *udev_device, const char *value, void *data),
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
struct name_entry *name_loop;
|
struct util_name_entry *name_loop;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
if (udev_device == NULL)
|
if (udev_device == NULL)
|
||||||
@ -393,17 +392,16 @@ int udev_device_get_properties(struct udev_device *udev_device,
|
|||||||
int (*cb)(struct udev_device *udev_device, const char *key, const char *value, void *data),
|
int (*cb)(struct udev_device *udev_device, const char *key, const char *value, void *data),
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
struct name_entry *name_loop;
|
struct util_name_entry *name_loop;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
if (udev_device == NULL)
|
if (udev_device == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
list_for_each_entry(name_loop, &udev_device->env_list, node) {
|
list_for_each_entry(name_loop, &udev_device->env_list, node) {
|
||||||
char name[PATH_SIZE];
|
char name[UTIL_PATH_SIZE];
|
||||||
char *val;
|
char *val;
|
||||||
|
|
||||||
strncpy(name, name_loop->name, PATH_SIZE);
|
strncpy(name, name_loop->name, sizeof(name));
|
||||||
name[PATH_SIZE-1] = '\0';
|
|
||||||
val = strchr(name, '=');
|
val = strchr(name, '=');
|
||||||
if (val == NULL)
|
if (val == NULL)
|
||||||
continue;
|
continue;
|
||||||
@ -418,7 +416,7 @@ int udev_device_get_properties(struct udev_device *udev_device,
|
|||||||
|
|
||||||
const char *udev_device_get_driver(struct udev_device *udev_device)
|
const char *udev_device_get_driver(struct udev_device *udev_device)
|
||||||
{
|
{
|
||||||
char driver[NAME_SIZE];
|
char driver[UTIL_PATH_SIZE];
|
||||||
|
|
||||||
if (udev_device == NULL)
|
if (udev_device == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -30,34 +30,33 @@
|
|||||||
|
|
||||||
#include "libudev.h"
|
#include "libudev.h"
|
||||||
#include "libudev-private.h"
|
#include "libudev-private.h"
|
||||||
#include "../udev.h"
|
|
||||||
|
|
||||||
static int devices_scan_subsystem(struct udev *udev,
|
static int devices_scan_subsystem(struct udev *udev,
|
||||||
const char *basedir, const char *subsystem, const char *subdir,
|
const char *basedir, const char *subsystem, const char *subdir,
|
||||||
struct list_head *device_list)
|
struct list_head *device_list)
|
||||||
{
|
{
|
||||||
char path[PATH_SIZE];
|
char path[UTIL_PATH_SIZE];
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *dent;
|
struct dirent *dent;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
len = strlcpy(path, udev_get_sys_path(udev), sizeof(path));
|
len = util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
|
||||||
strlcat(path, basedir, sizeof(path));
|
util_strlcat(path, basedir, sizeof(path));
|
||||||
strlcat(path, "/", sizeof(path));
|
util_strlcat(path, "/", sizeof(path));
|
||||||
strlcat(path, subsystem, sizeof(path));
|
util_strlcat(path, subsystem, sizeof(path));
|
||||||
if (subdir != NULL)
|
if (subdir != NULL)
|
||||||
strlcat(path, subdir, sizeof(path));
|
util_strlcat(path, subdir, sizeof(path));
|
||||||
dir = opendir(path);
|
dir = opendir(path);
|
||||||
if (dir == NULL)
|
if (dir == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
|
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
|
||||||
char devpath[PATH_SIZE];
|
char devpath[UTIL_PATH_SIZE];
|
||||||
|
|
||||||
if (dent->d_name[0] == '.')
|
if (dent->d_name[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
strlcpy(devpath, &path[len], sizeof(devpath));
|
util_strlcpy(devpath, &path[len], sizeof(devpath));
|
||||||
strlcat(devpath, "/", sizeof(devpath));
|
util_strlcat(devpath, "/", sizeof(devpath));
|
||||||
strlcat(devpath, dent->d_name, sizeof(devpath));
|
util_strlcat(devpath, dent->d_name, sizeof(devpath));
|
||||||
util_resolve_sys_link(udev, devpath, sizeof(devpath));
|
util_resolve_sys_link(udev, devpath, sizeof(devpath));
|
||||||
util_name_list_add(udev, device_list, devpath, 1);
|
util_name_list_add(udev, device_list, devpath, 1);
|
||||||
}
|
}
|
||||||
@ -69,15 +68,15 @@ static int devices_scan_subsystems(struct udev *udev,
|
|||||||
const char *basedir, const char *subsystem, const char *subdir,
|
const char *basedir, const char *subsystem, const char *subdir,
|
||||||
struct list_head *device_list)
|
struct list_head *device_list)
|
||||||
{
|
{
|
||||||
char path[PATH_SIZE];
|
char path[UTIL_PATH_SIZE];
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *dent;
|
struct dirent *dent;
|
||||||
|
|
||||||
if (subsystem != NULL)
|
if (subsystem != NULL)
|
||||||
return devices_scan_subsystem(udev, basedir, subsystem, subdir, device_list);
|
return devices_scan_subsystem(udev, basedir, subsystem, subdir, device_list);
|
||||||
|
|
||||||
strlcpy(path, udev_get_sys_path(udev), sizeof(path));
|
util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
|
||||||
strlcat(path, basedir, sizeof(path));
|
util_strlcat(path, basedir, sizeof(path));
|
||||||
dir = opendir(path);
|
dir = opendir(path);
|
||||||
if (dir == NULL)
|
if (dir == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@ -115,7 +114,7 @@ static int devices_call(struct udev *udev, const char *devpath,
|
|||||||
void *data,
|
void *data,
|
||||||
int *cb_rc)
|
int *cb_rc)
|
||||||
{
|
{
|
||||||
char subsystem[NAME_SIZE];
|
char subsystem[UTIL_PATH_SIZE];
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
name = strrchr(devpath, '/');
|
name = strrchr(devpath, '/');
|
||||||
@ -147,19 +146,19 @@ int udev_enumerate_devices(struct udev *udev, const char *subsystem,
|
|||||||
const char *devpath, const char *subsystem, const char *name, void *data),
|
const char *devpath, const char *subsystem, const char *name, void *data),
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
char base[PATH_SIZE];
|
char base[UTIL_PATH_SIZE];
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
struct list_head device_list;
|
struct list_head device_list;
|
||||||
struct name_entry *loop_device;
|
struct util_name_entry *loop_device;
|
||||||
struct name_entry *tmp_device;
|
struct util_name_entry *tmp_device;
|
||||||
int cb_rc = 0;
|
int cb_rc = 0;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
INIT_LIST_HEAD(&device_list);
|
INIT_LIST_HEAD(&device_list);
|
||||||
|
|
||||||
/* if we have /sys/subsystem/, forget all the old stuff */
|
/* if we have /sys/subsystem/, forget all the old stuff */
|
||||||
strlcpy(base, udev_get_sys_path(udev), sizeof(base));
|
util_strlcpy(base, udev_get_sys_path(udev), sizeof(base));
|
||||||
strlcat(base, "/subsystem", sizeof(base));
|
util_strlcat(base, "/subsystem", sizeof(base));
|
||||||
if (stat(base, &statbuf) == 0) {
|
if (stat(base, &statbuf) == 0) {
|
||||||
devices_scan_subsystems(udev, "/subsystem", subsystem, "/devices", &device_list);
|
devices_scan_subsystems(udev, "/subsystem", subsystem, "/devices", &device_list);
|
||||||
} else {
|
} else {
|
||||||
@ -174,6 +173,7 @@ int udev_enumerate_devices(struct udev *udev, const char *subsystem,
|
|||||||
if (devices_call(udev, loop_device->name, cb, data, &cb_rc) == 0)
|
if (devices_call(udev, loop_device->name, cb, data, &cb_rc) == 0)
|
||||||
count++;
|
count++;
|
||||||
list_del(&loop_device->node);
|
list_del(&loop_device->node);
|
||||||
|
free(loop_device->name);
|
||||||
free(loop_device);
|
free(loop_device);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,6 +183,7 @@ int udev_enumerate_devices(struct udev *udev, const char *subsystem,
|
|||||||
if (devices_call(udev, loop_device->name, cb, data, &cb_rc) == 0)
|
if (devices_call(udev, loop_device->name, cb, data, &cb_rc) == 0)
|
||||||
count++;
|
count++;
|
||||||
list_del(&loop_device->node);
|
list_del(&loop_device->node);
|
||||||
|
free(loop_device->name);
|
||||||
free(loop_device);
|
free(loop_device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
#include "libudev.h"
|
#include "libudev.h"
|
||||||
#include "libudev-private.h"
|
#include "libudev-private.h"
|
||||||
#include "../udev.h"
|
|
||||||
|
|
||||||
struct udev_monitor {
|
struct udev_monitor {
|
||||||
struct udev *udev;
|
struct udev *udev;
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include "libudev.h"
|
#include "libudev.h"
|
||||||
#include "../udev.h"
|
#include "list.h"
|
||||||
|
|
||||||
#ifdef USE_LOG
|
#ifdef USE_LOG
|
||||||
#ifdef USE_DEBUG
|
#ifdef USE_DEBUG
|
||||||
@ -104,6 +104,13 @@ extern const char *udev_ctrl_get_set_env(struct udev_ctrl_msg *ctrl_msg);
|
|||||||
extern int udev_ctrl_get_set_max_childs(struct udev_ctrl_msg *ctrl_msg);
|
extern int udev_ctrl_get_set_max_childs(struct udev_ctrl_msg *ctrl_msg);
|
||||||
|
|
||||||
/* libudev-utils */
|
/* libudev-utils */
|
||||||
|
#define UTIL_PATH_SIZE 1024
|
||||||
|
#define UTIL_LINE_SIZE 1024
|
||||||
|
struct util_name_entry {
|
||||||
|
struct list_head node;
|
||||||
|
char *name;
|
||||||
|
int *i;
|
||||||
|
};
|
||||||
extern ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size);
|
extern ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size);
|
||||||
extern ssize_t util_get_sys_driver(struct udev *udev, const char *devpath, char *driver, size_t size);
|
extern ssize_t util_get_sys_driver(struct udev *udev, const char *devpath, char *driver, size_t size);
|
||||||
extern int util_resolve_sys_link(struct udev *udev, char *devpath, size_t size);
|
extern int util_resolve_sys_link(struct udev *udev, char *devpath, size_t size);
|
||||||
@ -114,4 +121,6 @@ extern int util_log_priority(const char *priority);
|
|||||||
extern size_t util_path_encode(char *s, size_t len);
|
extern size_t util_path_encode(char *s, size_t len);
|
||||||
extern size_t util_path_decode(char *s);
|
extern size_t util_path_decode(char *s);
|
||||||
extern void util_remove_trailing_chars(char *path, char c);
|
extern void util_remove_trailing_chars(char *path, char c);
|
||||||
|
extern size_t util_strlcpy(char *dst, const char *src, size_t size);
|
||||||
|
extern size_t util_strlcat(char *dst, const char *src, size_t size);
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,18 +30,17 @@
|
|||||||
|
|
||||||
#include "libudev.h"
|
#include "libudev.h"
|
||||||
#include "libudev-private.h"
|
#include "libudev-private.h"
|
||||||
#include "../udev.h"
|
|
||||||
|
|
||||||
static ssize_t get_sys_link(struct udev *udev, const char *slink, const char *devpath, char *subsystem, size_t size)
|
static ssize_t get_sys_link(struct udev *udev, const char *slink, const char *devpath, char *subsystem, size_t size)
|
||||||
{
|
{
|
||||||
char path[PATH_SIZE];
|
char path[UTIL_PATH_SIZE];
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
const char *pos;
|
const char *pos;
|
||||||
|
|
||||||
strlcpy(path, udev_get_sys_path(udev), sizeof(path));
|
util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
|
||||||
strlcat(path, devpath, sizeof(path));
|
util_strlcat(path, devpath, sizeof(path));
|
||||||
strlcat(path, "/", sizeof(path));
|
util_strlcat(path, "/", sizeof(path));
|
||||||
strlcat(path, slink, sizeof(path));
|
util_strlcat(path, slink, sizeof(path));
|
||||||
len = readlink(path, path, sizeof(path));
|
len = readlink(path, path, sizeof(path));
|
||||||
if (len < 0 || len >= (ssize_t) sizeof(path))
|
if (len < 0 || len >= (ssize_t) sizeof(path))
|
||||||
return -1;
|
return -1;
|
||||||
@ -50,7 +49,7 @@ static ssize_t get_sys_link(struct udev *udev, const char *slink, const char *de
|
|||||||
if (pos == NULL)
|
if (pos == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
pos = &pos[1];
|
pos = &pos[1];
|
||||||
return strlcpy(subsystem, pos, size);
|
return util_strlcpy(subsystem, pos, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size)
|
ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size)
|
||||||
@ -65,14 +64,15 @@ ssize_t util_get_sys_driver(struct udev *udev, const char *devpath, char *driver
|
|||||||
|
|
||||||
int util_resolve_sys_link(struct udev *udev, char *devpath, size_t size)
|
int util_resolve_sys_link(struct udev *udev, char *devpath, size_t size)
|
||||||
{
|
{
|
||||||
char link_path[PATH_SIZE];
|
char link_path[UTIL_PATH_SIZE];
|
||||||
char link_target[PATH_SIZE];
|
char link_target[UTIL_PATH_SIZE];
|
||||||
|
|
||||||
int len;
|
int len;
|
||||||
int i;
|
int i;
|
||||||
int back;
|
int back;
|
||||||
|
|
||||||
strlcpy(link_path, udev_get_sys_path(udev), sizeof(link_path));
|
util_strlcpy(link_path, udev_get_sys_path(udev), sizeof(link_path));
|
||||||
strlcat(link_path, devpath, sizeof(link_path));
|
util_strlcat(link_path, devpath, sizeof(link_path));
|
||||||
len = readlink(link_path, link_target, sizeof(link_target));
|
len = readlink(link_path, link_target, sizeof(link_target));
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -90,17 +90,11 @@ int util_resolve_sys_link(struct udev *udev, char *devpath, size_t size)
|
|||||||
pos[0] = '\0';
|
pos[0] = '\0';
|
||||||
}
|
}
|
||||||
dbg(udev, "after moving back '%s'\n", devpath);
|
dbg(udev, "after moving back '%s'\n", devpath);
|
||||||
strlcat(devpath, "/", size);
|
util_strlcat(devpath, "/", size);
|
||||||
strlcat(devpath, &link_target[back * 3], size);
|
util_strlcat(devpath, &link_target[back * 3], size);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct util_name_entry {
|
|
||||||
struct list_head node;
|
|
||||||
char *name;
|
|
||||||
int *i;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct util_name_entry *util_name_list_add(struct udev *udev, struct list_head *name_list,
|
struct util_name_entry *util_name_list_add(struct udev *udev, struct list_head *name_list,
|
||||||
const char *name, int sort)
|
const char *name, int sort)
|
||||||
{
|
{
|
||||||
@ -122,9 +116,15 @@ struct util_name_entry *util_name_list_add(struct udev *udev, struct list_head *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
name_new->name = strdup(name);
|
name_new = malloc(sizeof(struct util_name_entry));
|
||||||
if (name_new->name == NULL)
|
if (name_new == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
memset(name_new, 0x00, sizeof(struct util_name_entry));
|
||||||
|
name_new->name = strdup(name);
|
||||||
|
if (name_new->name == NULL) {
|
||||||
|
free(name_new);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
dbg(udev, "adding '%s'\n", name_new->name);
|
dbg(udev, "adding '%s'\n", name_new->name);
|
||||||
list_add_tail(&name_new->node, &name_loop->node);
|
list_add_tail(&name_new->node, &name_loop->node);
|
||||||
return name_new;
|
return name_new;
|
||||||
@ -212,3 +212,46 @@ void util_remove_trailing_chars(char *path, char c)
|
|||||||
while (len > 0 && path[len-1] == c)
|
while (len > 0 && path[len-1] == c)
|
||||||
path[--len] = '\0';
|
path[--len] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t util_strlcpy(char *dst, const char *src, size_t size)
|
||||||
|
{
|
||||||
|
size_t bytes = 0;
|
||||||
|
char *q = dst;
|
||||||
|
const char *p = src;
|
||||||
|
char ch;
|
||||||
|
|
||||||
|
while ((ch = *p++)) {
|
||||||
|
if (bytes+1 < size)
|
||||||
|
*q++ = ch;
|
||||||
|
bytes++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If size == 0 there is no space for a final null... */
|
||||||
|
if (size)
|
||||||
|
*q = '\0';
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t util_strlcat(char *dst, const char *src, size_t size)
|
||||||
|
{
|
||||||
|
size_t bytes = 0;
|
||||||
|
char *q = dst;
|
||||||
|
const char *p = src;
|
||||||
|
char ch;
|
||||||
|
|
||||||
|
while (bytes < size && *q) {
|
||||||
|
q++;
|
||||||
|
bytes++;
|
||||||
|
}
|
||||||
|
if (bytes == size)
|
||||||
|
return (bytes + strlen(src));
|
||||||
|
|
||||||
|
while ((ch = *p++)) {
|
||||||
|
if (bytes+1 < size)
|
||||||
|
*q++ = ch;
|
||||||
|
bytes++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*q = '\0';
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
#include "libudev.h"
|
#include "libudev.h"
|
||||||
#include "libudev-private.h"
|
#include "libudev-private.h"
|
||||||
#include "../udev.h"
|
|
||||||
|
|
||||||
struct udev {
|
struct udev {
|
||||||
int refcount;
|
int refcount;
|
||||||
@ -201,7 +200,7 @@ struct udev *udev_new(void)
|
|||||||
goto err;
|
goto err;
|
||||||
f = fopen(config_file, "r");
|
f = fopen(config_file, "r");
|
||||||
if (f != NULL) {
|
if (f != NULL) {
|
||||||
char line[LINE_SIZE];
|
char line[UTIL_LINE_SIZE];
|
||||||
int line_nr = 0;
|
int line_nr = 0;
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), f)) {
|
while (fgets(line, sizeof(line), f)) {
|
||||||
|
286
udev/list.h
286
udev/list.h
@ -1,286 +0,0 @@
|
|||||||
/*
|
|
||||||
* Based on list.h in the Linux kernel source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _LIST_H
|
|
||||||
#define _LIST_H
|
|
||||||
|
|
||||||
/**
|
|
||||||
* container_of - cast a member of a structure out to the containing structure
|
|
||||||
*
|
|
||||||
* @ptr: the pointer to the member.
|
|
||||||
* @type: the type of the container struct this is embedded in.
|
|
||||||
* @member: the name of the member within the struct.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#define container_of(ptr, type, member) ({ \
|
|
||||||
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
|
||||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* These are non-NULL pointers that will result in page faults
|
|
||||||
* under normal circumstances, used to verify that nobody uses
|
|
||||||
* non-initialized list entries.
|
|
||||||
*/
|
|
||||||
#define LIST_POISON1 ((void *) 0x00100100)
|
|
||||||
#define LIST_POISON2 ((void *) 0x00200200)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Simple doubly linked list implementation.
|
|
||||||
*
|
|
||||||
* Some of the internal functions ("__xxx") are useful when
|
|
||||||
* manipulating whole lists rather than single entries, as
|
|
||||||
* sometimes we already know the next/prev entries and we can
|
|
||||||
* generate better code by using them directly rather than
|
|
||||||
* using the generic single-entry routines.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct list_head {
|
|
||||||
struct list_head *next, *prev;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
|
||||||
|
|
||||||
#define LIST_HEAD(name) \
|
|
||||||
struct list_head name = LIST_HEAD_INIT(name)
|
|
||||||
|
|
||||||
#define INIT_LIST_HEAD(ptr) do { \
|
|
||||||
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Insert a new entry between two known consecutive entries.
|
|
||||||
*
|
|
||||||
* This is only for internal list manipulation where we know
|
|
||||||
* the prev/next entries already!
|
|
||||||
*/
|
|
||||||
static inline void __list_add(struct list_head *new,
|
|
||||||
struct list_head *prev,
|
|
||||||
struct list_head *next)
|
|
||||||
{
|
|
||||||
next->prev = new;
|
|
||||||
new->next = next;
|
|
||||||
new->prev = prev;
|
|
||||||
prev->next = new;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_add - add a new entry
|
|
||||||
* @new: new entry to be added
|
|
||||||
* @head: list head to add it after
|
|
||||||
*
|
|
||||||
* Insert a new entry after the specified head.
|
|
||||||
* This is good for implementing stacks.
|
|
||||||
*/
|
|
||||||
static inline void list_add(struct list_head *new, struct list_head *head)
|
|
||||||
{
|
|
||||||
__list_add(new, head, head->next);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_add_tail - add a new entry
|
|
||||||
* @new: new entry to be added
|
|
||||||
* @head: list head to add it before
|
|
||||||
*
|
|
||||||
* Insert a new entry before the specified head.
|
|
||||||
* This is useful for implementing queues.
|
|
||||||
*/
|
|
||||||
static inline void list_add_tail(struct list_head *new, struct list_head *head)
|
|
||||||
{
|
|
||||||
__list_add(new, head->prev, head);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Delete a list entry by making the prev/next entries
|
|
||||||
* point to each other.
|
|
||||||
*
|
|
||||||
* This is only for internal list manipulation where we know
|
|
||||||
* the prev/next entries already!
|
|
||||||
*/
|
|
||||||
static inline void __list_del(struct list_head * prev, struct list_head * next)
|
|
||||||
{
|
|
||||||
next->prev = prev;
|
|
||||||
prev->next = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_del - deletes entry from list.
|
|
||||||
* @entry: the element to delete from the list.
|
|
||||||
* Note: list_empty on entry does not return true after this, the entry is
|
|
||||||
* in an undefined state.
|
|
||||||
*/
|
|
||||||
static inline void list_del(struct list_head *entry)
|
|
||||||
{
|
|
||||||
__list_del(entry->prev, entry->next);
|
|
||||||
entry->next = LIST_POISON1;
|
|
||||||
entry->prev = LIST_POISON2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_del_init - deletes entry from list and reinitialize it.
|
|
||||||
* @entry: the element to delete from the list.
|
|
||||||
*/
|
|
||||||
static inline void list_del_init(struct list_head *entry)
|
|
||||||
{
|
|
||||||
__list_del(entry->prev, entry->next);
|
|
||||||
INIT_LIST_HEAD(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_move - delete from one list and add as another's head
|
|
||||||
* @list: the entry to move
|
|
||||||
* @head: the head that will precede our entry
|
|
||||||
*/
|
|
||||||
static inline void list_move(struct list_head *list, struct list_head *head)
|
|
||||||
{
|
|
||||||
__list_del(list->prev, list->next);
|
|
||||||
list_add(list, head);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_move_tail - delete from one list and add as another's tail
|
|
||||||
* @list: the entry to move
|
|
||||||
* @head: the head that will follow our entry
|
|
||||||
*/
|
|
||||||
static inline void list_move_tail(struct list_head *list,
|
|
||||||
struct list_head *head)
|
|
||||||
{
|
|
||||||
__list_del(list->prev, list->next);
|
|
||||||
list_add_tail(list, head);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_empty - tests whether a list is empty
|
|
||||||
* @head: the list to test.
|
|
||||||
*/
|
|
||||||
static inline int list_empty(struct list_head *head)
|
|
||||||
{
|
|
||||||
return head->next == head;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void __list_splice(struct list_head *list,
|
|
||||||
struct list_head *head)
|
|
||||||
{
|
|
||||||
struct list_head *first = list->next;
|
|
||||||
struct list_head *last = list->prev;
|
|
||||||
struct list_head *at = head->next;
|
|
||||||
|
|
||||||
first->prev = head;
|
|
||||||
head->next = first;
|
|
||||||
|
|
||||||
last->next = at;
|
|
||||||
at->prev = last;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_splice - join two lists
|
|
||||||
* @list: the new list to add.
|
|
||||||
* @head: the place to add it in the first list.
|
|
||||||
*/
|
|
||||||
static inline void list_splice(struct list_head *list, struct list_head *head)
|
|
||||||
{
|
|
||||||
if (!list_empty(list))
|
|
||||||
__list_splice(list, head);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_splice_init - join two lists and reinitialise the emptied list.
|
|
||||||
* @list: the new list to add.
|
|
||||||
* @head: the place to add it in the first list.
|
|
||||||
*
|
|
||||||
* The list at @list is reinitialised
|
|
||||||
*/
|
|
||||||
static inline void list_splice_init(struct list_head *list,
|
|
||||||
struct list_head *head)
|
|
||||||
{
|
|
||||||
if (!list_empty(list)) {
|
|
||||||
__list_splice(list, head);
|
|
||||||
INIT_LIST_HEAD(list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_entry - get the struct for this entry
|
|
||||||
* @ptr: the &struct list_head pointer.
|
|
||||||
* @type: the type of the struct this is embedded in.
|
|
||||||
* @member: the name of the list_struct within the struct.
|
|
||||||
*/
|
|
||||||
#define list_entry(ptr, type, member) \
|
|
||||||
container_of(ptr, type, member)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_for_each - iterate over a list
|
|
||||||
* @pos: the &struct list_head to use as a loop counter.
|
|
||||||
* @head: the head for your list.
|
|
||||||
*/
|
|
||||||
#define list_for_each(pos, head) \
|
|
||||||
for (pos = (head)->next; pos != (head); \
|
|
||||||
pos = pos->next)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* __list_for_each - iterate over a list
|
|
||||||
* @pos: the &struct list_head to use as a loop counter.
|
|
||||||
* @head: the head for your list.
|
|
||||||
*
|
|
||||||
* This variant differs from list_for_each() in that it's the
|
|
||||||
* simplest possible list iteration code.
|
|
||||||
* Use this for code that knows the list to be very short (empty
|
|
||||||
* or 1 entry) most of the time.
|
|
||||||
*/
|
|
||||||
#define __list_for_each(pos, head) \
|
|
||||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_for_each_prev - iterate over a list backwards
|
|
||||||
* @pos: the &struct list_head to use as a loop counter.
|
|
||||||
* @head: the head for your list.
|
|
||||||
*/
|
|
||||||
#define list_for_each_prev(pos, head) \
|
|
||||||
for (pos = (head)->prev; pos != (head); pos = pos->prev)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_for_each_safe - iterate over a list safe against removal of list entry
|
|
||||||
* @pos: the &struct list_head to use as a loop counter.
|
|
||||||
* @n: another &struct list_head to use as temporary storage
|
|
||||||
* @head: the head for your list.
|
|
||||||
*/
|
|
||||||
#define list_for_each_safe(pos, n, head) \
|
|
||||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
|
||||||
pos = n, n = pos->next)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_for_each_entry - iterate over list of given type
|
|
||||||
* @pos: the type * to use as a loop counter.
|
|
||||||
* @head: the head for your list.
|
|
||||||
* @member: the name of the list_struct within the struct.
|
|
||||||
*/
|
|
||||||
#define list_for_each_entry(pos, head, member) \
|
|
||||||
for (pos = list_entry((head)->next, typeof(*pos), member); \
|
|
||||||
&pos->member != (head); \
|
|
||||||
pos = list_entry(pos->member.next, typeof(*pos), member))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_for_each_entry_reverse - iterate backwards over list of given type.
|
|
||||||
* @pos: the type * to use as a loop counter.
|
|
||||||
* @head: the head for your list.
|
|
||||||
* @member: the name of the list_struct within the struct.
|
|
||||||
*/
|
|
||||||
#define list_for_each_entry_reverse(pos, head, member) \
|
|
||||||
for (pos = list_entry((head)->prev, typeof(*pos), member); \
|
|
||||||
&pos->member != (head); \
|
|
||||||
pos = list_entry(pos->member.prev, typeof(*pos), member))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
|
||||||
* @pos: the type * to use as a loop counter.
|
|
||||||
* @n: another type * to use as temporary storage
|
|
||||||
* @head: the head for your list.
|
|
||||||
* @member: the name of the list_struct within the struct.
|
|
||||||
*/
|
|
||||||
#define list_for_each_entry_safe(pos, n, head, member) \
|
|
||||||
for (pos = list_entry((head)->next, typeof(*pos), member), \
|
|
||||||
n = list_entry(pos->member.next, typeof(*pos), member); \
|
|
||||||
&pos->member != (head); \
|
|
||||||
pos = n, n = list_entry(n->member.next, typeof(*n), member))
|
|
||||||
|
|
||||||
#endif /* _LIST_H */
|
|
@ -24,11 +24,11 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
#include "list.h"
|
|
||||||
#include "udev_sysdeps.h"
|
#include "udev_sysdeps.h"
|
||||||
#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE 1
|
#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE 1
|
||||||
#include "lib/libudev.h"
|
#include "lib/libudev.h"
|
||||||
#include "lib/libudev-private.h"
|
#include "lib/libudev-private.h"
|
||||||
|
#include "lib/list.h"
|
||||||
|
|
||||||
#define COMMENT_CHARACTER '#'
|
#define COMMENT_CHARACTER '#'
|
||||||
#define LINE_SIZE 512
|
#define LINE_SIZE 512
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#define UDEV_RULES_H
|
#define UDEV_RULES_H
|
||||||
|
|
||||||
#include "udev.h"
|
#include "udev.h"
|
||||||
#include "list.h"
|
|
||||||
|
|
||||||
#define PAIRS_MAX 5
|
#define PAIRS_MAX 5
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user