Sync with Tizen 2.4(v1.1.38)
[platform/core/connectivity/net-config.git] / src / wifi-dump.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <glib.h>
21
22 #include "log.h"
23
24 #include "util.h"
25 #include "netdbus.h"
26 #include "wifi-dump.h"
27
28 #define NETWORK_DUMP_SCRIPT             "/opt/var/lib/net-config/network_dump.sh"
29
30 static int _start_dump(gchar *dump_path)
31 {
32         int rv = 0;
33         gchar *path = NETWORK_DUMP_SCRIPT;
34         char *const args[] = { "/opt/var/lib/net-config/network_dump.sh", dump_path, NULL };
35         char *const envs[] = { NULL };
36
37         rv = netconfig_execute_file(path, args, envs);
38         if (rv < 0) {
39                 ERR("Fail to execute network_dump.sh");
40                 return -EIO;
41         }
42
43         return 0;
44 }
45
46 static void _send_dump_signal(const gchar *sig_name)
47 {
48         gboolean reply;
49         GDBusConnection *connection = NULL;
50         GError *error = NULL;
51
52         connection = netdbus_get_connection();
53         if (connection == NULL) {
54                 DBG("GDBusconnection is NULL");
55                 return;
56         }
57
58         reply = g_dbus_connection_emit_signal(connection,
59                         NULL,
60                         DUMP_SERVICE_OBJECT_PATH,
61                         DUMP_SERVICE_INTERFACE,
62                         sig_name,
63                         NULL,
64                         &error);
65         if (reply != TRUE) {
66                 if (error != NULL) {
67                         ERR("Failed to send signal [%s]", error->message);
68                         g_error_free(error);
69                 }
70                 return;
71         }
72 }
73
74 int netconfig_dump_log(const char *path)
75 {
76         gchar *dump_path = NULL;
77
78         if (!path) {
79                 ERR("path is NULL. Dump Fail");
80                 return -1;
81         }
82         ERR("Dump is started");
83         _send_dump_signal(DUMP_START_SIGNAL);
84
85         dump_path = g_strdup(path);
86         _start_dump(dump_path);
87         g_free(dump_path);
88
89         _send_dump_signal(DUMP_FINISH_SIGNAL);
90         ERR("Dump is finished");
91         return 0;
92 }