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);
-}
#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;
switch (pid) {
case 0:
/* child */
+ close(udevsendsock);
execle(udev_bin, "udev", msg->subsystem, NULL, msg->envp);
dbg("exec of child failed");
_exit(1);
int main(int argc, char *argv[], char *envp[])
{
- int ssock, maxsockplus;
+ int maxsockplus;
struct sockaddr_un saddr;
socklen_t addrlen;
int retval, fd;
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");
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);
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();
}
}
exit:
- close(ssock);
+ close(udevsendsock);
logging_close();
return 1;
}
#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, ...)
switch (child_pid) {
case 0:
/* daemon */
- setsid();
- chdir("/");
+ close(sock);
execl(UDEVD_BIN, "udevd", NULL);
dbg("exec of daemon failed");
_exit(1);
int subsystem_env = 0;
int bufpos = 0;
int retval = 1;
- int sock = -1;
int started_daemon = 0;
logging_init("udevsend");
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 */