PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/os/linux/ftk_linux.c

http://ftk.googlecode.com/
C | 113 lines | 67 code | 17 blank | 29 comment | 3 complexity | bcc4ca30442ccae87912dbc06060d1cd MD5 | raw file
  1/*
  2 * File: ftk_linux.c
  3 * Author:  Li XianJing <xianjimli@hotmail.com>
  4 * Brief:   linux specific functions.
  5 *
  6 * Copyright (c) 2009 - 2010  Li XianJing <xianjimli@hotmail.com>
  7 *
  8 * Licensed under the Academic Free License version 2.1
  9 *
 10 * This program is free software; you can redistribute it and/or modify
 11 * it under the terms of the GNU General Public License as published by
 12 * the Free Software Foundation; either version 2 of the License, or
 13 * (at your option) any later version.
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 *
 20 * You should have received a copy of the GNU General Public License
 21 * along with this program; if not, write to the Free Software
 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 23 */
 24
 25/*
 26 * History:
 27 * ================================================================
 28 * 2009-11-17 Li XianJing <xianjimli@hotmail.com> created
 29 *
 30 */
 31#include <signal.h>
 32#include "ftk_typedef.h"
 33
 34#ifdef HAVE_EXECINFO_H
 35#include <execinfo.h>
 36#endif
 37static void signal_handler(int sig)
 38{
 39#ifdef HAVE_EXECINFO_H
 40	int i = 0;
 41	void* buffer[100] = {0};
 42	int n = backtrace(buffer, 100);
 43	const char** symbols = (const char**)backtrace_symbols(buffer, n);
 44
 45	for(i = 0; i < n; i++)
 46	{
 47		printf("%p: %s\n", buffer[i], symbols[i]);
 48	}
 49
 50	fflush(stdout);
 51
 52	signal(SIGABRT, NULL);
 53	signal(SIGSEGV, NULL);
 54	signal(SIGILL,  NULL);
 55#endif
 56	_exit(0);
 57
 58	return;
 59}
 60
 61static void signal_int_handler(int sig)
 62{
 63	exit(0);
 64
 65	return;
 66}
 67
 68static void ftk_install_crash_signal(void)
 69{
 70	signal(SIGABRT, signal_handler);
 71	signal(SIGSEGV, signal_handler);
 72	signal(SIGILL,  signal_handler);
 73	signal(SIGINT,  signal_int_handler);
 74
 75	return ;
 76}
 77
 78static int ftk_set_tty_mode(int graphics)
 79{
 80    int r = 0;
 81#if !defined(PC_EMU) && defined(USE_LINUX_NATIVE)
 82	int fd = 0;
 83    fd = open("/dev/tty0", O_RDWR | O_SYNC);
 84    if (fd < 0)
 85        return -1;
 86    r = ioctl(fd, KDSETMODE, (void*) (graphics ? KD_GRAPHICS : KD_TEXT));
 87    close(fd);
 88#endif
 89    return r;
 90}
 91
 92size_t ftk_get_relative_time(void)
 93{
 94	struct timeval now = {0};
 95	gettimeofday(&now, NULL);
 96
 97	return now.tv_sec*1000 + now.tv_usec/1000;
 98}
 99
100int ftk_platform_init(int argc, char** argv)
101{
102	ftk_set_tty_mode(1);
103	ftk_install_crash_signal();
104
105	return RET_OK;
106}
107
108void ftk_platform_deinit(void)
109{
110	ftk_set_tty_mode(0);
111
112	return;
113}