Move background() to sys.[ch].
This commit is contained in:
parent
59a0661eb9
commit
8e905d0611
@ -29,9 +29,6 @@ static struct arpMsg arpreply;
|
||||
static int arpreply_offset;
|
||||
static struct dhcpMessage arp_dhcp_packet;
|
||||
|
||||
// from ndhc.c
|
||||
void background(void);
|
||||
|
||||
/* Returns fd of the arp socket, or -1 on failure. */
|
||||
static int arpping(uint32_t test_nip, const uint8_t *safe_mac,
|
||||
uint32_t from_ip, uint8_t *from_mac, const char *interface)
|
||||
@ -80,7 +77,6 @@ static int arpping(uint32_t test_nip, const uint8_t *safe_mac,
|
||||
return arpfd;
|
||||
}
|
||||
|
||||
// only called from packet.c
|
||||
void arp_check(struct client_state_t *cs, struct dhcpMessage *packet)
|
||||
{
|
||||
cs->arpPrevState = cs->dhcpState;
|
||||
@ -110,7 +106,6 @@ static void arp_failed(struct client_state_t *cs)
|
||||
change_listen_mode(cs, LM_RAW);
|
||||
}
|
||||
|
||||
// only called from timeout.c
|
||||
void arp_success(struct client_state_t *cs)
|
||||
{
|
||||
struct in_addr temp_addr;
|
||||
|
17
ndhc/ndhc.c
17
ndhc/ndhc.c
@ -95,8 +95,6 @@ struct client_config_t client_config = {
|
||||
.arp = "\0",
|
||||
};
|
||||
|
||||
static char pidfile[MAX_PATH_LENGTH] = PID_FILE_DEFAULT;
|
||||
|
||||
static void show_usage(void)
|
||||
{
|
||||
printf(
|
||||
@ -184,21 +182,6 @@ static void perform_release(void)
|
||||
cs.timeout = -1;
|
||||
}
|
||||
|
||||
void background(void)
|
||||
{
|
||||
static char called;
|
||||
if (!called && daemon(0, 0) == -1) {
|
||||
perror("fork");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
called = 1; /* Do not fork again. */
|
||||
if (file_exists(pidfile, "w") == -1) {
|
||||
log_line("FATAL - cannot open pidfile for write!");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
write_pid(pidfile);
|
||||
}
|
||||
|
||||
static void setup_signals()
|
||||
{
|
||||
sigset_t mask;
|
||||
|
49
ndhc/sys.c
Normal file
49
ndhc/sys.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/epoll.h>
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "pidfile.h"
|
||||
#include "sys.h"
|
||||
|
||||
char pidfile[MAX_PATH_LENGTH] = PID_FILE_DEFAULT;
|
||||
|
||||
void background(void)
|
||||
{
|
||||
static char called;
|
||||
if (!called && daemon(0, 0) == -1) {
|
||||
perror("fork");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
called = 1; /* Do not fork again. */
|
||||
if (file_exists(pidfile, "w") == -1) {
|
||||
log_line("FATAL - cannot open pidfile for write!");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
write_pid(pidfile);
|
||||
}
|
||||
|
||||
void epoll_add(struct client_state_t *cs, int fd)
|
||||
{
|
||||
struct epoll_event ev;
|
||||
int r;
|
||||
ev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP;
|
||||
ev.data.fd = fd;
|
||||
r = epoll_ctl(cs->epollFd, EPOLL_CTL_ADD, fd, &ev);
|
||||
if (r == -1)
|
||||
suicide("epoll_add failed %s", strerror(errno));
|
||||
}
|
||||
|
||||
void epoll_del(struct client_state_t *cs, int fd)
|
||||
{
|
||||
struct epoll_event ev;
|
||||
int r;
|
||||
ev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP;
|
||||
ev.data.fd = fd;
|
||||
r = epoll_ctl(cs->epollFd, EPOLL_CTL_DEL, fd, &ev);
|
||||
if (r == -1)
|
||||
suicide("epoll_del failed %s", strerror(errno));
|
||||
}
|
20
ndhc/sys.h
Normal file
20
ndhc/sys.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef SYS_H_
|
||||
#define SYS_H_
|
||||
|
||||
#include <sys/time.h>
|
||||
#include "ndhc-defines.h"
|
||||
|
||||
static inline unsigned long long curms()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return tv.tv_sec * 1000ULL + tv.tv_usec / 1000ULL;
|
||||
}
|
||||
|
||||
extern char pidfile[MAX_PATH_LENGTH];
|
||||
|
||||
void background(void);
|
||||
void epoll_add(struct client_state_t *cs, int fd);
|
||||
void epoll_del(struct client_state_t *cs, int fd);
|
||||
|
||||
#endif /* SYS_H_ */
|
@ -9,9 +9,6 @@
|
||||
#include "arpping.h"
|
||||
#include "log.h"
|
||||
|
||||
// from ndhc.c
|
||||
void background(void);
|
||||
|
||||
static void init_selecting_timeout(struct client_state_t *cs)
|
||||
{
|
||||
if (cs->packetNum < NUMPACKETS) {
|
||||
|
Loading…
Reference in New Issue
Block a user