summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
ab51035)
Change to the same timeout loop we use in the rest of the code. Change
some comments and names to be more descriptive.
I'm mostly finished with the overall cleanup. I will post a new patch
for the udevd-nofork experiment, which will be much smaller now.
static int pipefds[2];
static unsigned long long expected_seqnum = 0;
static int pipefds[2];
static unsigned long long expected_seqnum = 0;
-static volatile int children_waiting;
+static volatile int sigchilds_waiting;
static volatile int run_msg_q;
static volatile int sig_flag;
static int run_exec_q;
static volatile int run_msg_q;
static volatile int sig_flag;
static int run_exec_q;
static void exec_queue_manager(void);
static void msg_queue_manager(void);
static void user_sighandler(void);
static void exec_queue_manager(void);
static void msg_queue_manager(void);
static void user_sighandler(void);
-static void reap_kids(void);
+static void reap_sigchilds(void);
char *udev_bin;
#ifdef LOG
char *udev_bin;
#ifdef LOG
break;
case SIGCHLD:
/* set flag, then write to pipe if needed */
break;
case SIGCHLD:
/* set flag, then write to pipe if needed */
goto do_write;
break;
default:
goto do_write;
break;
default:
-static void reap_kids(void)
+static void reap_sigchilds(void)
- /* reap all dead children */
while(1) {
int pid = waitpid(-1, NULL, WNOHANG);
if ((pid == -1) || (pid == 0))
while(1) {
int pid = waitpid(-1, NULL, WNOHANG);
if ((pid == -1) || (pid == 0))
}
/* just read everything from the pipe and clear the flag,
}
/* just read everything from the pipe and clear the flag,
- * the useful flags were set in the signal handler
+ * the flags was set in the signal handler
*/
static void user_sighandler(void)
{
int sig;
while(1) {
*/
static void user_sighandler(void)
{
int sig;
while(1) {
- int rc = read(pipefds[0],&sig,sizeof(sig));
+ int rc = read(pipefds[0], &sig, sizeof(sig));
-
-int main(int argc, char *argv[])
+int main(int argc, char *argv[], char *envp[])
{
int ssock, maxsockplus;
struct sockaddr_un saddr;
socklen_t addrlen;
int retval, fd;
{
int ssock, maxsockplus;
struct sockaddr_un saddr;
socklen_t addrlen;
int retval, fd;
+ const int feature_on = 1;
struct sigaction act;
fd_set readfds;
struct sigaction act;
fd_set readfds;
if (getuid() != 0) {
dbg("need to be root, exit");
if (getuid() != 0) {
dbg("need to be root, exit");
- /* make sure we are at top of dir */
+
+ /* make sure we don't lock any path */
- umask( umask( 077 ) | 022 );
+ umask(umask(077) | 022);
+
/* Set fds to dev/null */
fd = open( "/dev/null", O_RDWR );
if ( fd < 0 ) {
/* Set fds to dev/null */
fd = open( "/dev/null", O_RDWR );
if ( fd < 0 ) {
dup2(fd, 2);
if (fd > 2)
close(fd);
dup2(fd, 2);
if (fd > 2)
close(fd);
- /* Get new session id so stray signals don't come our way. */
+
+ /* become session leader */
setsid();
/* setup signal handler pipe */
setsid();
/* setup signal handler pipe */
/* set signal handlers */
act.sa_handler = (void (*) (int))sig_handler;
sigemptyset(&act.sa_mask);
/* set signal handlers */
act.sa_handler = (void (*) (int))sig_handler;
sigemptyset(&act.sa_mask);
}
/* enable receiving of the sender credentials */
}
/* enable receiving of the sender credentials */
- setsockopt(ssock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
+ setsockopt(ssock, SOL_SOCKET, SO_PASSCRED, &feature_on, sizeof(feature_on));
/* possible override of udev binary, used for testing */
udev_bin = getenv("UDEV_BIN");
/* possible override of udev binary, used for testing */
udev_bin = getenv("UDEV_BIN");
if (FD_ISSET(pipefds[0], &workreadfds))
user_sighandler();
if (FD_ISSET(pipefds[0], &workreadfds))
user_sighandler();
- if (children_waiting) {
- children_waiting = 0;
- reap_kids();
+ if (sigchilds_waiting) {
+ sigchilds_waiting = 0;
+ reap_sigchilds();
- /* this is tricky. exec_queue_manager() loops over exec_list, and
- * calls running_with_devpath(), which loops over running_list. This gives
- * O(N*M), which can get *nasty*. Clean up running_list before
- * calling exec_queue_manager().
- */
- if (children_waiting) {
- children_waiting = 0;
- reap_kids();
+ /* clean up running_list before calling exec_queue_manager() */
+ if (sigchilds_waiting) {
+ sigchilds_waiting = 0;
+ reap_sigchilds();
exit:
close(ssock);
logging_close();
exit:
close(ssock);
logging_close();
#define UDEV_MAGIC "udevd_" UDEV_VERSION
#define EVENT_TIMEOUT_SEC 10
#define UDEV_MAGIC "udevd_" UDEV_VERSION
#define EVENT_TIMEOUT_SEC 10
-#define UDEVSEND_CONNECT_RETRY 20 /* x 100 millisec */
#define UDEVD_SOCK_PATH "udevd"
#define UDEVD_SOCK_PATH "udevd"
+#define SEND_WAIT_MAX_SECONDS 3
+#define SEND_WAIT_LOOP_PER_SECOND 10
+
struct hotplug_msg {
char magic[20];
struct hotplug_msg {
char magic[20];
switch (pid) {
case 0:
/* child */
switch (pid) {
case 0:
/* child */
- execl(UDEV_BIN, "udev", subsystem, NULL);
+ execl(UDEV_BIN, UDEV_BIN, subsystem, NULL);
dbg("exec of child failed");
dbg("exec of child failed");
break;
case -1:
dbg("fork of child failed");
break;
case -1:
dbg("fork of child failed");
unsigned long long seq;
int retval = 1;
int loop;
unsigned long long seq;
int retval = 1;
int loop;
int sock = -1;
struct sockaddr_un saddr;
socklen_t addrlen;
int sock = -1;
struct sockaddr_un saddr;
socklen_t addrlen;
strfieldcpy(msg.subsystem, subsystem);
/* If we can't send, try to start daemon and resend message */
strfieldcpy(msg.subsystem, subsystem);
/* If we can't send, try to start daemon and resend message */
- loop = UDEVSEND_CONNECT_RETRY;
- while (loop--) {
+ loop = SEND_WAIT_MAX_SECONDS * SEND_WAIT_LOOP_PER_SECOND;
+ while (--loop) {
retval = sendto(sock, &msg, sizeof(struct hotplug_msg), 0,
(struct sockaddr *)&saddr, addrlen);
if (retval != -1) {
retval = sendto(sock, &msg, sizeof(struct hotplug_msg), 0,
(struct sockaddr *)&saddr, addrlen);
if (retval != -1) {
dbg("daemon started");
started_daemon = 1;
} else {
dbg("daemon started");
started_daemon = 1;
} else {
- dbg("retry to connect %d", UDEVSEND_CONNECT_RETRY - loop);
- tspec.tv_sec = 0;
- tspec.tv_nsec = 100000000; /* 100 millisec */
- nanosleep(&tspec, NULL);
+ dbg("retry to connect %d", SEND_WAIT_MAX_SECONDS * SEND_WAIT_LOOP_PER_SECOND - loop);
+ usleep(1000 * 1000 / SEND_WAIT_LOOP_PER_SECOND);