/*
* dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2009 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
static char buffer[1024];
static char *argvp[255];
-struct sockaddr_un sun;
-struct fd_list *fds = NULL;
+static struct sockaddr_un sun;
+struct fd_list *control_fds = NULL;
+
+#ifdef DEBUG_MEMORY
+static void
+cleanup(void)
+{
+ struct fd_list *f;
+
+ f = control_fds;
+ while (f) {
+ control_fds = f->next;
+ free(f);
+ f = control_fds;
+ }
+}
+#endif
static void
remove_control_data(void *arg)
{
- struct fd_list *l, *last = NULL;
+ struct fd_list *l, *n, *last = NULL;
- for (l = fds; l != NULL; l = l->next) {
+ l = control_fds;
+ while (l) {
+ n = l->next;
if (l == arg) {
close(l->fd);
delete_event(l->fd);
if (last == NULL)
- fds = l->next;
+ control_fds = l->next;
else
last->next = l->next;
free(l);
break;
}
last = l;
+ l = n;
}
}
len = sizeof(run);
if ((f = accept(fd, (struct sockaddr *)&run, &len)) == -1)
return;
- l = xmalloc(sizeof(*l));
- l->fd = f;
- l->listener = 0;
- l->next = fds;
- fds = l;
- add_event(l->fd, handle_control_data, l);
+ set_cloexec(f);
+ l = malloc(sizeof(*l));
+ if (l) {
+ l->fd = f;
+ l->listener = 0;
+ l->next = control_fds;
+ control_fds = l;
+ add_event(l->fd, handle_control_data, l);
+ }
}
static int
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) == -1 ||
set_cloexec(fd) == -1 ||
set_nonblock(fd) == -1 ||
- listen(fd, sizeof(fds)) == -1)
+ listen(fd, sizeof(control_fds)) == -1)
{
close(fd);
return -1;
stop_control(void)
{
int retval = 0;
- struct fd_list *l, *ll;
+ struct fd_list *l;
delete_event(fd);
if (shutdown(fd, SHUT_RDWR) == -1)
if (unlink(CONTROLSOCKET) == -1)
retval = -1;
- l = fds;
+ l = control_fds;
while (l != NULL) {
- ll = l->next;
+ control_fds = l->next;
delete_event(l->fd);
shutdown(l->fd, SHUT_RDWR);
free(l);
- l = ll;
+ l = control_fds;
}
return retval;
if ((len = make_sock()) == -1)
return -1;
+#ifdef DEBUG_MEMORY
+ atexit(cleanup);
+#endif
return connect(fd, (struct sockaddr *)&sun, len);
}
/*
* dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2008 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
int listener;
struct fd_list *next;
};
-extern struct fd_list *fds;
+extern struct fd_list *control_fds;
int start_control(void);
int stop_control(void);