Modified directory path by tizen platform config
[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 #include <tzplatform_config.h>
22
23 #include "log.h"
24
25 #include "util.h"
26 #include "netdbus.h"
27 #include "wifi-dump.h"
28
29 #define NETWORK_DUMP_SCRIPT            tzplatform_mkpath(TZ_SYS_VAR, "/lib/net-config/network_dump.sh")
30
31 static int _start_dump(gchar *dump_path)
32 {
33         int rv = 0;
34         gchar *path = NETWORK_DUMP_SCRIPT;
35         char *const args[] = { path, dump_path, NULL };
36         char *const envs[] = { NULL };
37
38         rv = netconfig_execute_file(path, args, envs);
39         if (rv < 0) {
40                 ERR("Fail to execute network_dump.sh");
41                 return -EIO;
42         }
43
44         return 0;
45 }
46
47 static void _send_dump_signal(const gchar *sig_name)
48 {
49         gboolean reply;
50         GDBusConnection *connection = NULL;
51         GError *error = NULL;
52
53         connection = netdbus_get_connection();
54         if (connection == NULL) {
55                 DBG("GDBusconnection is NULL");
56                 return;
57         }
58
59         reply = g_dbus_connection_emit_signal(connection,
60                         NULL,
61                         DUMP_SERVICE_OBJECT_PATH,
62                         DUMP_SERVICE_INTERFACE,
63                         sig_name,
64                         NULL,
65                         &error);
66         if (reply != TRUE) {
67                 if (error != NULL) {
68                         ERR("Failed to send signal [%s]", error->message);
69                         g_error_free(error);
70                 }
71                 return;
72         }
73 }
74
75 int netconfig_dump_log(const char *path)
76 {
77         gchar *dump_path = NULL;
78
79         if (!path) {
80                 ERR("path is NULL. Dump Fail");
81                 return -1;
82         }
83         ERR("Dump is started");
84         _send_dump_signal(DUMP_START_SIGNAL);
85
86         dump_path = g_strdup(path);
87         _start_dump(dump_path);
88         g_free(dump_path);
89
90         _send_dump_signal(DUMP_FINISH_SIGNAL);
91         ERR("Dump is finished");
92         return 0;
93 }