2 KSysGuard, the KDE System Guard
4 Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of version 2 of the GNU General Public
8 License as published by the Free Software Foundation.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include <config-workspace.h>
30 #include "ksysguardd.h"
33 static CONTAINER LogFiles
= 0;
34 static unsigned long counter
= 1;
42 extern CONTAINER LogFileList
;
45 ================================ public part =================================
48 void initLogFile(struct SensorModul
* sm
)
53 registerCommand("logfile_register", registerLogFile
);
54 registerCommand("logfile_unregister", unregisterLogFile
);
55 registerCommand("logfile_registered", printRegistered
);
57 for (entry
= first_ctnr(LogFileList
); entry
; entry
= next_ctnr(LogFileList
))
61 /* register the log file if we can actually read the file. */
62 if ((fp
= fopen(entry
->path
, "r")) != NULL
)
65 snprintf(monitor
, 1024, "logfiles/%s", entry
->name
);
66 registerMonitor(monitor
, "logfile", printLogFile
,
67 printLogFileInfo
, sm
);
71 LogFiles
= new_ctnr();
74 void exitLogFile(void)
76 destr_ctnr(LogFiles
, free
);
79 void printLogFile(const char* cmd
)
87 sscanf(cmd
, "%*s %lu", &id
);
89 for (entry
= first_ctnr(LogFiles
); entry
; entry
= next_ctnr(LogFiles
)) {
90 if (entry
->id
== id
) {
91 while (fgets(line
, sizeof(line
), entry
->fh
) != NULL
) {
92 fprintf(CurrentClient
, "%s", line
);
98 fprintf(CurrentClient
, "\n");
101 void printLogFileInfo(const char* cmd
)
103 fprintf(CurrentClient
, "LogFile\n");
106 void registerLogFile(const char* cmd
)
113 memset(name
, 0, sizeof(name
));
114 sscanf(cmd
, "%*s %256s", name
);
116 for (conf
= first_ctnr(LogFileList
); conf
; conf
= next_ctnr(LogFileList
)) {
117 if (!strcmp(conf
->name
, name
)) {
118 if ((file
= fopen(conf
->path
, "r")) == NULL
) {
119 print_error("fopen()");
120 fprintf(CurrentClient
, "0\n");
124 fseek(file
, 0, SEEK_END
);
126 if ((entry
= (LogFileEntry
*)malloc(sizeof(LogFileEntry
))) == NULL
) {
127 print_error("malloc()");
128 fprintf(CurrentClient
, "0\n");
133 strlcpy(entry
->name
, conf
->name
, sizeof(entry
->name
));
136 push_ctnr(LogFiles
, entry
);
138 fprintf(CurrentClient
, "%lu\n", counter
);
145 fprintf(CurrentClient
, "0\n");
148 void unregisterLogFile(const char* cmd
)
153 sscanf(cmd
, "%*s %lu", &id
);
155 for (entry
= first_ctnr(LogFiles
); entry
; entry
= next_ctnr(LogFiles
)) {
156 if (entry
->id
== id
) {
158 free(remove_ctnr(LogFiles
));
159 fprintf(CurrentClient
, "\n");
164 fprintf(CurrentClient
, "\n");
167 void printRegistered(const char* cmd
)
171 for (entry
= first_ctnr(LogFiles
); entry
; entry
= next_ctnr(LogFiles
))
172 fprintf(CurrentClient
, "%s:%lu\n", entry
->name
, entry
->id
);
174 fprintf(CurrentClient
, "\n");