summaryrefslogtreecommitdiff
path: root/plugins/resolvfile.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-08-09 04:59:25 +0200
committerMarcel Holtmann <marcel@holtmann.org>2008-08-09 04:59:25 +0200
commit4658b59abd4e0fc58821a67e6847667c1bab33ca (patch)
tree08f4efd90e3e6aff3fdbe0995bf3289f9f43ef77 /plugins/resolvfile.c
parent6232321cbe36b7ddaa3f6946a8c562a32d25845e (diff)
downloadconnman-4658b59abd4e0fc58821a67e6847667c1bab33ca.tar.gz
connman-4658b59abd4e0fc58821a67e6847667c1bab33ca.tar.bz2
connman-4658b59abd4e0fc58821a67e6847667c1bab33ca.zip
Write /etc/resolv.conf file directly
Diffstat (limited to 'plugins/resolvfile.c')
-rw-r--r--plugins/resolvfile.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/plugins/resolvfile.c b/plugins/resolvfile.c
index d39b2e1d..bf480818 100644
--- a/plugins/resolvfile.c
+++ b/plugins/resolvfile.c
@@ -23,7 +23,11 @@
#include <config.h>
#endif
-#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/stat.h>
#include <connman/plugin.h>
#include <connman/driver.h>
@@ -34,7 +38,7 @@ static int resolvfile_probe(struct connman_element *element)
const char *nameserver = NULL;
struct connman_element *internet;
gchar *cmd;
- int err;
+ int fd, len, err;
DBG("element %p name %s", element, element->name);
@@ -44,15 +48,21 @@ static int resolvfile_probe(struct connman_element *element)
if (nameserver == NULL)
return -EINVAL;
- cmd = g_strdup_printf("echo \"nameserver %s\" > /etc/resolv.conf",
- nameserver);
+ fd = open("/etc/resolv.conf", O_RDWR | O_CREAT,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (fd < 0)
+ return errno;
- DBG("%s", cmd);
+ err = ftruncate(fd, 0);
- err = system(cmd);
+ cmd = g_strdup_printf("nameserver %s\n", nameserver);
+
+ len = write(fd, cmd, strlen(cmd));
g_free(cmd);
+ close(fd);
+
internet = connman_element_create();
internet->type = CONNMAN_ELEMENT_TYPE_INTERNET;