Remove some empty lines to make it more readable
[connman] / plugins / resolvfile.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdio.h>
27 #include <errno.h>
28 #include <fcntl.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <sys/stat.h>
32
33 #define CONNMAN_API_SUBJECT_TO_CHANGE
34 #include <connman/plugin.h>
35 #include <connman/resolver.h>
36 #include <connman/log.h>
37
38 #include <glib.h>
39
40 static int resolvfile_append(const char *interface, const char *domain,
41                                                         const char *server)
42 {
43         char *cmd;
44         int fd, len, err;
45
46         DBG("server %s", server);
47
48         fd = open("/etc/resolv.conf", O_RDWR | O_CREAT,
49                                         S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
50         if (fd < 0)
51                 return errno;
52
53         err = ftruncate(fd, 0);
54
55         cmd = g_strdup_printf("nameserver %s\n", server);
56
57         len = write(fd, cmd, strlen(cmd));
58
59         g_free(cmd);
60
61         close(fd);
62
63         return 0;
64 }
65
66 static int resolvfile_remove(const char *interface, const char *domain,
67                                                         const char *server)
68 {
69         DBG("server %s", server);
70
71         return 0;
72 }
73
74 static struct connman_resolver resolvfile_resolver = {
75         .name           = "resolvfile",
76         .priority       = CONNMAN_RESOLVER_PRIORITY_LOW,
77         .append         = resolvfile_append,
78         .remove         = resolvfile_remove,
79 };
80
81 static int resolvfile_init(void)
82 {
83         return connman_resolver_register(&resolvfile_resolver);
84 }
85
86 static void resolvfile_exit(void)
87 {
88         connman_resolver_unregister(&resolvfile_resolver);
89 }
90
91 CONNMAN_PLUGIN_DEFINE(resolvfile, "Name resolver plugin", VERSION,
92                                         resolvfile_init, resolvfile_exit)