Skip to content

Commit 98fce11

Browse files
committed
Merge pull request #170 from acv/split-main
Refactor main() to allow for unit tests
2 parents d809997 + cdfa702 commit 98fce11

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*.swp
22
.DS_Store
33
*.o
4+
*.a
45
*.la
56
*.so
67
*.lo

src/Makefile.am

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# $Id$
33
#
44

5+
noinst_LIBRARIES = libgateway.a
6+
57
bin_PROGRAMS = wifidog \
68
wdctl
79

@@ -11,9 +13,11 @@ AM_CPPFLAGS = \
1113
-Wall \
1214
-Wextra \
1315
-Wno-unused-parameter
14-
wifidog_LDADD = $(top_builddir)/libhttpd/libhttpd.la
16+
wifidog_LDADD = libgateway.a $(top_builddir)/libhttpd/libhttpd.la
17+
18+
wifidog_SOURCES = main.c
1519

16-
wifidog_SOURCES = commandline.c \
20+
libgateway_a_SOURCES = commandline.c \
1721
conf.c \
1822
debug.c \
1923
fw_iptables.c \
@@ -51,4 +55,6 @@ noinst_HEADERS = commandline.h \
5155
simple_http.h \
5256
pstring.h
5357

58+
wdctl_LDADD = libgateway.a
59+
5460
wdctl_SOURCES = wdctl.c

src/gateway.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
* *
2020
\********************************************************************/
2121

22-
/* $Id$ */
2322
/** @internal
2423
@file gateway.c
2524
@brief Main loop
@@ -483,7 +482,7 @@ main_loop(void)
483482

484483
/** Reads the configuration file and then starts the main loop */
485484
int
486-
main(int argc, char **argv)
485+
gw_main(int argc, char **argv)
487486
{
488487

489488
s_config *config = config_get_config();

src/gateway.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@
2828
#ifndef _GATEWAY_H_
2929
#define _GATEWAY_H_
3030

31+
#include <stdio.h>
32+
3133
#include "httpd.h"
3234

3335
extern time_t started_time;
3436

35-
/* The internal web server */
37+
/** @brief The internal web server */
3638
extern httpd *webserver;
3739

40+
/** @brief actual program entry point. */
41+
int gw_main(int, char **);
42+
3843
/** @brief exits cleanly and clear the firewall rules. */
3944
void termination_handler(int s);
4045

src/main.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* vim: set et sw=4 ts=4 sts=4 : */
2+
/********************************************************************\
3+
* This program is free software; you can redistribute it and/or *
4+
* modify it under the terms of the GNU General Public License as *
5+
* published by the Free:Software Foundation; either version 2 of *
6+
* the License, or (at your option) any later version. *
7+
* *
8+
* This program is distributed in the hope that it will be useful, *
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11+
* GNU General Public License for more details. *
12+
* *
13+
* You should have received a copy of the GNU General Public License*
14+
* along with this program; if not, contact: *
15+
* *
16+
* Free Software Foundation Voice: +1-617-542-5942 *
17+
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
18+
* Boston, MA 02111-1307, USA [email protected] *
19+
* *
20+
\********************************************************************/
21+
22+
/** @internal
23+
@file main.c
24+
@brief Entry point only
25+
@author Copyright (C) 2015 Alexandre Carmel-Veilleux <[email protected]>
26+
*/
27+
28+
#include "gateway.h"
29+
30+
int
31+
main(int argc, char **argv)
32+
{
33+
return gw_main(argc, argv);
34+
}

0 commit comments

Comments
 (0)