Index: NetworkManager/src/backends/NetworkManagerDebian.c =================================================================== --- NetworkManager.orig/src/backends/NetworkManagerDebian.c 2008-06-11 12:28:11.000000000 +0200 +++ NetworkManager/src/backends/NetworkManagerDebian.c 2008-06-11 12:33:02.000000000 +0200 @@ -74,18 +74,21 @@ nm_spawn_process ("/usr/bin/killall -q dhclient"); } +#define RESOLVCONF "resolvconf" /* * nm_system_update_dns * - * Make glibc/nscd aware of any changes to the resolv.conf file by - * restarting nscd. + * Invalidate the nscd host cache, if it exists, since + * we changed resolv.conf. * */ void nm_system_update_dns (void) { - nm_spawn_process ("/usr/sbin/invoke-rc.d nscd restart"); - + if (g_file_test ("/usr/sbin/nscd", G_FILE_TEST_IS_EXECUTABLE)) { + nm_info ("Clearing nscd hosts cache."); + nm_spawn_process ("/usr/sbin/nscd -i hosts"); + } } /* @@ -125,6 +128,9 @@ */ gboolean nm_system_should_modify_resolv_conf (void) { - return TRUE; + if (g_find_program_in_path(RESOLVCONF) != NULL) + return FALSE; + else + return TRUE; } Index: NetworkManager/src/backends/interface_parser.c =================================================================== --- NetworkManager.orig/src/backends/interface_parser.c 2008-06-11 12:28:11.000000000 +0200 +++ NetworkManager/src/backends/interface_parser.c 2008-06-11 12:33:02.000000000 +0200 @@ -73,14 +73,18 @@ //printf("added data '%s' with key '%s'\n",data,key); } -#define SPACE_OR_TAB(string,ret) {ret = strchr(string,' ');ret=(ret == NULL?strchr(string,'\t'):ret);} +// define what we consider a whitespace +#define WS " \t" void ifparser_init(void) { FILE *inp = fopen(INTERFACES,"r"); int ret = 0; + int pos; + int len; char *line; - char *space; + char *key; + char *data; char rline[255]; if (inp == NULL) @@ -91,7 +95,7 @@ first = last = NULL; while(1) { - line = space = NULL; + line = NULL; ret = fscanf(inp,"%255[^\n]\n",rline); if (ret == EOF) break; @@ -104,50 +108,71 @@ line = rline; while(line[0] == ' ') line++; - if (line[0]=='#' || line[0]=='\0') + if (line[0] == '#' || line[0] == '\0') continue; - SPACE_OR_TAB(line,space) - if (space == NULL) + len = strlen(line); + pos = 0; + while (!strchr(WS, line[pos]) && pos < len) pos++; + + // terminate key string and skip further whitespaces + line[pos++] = '\0'; + while (strchr(WS, line[pos]) && pos < len) pos++; + + if (pos >= len) { - nm_warning ("Error: Can't parse interface line '%s'\n",line); + nm_warning ("Error: Can't parse line '%s'\n", line); continue; } - space[0] = '\0'; - + key = &line[0]; + data = &line[pos]; + // There are four different stanzas: // iface, mapping, auto and allow-*. Create a block for each of them. - if (strcmp(line,"iface")==0) + if (strcmp(key, "iface") == 0) { - char *space2 = strchr(space+1,' '); - if (space2 == NULL) + char *key2; + + while (!strchr(WS, line[pos]) && pos < len ) pos++; + + // terminate first data string and skip further whitespaces + line[pos++] = '\0'; + while (strchr(WS, line[pos]) && pos < len) pos++; + if (pos >= len) { - nm_warning ("Error: Can't parse iface line '%s'\n",space+1); + nm_warning ("Error: Can't parse iface line '%s'\n", data); continue; } - space2[0]='\0'; - add_block(line,space+1); + key2 = &line[pos]; + + add_block(key, data); - if (space2[1]!='\0') + if (pos < len) { - space = strchr(space2+1,' '); - if (space == NULL) + + while (!strchr(WS, line[pos]) && pos < len ) pos++; + + // terminate key2 string and skip further whitespaces + line[pos++] = '\0'; + while (strchr(WS, line[pos]) && pos < len) pos++; + if (pos >= len) { - nm_warning ("Error: Can't parse data '%s'\n",space2+1); + nm_warning ("Error: Can't parse inet line '%s'\n", key2); continue; } - space[0] = '\0'; - add_data(space2+1,space+1); + data = &line[pos]; + + add_data(key2, data); } } - else if (strcmp(line,"auto")==0) - add_block(line,space+1); - else if (strcmp(line,"mapping")==0) - add_block(line,space+1); - else if (strncmp(line,"allow-",6)==0) - add_block(line,space+1); + else if (strcmp(key, "auto") == 0) + add_block(key, data); + else if (strcmp(key, "mapping") == 0) + add_block(key, data); + else if (strncmp(key, "allow-", 6) == 0) + add_block(key, data); else - add_data(line,space+1); + add_data(key, data); //printf("line: '%s' ret=%d\n",rline,ret); } @@ -200,6 +225,18 @@ return NULL; } +if_block *ifparser_getmapping(const char* iface) +{ + if_block *curr = first; + while(curr!=NULL) + { + if (strcmp(curr->type,"mapping")==0 && strcmp(curr->name,iface)==0) + return curr; + curr = curr->next; + } + return NULL; +} + const char *ifparser_getkey(if_block* iface, const char *key) { if_data *curr = iface->info; Index: NetworkManager/src/backends/interface_parser.h =================================================================== --- NetworkManager.orig/src/backends/interface_parser.h 2008-06-11 12:28:11.000000000 +0200 +++ NetworkManager/src/backends/interface_parser.h 2008-06-11 12:33:02.000000000 +0200 @@ -44,6 +44,7 @@ void ifparser_destroy(void); if_block *ifparser_getif(const char* iface); +if_block *ifparser_getmapping(const char* iface); if_block *ifparser_getfirst(void); const char *ifparser_getkey(if_block* iface, const char *key);