From: kay.sievers@vrfy.org Date: Sun, 6 Mar 2005 05:16:52 +0000 (+0100) Subject: [PATCH] remove Makefile magic for klibc integration X-Git-Tag: 055~41 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57e1a2770c4d85edd377488906c437f6d1e9b369;p=systemd [PATCH] remove Makefile magic for klibc integration The new libsysfs and klibc don't need that anymore. Wrap getpwnam(), so we can use the built-in /etc/passwd parser for statically compiled glibc binaries too. --- diff --git a/Makefile b/Makefile index 8184620a..baecda66 100644 --- a/Makefile +++ b/Makefile @@ -118,14 +118,15 @@ WARNINGS += $(call cc-supports,-Wdeclaration-after-statement) CFLAGS := -pipe HEADERS = \ - udev.h \ - udev_utils.h \ - namedev.h \ - udev_version.h \ - udev_db.h \ - udev_sysfs.h \ - logging.h \ - udev_selinux.h \ + udev.h \ + udev_utils.h \ + namedev.h \ + udev_version.h \ + udev_db.h \ + udev_sysfs.h \ + logging.h \ + udev_libc_wrapper.h \ + udev_selinux.h \ list.h SYSFS_OBJS = \ @@ -146,7 +147,8 @@ UDEV_OBJS = \ udev_db.o \ udev_multiplex.o \ namedev.o \ - namedev_parse.o + namedev_parse.o \ + udev_libc_wrapper.o OBJS = \ udev.a \ @@ -158,7 +160,7 @@ CFLAGS += -I$(PWD)/libsysfs/sysfs \ -I$(PWD)/libsysfs ifeq ($(strip $(USE_LOG)),true) - CFLAGS += -DLOG + CFLAGS += -DLOG endif # if DEBUG is enabled, then we do not strip or optimize @@ -175,7 +177,6 @@ endif # If we are using our version of klibc, then we need to build, link it, and then # link udev against it statically. Otherwise, use glibc and link dynamically. ifeq ($(strip $(USE_KLIBC)),true) - KLIBC_FIXUPS_DIR= $(PWD)/klibc_fixups KLIBC_BASE = $(PWD)/klibc KLIBC_DIR = $(KLIBC_BASE)/klibc INCLUDE_DIR := $(KLIBC_BASE)/include @@ -190,7 +191,6 @@ ifeq ($(strip $(USE_KLIBC)),true) CFLAGS += $(WARNINGS) -nostdinc \ $(OPTFLAGS) $(REQFLAGS) \ -D__KLIBC__ -fno-builtin-printf \ - -I$(KLIBC_FIXUPS_DIR) \ -I$(INCLUDE_DIR) \ -I$(INCLUDE_DIR)/arch/$(ARCH) \ -I$(INCLUDE_DIR)/bits$(BITSIZE) \ @@ -199,20 +199,12 @@ ifeq ($(strip $(USE_KLIBC)),true) LIB_OBJS = LDFLAGS = --static --nostdlib -nostartfiles -nodefaultlibs - HEADERS += \ - klibc_fixups/pwd.h - - KLIBC_FIXUP_OBJS = \ - klibc_fixups/klibc_fixups.o - - OBJS += klibc_fixups/klibc_fixups.a else WARNINGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations CRT0 = LIBC = CFLAGS += $(WARNINGS) -I$(GCCINCDIR) LIB_OBJS = -lc - LDFLAGS = endif ifeq ($(strip $(USE_SELINUX)),true) @@ -261,11 +253,6 @@ libsysfs/sysfs.a: $(SYSFS_OBJS) $(QUIET) $(AR) cq $@ $(SYSFS_OBJS) $(QUIET) $(RANLIB) $@ -klibc_fixups/klibc_fixups.a: $(KLIBC_FIXUP_OBJS) - rm -f $@ - $(QUIET) $(AR) cq $@ $(KLIBC_FIXUP_OBJS) - $(QUIET) $(RANLIB) $@ - # header files automatically generated GEN_HEADERS = udev_version.h @@ -298,7 +285,6 @@ $(GEN_MANPAGES): $(GEN_MANPAGESIN) $(UDEV_OBJS): $(GEN_HEADERS) $(HOST_PROGS) $(SYSFS_OBJS): $(HOST_PROGS) -$(KLIBC_FIXUP_OBJS): $(HOST_PROGS) $(OBJS): $(GEN_HEADERS) $(HOST_PROGS) $(ROOT).o: $(GEN_HEADERS) $(HOST_PROGS) $(TESTER).o: $(GEN_HEADERS) $(HOST_PROGS) diff --git a/klibc_fixups/pwd.h b/klibc_fixups/pwd.h deleted file mode 100644 index f5de6c50..00000000 --- a/klibc_fixups/pwd.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifdef __KLIBC__ - -#ifndef _PWD_H -#define _PWD_H - -struct passwd { - char *pw_name; /* user name */ - char *pw_passwd; /* user password */ - uid_t pw_uid; /* user id */ - gid_t pw_gid; /* group id */ - char *pw_gecos; /* real name */ - char *pw_dir; /* home directory */ - char *pw_shell; /* shell program */ -}; - -struct group { - char *gr_name; /* group name */ - char *gr_passwd; /* group password */ - gid_t gr_gid; /* group id */ - char **gr_mem; /* group members */ -}; - -struct passwd *getpwnam(const char *name); -struct group *getgrnam(const char *name); - -#endif /* _PWD_H */ -#endif /* __KLIBC__ */ diff --git a/udev_add.c b/udev_add.c index aa19d874..e05710ce 100644 --- a/udev_add.c +++ b/udev_add.c @@ -34,9 +34,9 @@ #include #include #include -#include #include "libsysfs/sysfs/libsysfs.h" +#include "udev_libc_wrapper.h" #include "udev.h" #include "udev_utils.h" #include "udev_sysfs.h" @@ -132,15 +132,8 @@ static int create_node(struct udevice *udev, struct sysfs_class_device *class_de if (endptr[0] == '\0') uid = (uid_t) id; - else { - struct passwd *pw; - - pw = getpwnam(udev->owner); - if (pw == NULL) - dbg("specified user unknown '%s'", udev->owner); - else - uid = pw->pw_uid; - } + else + uid = lookup_user(udev->owner); } if (udev->group[0] != '\0') { @@ -149,13 +142,8 @@ static int create_node(struct udevice *udev, struct sysfs_class_device *class_de if (endptr[0] == '\0') gid = (gid_t) id; - else { - struct group *gr = getgrnam(udev->group); - if (gr == NULL) - dbg("specified group unknown '%s'", udev->group); - else - gid = gr->gr_gid; - } + else + gid = lookup_group(udev->group); } if (!udev->test_run) { diff --git a/klibc_fixups/klibc_fixups.c b/udev_libc_wrapper.c similarity index 58% rename from klibc_fixups/klibc_fixups.c rename to udev_libc_wrapper.c index 175cf27f..df545152 100644 --- a/klibc_fixups/klibc_fixups.c +++ b/udev_libc_wrapper.c @@ -1,8 +1,9 @@ /* - * klibc_fixups.c - very simple implementation of stuff missing in klibc + * udev_libc_wrapper - wrapping of functions missing in a specific libc + * or not working in a statically compiled binary * * Copyright (C) 2003 Greg Kroah-Hartman - * Copyright (C) 2004 Kay Sievers + * Copyright (C) 2005 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 @@ -19,8 +20,6 @@ * */ -#ifdef __KLIBC__ - #include #include #include @@ -28,18 +27,62 @@ #include #include -#include "pwd.h" +#include "../udev_libc_wrapper.h" #include "../udev.h" #include "../udev_utils.h" #include "../logging.h" -#define PW_FILE "/etc/passwd" -#define GR_FILE "/etc/group" + +#ifdef __KLIBC__ +#define __OWN_USERDB_PARSER__ +#endif +#ifdef USE_STATIC +#define __OWN_USERDB_PARSER__ +#endif + +#ifndef __OWN_USERDB_PARSER__ + +#include +#include +#include + +uid_t lookup_user(const char *user) +{ + struct passwd *pw; + uid_t uid = 0; + + pw = getpwnam(user); + if (pw == NULL) + dbg("specified user unknown '%s'", user); + else + uid = pw->pw_uid; + + return uid; +} + +gid_t lookup_group(const char *group) +{ + struct group *gr; + gid_t gid = 0; + + gr = getgrnam(group); + if (gr == NULL) + dbg("specified group unknown '%s'", group); + else + gid = gr->gr_gid; + + return gid; +} + +#else /* __OWN_USERDB_PARSER__ */ + +#define PASSWD_FILE "/etc/passwd" +#define GROUP_FILE "/etc/group" /* return the id of a passwd style line, selected by the users name */ static unsigned long get_id_by_name(const char *uname, const char *dbfile) { - unsigned long id = -1; + unsigned long id = 0; char line[LINE_SIZE]; char *buf; char *bufline; @@ -51,12 +94,11 @@ static unsigned long get_id_by_name(const char *uname, const char *dbfile) char *idstr; char *tail; - if (file_map(dbfile, &buf, &bufsize) == 0) { - dbg("reading '%s' as db file", dbfile); - } else { + if (file_map(dbfile, &buf, &bufsize) != 0) { dbg("can't open '%s' as db file", dbfile); - return -1; + return 0; } + dbg("reading '%s' as db file", dbfile); /* loop through the whole file */ cur = 0; @@ -88,9 +130,10 @@ static unsigned long get_id_by_name(const char *uname, const char *dbfile) if (strcmp(uname, name) == 0) { id = strtoul(idstr, &tail, 10); - if (tail[0] != '\0') - id = -1; - else + if (tail[0] != '\0') { + id = 0; + dbg("no id found for '%s'", name); + } else dbg("id for '%s' is '%li'", name, id); break; } @@ -100,28 +143,20 @@ static unsigned long get_id_by_name(const char *uname, const char *dbfile) return id; } -struct passwd *getpwnam(const char *name) +uid_t lookup_user(const char *user) { - static struct passwd pw; + unsigned long id; - memset(&pw, 0x00, sizeof(struct passwd)); - pw.pw_uid = (uid_t) get_id_by_name(name, PW_FILE); - if (pw.pw_uid < 0) - return NULL; - else - return &pw; + id = get_id_by_name(user, PASSWD_FILE); + return (uid_t) id; } -struct group *getgrnam(const char *name) +gid_t lookup_group(const char *group) { - static struct group gr; + unsigned long id; - memset(&gr, 0x00, sizeof(struct group)); - gr.gr_gid = (gid_t) get_id_by_name(name, GR_FILE); - if (gr.gr_gid < 0) - return NULL; - else - return &gr; + id = get_id_by_name(group, GROUP_FILE); + return (gid_t) id; } -#endif /* __KLIBC__ */ +#endif /* __OWN_USERDB_PARSER__ */ diff --git a/udev_libc_wrapper.h b/udev_libc_wrapper.h new file mode 100644 index 00000000..2df2f442 --- /dev/null +++ b/udev_libc_wrapper.h @@ -0,0 +1,28 @@ +/* + * udev_libc_wrapper - wrapping of functions missing in a specific libc + * or not working in a statically compiled binary + * + * Copyright (C) 2005 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 version 2 of the License. + * + * 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, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef _UDEV_LIBC_WRAPPER_H_ +#define _UDEV_LIBC_WRAPPER_H_ + +extern uid_t lookup_user(const char *user); +extern gid_t lookup_group(const char *group); + +#endif /* _UDEV_LIBC_WRAPPER_H_ */