]> git.ozlabs.org Git - petitboot/blob - ui/twin/pbt-main.c
Speed up --start-daemon option
[petitboot] / ui / twin / pbt-main.c
1 /*
2  *  Copyright Geoff Levand <geoff@infradead.org>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; version 2 of the License.
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, write to the Free Software
15  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17
18 #if defined(HAVE_CONFIG_H)
19 #include "config.h"
20 #endif
21
22 #define _GNU_SOURCE
23 #include <stdio.h>
24 #include <getopt.h>
25
26 #include "pbt-main.h"
27
28 void pbt_print_version(void)
29 {
30         printf("petitboot-twin (" PACKAGE_NAME ") " PACKAGE_VERSION "\n");
31 }
32
33 void pbt_print_usage(void)
34 {
35         pbt_print_version();
36         printf(
37 "Usage: petitboot-twin [-d, --dry-run] [-h, --help] [-l, --log log-file]\n"
38 "                      [-r, --reset-defaults] [-s, --start-daemon]\n"
39 "                      [-t, --timeout] [-V, --version]\n"
40 "                      [[-f --fbdev] | [-x --x11]]\n");
41 }
42
43 /**
44  * pbt_opts_parse - Parse the command line options.
45  */
46
47 int pbt_opts_parse(struct pbt_opts *opts, int argc, char *argv[])
48 {
49         static const struct option long_options[] = {
50                 {"dry-run",        no_argument,       NULL, 'd'},
51                 {"fbdev",          no_argument,       NULL, 'f'},
52                 {"help",           no_argument,       NULL, 'h'},
53                 {"log",            required_argument, NULL, 'l'},
54                 {"reset-defaults", no_argument,       NULL, 'r'},
55                 {"start-daemon",   no_argument,       NULL, 's'},
56                 {"timeout",        no_argument,       NULL, 't'},
57                 {"version",        no_argument,       NULL, 'V'},
58                 {"x11",            no_argument,       NULL, 'x'},
59                 { NULL, 0, NULL, 0},
60         };
61         static const char short_options[] = "dfhl:strVx";
62         static const struct pbt_opts default_values = {
63                 .backend = pbt_twin_x11,
64                 .log_file = "/var/log/petitboot/petitboot-twin.log",
65         };
66
67         *opts = default_values;
68
69         while (1) {
70                 int c = getopt_long(argc, argv, short_options, long_options,
71                         NULL);
72
73                 if (c == EOF)
74                         break;
75
76                 switch (c) {
77                 case 'd':
78                         opts->dry_run = pbt_opt_yes;
79                         break;
80                 case 'f':
81                         opts->backend = pbt_twin_fbdev;
82                         break;
83                 case 'h':
84                         opts->show_help = pbt_opt_yes;
85                         break;
86                 case 'l':
87                         opts->log_file = optarg;
88                         break;
89                 case 's':
90                         opts->start_daemon = pbt_opt_yes;
91                         break;
92                 case 't':
93                         opts->use_timeout = pbt_opt_yes;
94                         break;
95                 case 'r':
96                         opts->reset_defaults = pbt_opt_yes;
97                         break;
98                 case 'V':
99                         opts->show_version = pbt_opt_yes;
100                         break;
101                 case 'x':
102                         opts->backend = pbt_twin_x11;
103                         break;
104                 default:
105                         opts->show_help = pbt_opt_yes;
106                         return -1;
107                 }
108         }
109
110         return optind != argc;
111 }