Merge branch 'master' of octo@verplant.org:/var/lib/git/collectd
[collectd.git] / src / utils_cmd_flush.c
1 /**
2  * collectd - src/utils_cmd_flush.c
3  * Copyright (C) 2008  Sebastian Harl
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  *
18  * Author:
19  *   Sebastian "tokkee" Harl <sh at tokkee.org>
20  **/
21
22 #include "collectd.h"
23 #include "plugin.h"
24
25 int handle_flush (FILE *fh, char **fields, int fields_num)
26 {
27         int timeout = -1;
28
29         if ((fields_num != 1) && (fields_num != 2))
30         {
31                 DEBUG ("unixsock plugin: us_handle_flush: "
32                                 "Wrong number of fields: %i", fields_num);
33                 fprintf (fh, "-1 Wrong number of fields: Got %i, expected 1 or 2.\n",
34                                 fields_num);
35                 fflush (fh);
36                 return (-1);
37         }
38
39         if (fields_num == 2)
40                 timeout = atoi (fields[1]);
41
42         INFO ("unixsock plugin: flushing all data");
43         plugin_flush_all (timeout);
44         INFO ("unixsock plugin: finished flushing all data");
45
46         fprintf (fh, "0 Done\n");
47         fflush (fh);
48         return (0);
49 } /* int handle_flush */
50
51 /* vim: set sw=4 ts=4 tw=78 noexpandtab : */
52