Added exception lists for monitoring
[platform/core/connectivity/stc-manager.git] / src / monitor / stc-exception.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * This file implements exceptions entity handler methods.
19  *
20  * @file        stc-exception.c
21  */
22
23 #include "stc-manager.h"
24 #include "stc-exception.h"
25
26 #define EXCEPTION_BUF_MAX   64
27 #define EXCEPTION_STORAGE   "/var/lib/stc/exceptions"
28
29 stc_error_e table_exceptions_foreach(const table_exceptions_info_cb exception_cb,
30                                        void *user_data)
31 {
32         __STC_LOG_FUNC_ENTER__;
33
34         stc_error_e error_code = STC_ERROR_NONE;
35         table_exceptions_info data;
36
37         FILE *fp = NULL;
38         char buf[EXCEPTION_BUF_MAX] = {0, };
39
40         fp = fopen(EXCEPTION_STORAGE, "r");
41         ret_value_msg_if(!fp, STC_ERROR_FAIL, "Failed to open %s file");
42
43         while (fgets(buf, sizeof(buf), fp) != NULL) {
44                 char *process_name, *exe_type;
45                 char *save_ptr = NULL;
46
47                 process_name = strtok_r(buf, ":", &save_ptr);
48                 if (process_name != NULL)
49                         data.process_name = process_name;
50                 else
51                         data.process_name = "none";
52
53                 exe_type = strtok_r(NULL, "\n", &save_ptr);
54                 if (exe_type != NULL)
55                         data.exe_type = exe_type;
56                 else
57                         data.exe_type = "none";
58
59                 if (exception_cb(&data, user_data) == STC_CANCEL)
60                         break;
61         }
62         fclose(fp);
63
64         __STC_LOG_FUNC_EXIT__;
65         return error_code;
66 }