main.c (3402B)
1 /* 2 * 3 * Ethernet daemon for Linux 4 * 5 * Copyright (C) 2017-2019 Intel Corporation. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 * 21 */ 22 23 #ifdef HAVE_CONFIG_H 24 #include <config.h> 25 #endif 26 27 #include <stdio.h> 28 #include <stdlib.h> 29 #include <errno.h> 30 #include <getopt.h> 31 #include <ell/ell.h> 32 33 #include "src/module.h" 34 #include "src/eap.h" 35 #include "wired/dbus.h" 36 #include "wired/ethdev.h" 37 #include "wired/network.h" 38 39 struct main_opts { 40 const char *interfaces; 41 const char *nointerfaces; 42 }; 43 44 static void dbus_ready(struct l_dbus *dbus, void *user_data) 45 { 46 struct main_opts *opts = user_data; 47 48 l_info("System ready"); 49 50 if (iwd_modules_init() < 0) { 51 l_main_quit(); 52 return; 53 } 54 55 ethdev_init(opts->interfaces, opts->nointerfaces); 56 } 57 58 static void dbus_shutdown(struct l_dbus *dbus, void *user_data) 59 { 60 l_info("System shutdown"); 61 62 ethdev_exit(); 63 64 iwd_modules_exit(); 65 66 dbus_app_shutdown_complete(); 67 } 68 69 static const struct dbus_app app = { 70 .bus = L_DBUS_SYSTEM_BUS, 71 .name = "net.connman.ead", 72 .ready = dbus_ready, 73 .shutdown = dbus_shutdown, 74 }; 75 76 static void usage(void) 77 { 78 printf("ead - Authentication daemon\n" 79 "Usage:\n"); 80 printf("\tead [options]\n"); 81 printf("Options:\n" 82 "\t-i, --interfaces Interfaces to manage\n" 83 "\t-I, --nointerfaces Interfaces to ignore\n" 84 "\t-d, --debug Enable debug output\n" 85 "\t-h, --help Show help options\n"); 86 } 87 88 static const struct option main_options[] = { 89 { "interfaces", required_argument, NULL, 'i' }, 90 { "nointerfaces", required_argument, NULL, 'I' }, 91 { "debug", optional_argument, NULL, 'd' }, 92 { "version", no_argument, NULL, 'v' }, 93 { "help", no_argument, NULL, 'h' }, 94 { } 95 }; 96 97 int main(int argc, char *argv[]) 98 { 99 struct main_opts opts; 100 const char *debugopt = NULL; 101 102 opts.interfaces = NULL; 103 opts.nointerfaces = NULL; 104 105 for (;;) { 106 int opt; 107 108 opt = getopt_long(argc, argv, "i:I:d::vh", main_options, NULL); 109 if (opt < 0) 110 break; 111 112 switch (opt) { 113 case 'i': 114 opts.interfaces = optarg; 115 break; 116 case 'I': 117 opts.nointerfaces = optarg; 118 break; 119 case 'd': 120 if (optarg) 121 debugopt = optarg; 122 else if (argv[optind] && argv[optind][0] != '-') 123 debugopt = argv[optind++]; 124 else 125 debugopt = "*"; 126 break; 127 case 'v': 128 printf("%s\n", VERSION); 129 return EXIT_SUCCESS; 130 case 'h': 131 usage(); 132 return EXIT_SUCCESS; 133 default: 134 return EXIT_FAILURE; 135 } 136 } 137 138 if (argc - optind > 0) { 139 fprintf(stderr, "Invalid command line parameters\n"); 140 return EXIT_FAILURE; 141 } 142 143 l_log_set_stderr(); 144 145 if (debugopt) 146 l_debug_enable(debugopt); 147 148 l_info("Authentication daemon version %s", VERSION); 149 150 return dbus_app_run(&app, &opts, NULL); 151 }