Browse Source

get rid of this ugly di_system_prebaseconfig_append junk and replace with

a monolithic script that does the right thing

r16462
tags/0.68
Joshua Kwan 17 years ago
parent
commit
b6d0d516d5
9 changed files with 63 additions and 60 deletions
  1. +4
    -0
      debian/changelog
  2. +27
    -26
      dhcp.c
  3. +13
    -17
      netcfg-common.c
  4. +1
    -0
      netcfg-dhcp.c
  5. +1
    -0
      netcfg-static.c
  6. +1
    -0
      netcfg.c
  7. +5
    -5
      netcfg.h
  8. +8
    -1
      prebaseconfig
  9. +3
    -11
      static.c

+ 4
- 0
debian/changelog View File

@@ -6,6 +6,10 @@ netcfg (0.68) UNRELEASED; urgency=low
- Rework is_hotpluggable_iface a tad.
- Fix problem where broadcast address was being used twice.. only on
some architectures, due to code with unspecified behavior.
- Excise our dynamic prebaseconfig system and replace with a static one
that copies all available files into /target.
- For this, make sure we always start with a clean slate by removing
those files at startup.

-- Joshua Kwan <joshk@triplehelix.org> Fri, 28 May 2004 10:05:29 -0700



+ 27
- 26
dhcp.c View File

@@ -15,12 +15,14 @@
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/utsname.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <time.h>
#include <netdb.h>

int dhcp_running = 0, dhcp_exit_status = 1;
pid_t dhcp_pid = -1;

/* Signal handler for DHCP client child */
static void dhcp_client_sigchld(int sig __attribute__ ((unused)))
@@ -31,7 +33,7 @@ static void dhcp_client_sigchld(int sig __attribute__ ((unused)))
}
}

static void netcfg_write_dhcp (char* prebaseconfig, char *iface)
static void netcfg_write_dhcp (char *iface)
{
FILE *fp;

@@ -55,9 +57,6 @@ static void netcfg_write_dhcp (char* prebaseconfig, char *iface)
if ((fp = file_open(RESOLV_FILE, "a"))) {
fclose(fp);
}
di_system_prebaseconfig_append(prebaseconfig, "cp %s %s\n", RESOLV_FILE,
"/target" RESOLV_FILE);
}

#define DHCP_SECONDS 15
@@ -278,7 +277,7 @@ int netcfg_activate_dhcp (struct debconfclient *client)
case 2: state = STATIC; break;
case 3: /* no net config at this time :( */
kill_dhcp_client();
netcfg_write_loopback("40netcfg");
netcfg_write_loopback();
quit_after_hostname = 1;
state = HOSTNAME;
break;
@@ -326,34 +325,30 @@ int netcfg_activate_dhcp (struct debconfclient *client)
char *ptr = NULL;
FILE *d = NULL;

if ((d = fopen("/tmp/domain_name", "r")) != NULL)
have_domain = 0;
if ((d = fopen(DOMAIN_FILE, "r")) != NULL)
{
fgets(buf, 65, d);
char domain[_UTSNAME_LENGTH + 1] = { 0 };
fgets(domain, _UTSNAME_LENGTH, d);
fclose(d);
unlink("/tmp/domain_name");
}
unlink(DOMAIN_FILE);

/* Seed the domain. We will prefer the domain name passed
* by the DHCP server if there is one. */
if (!empty_str(buf))
{
debconf_set(client, "netcfg/get_domain", buf);
have_domain = 1;
}
else if ((ptr = strchr(buf, '.')) != NULL)
{
debconf_set(client, "netcfg/get_domain", ptr + 1);
have_domain = 1;
/* Seed the domain. We will prefer the domain name passed
* by the DHCP server if there is one. */
if (!empty_str(domain))
{
debconf_set(client, "netcfg/get_domain", domain);
have_domain = 1;
}
}
else
have_domain = 0; /* shouldn't be needed, but what the hell */
/* dhcp hostname, ask for one with the dhcp hostname
* as a seed */
if (gethostname(buf, sizeof(buf)) == 0 && !empty_str(buf)
&& strcmp(buf, "(none)") != 0)
{
di_info("hostname = \"%s\"", buf);
di_info("DHCP hostname: \"%s\"", buf);
debconf_set(client, "netcfg/get_hostname", buf);
}
else
@@ -372,6 +367,12 @@ int netcfg_activate_dhcp (struct debconfclient *client)
di_error("ioctl failed (%s)", strerror(errno));
}

if (have_domain == 0 && (ptr = strchr(buf, '.')) != NULL)
{
debconf_set(client, "netcfg/get_domain", ptr + 1);
have_domain = 1;
}
state = HOSTNAME;
}
break;
@@ -394,7 +395,7 @@ int netcfg_activate_dhcp (struct debconfclient *client)
state = HOSTNAME;
else if (quit_after_hostname)
{
netcfg_write_common("40netcfg", ipaddress, hostname, domain);
netcfg_write_common(ipaddress, hostname, domain);
exit(0);
}
else
@@ -408,8 +409,8 @@ int netcfg_activate_dhcp (struct debconfclient *client)
case END:
/* write configuration */
netcfg_write_common("40netcfg", ipaddress, hostname, domain);
netcfg_write_dhcp("40netcfg", interface);
netcfg_write_common(ipaddress, hostname, domain);
netcfg_write_dhcp(interface);
return 0;
}


+ 13
- 17
netcfg-common.c View File

@@ -49,8 +49,6 @@ char *domain = NULL;
struct in_addr ipaddress = { 0 };
int have_domain = 0;

pid_t dhcp_pid = -1;

/* File descriptors for ioctls and such */
int skfd = 0;
int wfd = 0;
@@ -530,7 +528,7 @@ int netcfg_get_domain(struct debconfclient *client, char **domain)
"ff02::2 ip6-allrouters\n" \
"ff02::3 ip6-allhosts\n"

void netcfg_write_loopback(const char* prebaseconfig)
void netcfg_write_loopback (void)
{
FILE *fp;

@@ -540,13 +538,9 @@ void netcfg_write_loopback(const char* prebaseconfig)
fprintf(fp, "iface lo inet loopback\n\n");
fclose(fp);
}
di_system_prebaseconfig_append(prebaseconfig, "cp %s %s\n",
INTERFACES_FILE,
"/target" INTERFACES_FILE);
}

void netcfg_write_common(const char *prebaseconfig, struct in_addr ipaddress,
char *hostname, char *domain)
void netcfg_write_common(struct in_addr ipaddress, char *hostname, char *domain)
{
FILE *fp;

@@ -565,10 +559,6 @@ void netcfg_write_common(const char *prebaseconfig, struct in_addr ipaddress,
}

fclose(fp);

di_system_prebaseconfig_append(prebaseconfig, "cp %s %s\n",
INTERFACES_FILE,
"/target" INTERFACES_FILE);
}

/* Currently busybox, hostname is not available. */
@@ -577,8 +567,6 @@ void netcfg_write_common(const char *prebaseconfig, struct in_addr ipaddress,
if ((fp = file_open(HOSTNAME_FILE, "w"))) {
fprintf(fp, "%s\n", hostname);
fclose(fp);
di_system_prebaseconfig_append(prebaseconfig, "cp %s %s\n",
HOSTNAME_FILE, "/target" HOSTNAME_FILE);
}

if ((fp = file_open(HOSTS_FILE, "w"))) {
@@ -599,9 +587,6 @@ void netcfg_write_common(const char *prebaseconfig, struct in_addr ipaddress,
fprintf(fp, "\n" IPV6_HOSTS);
fclose(fp);

di_system_prebaseconfig_append(prebaseconfig, "cp %s %s\n",
HOSTS_FILE, "/target" HOSTS_FILE);
}
}

@@ -704,3 +689,14 @@ void parse_args (int argc, char ** argv)
exit(EXIT_FAILURE);
}
}

void reap_old_files (void)
{
static char* remove[] =
{ INTERFACES_FILE, HOSTS_FILE, HOSTNAME_FILE, NETWORKS_FILE,
RESOLV_FILE, DHCLIENT_CONF, DHCLIENT3_CONF, DOMAIN_FILE, 0 };
char **ptr = remove;

while (*ptr)
unlink(*ptr++);
}

+ 1
- 0
netcfg-dhcp.c View File

@@ -41,6 +41,7 @@ int main(int argc, char *argv[])
di_system_init("netcfg-dhcp");

parse_args(argc, argv);
reap_old_files();
open_sockets();

/* initialize debconf */


+ 1
- 0
netcfg-static.c View File

@@ -39,6 +39,7 @@ int main(int argc, char** argv)
di_system_init("netcfg-static");

parse_args(argc, argv);
reap_old_files();
open_sockets();
/* initialize debconf */


+ 1
- 0
netcfg.c View File

@@ -67,6 +67,7 @@ int main(int argc, char *argv[])
di_system_init("netcfg");

parse_args (argc, argv);
reap_old_files ();
open_sockets();

/* initialize debconf */


+ 5
- 5
netcfg.h View File

@@ -8,6 +8,7 @@
#define RESOLV_FILE "/etc/resolv.conf"
#define DHCLIENT_CONF "/etc/dhclient.conf"
#define DHCLIENT3_CONF "/etc/dhcp3/dhclient.conf"
#define DOMAIN_FILE "/tmp/domain_name"

#define _GNU_SOURCE

@@ -31,7 +32,6 @@ extern int netcfg_progress_displayed;
extern int wfd, skfd;
extern int input_result;
extern int have_domain;
extern pid_t dhcp_pid;

/* network config */
extern char *interface;
@@ -74,7 +74,6 @@ extern int netcfg_get_domain(struct debconfclient *client, char **domain);
extern int netcfg_get_dhcp(struct debconfclient *client);

extern int netcfg_get_static(struct debconfclient *client);
extern int do_hostname_jig (struct debconfclient *client);

extern int netcfg_activate_dhcp(struct debconfclient *client);

@@ -82,9 +81,8 @@ extern int kill_dhcp_client(void);
extern int ask_dhcp_retry (struct debconfclient *client);
extern int netcfg_activate_static(struct debconfclient *client);

extern void netcfg_write_loopback (const char* prebaseconfig);
extern void netcfg_write_common (const char *prebaseconfig,
struct in_addr ipaddress, char *hostname,
extern void netcfg_write_loopback (void);
extern void netcfg_write_common (struct in_addr ipaddress, char *hostname,
char *domain);

void netcfg_nameservers_to_array(char *nameservers, struct in_addr array[]);
@@ -105,8 +103,10 @@ extern void seed_hostname_from_dns(struct debconfclient *client, struct in_addr

extern int inet_ptom (const char *src, int *dst, struct in_addr * addrp);
extern const char *inet_mtop (int src, char *dst, socklen_t cnt);

extern void parse_args (int argc, char** argv);
extern void open_sockets (void);
extern void reap_old_files (void);

extern void netcfg_rewrite_resolv (char*, struct in_addr *);
#endif /* _NETCFG_H_ */

+ 8
- 1
prebaseconfig View File

@@ -1,2 +1,9 @@
#!/bin/sh -e
# netcfg adds commands to this
# Copy all relevant networking-related files to /target.

for file in /etc/network/interfaces /etc/networks /etc/hostname /etc/resolv.conf /etc/hosts /etc/dhclient.conf /etc/dhcp3/dhclient.conf; do
if [ -f "$file" ]; then
mkdir /target/$(dirname $file) -p
cp $file /target/$file
fi
done

+ 3
- 11
static.c View File

@@ -232,8 +232,7 @@ void netcfg_nameservers_to_array(char *nameservers, struct in_addr array[])
array[0].s_addr = 0;
}

static int netcfg_write_static(char *prebaseconfig, char *domain,
struct in_addr nameservers[])
static int netcfg_write_static(char *domain, struct in_addr nameservers[])
{
char ptr1[INET_ADDRSTRLEN];
FILE *fp;
@@ -241,10 +240,6 @@ static int netcfg_write_static(char *prebaseconfig, char *domain,
if ((fp = file_open(NETWORKS_FILE, "w"))) {
fprintf(fp, "localnet %s\n", inet_ntop (AF_INET, &network, ptr1, sizeof (ptr1)));
fclose(fp);
di_system_prebaseconfig_append(prebaseconfig, "cp %s %s\n",
NETWORKS_FILE,
"/target" NETWORKS_FILE);
} else
goto error;

@@ -290,9 +285,6 @@ static int netcfg_write_static(char *prebaseconfig, char *domain,
} else
goto error;

di_system_prebaseconfig_append(prebaseconfig, "cp %s %s\n", RESOLV_FILE,
"/target" RESOLV_FILE);

return 0;
error:
return -1;
@@ -481,8 +473,8 @@ int netcfg_get_static(struct debconfclient *client)
break;
case QUIT:
netcfg_write_common("40netcfg", ipaddress, hostname, domain);
netcfg_write_static("40netcfg", domain, nameserver_array);
netcfg_write_common(ipaddress, hostname, domain);
netcfg_write_static(domain, nameserver_array);
return 0;
break;
}


Loading…
Cancel
Save