3 * \author written by Emmanuel Roullit emmanuel.roullit@gmail.com (c) 2012
7 /* __LICENSE_HEADER_BEGIN__ */
10 * Copyright (C) 2012 Emmanuel Roullit <emmanuel.roullit@gmail.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
28 /* __LICENSE_HEADER_END__ */
34 dabba - Send queries to dabbad and process its replies.
38 dabba <command> <arguments> [--help]
42 dabba is here to generate IPC queries to dabbad and output its
43 replies formatted in a YAML output
51 Prints help output and the currently supported commands.
57 Written by Emmanuel Roullit <emmanuel.roullit@gmail.com>
63 =item Please report bugs to <https://github.com/eroullit/dabba/issues>
65 =item dabba project project page: <https://github.com/eroullit/dabba>
73 =item Copyright © 2012 Emmanuel Roullit.
75 =item License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.
77 =item This is free software: you are free to change and redistribute it.
79 =item There is NO WARRANTY, to the extent permitted by law.
95 #include <libdabba/macros.h>
96 #include <dabbad/dabbad.h>
97 #include <dabba/dabba.h>
98 #include <dabba/help.h>
99 #include <dabba/interface.h>
100 #include <dabba/capture.h>
102 int run_builtin(struct cmd_struct
*p
, int argc
, const char **argv
)
109 status
= p
->fn(argc
, argv
);
113 /* Somebody closed stdout? */
114 if (fstat(fileno(stdout
), &st
))
116 /* Ignore write errors for pipes and sockets.. */
117 if (S_ISFIFO(st
.st_mode
) || S_ISSOCK(st
.st_mode
))
120 /* Check for ENOSPC and EIO errors.. */
121 if (fflush(stdout
)) {
122 perror("write failure on standard output");
126 if (ferror(stdout
)) {
127 perror("unknown write failure on standard output");
131 if (fclose(stdout
)) {
132 perror("close failed on standard output");
139 static int handle_internal_command(int argc
, const char **argv
)
142 const char *cmd
= argv
[0];
143 static struct cmd_struct commands
[] = {
144 {"interface", cmd_interface
},
145 {"capture", cmd_capture
},
149 if (argc
== 0 || cmd
== NULL
|| !strcmp(cmd
, "--help"))
152 /* Turn "dabba cmd --help" into "dabba help cmd" */
153 if (argc
> 1 && !strcmp(argv
[1], "--help")) {
155 argv
[0] = cmd
= "help";
158 for (i
= 0; i
< ARRAY_SIZE(commands
); i
++) {
159 struct cmd_struct
*p
= commands
+ i
;
160 if (strcmp(p
->cmd
, cmd
))
166 return (run_builtin(p
, argc
, argv
));
169 help_unknown_cmd(cmd
);
174 int main(int argc
, const char **argv
)
182 return (handle_internal_command(argc
, argv
));