]>
git.ipfire.org Git - people/ms/rstp.git/blob - main.c
1 /*****************************************************************************
2 Copyright (c) 2006 EMC Corporation.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2 of the License, or (at your option)
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc., 59
16 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 The full GNU General Public License is included in this distribution in the
21 Authors: Srinivas Aji <Aji_Srinivas@emc.com>
23 ******************************************************************************/
25 #include "epoll_loop.h"
26 #include "bridge_ctl.h"
27 #include "ctl_socket_server.h"
28 #include "netif_utils.h"
39 static int become_daemon
= 1;
40 static int is_daemon
= 0;
41 int log_level
= LOG_LEVEL_DEFAULT
;
43 int main(int argc
, char *argv
[])
46 while ((c
= getopt(argc
, argv
, "dv:")) != -1) {
55 l
= strtoul(optarg
, &end
, 0);
56 if (*optarg
== 0 || *end
!= 0
57 || l
> LOG_LEVEL_MAX
) {
58 ERROR("Invalid loglevel %s", optarg
);
69 TST(init_epoll() == 0, -1);
70 TST(ctl_socket_init() == 0, -1);
71 TST(packet_sock_init() == 0, -1);
72 TST(netsock_init() == 0, -1);
73 TST(init_bridge_ops() == 0, -1);
75 FILE *f
= fopen("/var/run/rstpd.pid", "w");
77 ERROR("can't open /var/run/rstp.pid");
80 openlog("rstpd", 0, LOG_DAEMON
);
83 ERROR("daemon() failed");
87 fprintf(f
, "%d", getpid());
90 return epoll_main_loop();
93 /*********************** Logging *********************/
98 void vDprintf(int level
, const char *fmt
, va_list ap
)
100 if (level
> log_level
)
109 local_tm
= localtime(&clock
);
111 strftime(logbuf
, sizeof(logbuf
) - 1, "%F %T ", local_tm
);
112 vsnprintf(logbuf
+ l
, sizeof(logbuf
) - l
- 1, fmt
, ap
);
113 printf("%s\n", logbuf
);
115 vsyslog((level
<= LOG_LEVEL_INFO
) ? LOG_INFO
: LOG_DEBUG
, fmt
,
120 void Dprintf(int level
, const char *fmt
, ...)
124 vDprintf(level
, fmt
, ap
);