dhcp_interface_startup_hook = dhclient_interface_startup_hook;
for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "-4")) {
+ if (!strcmp(argv[i], "-r")) {
+ release_mode = 1;
+ no_daemon = 1;
+#ifdef DHCPv6
+ } else if (!strcmp(argv[i], "-4")) {
if (local_family_set && local_family != AF_INET)
log_fatal("Client can only do v4 or v6, not "
"both.");
"both.");
local_family_set = 1;
local_family = AF_INET6;
- } else if (!strcmp(argv[i], "-r")) {
- release_mode = 1;
- no_daemon = 1;
+#endif /* DHCPv6 */
} else if (!strcmp (argv [i], "-x")) { /* eXit, no release */
release_mode = 0;
no_daemon = 0;
oldpid = (pid_t)temp;
if (e != 0 && e != EOF) {
- if (oldpid) {
- if (kill(oldpid, SIGTERM) == 0)
- unlink(path_dhclient_pid);
- }
+ if (oldpid)
+ kill(oldpid, SIGTERM);
}
fclose(pidfd);
}
log_info (arr);
log_info (url);
- log_error ("Usage: dhclient [-1dvrx] [-nw] [-p <port>] %s",
+ log_error ("Usage: dhclient %s %s",
+#ifdef DHCPv6
+ "[-4|-6] [-1dvrx] [-nw] [-p <port>]",
+#else /* DHCPv6 */
+ "[-1dvrx] [-nw] [-p <port>]",
+#endif /* DHCPv6 */
"[-s server]");
log_error (" [-cf config-file] [-lf lease-file]%s",
"[-pf pid-file] [-e VAR=val]");
int cftest = 0;
int lftest = 0;
#ifndef DEBUG
- int pidfilewritten = 0;
int pid;
char pbuf [20];
int daemon = 1;
/* Read previous pid file. */
if ((i = open (path_dhcpd_pid, O_RDONLY)) >= 0) {
- status = read (i, pbuf, (sizeof pbuf) - 1);
+ status = read(i, pbuf, (sizeof pbuf) - 1);
close (i);
if (status > 0) {
- pbuf [status] = 0;
- pid = atoi (pbuf);
-
- /* If the previous server process is not still running,
- write a new pid file immediately. */
- if (pid && (pid == getpid() || kill (pid, 0) < 0)) {
- unlink (path_dhcpd_pid);
- if ((i = open (path_dhcpd_pid,
- O_WRONLY | O_CREAT, 0644)) >= 0) {
- sprintf (pbuf, "%d\n", (int)getpid ());
- write (i, pbuf, strlen (pbuf));
- close (i);
- pidfilewritten = 1;
- }
- } else
- log_fatal ("There's already a DHCP server running.");
+ pbuf[status] = 0;
+ pid = atoi(pbuf);
+
+ /*
+ * If there was a previous server process and it's
+ * is still running, abort
+ */
+ if (!pid || (pid != getpid() && kill(pid, 0) == 0))
+ log_fatal("There's already a "
+ "DHCP server running.");
}
}
+ /* Write new pid file. */
+ if ((i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC, 0644)) >= 0) {
+ sprintf(pbuf, "%d\n", (int) getpid());
+ write(i, pbuf, strlen(pbuf));
+ close(i);
+ } else {
+ log_error("Can't create PID file %s: %m.", path_dhcpd_pid);
+ }
+
+
/* If we were requested to log to stdout on the command line,
keep doing so; otherwise, stop. */
if (log_perror == -1)
else
log_perror = 0;
- /* If we didn't write the pid file earlier because we found a
- process running the logged pid, but we made it to here,
- meaning nothing is listening on the bootp port, then write
- the pid file out - what's in it now is bogus anyway. */
- if (!pidfilewritten) {
- unlink (path_dhcpd_pid);
- if ((i = open (path_dhcpd_pid,
- O_WRONLY | O_CREAT, 0644)) >= 0) {
- sprintf (pbuf, "%d\n", (int)getpid ());
- write (i, pbuf, strlen (pbuf));
- close (i);
- pidfilewritten = 1;
- }
- }
-
if (daemon) {
/* Become session leader and get pid... */
pid = setsid();