Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check for resolv.conf symlink #2349

Merged
merged 3 commits into from
Jan 7, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -367,6 +370,17 @@ private synchronized String getRealPath(File file) throws KuraException {

private synchronized void writeDnsFile(Set<IPAddress> servers) {
logger.debug("Writing DNS servers to file");
// Check if DNS_FILE_NAME is a symlink and it is broken or points to unmanaged location.
// In this case, delete it.
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this block to a specific method with a meaningful name, in order to be able to remove the comment.

if (Files.isSymbolicLink(Paths.get(DNS_FILE_NAME))
&& !Files.readSymbolicLink(Paths.get(DNS_FILE_NAME)).equals(Paths.get(getPppDnsFileName()))) {
Files.delete(Paths.get(DNS_FILE_NAME));
}
} catch (IOException e) {
logger.error("Cannot read symlink", e);
}

try (FileOutputStream fos = new FileOutputStream(DNS_FILE_NAME); PrintWriter pw = new PrintWriter(fos);) {
String[] existingFile = getModifiedFile();
for (String element : existingFile) {
Expand All @@ -378,8 +392,8 @@ private synchronized void writeDnsFile(Set<IPAddress> servers) {
}
pw.flush();
fos.getFD().sync();
} catch (Exception e) {
logger.error("writeDnsFile() :: failed to write the {} file ", DNS_FILE_NAME, e);
} catch (Exception e1) {
logger.error("writeDnsFile() :: failed to write the {} file ", DNS_FILE_NAME, e1);
}
}

Expand Down