Browse Source

Code cleanup and whitespace police, run through the testmill this time.

r7149
master
Thiemo Seufer 19 years ago
parent
commit
c17a709eca
  1. 3
      debian/changelog
  2. 74
      netcfg-common.c
  3. 15
      netcfg-dhcp.c
  4. 20
      netcfg-static.c
  5. 21
      netcfg.c

3
debian/changelog

@ -2,6 +2,9 @@ netcfg (0.40) UNRELEASED; urgency=low
* Bart Cornelis
- Merged Norwegian Nynorsk (nn.po) translation from skolelinux-cvs
* Thiemo Seufer
- Code cleanup and whitespace police, run through the testmill
this time.
-- Bart Cornelis <cobaco@linux.be> Sat, 27 Dec 2003 01:47:04 +0100

74
netcfg-common.c

@ -128,7 +128,6 @@ void get_name(char *name, char *p)
}
static FILE *ifs = NULL;
static char ibuf[512];
@ -178,14 +177,14 @@ char *get_ifdsc(struct debconfclient *client, const char *ifp)
char template[256];
if (strlen(ifp) < 100) {
/* strip away the number from the interface (eth0 -> eth) */
/* strip away the number from the interface (eth0 -> eth) */
char *new_ifp = strdup(ifp), *ptr = new_ifp;
while ((*ptr < '0' || *ptr > '9') && *ptr != '\0')
ptr++;
*ptr = '\0';
sprintf(template, "netcfg/internal-%s", new_ifp);
free(new_ifp);
sprintf(template, "netcfg/internal-%s", new_ifp);
free(new_ifp);
debconf_metaget(client, template, "description");
if (client->value != NULL)
@ -422,7 +421,6 @@ int netcfg_get_domain(struct debconfclient *client, char **domain)
}
void netcfg_write_common(const char *prebaseconfig, u_int32_t ipaddress,
char *domain, char *hostname, u_int32_t nameservers[])
{
@ -482,9 +480,9 @@ int netcfg_get_ipaddress(struct debconfclient *client)
char *ptr;
ret = my_debconf_input(client,"critical", "netcfg/get_ipaddress", &ptr);
if (ret)
if (ret)
return ret;
dot2num(&ipaddress, ptr);
return 0;
}
@ -493,7 +491,7 @@ int netcfg_get_pointopoint(struct debconfclient *client)
{
int ret;
char *ptr;
ret = my_debconf_input(client,"critical", "netcfg/get_pointopoint", &ptr);
if (ret)
return ret;
@ -513,9 +511,9 @@ int netcfg_get_netmask(struct debconfclient *client)
ret = my_debconf_input(client,"critical", "netcfg/get_netmask", &ptr);
if (ret)
if (ret)
return ret;
dot2num(&netmask, ptr);
network = ipaddress & netmask;
broadcast = (network | ~netmask);
@ -531,8 +529,7 @@ int netcfg_get_gateway(struct debconfclient *client)
{
int ret;
char *ptr;
ret = my_debconf_input(client, "critical", "netcfg/get_gateway", &ptr);
if (ret)
return ret;
@ -556,7 +553,7 @@ int netcfg_get_nameservers (struct debconfclient *client, char **nameservers)
*nameservers = strdup(ptr);
return ret;
}
void netcfg_nameservers_to_array(char *nameservers, u_int32_t array[])
{
@ -578,7 +575,6 @@ void netcfg_nameservers_to_array(char *nameservers, u_int32_t array[])
free(save);
} else
array[0] = 0;
}
static int netcfg_write_static(char *prebaseconfig)
@ -633,7 +629,7 @@ int kill_dhcp_client(void) {
return 1;
ret = getline(&pid_char, &linesize, ps);
if (ret < 1)
if (ret < 1)
return 2;
pclose(ps);
@ -645,8 +641,8 @@ int kill_dhcp_client(void) {
sleep(2);
if (kill(pid_int, SIGTERM) == 0)
kill(pid_int, SIGKILL);
if (kill(pid_int, SIGTERM) == 0)
kill(pid_int, SIGKILL);
else
return 0;
@ -734,7 +730,7 @@ int netcfg_activate_static(struct debconfclient *client)
/* write configuration */
strncat(progname, di_progname_get(), PATH_MAX-2);
strncat(progname, di_progname_get(), PATH_MAX-2);
netcfg_write_common(progname, ipaddress, domain, hostname,
nameserver_array);
@ -745,7 +741,6 @@ int netcfg_activate_static(struct debconfclient *client)
int netcfg_get_static(struct debconfclient *client)
{
char *nameservers = NULL;
char *ptr;
char *none;
@ -793,7 +788,7 @@ int netcfg_get_static(struct debconfclient *client)
if (netcfg_get_gateway(client))
state = GET_NETMASK;
else
if (gateway && ((gateway & netmask) != network))
if (gateway && ((gateway & netmask) != network))
state = GATEWAY_UNREACHABLE;
else
state = GET_NAMESERVERS;
@ -806,7 +801,7 @@ int netcfg_get_static(struct debconfclient *client)
debconf_capb(client, "backup");
break;
case GET_NAMESERVERS:
state = (netcfg_get_nameservers (client, &nameservers)) ?
state = (netcfg_get_nameservers (client, &nameservers)) ?
GET_GATEWAY : GET_HOSTNAME;
break;
case GET_HOSTNAME:
@ -814,7 +809,7 @@ int netcfg_get_static(struct debconfclient *client)
GET_NAMESERVERS : GET_DOMAIN;
break;
case GET_DOMAIN:
state = (netcfg_get_domain (client, &domain)) ?
state = (netcfg_get_domain (client, &domain)) ?
GET_HOSTNAME : CONFIRM;
break;
case CONFIRM:
@ -828,7 +823,7 @@ int netcfg_get_static(struct debconfclient *client)
debconf_subst(client, "netcfg/confirm_static", "gateway",
(gateway ? num2dot(gateway) : none));
debconf_subst(client, "netcfg/confirm_static", "hostname", hostname);
debconf_subst(client, "netcfg/confirm_static", "domain",
debconf_subst(client, "netcfg/confirm_static", "domain",
(domain ? domain : none));
debconf_subst(client, "netcfg/confirm_static", "nameservers",
(nameservers ? nameservers : none));
@ -854,7 +849,7 @@ static int netcfg_get_dhcp_hostname(struct debconfclient *client, char **dhcp_ho
debconf_input(client, "low", "netcfg/dhcp_hostname");
ret = debconf_go(client);
if (ret == 30)
if (ret == 30)
return ret;
if (*dhcp_hostname) {
free(*dhcp_hostname);
@ -870,7 +865,6 @@ static int netcfg_get_dhcp_hostname(struct debconfclient *client, char **dhcp_ho
static void netcfg_write_dhcp(char *iface, char *host)
{
FILE *fp;
if ((fp = file_open(INTERFACES_FILE, "a"))) {
@ -896,7 +890,7 @@ int netcfg_activate_dhcp(struct debconfclient *client)
int ret;
char progname[PATH_MAX] = "40";
enum { PUMP, DHCLIENT, UDHCPC } dhcp_client = PUMP;
enum { PUMP, DHCLIENT, UDHCPC } dhcp_client;
if (stat("/sbin/dhclient", &stat_buf) == 0)
dhcp_client = DHCLIENT;
@ -909,14 +903,14 @@ int netcfg_activate_dhcp(struct debconfclient *client)
debconf_go(client);
exit(1);
}
deconfigure_network();
/* setup loopback */
di_exec_shell_log("/sbin/ifconfig lo 127.0.0.1");
/* load kernel module for network sockets */
di_exec_shell_log("/sbin/modprobe af_packet");
di_exec_shell_log("/sbin/modprobe af_packet");
/* get dhcp lease */
switch (dhcp_client) {
@ -941,7 +935,6 @@ int netcfg_activate_dhcp(struct debconfclient *client)
}
while (retry == 1) {
/* show progress bar */
debconf_progress_start(client, 0, 10, "netcfg/dhcp_progress");
debconf_progress_info(client, "netcfg/dhcp_progress_note");
@ -954,16 +947,15 @@ int netcfg_activate_dhcp(struct debconfclient *client)
((WIFEXITED(ret) && (WEXITSTATUS(ret) != 0)) || WIFSIGNALED(ret)) ?
_exit(EXIT_FAILURE) : _exit(EXIT_SUCCESS);
}
if (pid)
if (pid)
dhcp_running = 1;
else
return 1;
signal(SIGCHLD, &dhcp_client_sigchld);
signal(SIGCHLD, &dhcp_client_sigchld);
}
/* wait 10s for a DHCP lease */
while (dhcp_running && ((now - start_time) < 10)) {
while (dhcp_running && ((now - start_time) < 10)) {
sleep(1);
debconf_progress_step(client, 1);
now = time(NULL);
@ -976,11 +968,11 @@ int netcfg_activate_dhcp(struct debconfclient *client)
/* got a lease? */
if (!dhcp_running && (dhcp_exit_status == 0)) {
/* write configuration */
strncat(progname, di_progname_get(), PATH_MAX-2);
strncat(progname, di_progname_get(), PATH_MAX-2);
netcfg_write_common(progname, ipaddress, domain, hostname,
nameserver_array);
netcfg_write_dhcp(interface, dhcp_hostname);
netcfg_write_dhcp(interface, dhcp_hostname);
return 0;
}
@ -989,9 +981,9 @@ int netcfg_activate_dhcp(struct debconfclient *client)
ret = my_debconf_input(client, "high", "netcfg/dhcp_retry", &ptr);
retry = strstr(ptr, "true") ? 1 : 0;
debconf_capb(client, "backup");
}
if (dhcp_running) {
if (dhcp_running) {
kill(pid, SIGTERM);
}
return 1;
@ -999,15 +991,14 @@ int netcfg_activate_dhcp(struct debconfclient *client)
int netcfg_get_dhcp(struct debconfclient *client) {
enum { BACKUP, GET_HOSTNAME, GET_DHCP_HOSTNAME,
enum { BACKUP, GET_HOSTNAME, GET_DHCP_HOSTNAME,
QUIT } state = GET_HOSTNAME;
while (state != QUIT) {
while (1) {
switch (state) {
case BACKUP:
return 10; // Back to main
break;
case GET_HOSTNAME:
case GET_HOSTNAME:
state = netcfg_get_hostname(client, &hostname) ?
BACKUP : GET_DHCP_HOSTNAME;
break;
@ -1017,7 +1008,6 @@ int netcfg_get_dhcp(struct debconfclient *client) {
break;
case QUIT:
return 0;
break;
}
}
return 0;

15
netcfg-dhcp.c

@ -40,7 +40,7 @@ int main(void)
int num_interfaces;
static struct debconfclient *client;
enum { BACKUP, GET_INTERFACE, GET_DHCP,
enum { BACKUP, GET_INTERFACE, GET_DHCP,
QUIT } state = GET_INTERFACE;
/* initialize libd-i */
@ -51,13 +51,11 @@ int main(void)
debconf_capb(client,"backup");
while (state != QUIT) {
switch(state) {
case BACKUP:
exit(10);
break;
return 10;
case GET_INTERFACE:
state = netcfg_get_interface(client, &interface, &num_interfaces) ?
state = netcfg_get_interface(client, &interface, &num_interfaces) ?
BACKUP : GET_DHCP;
break;
case GET_DHCP:
@ -67,12 +65,11 @@ int main(void)
state = QUIT;
break;
case QUIT:
break;
if (netcfg_activate_dhcp(client) != 0)
return 1;
return 0;
}
}
if (netcfg_activate_dhcp(client) != 0)
exit(1);
return 0;
}

20
netcfg-static.c

@ -34,9 +34,9 @@
int main(void)
{
int num_interfaces =0;
int num_interfaces = 0;
static struct debconfclient *client;
enum { BACKUP, GET_INTERFACE, GET_STATIC, QUIT} state = GET_INTERFACE;
/* initialize libd-i */
@ -46,14 +46,12 @@ int main(void)
client = debconfclient_new();
debconf_capb(client, "backup");
while (state != QUIT) {
while (1) {
switch(state) {
case BACKUP:
exit(10);
break;
return 10;
case GET_INTERFACE:
state = netcfg_get_interface(client, &interface, &num_interfaces) ?
state = netcfg_get_interface(client, &interface, &num_interfaces) ?
BACKUP : GET_STATIC;
break;
case GET_STATIC:
@ -63,13 +61,11 @@ int main(void)
state = QUIT;
break;
case QUIT:
break;
if (netcfg_activate_static(client) != 0)
return 1;
return 0;
}
}
if (netcfg_activate_static(client) != 0)
exit(1);
return 0;
}

21
netcfg.c

@ -39,7 +39,6 @@ static enum {DHCP, STATIC} netcfg_method = DHCP;
int netcfg_get_method(struct debconfclient *client)
{
char *method;
int ret;
@ -50,14 +49,14 @@ int netcfg_get_method(struct debconfclient *client)
else
netcfg_method = STATIC;
return ret;
return ret;
}
int main(void)
{
int num_interfaces =0;
enum { BACKUP, GET_INTERFACE, GET_METHOD, GET_DHCP, GET_STATIC, QUIT} state = GET_INTERFACE;
int num_interfaces = 0;
enum { BACKUP, GET_INTERFACE, GET_METHOD, GET_DHCP, GET_STATIC, QUIT } state = GET_INTERFACE;
static struct debconfclient *client;
static char *none;
@ -68,17 +67,15 @@ int main(void)
client = debconfclient_new();
debconf_capb(client, "backup");
debconf_metaget(client, "netcfg/internal-none", "description");
debconf_metaget(client, "netcfg/internal-none", "description");
none = client->value ? strdup(client->value) : strdup("<none>");
while (state != QUIT) {
while (1) {
switch(state) {
case BACKUP:
exit(10);
break;
return 10;
case GET_INTERFACE:
state = netcfg_get_interface(client, &interface, &num_interfaces) ?
state = netcfg_get_interface(client, &interface, &num_interfaces) ?
BACKUP : GET_METHOD;
break;
case GET_METHOD:
@ -111,11 +108,9 @@ int main(void)
}
break;
case QUIT:
break;
return 0;
}
}
return 0;
}

Loading…
Cancel
Save