Commits

Tobias W. Kjeldsen  committed f1f2205

Added SUCCESS and FAIL indicator.
Corrected a FILE descriptor that was not closed.

  • Participants
  • Parent commits 3b62b3c

Comments (0)

Files changed (1)

 	bzero(commandExec, 1024);
 	
 	// We copy (and backup) original hosts file for later revert
-	if(fopen(HOSTS_BACKUP_F, "r") == NULL ) {
+	FILE* f;
+	if((f = fopen(HOSTS_BACKUP_F, "r")) == NULL ) {
 		sprintf(commandExec, "cp /etc/hosts %s", HOSTS_BACKUP_F);
 		system(commandExec);
 	
 		bzero(commandExec, 1024);
+	} else {
+		fclose(f);
 	}
 	
 	// We merge the original hosts file with a new one containing latest hosts to block
 	sprintf(commandExec, "cat %s %s | sort | uniq > /etc/hosts", HOSTS_OLD_F, PROVIDER_HOSTS_F);
-	system(commandExec);
+	int res = system(commandExec);	
 
 	bzero(commandExec, 1024);
 
 	// We cleanup the temporary files we've made
 	sprintf(commandExec, "rm -f %s %s", HOSTS_OLD_F, PROVIDER_HOSTS_F);
 	system(commandExec);
-
-	printf("SUCCESS!\n");	
-	printf("Your hosts file has been merged with the latest provided ad-block hosts.\n");
-	printf("You may need to restart your system before blocking of ads will take affect!\n");
+	
+	if(res==0) {
+		printf("SUCCESS!\n");	
+		printf("Your hosts file has been merged with the latest provided ad-block hosts.\n");
+		printf("You may need to restart your system before blocking of ads will take affect!\n");
+	} else {
+		printf("FAIL!\n");
+		printf("Remember to run with root permissions!\n");
+	}
 }
 
 int main(int argc, char *argv[]) {