4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Sangchul Lee <sc11.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
25 #include <sys/types.h>
33 #define FIFO_FILE "/tmp/logman.fifo"
40 void dump_logmanager(void);
41 int reload_logmanager(void);
42 static int get_options(int argc, char* argv[]);
43 static int usage(int argc, char* argv[]);
44 static void run_viewer(void);
46 static struct sigaction sigint_action; /* Backup pointer of SIGINT handler */
49 void interrupt_signal(int sig)
54 sigaction(SIGINT, &sigint_action, NULL);
59 int main(int argc, char **argv)
61 switch(get_options(argc,argv))
78 static int get_options(int argc, char* argv[])
81 int operation = OP_USAGE;
84 return usage(argc, argv);
86 while((ch = getopt(argc, argv, "vrd")) != EOF)
91 operation = OP_VIEWER;
94 operation = OP_RELOAD;
100 return usage(argc, argv);
104 return usage(argc, argv);
109 static int usage(int argc, char* argv[])
111 fprintf(stderr, "Usage : %s option\n", argv[0]);
112 fprintf(stderr, "[OPTIONS]\n");
113 fprintf(stderr, " -v : Run logviewer\n");
114 fprintf(stderr, " -r : Reload configuration\n");
115 fprintf(stderr, " -d : Dump current log settings\n");
119 static void run_viewer(void)
124 struct sigaction action;
126 action.sa_handler = interrupt_signal;
128 sigemptyset(&action.sa_mask);
130 sigaction(SIGINT, &action, &sigint_action);
133 if (mknod(FIFO_FILE, S_IFIFO|0666, 0) == -1)
135 perror ("mknod failed\n");
139 fd = open(FIFO_FILE, O_RDONLY|O_NONBLOCK);
143 perror("PIPE CREATE\n");
147 memset(readbuf, 0, 4097);
150 byte_read = read(fd,readbuf, 4096);
151 if(byte_read > 0 && byte_read <= 4096 && readbuf[0] != '\0')
153 readbuf[byte_read] = '\0';
154 printf("%s", readbuf);
155 memset(readbuf, 0, 4097);