new release 1.2.0
[psensor-pkg-debian.git] / src / notify_cmd.c
1 /*
2  * Copyright (C) 2010-2016 jeanfi@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
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
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23
24 #include <notify_cmd.h>
25 #include <cfg.h>
26
27 void notify_cmd(struct psensor *s)
28 {
29         char *script, *v, *cmd;
30         int ret;
31
32         script = config_get_notif_script();
33
34         if (script) {
35                 v = psensor_current_value_to_str(s, 1);
36
37                 cmd = malloc(strlen(script)
38                              + 1
39                              + 1
40                              + strlen(s->id)
41                              + 1
42                              + 1
43                              + strlen(v)
44                              + 1);
45
46                 sprintf(cmd, "%s \"%s\" %s", script, s->id, v);
47
48                 log_fct("execute cmd: %s", cmd);
49
50                 ret = system(cmd);
51
52                 log_fct("cmd returns: %d", ret);
53
54                 free(cmd);
55                 free(v);
56                 free(script);
57         }
58 }
59