2 * Network Configuration Module
4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <systemd/sd-daemon.h>
31 #include "network-clock.h"
32 #include "network-state.h"
33 #include "network-statistics.h"
34 #include "signal-handler.h"
35 #include "wifi-agent.h"
37 static GMainLoop *main_loop = NULL;
39 static int no_fork = FALSE;
41 void netconfig_signal_handler_SIGTERM(int signum)
43 g_main_loop_quit(main_loop);
46 int netconfig_register_signal_handler_SIGTERM(void)
48 struct sigaction sigset;
50 sigemptyset(&sigset.sa_mask);
51 sigaddset( &sigset.sa_mask, SIGTERM );
53 sigset.sa_handler = netconfig_signal_handler_SIGTERM;
55 if (sigaction( SIGTERM, &sigset, NULL) < 0) {
56 ERR("Sigaction for SIGTERM failed [%s]", strerror( errno ));
60 INFO( "Handler for SIGTERM ok" );
64 int netconfig_test_input_parameters(int argc, char* argv[])
66 struct option tab[] = {
67 { "nofork", no_argument, 0, 0 },
72 while (getopt_long(argc, argv, "", tab, &idx) >= 0) {
81 int main(int argc, char* argv[])
83 DBusGConnection *connection;
85 DBG("Network Configuration Module");
88 * Call parameters veryfication
90 netconfig_test_input_parameters(argc, argv);
93 if (daemon(0, 0) != 0)
94 DBG("Cannot start daemon");
97 netconfig_set_wifi_mac_address();
101 main_loop = g_main_loop_new(NULL, FALSE);
103 connection = netconfig_setup_dbus();
104 if (connection == NULL)
107 if (netconfig_network_state_create_and_init(connection) == NULL)
110 netconfig_register_signal();
112 /* Registering the agent for exchanging security credentials */
113 netconfig_agent_register();
115 if (netconfig_wifi_create_and_init(connection) == NULL)
118 if (netconfig_network_statistics_create_and_init(connection) == NULL)
121 /* Register SIGCHLD signal handler function */
122 if (netconfig_register_signal_handler_SIGTERM() != 0)
125 /* If its environment uses Emulator, network configuration is set by emulator default */
126 netconfig_emulator_test_and_start();
128 // Notyfication to systemd
129 sd_notify(0, "READY=1");
131 g_main_loop_run(main_loop);
133 netconfig_deregister_signal();
134 netconfig_wifi_state_notifier_cleanup();
136 /* Unregistering the agent */
137 netconfig_agent_unregister();