Fri, 18 Jul 2014 16:57:27 +0200
New screen layout
103
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /***************************************************************************** |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * Copyright (C) 2014 |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * Michiel Broek <mbroek at mbse dot eu> |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * This file is part of the mbsePi-apps |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * This is free software; you can redistribute it and/or modify it |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * under the terms of the GNU General Public License as published by the |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * Free Software Foundation; either version 2, or (at your option) any |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * later version. |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * mbsePi-apps is distributed in the hope that it will be useful, but |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * General Public License for more details. |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | * along with EC-65K; see the file COPYING. If not, write to the Free |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | *****************************************************************************/ |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | #include "mash.h" |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | #include "xutil.h" |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | #include "logger.h" |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | void logger(char *filename, char *progname, char *data) |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | { |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | struct timeval now; |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | struct tm ptm; |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | char *outstr = NULL, *name = NULL; |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | FILE *logfile; |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | name = xstrcpy((char *)"/var/local/log/"); |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | name = xstrcat(name, progname); |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | name = xstrcat(name, (char *)"/"); |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | name = xstrcat(name, filename); |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | gettimeofday(&now, NULL); |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | localtime_r(&now.tv_sec, &ptm); |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | if ((logfile = fopen(name, "a+"))) { |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | outstr = calloc(10240, sizeof(char)); |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
45 | snprintf(outstr, 10239, "%04d-%02d-%02d %02d:%02d,%s\n", ptm.tm_year + 1900, ptm.tm_mon + 1, ptm.tm_mday, ptm.tm_hour, ptm.tm_min, data); |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | fprintf(logfile, outstr); |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | fclose(logfile); |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | free(outstr); |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | outstr = NULL; |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | } else { |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | syslog(LOG_NOTICE, "logger: cannot open %s for writing", name); |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | } |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | free(name); |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
55 | name = NULL; |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | } |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
57 | |
99c47a8a61cb
Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
58 |