2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-09-01 06:45:27 +00:00

Daemonize by default. Fix a couple of uninitialized automatic variables. Add -q flag which shuts up interface status printout. Write a pid file.

This commit is contained in:
Ted Lemon
1997-11-22 07:55:36 +00:00
parent 921a501249
commit e7012e3fe6

View File

@@ -42,7 +42,7 @@
#ifndef lint #ifndef lint
static char copyright[] = static char copyright[] =
"$Id: dhcrelay.c,v 1.7 1997/06/02 23:28:18 mellon Exp $ Copyright (c) 1997 The Internet Software Consortium. All rights reserved.\n"; "$Id: dhcrelay.c,v 1.8 1997/11/22 07:55:36 mellon Exp $ Copyright (c) 1997 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#include "dhcpd.h" #include "dhcpd.h"
@@ -56,6 +56,8 @@ struct tree_cache *global_options [256];
int log_perror = 1; int log_perror = 1;
char *path_dhcrelay_pid = _PATH_DHCRELAY_PID;
#ifdef USE_FALLBACK #ifdef USE_FALLBACK
struct interface_info fallback_interface; struct interface_info fallback_interface;
#endif #endif
@@ -75,8 +77,9 @@ int main (argc, argv, envp)
{ {
int i; int i;
struct servent *ent; struct servent *ent;
struct server_list *sp; struct server_list *sp = (struct server_list *)0;
int no_daemon; int no_daemon = 0;
int quiet = 0;
#ifdef SYSLOG_4_2 #ifdef SYSLOG_4_2
openlog ("dhcrelay", LOG_NDELAY); openlog ("dhcrelay", LOG_NDELAY);
@@ -99,20 +102,23 @@ int main (argc, argv, envp)
} else if (!strcmp (argv [i], "-d")) { } else if (!strcmp (argv [i], "-d")) {
no_daemon = 1; no_daemon = 1;
} else if (!strcmp (argv [i], "-i")) { } else if (!strcmp (argv [i], "-i")) {
struct interface_info *tmp = struct interface_info *tmp =
((struct interface_info *) ((struct interface_info *)
dmalloc (sizeof *tmp, "specified_interface")); dmalloc (sizeof *tmp, "specified_interface"));
if (!tmp) if (!tmp)
error ("Insufficient memory to %s %s", error ("Insufficient memory to %s %s",
"record interface", argv [i]); "record interface", argv [i]);
if (++i == argc) { if (++i == argc) {
usage (); usage ();
} }
memset (tmp, 0, sizeof *tmp); memset (tmp, 0, sizeof *tmp);
strcpy (tmp -> name, argv [i]); strcpy (tmp -> name, argv [i]);
tmp -> next = interfaces; tmp -> next = interfaces;
tmp -> flags = INTERFACE_REQUESTED; tmp -> flags = INTERFACE_REQUESTED;
interfaces = tmp; interfaces = tmp;
} else if (!strcmp (argv [i], "-q")) {
quiet = 1;
quiet_interface_discovery = 1;
} else if (argv [i][0] == '-') { } else if (argv [i][0] == '-') {
usage (); usage ();
} else { } else {
@@ -140,6 +146,7 @@ int main (argc, argv, envp)
} }
} }
} }
/* Default to the DHCP/BOOTP port. */ /* Default to the DHCP/BOOTP port. */
if (!local_port) { if (!local_port) {
ent = getservbyname ("dhcps", "udp"); ent = getservbyname ("dhcps", "udp");
@@ -174,6 +181,41 @@ int main (argc, argv, envp)
/* Set up the bootp packet handler... */ /* Set up the bootp packet handler... */
bootp_packet_handler = relay; bootp_packet_handler = relay;
/* Become a daemon... */
if (!no_daemon) {
int pid;
FILE *pf;
int pfdesc;
log_perror = 0;
if ((pid = fork()) < 0)
error ("can't fork daemon: %m");
else if (pid)
exit (0);
pfdesc = open (path_dhcrelay_pid,
O_CREAT | O_TRUNC | O_WRONLY, 0644);
if (pfdesc < 0) {
warn ("Can't create %s: %m", path_dhcrelay_pid);
} else {
pf = fdopen (pfdesc, "w");
if (!pf)
warn ("Can't fdopen %s: %m",
path_dhcrelay_pid);
else {
fprintf (pf, "%d\n", getpid ());
fclose (pf);
}
}
close (0);
close (1);
close (2);
pid = setsid ();
}
/* Start dispatching packets and timeouts... */ /* Start dispatching packets and timeouts... */
dispatch (); dispatch ();