Introduce dlog_is_fd_redirected
[platform/core/system/dlog.git] / include / logpipe.h
1 /*  MIT License
2  *
3  * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is furnished
10  * to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  * THE SOFTWARE. */
22
23 #ifndef _LOGPIPE_H
24 #define _LOGPIPE_H
25
26 #include <stdint.h>
27 #include <unistd.h>
28
29 #include <dlog.h>
30
31 #define PIPE_FIFO_PATH_TEMPLATE_BASE "/run/dlog/priv/fifo/fd-"
32 #define PIPE_FIFO_PATH_TEMPLATE_FULL PIPE_FIFO_PATH_TEMPLATE_BASE "XXXXXX"
33
34 #define DLOG_CTRL_REQ_PIPE (struct dlog_control_msg) {sizeof(struct dlog_control_msg), DLOG_REQ_PIPE, 0}
35
36 enum {
37         DLOG_REQ_REPLY                        = 1,
38
39         /* the following can be OR'd with REPLY,
40          * but are exclusive with each other */
41         DLOG_REQ_PIPE                         = 1 << 1,
42         DLOG_REQ_CLEAR                        = 2 << 1,
43         DLOG_REQ_HANDLE_LOGUTIL               = 3 << 1,
44         DLOG_REQ_GET_CAPACITY                 = 4 << 1,
45         DLOG_REQ_GET_USAGE                    = 5 << 1,
46         DLOG_REQ_STDOUT                       = 6 << 1,
47         DLOG_REQ_GLOBAL_ENABLE_DISABLE_STDOUT = 7 << 1,
48 };
49
50 enum {
51         DLOG_REQ_RESULT_OK = 0,
52         DLOG_REQ_RESULT_ERR,
53 };
54
55 struct dlog_control_msg {
56         unsigned char length;
57
58         /* signed - declared explicitly to suppress static analyzer SVACE warning:
59          * "In some build environments it [char] can be interpreted as 'unsigned char' [...]" */
60         signed char request;
61         char result;
62         char data[];
63 };
64
65 struct dlog_control_msg_stdout {
66         pid_t pid;
67         log_priority prio;
68         char tag[];
69 };
70
71 /* should fit a whole command line with concatenated arguments (reasonably) */
72 #define MAX_LOGGER_REQUEST_LEN 127
73
74 int connect_pipe(const char *path, struct dlog_control_msg *ctrl_msg, int timeout_ms);
75
76 #endif