1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

prefix udev-util.c functions with util_*

This commit is contained in:
Kay Sievers 2008-10-18 20:12:55 +02:00
parent c3b1fa66d2
commit 54808d77a3
8 changed files with 44 additions and 48 deletions

View File

@ -68,7 +68,7 @@ int main(int argc, char **argv)
logging_init("create_floppy_devices"); logging_init("create_floppy_devices");
udev_set_log_fn(udev, log_fn); udev_set_log_fn(udev, log_fn);
selinux_init(udev); udev_selinux_init(udev);
while ((c = getopt(argc, argv, "cudm:U:G:M:t:")) != -1) { while ((c = getopt(argc, argv, "cudm:U:G:M:t:")) != -1) {
switch (c) { switch (c) {
@ -79,10 +79,10 @@ int main(int argc, char **argv)
print_nodes = 1; print_nodes = 1;
break; break;
case 'U': case 'U':
uid = lookup_user(udev, optarg); uid = util_lookup_user(udev, optarg);
break; break;
case 'G': case 'G':
gid = lookup_group(udev, optarg); gid = util_lookup_group(udev, optarg);
break; break;
case 'M': case 'M':
mode = strtol(optarg, NULL, 0); mode = strtol(optarg, NULL, 0);
@ -162,7 +162,7 @@ int main(int argc, char **argv)
i++; i++;
} }
selinux_exit(udev); udev_selinux_exit(udev);
udev_unref(udev); udev_unref(udev);
exit: exit:
return 0; return 0;

View File

@ -50,7 +50,7 @@ int udev_device_update_db(struct udev_device *udev_device)
devpath_to_db_path(udev, devpath_to_db_path(udev,
udev_device_get_devpath(udev_device), udev_device_get_devpath(udev_device),
filename, sizeof(filename)); filename, sizeof(filename));
create_path(udev, filename); util_create_path(udev, filename);
unlink(filename); unlink(filename);
udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device))

View File

@ -732,7 +732,7 @@ int udev_event_execute_run(struct udev_event *event)
util_strlcpy(program, cmd, sizeof(program)); util_strlcpy(program, cmd, sizeof(program));
udev_event_apply_format(event, program, sizeof(program)); udev_event_apply_format(event, program, sizeof(program));
envp = udev_device_get_properties_envp(event->dev); envp = udev_device_get_properties_envp(event->dev);
if (run_program(event->udev, program, envp, NULL, 0, NULL) != 0) { if (util_run_program(event->udev, program, envp, NULL, 0, NULL) != 0) {
if (!udev_list_entry_get_flag(list_entry)) if (!udev_list_entry_get_flag(list_entry))
err = -1; err = -1;
} }

View File

@ -53,14 +53,14 @@ static int name_index(struct udev *udev, const char *devpath, const char *name,
if (add) { if (add) {
info(udev, "creating index: '%s'\n", filename); info(udev, "creating index: '%s'\n", filename);
create_path(udev, filename); util_create_path(udev, filename);
fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 0644); fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 0644);
if (fd > 0) if (fd > 0)
close(fd); close(fd);
} else { } else {
info(udev, "removing index: '%s'\n", filename); info(udev, "removing index: '%s'\n", filename);
unlink(filename); unlink(filename);
delete_path(udev, filename); util_delete_path(udev, filename);
} }
return 0; return 0;
} }
@ -288,7 +288,7 @@ static int update_link(struct udev_device *dev, const char *slink, int test)
info(udev, "no reference left, remove '%s'\n", slink); info(udev, "no reference left, remove '%s'\n", slink);
if (!test) { if (!test) {
unlink(slink); unlink(slink);
delete_path(udev, slink); util_delete_path(udev, slink);
} }
goto out; goto out;
} }
@ -349,7 +349,7 @@ static int update_link(struct udev_device *dev, const char *slink, int test)
/* create symlink to the target with the highest priority */ /* create symlink to the target with the highest priority */
info(udev, "'%s' with target '%s' has the highest priority %i, create it\n", slink, target, priority); info(udev, "'%s' with target '%s' has the highest priority %i, create it\n", slink, target, priority);
if (!test) { if (!test) {
create_path(udev, slink); util_create_path(udev, slink);
node_symlink(udev, target, slink); node_symlink(udev, target, slink);
} }
out: out:
@ -400,7 +400,7 @@ int udev_node_add(struct udev_device *dev, mode_t mode, const char *owner, const
struct udev_list_entry *list_entry; struct udev_list_entry *list_entry;
int err = 0; int err = 0;
create_path(udev, udev_device_get_devnode(dev)); util_create_path(udev, udev_device_get_devnode(dev));
if (strcmp(owner, "root") == 0) if (strcmp(owner, "root") == 0)
uid = 0; uid = 0;
@ -412,7 +412,7 @@ int udev_node_add(struct udev_device *dev, mode_t mode, const char *owner, const
if (endptr[0] == '\0') if (endptr[0] == '\0')
uid = (uid_t) id; uid = (uid_t) id;
else else
uid = lookup_user(udev, owner); uid = util_lookup_user(udev, owner);
} }
if (strcmp(group, "root") == 0) if (strcmp(group, "root") == 0)
@ -425,7 +425,7 @@ int udev_node_add(struct udev_device *dev, mode_t mode, const char *owner, const
if (endptr[0] == '\0') if (endptr[0] == '\0')
gid = (gid_t) id; gid = (gid_t) id;
else else
gid = lookup_group(udev, group); gid = util_lookup_group(udev, group);
} }
info(udev, "creating device node '%s', devnum=%d:%d, mode=%#o, uid=%d, gid=%d\n", info(udev, "creating device node '%s', devnum=%d:%d, mode=%#o, uid=%d, gid=%d\n",
@ -503,7 +503,7 @@ extern int udev_node_remove(struct udev_device *dev, int test)
info(udev, "removing device node '%s'\n", devnode); info(udev, "removing device node '%s'\n", devnode);
if (!test) if (!test)
err = unlink_secure(udev, devnode); err = util_unlink_secure(udev, devnode);
if (err) if (err)
return err; return err;
@ -518,9 +518,9 @@ extern int udev_node_remove(struct udev_device *dev, int test)
snprintf(partitionname, sizeof(partitionname), "%s%d", devnode, i); snprintf(partitionname, sizeof(partitionname), "%s%d", devnode, i);
partitionname[sizeof(partitionname)-1] = '\0'; partitionname[sizeof(partitionname)-1] = '\0';
if (!test) if (!test)
unlink_secure(udev, partitionname); util_unlink_secure(udev, partitionname);
} }
} }
delete_path(udev, devnode); util_delete_path(udev, devnode);
return err; return err;
} }

View File

@ -290,7 +290,7 @@ static int import_program_into_env(struct udev_device *dev, const char *program)
char *line; char *line;
envp = udev_device_get_properties_envp(dev); envp = udev_device_get_properties_envp(dev);
if (run_program(udev, program, envp, result, sizeof(result), &reslen) != 0) if (util_run_program(udev, program, envp, result, sizeof(result), &reslen) != 0)
return -1; return -1;
line = result; line = result;
@ -690,7 +690,7 @@ try_parent:
util_strlcpy(program, key_val(rule, &rule->program), sizeof(program)); util_strlcpy(program, key_val(rule, &rule->program), sizeof(program));
udev_event_apply_format(event, program, sizeof(program)); udev_event_apply_format(event, program, sizeof(program));
envp = udev_device_get_properties_envp(dev); envp = udev_device_get_properties_envp(dev);
if (run_program(event->udev, program, envp, result, sizeof(result), NULL) != 0) { if (util_run_program(event->udev, program, envp, result, sizeof(result), NULL) != 0) {
dbg(event->udev, "PROGRAM is false\n"); dbg(event->udev, "PROGRAM is false\n");
event->program_result[0] = '\0'; event->program_result[0] = '\0';
if (rule->program.operation != KEY_OP_NOMATCH) if (rule->program.operation != KEY_OP_NOMATCH)
@ -999,7 +999,7 @@ int udev_rules_get_name(struct udev_rules *rules, struct udev_event *event)
if (event->tmp_node[0] != '\0') { if (event->tmp_node[0] != '\0') {
dbg(event->udev, "removing temporary device node\n"); dbg(event->udev, "removing temporary device node\n");
unlink_secure(event->udev, event->tmp_node); util_unlink_secure(event->udev, event->tmp_node);
event->tmp_node[0] = '\0'; event->tmp_node[0] = '\0';
} }
return 0; return 0;
@ -1541,7 +1541,7 @@ static int add_to_rules(struct udev_rules *rules, char *line, const char *filena
strtoul(value, &endptr, 10); strtoul(value, &endptr, 10);
if (endptr[0] != '\0') { if (endptr[0] != '\0') {
char owner[32]; char owner[32];
uid_t uid = lookup_user(rules->udev, value); uid_t uid = util_lookup_user(rules->udev, value);
dbg(rules->udev, "replacing username='%s' by id=%i\n", value, uid); dbg(rules->udev, "replacing username='%s' by id=%i\n", value, uid);
sprintf(owner, "%u", (unsigned int) uid); sprintf(owner, "%u", (unsigned int) uid);
add_rule_key(rule, &rule->owner, operation, owner); add_rule_key(rule, &rule->owner, operation, owner);
@ -1560,7 +1560,7 @@ static int add_to_rules(struct udev_rules *rules, char *line, const char *filena
strtoul(value, &endptr, 10); strtoul(value, &endptr, 10);
if (endptr[0] != '\0') { if (endptr[0] != '\0') {
char group[32]; char group[32];
gid_t gid = lookup_group(rules->udev, value); gid_t gid = util_lookup_group(rules->udev, value);
dbg(rules->udev, "replacing groupname='%s' by id=%i\n", value, gid); dbg(rules->udev, "replacing groupname='%s' by id=%i\n", value, gid);
sprintf(group, "%u", (unsigned int) gid); sprintf(group, "%u", (unsigned int) gid);
add_rule_key(rule, &rule->group, operation, group); add_rule_key(rule, &rule->group, operation, group);
@ -1794,7 +1794,7 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
util_strlcpy(filename, udev_get_dev_path(udev), sizeof(filename)); util_strlcpy(filename, udev_get_dev_path(udev), sizeof(filename));
util_strlcat(filename, "/.udev/rules.d", sizeof(filename)); util_strlcat(filename, "/.udev/rules.d", sizeof(filename));
if (stat(filename, &statbuf) != 0) { if (stat(filename, &statbuf) != 0) {
create_path(udev, filename); util_create_path(udev, filename);
udev_selinux_setfscreatecon(udev, filename, S_IFDIR|0755); udev_selinux_setfscreatecon(udev, filename, S_IFDIR|0755);
mkdir(filename, 0755); mkdir(filename, 0755);
udev_selinux_resetfscreatecon(udev); udev_selinux_resetfscreatecon(udev);

View File

@ -29,7 +29,7 @@
#include "udev.h" #include "udev.h"
int create_path(struct udev *udev, const char *path) int util_create_path(struct udev *udev, const char *path)
{ {
char p[UTIL_PATH_SIZE]; char p[UTIL_PATH_SIZE];
char *pos; char *pos;
@ -49,7 +49,7 @@ int create_path(struct udev *udev, const char *path)
if (stat(p, &stats) == 0 && (stats.st_mode & S_IFMT) == S_IFDIR) if (stat(p, &stats) == 0 && (stats.st_mode & S_IFMT) == S_IFDIR)
return 0; return 0;
if (create_path(udev, p) != 0) if (util_create_path(udev, p) != 0)
return -1; return -1;
dbg(udev, "mkdir '%s'\n", p); dbg(udev, "mkdir '%s'\n", p);
@ -65,7 +65,7 @@ int create_path(struct udev *udev, const char *path)
return -1; return -1;
} }
int delete_path(struct udev *udev, const char *path) int util_delete_path(struct udev *udev, const char *path)
{ {
char p[UTIL_PATH_SIZE]; char p[UTIL_PATH_SIZE];
char *pos; char *pos;
@ -102,7 +102,7 @@ int delete_path(struct udev *udev, const char *path)
/* Reset permissions on the device node, before unlinking it to make sure, /* Reset permissions on the device node, before unlinking it to make sure,
* that permisions of possible hard links will be removed too. * that permisions of possible hard links will be removed too.
*/ */
int unlink_secure(struct udev *udev, const char *filename) int util_unlink_secure(struct udev *udev, const char *filename)
{ {
int retval; int retval;
@ -124,7 +124,7 @@ int unlink_secure(struct udev *udev, const char *filename)
return retval; return retval;
} }
uid_t lookup_user(struct udev *udev, const char *user) uid_t util_lookup_user(struct udev *udev, const char *user)
{ {
struct passwd *pw; struct passwd *pw;
uid_t uid = 0; uid_t uid = 0;
@ -142,7 +142,7 @@ uid_t lookup_user(struct udev *udev, const char *user)
return uid; return uid;
} }
extern gid_t lookup_group(struct udev *udev, const char *group) extern gid_t util_lookup_group(struct udev *udev, const char *group)
{ {
struct group *gr; struct group *gr;
gid_t gid = 0; gid_t gid = 0;
@ -160,8 +160,8 @@ extern gid_t lookup_group(struct udev *udev, const char *group)
return gid; return gid;
} }
int run_program(struct udev *udev, const char *command, char **envp, int util_run_program(struct udev *udev, const char *command, char **envp,
char *result, size_t ressize, size_t *reslen) char *result, size_t ressize, size_t *reslen)
{ {
int status; int status;
int outpipe[2] = {-1, -1}; int outpipe[2] = {-1, -1};

View File

@ -33,10 +33,6 @@
#define DEFAULT_FAKE_PARTITIONS_COUNT 15 #define DEFAULT_FAKE_PARTITIONS_COUNT 15
#define UDEV_EVENT_TIMEOUT 180 #define UDEV_EVENT_TIMEOUT 180
/* linux/include/linux/kobject.h */
#define UEVENT_BUFFER_SIZE 2048
#define UEVENT_NUM_ENVP 32
#define UDEV_CTRL_SOCK_PATH "@" UDEV_PREFIX "/org/kernel/udev/udevd" #define UDEV_CTRL_SOCK_PATH "@" UDEV_PREFIX "/org/kernel/udev/udevd"
#define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b)) #define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
@ -109,13 +105,13 @@ extern int udev_node_remove(struct udev_device *dev, int test);
extern void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev_old, int test); extern void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev_old, int test);
/* udev-util.c */ /* udev-util.c */
extern int create_path(struct udev *udev, const char *path); extern int util_create_path(struct udev *udev, const char *path);
extern int delete_path(struct udev *udev, const char *path); extern int util_delete_path(struct udev *udev, const char *path);
extern int unlink_secure(struct udev *udev, const char *filename); extern int util_unlink_secure(struct udev *udev, const char *filename);
extern uid_t lookup_user(struct udev *udev, const char *user); extern uid_t util_lookup_user(struct udev *udev, const char *user);
extern gid_t lookup_group(struct udev *udev, const char *group); extern gid_t util_lookup_group(struct udev *udev, const char *group);
extern int run_program(struct udev *udev, const char *command, char **envp, extern int util_run_program(struct udev *udev, const char *command, char **envp,
char *result, size_t ressize, size_t *reslen); char *result, size_t ressize, size_t *reslen);
/* udev-selinux.c */ /* udev-selinux.c */
#ifndef USE_SELINUX #ifndef USE_SELINUX

View File

@ -109,8 +109,8 @@ static void export_event_state(struct udev_event *event, enum event_state state)
switch (state) { switch (state) {
case EVENT_QUEUED: case EVENT_QUEUED:
if(unlink(filename_failed) == 0) if(unlink(filename_failed) == 0)
delete_path(event->udev, filename_failed); util_delete_path(event->udev, filename_failed);
create_path(event->udev, filename); util_create_path(event->udev, filename);
udev_selinux_setfscreatecon(event->udev, filename, S_IFLNK); udev_selinux_setfscreatecon(event->udev, filename, S_IFLNK);
symlink(udev_device_get_devpath(event->dev), filename); symlink(udev_device_get_devpath(event->dev), filename);
udev_selinux_resetfscreatecon(event->udev); udev_selinux_resetfscreatecon(event->udev);
@ -131,23 +131,23 @@ static void export_event_state(struct udev_event *event, enum event_state state)
udev_device_get_devpath_old(event->dev), udev_device_get_devpath(event->dev)); udev_device_get_devpath_old(event->dev), udev_device_get_devpath(event->dev));
} else { } else {
if (unlink(filename_failed) == 0) if (unlink(filename_failed) == 0)
delete_path(event->udev, filename_failed); util_delete_path(event->udev, filename_failed);
} }
unlink(filename); unlink(filename);
/* clean up possibly empty queue directory */ /* clean up possibly empty queue directory */
if (udev_list_is_empty(&exec_list) && udev_list_is_empty(&running_list)) if (udev_list_is_empty(&exec_list) && udev_list_is_empty(&running_list))
delete_path(event->udev, filename); util_delete_path(event->udev, filename);
break; break;
case EVENT_FAILED: case EVENT_FAILED:
/* move failed event to the failed directory */ /* move failed event to the failed directory */
create_path(event->udev, filename_failed); util_create_path(event->udev, filename_failed);
rename(filename, filename_failed); rename(filename, filename_failed);
/* clean up possibly empty queue directory */ /* clean up possibly empty queue directory */
if (udev_list_is_empty(&exec_list) && udev_list_is_empty(&running_list)) if (udev_list_is_empty(&exec_list) && udev_list_is_empty(&running_list))
delete_path(event->udev, filename); util_delete_path(event->udev, filename);
break; break;
} }
@ -613,7 +613,7 @@ static void export_initial_seqnum(struct udev *udev)
} }
util_strlcpy(filename, udev_get_dev_path(udev), sizeof(filename)); util_strlcpy(filename, udev_get_dev_path(udev), sizeof(filename));
util_strlcat(filename, "/.udev/uevent_seqnum", sizeof(filename)); util_strlcat(filename, "/.udev/uevent_seqnum", sizeof(filename));
create_path(udev, filename); util_create_path(udev, filename);
fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 0644); fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 0644);
if (fd >= 0) { if (fd >= 0) {
write(fd, seqnum, len); write(fd, seqnum, len);