{
char *cmd;
int fd, len, err;
+ mode_t old_umask;
DBG("interface %s server %s", interface, server);
if (interface == NULL)
return -ENOENT;
+ old_umask = umask(022);
+
fd = open("/etc/resolv.conf", O_RDWR | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- if (fd < 0)
- return -errno;
+ if (fd < 0) {
+ err = -errno;
+ goto done;
+ }
+
+ if (ftruncate(fd, 0) < 0) {
+ err = -errno;
+ goto failed;
+ }
- err = ftruncate(fd, 0);
+ err = 0;
cmd = g_strdup_printf("# Generated by Connection Manager\n"
"options edns0\n"
"nameserver %s\n", server);
len = write(fd, cmd, strlen(cmd));
+ if (len < 0)
+ err = -errno;
g_free(cmd);
+failed:
close(fd);
- return 0;
+done:
+ umask(old_umask);
+
+ return err;
}
static int resolvfile_remove(const char *interface, const char *domain,