From 44b49d3736bfdc94da31b5670a2c5a3477a201eb Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Tue, 9 Jun 2009 23:05:25 +0200 Subject: [PATCH] move common stuff from udev/ to private parts of libudev/ --- extras/floppy/Makefile.am | 8 ++--- extras/floppy/create_floppy_devices.c | 1 - libudev/libudev-device-db-write.c | 3 +- libudev/libudev-private.h | 31 ++++++++++++++++++- libudev/libudev-queue-export.c | 7 ++--- .../libudev-selinux-private.c | 21 +++++-------- .../libudev-util-private.c | 21 +++++-------- udev/Makefile.am | 4 +-- udev/udev.h | 30 ------------------ 9 files changed, 56 insertions(+), 70 deletions(-) rename udev/udev-selinux.c => libudev/libudev-selinux-private.c (72%) rename udev/udev-util.c => libudev/libudev-util-private.c (93%) diff --git a/extras/floppy/Makefile.am b/extras/floppy/Makefile.am index 365ece9ee..cbdcf6e8f 100644 --- a/extras/floppy/Makefile.am +++ b/extras/floppy/Makefile.am @@ -7,17 +7,17 @@ udevhome_PROGRAMS = \ create_floppy_devices_SOURCES = \ create_floppy_devices.c \ ../../libudev/libudev.h \ + ../../libudev/libudev-private.h \ ../../libudev/libudev.c \ ../../libudev/libudev-list.c \ ../../libudev/libudev-util.c \ + ../../libudev/libudev-util-private.c \ ../../libudev/libudev-device.c \ - ../../libudev/libudev-enumerate.c \ - ../../udev/udev.h \ - ../../udev/udev-util.c + ../../libudev/libudev-enumerate.c if USE_SELINUX create_floppy_devices_SOURCES += \ - ../../udev/udev-selinux.c + ../../libudev/libudev-selinux-private.c create_floppy_devices_LDADD = \ $(SELINUX_LIBS) endif diff --git a/extras/floppy/create_floppy_devices.c b/extras/floppy/create_floppy_devices.c index b0d7b0bc8..2fc05cc49 100644 --- a/extras/floppy/create_floppy_devices.c +++ b/extras/floppy/create_floppy_devices.c @@ -26,7 +26,6 @@ #include "libudev.h" #include "libudev-private.h" -#include "../../udev/udev.h" static char *table[] = { "", "d360", "h1200", "u360", "u720", "h360", "h720", diff --git a/libudev/libudev-device-db-write.c b/libudev/libudev-device-db-write.c index a8e66f788..68dc0a5b9 100644 --- a/libudev/libudev-device-db-write.c +++ b/libudev/libudev-device-db-write.c @@ -18,7 +18,8 @@ #include #include -#include "udev.h" +#include "libudev.h" +#include "libudev-private.h" static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *filename, size_t len) { diff --git a/libudev/libudev-private.h b/libudev/libudev-private.h index 21eb626dc..9cda7bcb1 100644 --- a/libudev/libudev-private.h +++ b/libudev/libudev-private.h @@ -16,6 +16,9 @@ #include "libudev.h" #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b)) +#define READ_END 0 +#define WRITE_END 1 static inline void __attribute__((always_inline, format(printf, 2, 3))) udev_log_null(struct udev *udev, const char *format, ...) {} @@ -182,7 +185,7 @@ int udev_queue_export_device_queued(struct udev_queue_export *udev_queue_export, int udev_queue_export_device_finished(struct udev_queue_export *udev_queue_export, struct udev_device *udev_device); int udev_queue_export_device_failed(struct udev_queue_export *udev_queue_export, struct udev_device *udev_device); -/* libudev-utils.c */ +/* libudev-util.c */ #define UTIL_PATH_SIZE 1024 #define UTIL_LINE_SIZE 2048 #define UTIL_NAME_SIZE 512 @@ -203,4 +206,30 @@ int udev_util_replace_chars(char *str, const char *white); int udev_util_encode_string(const char *str, char *str_enc, size_t len); void util_set_fd_cloexec(int fd); unsigned int util_string_hash32(const char *str); + +/* libudev-util-private.c */ +int util_create_path(struct udev *udev, const char *path); +int util_delete_path(struct udev *udev, const char *path); +int util_unlink_secure(struct udev *udev, const char *filename); +uid_t util_lookup_user(struct udev *udev, const char *user); +gid_t util_lookup_group(struct udev *udev, const char *group); +int util_run_program(struct udev *udev, const char *command, char **envp, + char *result, size_t ressize, size_t *reslen); +int util_resolve_subsys_kernel(struct udev *udev, const char *string, + char *result, size_t maxsize, int read_value); + +/* libudev-selinux-private.c */ +#ifndef USE_SELINUX +static inline void udev_selinux_init(struct udev *udev) {} +static inline void udev_selinux_exit(struct udev *udev) {} +static inline void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode) {} +static inline void udev_selinux_setfscreatecon(struct udev *udev, const char *file, unsigned int mode) {} +static inline void udev_selinux_resetfscreatecon(struct udev *udev) {} +#else +void udev_selinux_init(struct udev *udev); +void udev_selinux_exit(struct udev *udev); +void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode); +void udev_selinux_setfscreatecon(struct udev *udev, const char *file, unsigned int mode); +void udev_selinux_resetfscreatecon(struct udev *udev); +#endif #endif diff --git a/libudev/libudev-queue-export.c b/libudev/libudev-queue-export.c index a36ff5150..9ae680c38 100644 --- a/libudev/libudev-queue-export.c +++ b/libudev/libudev-queue-export.c @@ -14,7 +14,6 @@ * DISCLAIMER - The file format mentioned here is private to udev/libudev, * and may be changed without notice. * - * * The udev event queue is exported as a binary log file. * Each log record consists of a sequence number followed by the device path. * @@ -31,7 +30,6 @@ * The queue does not grow indefinitely. It is periodically re-created * to remove finished events. Atomic rename() makes this transparent to readers. * - * * The queue file starts with a single sequence number which specifies the * minimum sequence number in the log that follows. Any events prior to this * sequence number have already finished. @@ -48,7 +46,8 @@ #include #include -#include "udev.h" +#include "libudev.h" +#include "libudev-private.h" static int rebuild_queue_file(struct udev_queue_export *udev_queue_export); @@ -108,7 +107,6 @@ void udev_queue_export_cleanup(struct udev_queue_export *udev_queue_export) unlink(filename); } - static int skip_to(FILE *file, long offset) { long old_offset; @@ -320,7 +318,6 @@ write_error: return -1; } - enum device_state { DEVICE_QUEUED, DEVICE_FINISHED, diff --git a/udev/udev-selinux.c b/libudev/libudev-selinux-private.c similarity index 72% rename from udev/udev-selinux.c rename to libudev/libudev-selinux-private.c index 4f1b2bb2d..84f8b6a63 100644 --- a/udev/udev-selinux.c +++ b/libudev/libudev-selinux-private.c @@ -1,18 +1,12 @@ /* - * Copyright (C) 2008 Kay Sievers - * - * This program is free software: you can redistribute it and/or modify - * 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. + * libudev - interface to udev device information * - * 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. + * Copyright (C) 2008 Kay Sievers * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. */ #include @@ -22,7 +16,8 @@ #include #include -#include "udev.h" +#include "libudev.h" +#include "libudev-private.h" static int selinux_enabled; security_context_t selinux_prev_scontext; diff --git a/udev/udev-util.c b/libudev/libudev-util-private.c similarity index 93% rename from udev/udev-util.c rename to libudev/libudev-util-private.c index 645293d38..f22c04184 100644 --- a/udev/udev-util.c +++ b/libudev/libudev-util-private.c @@ -1,18 +1,12 @@ /* - * Copyright (C) 2004-2008 Kay Sievers + * libudev - interface to udev device information * - * This program is free software: you can redistribute it and/or modify - * 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. + * Copyright (C) 2004-2009 Kay Sievers * - * 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 . + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. */ #include @@ -27,7 +21,8 @@ #include #include -#include "udev.h" +#include "libudev.h" +#include "libudev-private.h" int util_create_path(struct udev *udev, const char *path) { diff --git a/udev/Makefile.am b/udev/Makefile.am index ca5b4fae5..f2ceb9977 100644 --- a/udev/Makefile.am +++ b/udev/Makefile.am @@ -15,12 +15,12 @@ common_files = \ udev-watch.c \ udev-node.c \ udev-rules.c \ - udev-util.c \ ../libudev/libudev.h \ ../libudev/libudev-private.h \ ../libudev/libudev.c \ ../libudev/libudev-list.c \ ../libudev/libudev-util.c \ + ../libudev/libudev-util-private.c \ ../libudev/libudev-device.c \ ../libudev/libudev-device-db-write.c \ ../libudev/libudev-monitor.c \ @@ -31,7 +31,7 @@ common_files = \ if USE_SELINUX common_files += \ - udev-selinux.c + ../libudev/libudev-selinux-private.c common_ldadd += \ $(SELINUX_LIBS) endif diff --git a/udev/udev.h b/udev/udev.h index bd3686b28..3e3ecfb1f 100644 --- a/udev/udev.h +++ b/udev/udev.h @@ -30,10 +30,6 @@ #define UDEV_CTRL_SOCK_PATH "@" UDEV_PREFIX "/org/kernel/udev/udevd" -#define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b)) -#define READ_END 0 -#define WRITE_END 1 - struct udev_event { struct udev *udev; struct udev_device *dev; @@ -89,32 +85,6 @@ int udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid); int udev_node_remove(struct udev_device *dev); void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev_old); -/* udev-util.c */ -int util_create_path(struct udev *udev, const char *path); -int util_delete_path(struct udev *udev, const char *path); -int util_unlink_secure(struct udev *udev, const char *filename); -uid_t util_lookup_user(struct udev *udev, const char *user); -gid_t util_lookup_group(struct udev *udev, const char *group); -int util_run_program(struct udev *udev, const char *command, char **envp, - char *result, size_t ressize, size_t *reslen); -int util_resolve_subsys_kernel(struct udev *udev, const char *string, - char *result, size_t maxsize, int read_value); - -/* udev-selinux.c */ -#ifndef USE_SELINUX -static inline void udev_selinux_init(struct udev *udev) {} -static inline void udev_selinux_exit(struct udev *udev) {} -static inline void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode) {} -static inline void udev_selinux_setfscreatecon(struct udev *udev, const char *file, unsigned int mode) {} -static inline void udev_selinux_resetfscreatecon(struct udev *udev) {} -#else -void udev_selinux_init(struct udev *udev); -void udev_selinux_exit(struct udev *udev); -void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode); -void udev_selinux_setfscreatecon(struct udev *udev, const char *file, unsigned int mode); -void udev_selinux_resetfscreatecon(struct udev *udev); -#endif - /* udevadm commands */ int udevadm_monitor(struct udev *udev, int argc, char *argv[]); int udevadm_info(struct udev *udev, int argc, char *argv[]); -- 2.30.2