2
* dhcpcd - DHCP client daemon -
3
* Copyright (C) 1996 - 1997 Yoichi Hariguchi <yoichi@fore.com>
4
* Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
5
* Copyright (C) 2005 Roy Marples <uberlord@gentoo.org>
6
* Copyright (C) 2005 Simon Kelley <simon@thekelleys.org.uk>
8
* dhcpcd is an RFC2131 and RFC1541 compliant DHCP client daemon.
10
* This is free software; you can redistribute it and/or modify it
11
* under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful, but
16
* WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
* See the GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
#include <sys/types.h>
33
#include "pathnames.h"
36
extern char *ProgramName;
37
extern char *IfNameExt;
38
extern char *ConfigDir;
40
extern int Persistent;
42
extern void *(*currState)();
43
/*****************************************************************************/
50
snprintf(pidfile,sizeof(pidfile),PID_FILE_PATH,IfNameExt);
51
fp=fopen(pidfile,"r");
52
if ( fp == NULL ) goto ntrn;
58
ntrn: if ( sig == SIGALRM ) return;
59
fprintf(stderr,"**** %s: not running\n",ProgramName);
63
/*****************************************************************************/
64
void writePidFile(pid_t pid)
68
snprintf(pidfile,sizeof(pidfile),PID_FILE_PATH,IfNameExt);
69
fp=fopen(pidfile,"w");
72
syslog(LOG_ERR,"writePidFile: fopen: %m\n");
75
fprintf(fp,"%u\n",pid);
78
/*****************************************************************************/
82
snprintf(pidfile,sizeof(pidfile),PID_FILE_PATH,IfNameExt);
85
/*****************************************************************************/
91
waitpid(-1,NULL,WNOHANG);
96
if ( currState == &dhcpBound )
97
siglongjmp(env,1); /* this timeout is T1 */
100
if ( currState == &dhcpRenew )
101
siglongjmp(env,2); /* this timeout is T2 */
104
if ( currState == &dhcpRebind )
105
siglongjmp(env,3); /* this timeout is dhcpIpLeaseTime */
108
if ( currState == &dhcpReboot )
109
siglongjmp(env,4); /* failed to acquire the same IP address */
111
syslog(LOG_ERR,"timed out waiting for a valid DHCP server response\n");
121
/* allow time for final packets to be transmitted before shutting down */
122
/* otherwise 2.0 drops unsent packets. fixme: find a better way than sleep */
125
syslog(LOG_ERR,"terminating on signal %d\n",sig);
127
if (!Persistent || sig != SIGTERM)
132
/*****************************************************************************/
136
struct sigaction action;
137
sigaction(SIGHUP,NULL,&action);
138
action.sa_handler= &sigHandler;
140
for (i=1;i<16;i++) sigaction(i,&action,NULL);
141
sigaction(SIGCHLD,&action,NULL);