mirror of
https://github.com/systemd/systemd.git
synced 2025-01-12 13:18:14 +03:00
[PATCH] remove udev_lib dependency from udevsend, which makes it smaller
This commit is contained in:
parent
c6478ec1e1
commit
13f24d596c
2
Makefile
2
Makefile
@ -300,7 +300,7 @@ $(DAEMON): $(LIBC) $(DAEMON).o $(OBJS) udevd.h
|
||||
$(QUIET) $(STRIPCMD) $@
|
||||
|
||||
$(SENDER): $(LIBC) $(SENDER).o $(OBJS) udevd.h
|
||||
$(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o udev_lib.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
|
||||
$(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
|
||||
$(QUIET) $(STRIPCMD) $@
|
||||
|
||||
$(WAIT): $(WAIT).o $(OBJS) $(HEADERS) $(LIBC)
|
||||
|
19
udev_lib.c
19
udev_lib.c
@ -229,22 +229,3 @@ int call_foreach_file(int fnct(char *f) , char *dirname, char *suffix)
|
||||
closedir(dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set the FD_CLOEXEC flag of desc if value is nonzero,
|
||||
or clear the flag if value is 0.
|
||||
Return 0 on success, or -1 on error with errno set. */
|
||||
|
||||
int set_cloexec_flag (int desc, int value)
|
||||
{
|
||||
int oldflags = fcntl (desc, F_GETFD, 0);
|
||||
/* If reading the flags failed, return error indication now. */
|
||||
if (oldflags < 0)
|
||||
return oldflags;
|
||||
/* Set just the flag we want to set. */
|
||||
if (value != 0)
|
||||
oldflags |= FD_CLOEXEC;
|
||||
else
|
||||
oldflags &= ~FD_CLOEXEC;
|
||||
/* Store modified flag word in the descriptor. */
|
||||
return fcntl (desc, F_SETFD, oldflags);
|
||||
}
|
||||
|
@ -85,6 +85,5 @@ extern void file_unmap(char *buf, size_t bufsize);
|
||||
extern size_t buf_get_line(char *buf, size_t buflen, size_t cur);
|
||||
extern void no_trailing_slash(char *path);
|
||||
extern int call_foreach_file(int fnct(char *f) , char *filename, char *extension);
|
||||
extern int set_cloexec_flag (int desc, int value);
|
||||
|
||||
#endif
|
||||
|
31
udevd.c
31
udevd.c
@ -43,6 +43,9 @@
|
||||
#include "udevd.h"
|
||||
#include "logging.h"
|
||||
|
||||
/* global variables*/
|
||||
static int udevsendsock;
|
||||
|
||||
static int pipefds[2];
|
||||
static unsigned long long expected_seqnum = 0;
|
||||
static volatile int sigchilds_waiting;
|
||||
@ -127,6 +130,7 @@ static void udev_run(struct hotplug_msg *msg)
|
||||
switch (pid) {
|
||||
case 0:
|
||||
/* child */
|
||||
close(udevsendsock);
|
||||
execle(udev_bin, "udev", msg->subsystem, NULL, msg->envp);
|
||||
dbg("exec of child failed");
|
||||
_exit(1);
|
||||
@ -397,7 +401,7 @@ static void user_sighandler(void)
|
||||
|
||||
int main(int argc, char *argv[], char *envp[])
|
||||
{
|
||||
int ssock, maxsockplus;
|
||||
int maxsockplus;
|
||||
struct sockaddr_un saddr;
|
||||
socklen_t addrlen;
|
||||
int retval, fd;
|
||||
@ -476,28 +480,21 @@ int main(int argc, char *argv[], char *envp[])
|
||||
strcpy(&saddr.sun_path[1], UDEVD_SOCK_PATH);
|
||||
addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1;
|
||||
|
||||
ssock = socket(AF_LOCAL, SOCK_DGRAM, 0);
|
||||
if (ssock == -1) {
|
||||
udevsendsock = socket(AF_LOCAL, SOCK_DGRAM, 0);
|
||||
if (udevsendsock == -1) {
|
||||
dbg("error getting socket, exit");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
set_cloexec_flag(ssock, 1);
|
||||
|
||||
/* the bind takes care of ensuring only one copy running */
|
||||
retval = bind(ssock, (struct sockaddr *) &saddr, addrlen);
|
||||
retval = bind(udevsendsock, (struct sockaddr *) &saddr, addrlen);
|
||||
if (retval < 0) {
|
||||
dbg("bind failed, exit");
|
||||
goto exit;
|
||||
}
|
||||
retval = fcntl(ssock, F_SETFD, FD_CLOEXEC);
|
||||
if (retval < 0) {
|
||||
dbg("error fcntl on ssock: %s", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* enable receiving of the sender credentials */
|
||||
setsockopt(ssock, SOL_SOCKET, SO_PASSCRED, &feature_on, sizeof(feature_on));
|
||||
setsockopt(udevsendsock, SOL_SOCKET, SO_PASSCRED, &feature_on, sizeof(feature_on));
|
||||
|
||||
/* possible override of udev binary, used for testing */
|
||||
udev_bin = getenv("UDEV_BIN");
|
||||
@ -507,9 +504,9 @@ int main(int argc, char *argv[], char *envp[])
|
||||
udev_bin = UDEV_BIN;
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(ssock, &readfds);
|
||||
FD_SET(udevsendsock, &readfds);
|
||||
FD_SET(pipefds[0], &readfds);
|
||||
maxsockplus = ssock+1;
|
||||
maxsockplus = udevsendsock+1;
|
||||
while (1) {
|
||||
fd_set workreadfds = readfds;
|
||||
retval = select(maxsockplus, &workreadfds, NULL, NULL, NULL);
|
||||
@ -520,8 +517,8 @@ int main(int argc, char *argv[], char *envp[])
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FD_ISSET(ssock, &workreadfds))
|
||||
handle_udevsend_msg(ssock);
|
||||
if (FD_ISSET(udevsendsock, &workreadfds))
|
||||
handle_udevsend_msg(udevsendsock);
|
||||
|
||||
if (FD_ISSET(pipefds[0], &workreadfds))
|
||||
user_sighandler();
|
||||
@ -548,7 +545,7 @@ int main(int argc, char *argv[], char *envp[])
|
||||
}
|
||||
}
|
||||
exit:
|
||||
close(ssock);
|
||||
close(udevsendsock);
|
||||
logging_close();
|
||||
return 1;
|
||||
}
|
||||
|
@ -41,6 +41,9 @@
|
||||
#include "udevd.h"
|
||||
#include "logging.h"
|
||||
|
||||
/* global variables */
|
||||
static int sock = -1;
|
||||
|
||||
#ifdef LOG
|
||||
unsigned char logname[LOGNAME_SIZE];
|
||||
void log_message (int level, const char *format, ...)
|
||||
@ -66,8 +69,7 @@ static int start_daemon(void)
|
||||
switch (child_pid) {
|
||||
case 0:
|
||||
/* daemon */
|
||||
setsid();
|
||||
chdir("/");
|
||||
close(sock);
|
||||
execl(UDEVD_BIN, "udevd", NULL);
|
||||
dbg("exec of daemon failed");
|
||||
_exit(1);
|
||||
@ -119,7 +121,6 @@ int main(int argc, char *argv[], char *envp[])
|
||||
int subsystem_env = 0;
|
||||
int bufpos = 0;
|
||||
int retval = 1;
|
||||
int sock = -1;
|
||||
int started_daemon = 0;
|
||||
|
||||
logging_init("udevsend");
|
||||
@ -137,8 +138,6 @@ int main(int argc, char *argv[], char *envp[])
|
||||
goto fallback;
|
||||
}
|
||||
|
||||
set_cloexec_flag(sock, 1);
|
||||
|
||||
memset(&saddr, 0x00, sizeof(struct sockaddr_un));
|
||||
saddr.sun_family = AF_LOCAL;
|
||||
/* use abstract namespace for socket path */
|
||||
|
Loading…
Reference in New Issue
Block a user