Lines Matching +full:- +full:- +full:daemon
1 /* dnsmasq is Copyright (c) 2000-2009 Simon Kelley
59 if (pipe(pipefd) == -1 || !fix_fd(pipefd[1]) || (pid = fork()) == -1) { in create_helper()
77 if (!(daemon->options & OPT_DEBUG) && uid != 0) { in create_helper()
79 if (setgroups(0, &unused) == -1 || setgid(gid) == -1 || setuid(uid) == -1) { in create_helper()
80 if (daemon->options & OPT_NO_FORK) /* send error to daemon process if no-fork */ in create_helper()
83 /* kill daemon */ in create_helper()
94 for (max_fd--; max_fd >= 0; max_fd--) in create_helper()
103 unsigned char* buf = (unsigned char*) daemon->namebuff; in create_helper()
119 p = daemon->dhcp_buff; in create_helper()
121 p += sprintf(p, "%.2x-", data.hwaddr_type); in create_helper()
124 if (i != data.hwaddr_len - 1) p += sprintf(p, ":"); in create_helper()
129 for (p = daemon->packet, i = 0; i < data.clid_len; i++) { in create_helper()
131 if (i != data.clid_len - 1) p += sprintf(p, ":"); in create_helper()
136 sprintf(daemon->dhcp_buff2, "%u ", data.length); in create_helper()
138 sprintf(daemon->dhcp_buff2, "%lu ", (unsigned long) data.expires); in create_helper()
146 while ((pid = fork()) == -1 && (errno == EAGAIN || errno == ENOMEM)) sleep(2); in create_helper()
148 if (pid == -1) continue; in create_helper()
166 if (rc == -1 && errno != EINTR) break; in create_helper()
172 if (data.clid_len != 0) my_setenv("DNSMASQ_CLIENT_ID", daemon->packet, &err); in create_helper()
177 my_setenv("DNSMASQ_LEASE_LENGTH", daemon->dhcp_buff2, &err); in create_helper()
179 my_setenv("DNSMASQ_LEASE_EXPIRES", daemon->dhcp_buff2, &err); in create_helper()
183 buf[data.vclass_len - 1] = 0; /* don't trust zero-term */ in create_helper()
184 /* cannot have = chars in env - truncate if found . */ in create_helper()
192 buf[data.uclass_len - 1] = 0; /* don't trust zero-term */ in create_helper()
198 sprintf(daemon->dhcp_buff2, "DNSMASQ_USER_CLASS%i", i++); in create_helper()
199 my_setenv(daemon->dhcp_buff2, (char*) buf, &err); in create_helper()
206 buf[data.shost_len - 1] = 0; /* don't trust zero-term */ in create_helper()
207 /* cannot have = chars in env - truncate if found . */ in create_helper()
216 sprintf(daemon->dhcp_buff2, "%u ", data.remaining_time); in create_helper()
217 my_setenv("DNSMASQ_TIME_REMAINING", daemon->dhcp_buff2, &err); in create_helper()
222 hostname[data.hostname_len - 1] = 0; in create_helper()
237 if ((i = fcntl(event_fd, F_GETFD)) != -1) fcntl(event_fd, F_SETFD, i | FD_CLOEXEC); in create_helper()
240 p = strrchr(daemon->lease_change_command, '/'); in create_helper()
242 execl(daemon->lease_change_command, p ? p + 1 : daemon->lease_change_command, in create_helper()
243 action_str, daemon->dhcp_buff, inet_ntoa(data.addr), hostname, (char*) NULL); in create_helper()
264 if (daemon->helperfd == -1) return; in queue_script()
266 if (lease->vendorclass) vclass_len = lease->vendorclass_len; in queue_script()
267 if (lease->userclass) uclass_len = lease->userclass_len; in queue_script()
268 if (lease->supplied_hostname) shost_len = lease->supplied_hostname_len; in queue_script()
269 if (lease->clid) clid_len = lease->clid_len; in queue_script()
287 buf->action = action; in queue_script()
288 buf->hwaddr_len = lease->hwaddr_len; in queue_script()
289 buf->hwaddr_type = lease->hwaddr_type; in queue_script()
290 buf->clid_len = clid_len; in queue_script()
291 buf->vclass_len = vclass_len; in queue_script()
292 buf->uclass_len = uclass_len; in queue_script()
293 buf->shost_len = shost_len; in queue_script()
294 buf->hostname_len = hostname_len; in queue_script()
295 buf->addr = lease->addr; in queue_script()
296 buf->giaddr = lease->giaddr; in queue_script()
297 memcpy(buf->hwaddr, lease->hwaddr, lease->hwaddr_len); in queue_script()
298 buf->interface[0] = 0; in queue_script()
300 if (lease->last_interface != 0) { in queue_script()
302 ifr.ifr_ifindex = lease->last_interface; in queue_script()
303 if (ioctl(daemon->dhcpfd, SIOCGIFNAME, &ifr) != -1) in queue_script()
304 strncpy(buf->interface, ifr.ifr_name, IF_NAMESIZE); in queue_script()
307 if (lease->last_interface != 0) if_indextoname(lease->last_interface, buf->interface); in queue_script()
311 buf->length = lease->length; in queue_script()
313 buf->expires = lease->expires; in queue_script()
315 buf->remaining_time = (unsigned int) difftime(lease->expires, now); in queue_script()
319 memcpy(p, lease->clid, clid_len); in queue_script()
323 memcpy(p, lease->vendorclass, vclass_len); in queue_script()
327 memcpy(p, lease->userclass, uclass_len); in queue_script()
331 memcpy(p, lease->supplied_hostname, shost_len); in queue_script()
339 bytes_in_buf = p - (unsigned char*) buf; in queue_script()
351 if ((rc = write(daemon->helperfd, buf, bytes_in_buf)) != -1) { in helper_write()
352 if (bytes_in_buf != (size_t) rc) memmove(buf, buf + rc, bytes_in_buf - rc); in helper_write()
353 bytes_in_buf -= rc; in helper_write()