int monitor_init(void) {
  int rc;

  /* Registering device */
  rc = register_chrdev(monitor_major, "badmonitor", &monitor_fops);
  if (rc < 0) {
    printk(
      "<1>badmonitor: cannot obtain major number %d\n", monitor_major);
    return rc;
  }

  /* Allocating monitor_buffer */
  monitor_buffer = kmalloc(MAX_SIZE, GFP_KERNEL); 
  if (!monitor_buffer) { 
    rc = -ENOMEM;
    goto fail; 
  } 
  memset(monitor_buffer, 0, MAX_SIZE);
  curr_size= 0;
  curr_pos= 0;
  m_init(&mutex);
  c_init(&wait_queue);

  printk("<1>Inserting badmonitor module\n"); 
  return 0;

  fail: 
    monitor_exit(); 
    return rc;
}
void LIRGenerator::do_MonitorExit(MonitorExit* x) {
  assert(x->is_pinned(),"");

  LIRItem obj(x->obj(), this);
  obj.dont_load_item();

  LIR_Opr lock = new_register(T_INT);
  LIR_Opr obj_temp = new_register(T_INT);
  set_no_result(x);
  monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());
}
void LIRGenerator::do_MonitorExit(MonitorExit* x) {
  assert(x->is_root(),"");
  LIRItem obj(x->obj(), this);
  obj.dont_load_item();

  set_no_result(x);
  LIR_Opr lock      = FrameMap::G1_opr;
  LIR_Opr hdr       = FrameMap::G3_opr;
  LIR_Opr obj_temp  = FrameMap::G4_opr;
  monitor_exit(obj_temp, lock, hdr, x->monitor_no());
}
Exemple #4
0
/*---------------------------------------------------------------------------*
 *	program exit
 *---------------------------------------------------------------------------*/
void
error_exit(int exitval, const char *fmt, ...)
{
	close_allactive();

	unlink(PIDFILE);

	dolog(LL_DMN, "fatal error, daemon terminating, exitval = %d", exitval);

#ifdef USE_CURSES
	if(do_fullscreen)
		endwin();
#endif

#ifdef I4B_EXTERNAL_MONITOR
	monitor_exit();
#endif

	if(mailto[0] && mailer[0])
	{

#define EXITBL 2048

		char ebuffer[EXITBL];
		char sbuffer[EXITBL];
		va_list ap;

		va_start(ap, fmt);
		vsnprintf(ebuffer, EXITBL-1, fmt, ap);
		va_end(ap);

		signal(SIGCHLD, SIG_IGN);	/* remove handler */

		snprintf(sbuffer, sizeof(sbuffer), "%s%s%s%s%s%s%s%s",
			"cat << ENDOFDATA | ",
			mailer,
			" -s \"i4b isdnd: fatal error, terminating\" ",
			mailto,
			"\nThe isdnd terminated because of a fatal error:\n\n",
			ebuffer,
			"\n\nYours sincerely,\n   the isdnd\n",
			"\nENDOFDATA\n");
		system(sbuffer);
	}

	exit(exitval);
}
Exemple #5
0
/*---------------------------------------------------------------------------*
 *	program exit
 *---------------------------------------------------------------------------*/
void
do_exit(int exitval)
{
	close_allactive();

	unlink(PIDFILE);

	dolog(LL_DMN, "daemon terminating, exitval = %d", exitval);

#ifdef USE_CURSES
	if(do_fullscreen)
		endwin();
#endif

#ifdef I4B_EXTERNAL_MONITOR
	monitor_exit();
#endif

	exit(exitval);
}
Exemple #6
0
/*
 * Read data with the assertion that it all must come through, or else abort
 * the process.  Based on atomicio() from openssh.
 */
static void
must_read(void *buf, size_t n)
{
        char *s = buf;
	size_t pos = 0;
        ssize_t res;

        while (n > pos) {
                res = read(m_state.s, s + pos, n - pos);
                switch (res) {
                case -1:
                        if (errno == EINTR || errno == EAGAIN)
                                continue;
                case 0:
			monitor_exit(0);
                default:
                        pos += res;
                }
        }
}
Exemple #7
0
static void daemon_thread(void)
{
	static INT32 thread_run = 1;
	struct mp_node_t *p_node_it = NULL;
	struct mp_mem_head_t *p_mem_head = NULL;
	M_CC_MSG_t msg = {0, 0, 0};
	UINT64 curr_time = 0;
	HRESULT ret = E_FAIL;
	INT32 timeout_occured = 0;

	p_mem_head = (struct mp_mem_head_t *)h_mem;
	notify_watchdog(M_SM_WD_APP_START);

	while (thread_run) {
		if (M_OSAL_Task_MsgQ_GetTry(&h_daemon, &msg) == S_OK) {
			if (msg.m_MsgID == MSG_CMD_EXIT) {
				M_DAEMON_PRINT(LOG_INFO,
						"daemon_thread is to exit.\n");
				thread_run = 0;
			}
			else
				M_DAEMON_PRINT(LOG_INFO,
						"msg id undefined: 0x%X\n",
						msg.m_MsgID);
		}
#ifndef __BIONIC__
		ret = mp_sem_acquire(semid);
		M_DAEMON_ASSERT(ret == 0);
#endif
		mp_update_pool(h_mem);

		/* iterate each module node */
		curr_time = get_clock();
		timeout_occured = 0;
		/*
		 * FIXME
		 * We do need a lock here to avoid some maybe
		 * concurrency issue. In RegisterModule, before the
		 * whole register flow finish, daemon should not access
		 * the data of the module which is being registered.
		 */
		for (p_node_it = p_mem_head->p_node_first;
				(p_node_it != NULL) && (p_node_it->data.ready == 1);
				p_node_it = p_node_it->p_next) {
			if (p_node_it->data.callback_fn != NULL) {
				ret = p_node_it->data.callback_fn();
				if (ret == S_OK)
					p_node_it->data.time = curr_time;
				else
					M_DAEMON_PRINT(LOG_WARN,
							"#%d %s return fail!\n",
							p_node_it->data.mid,
							p_node_it->data.attr.name);
			}
			if (curr_time - p_node_it->data.time >
					(UINT64)p_node_it->data.attr.timeout) {
				M_DAEMON_PRINT(LOG_ERROR, "#%d %s timeout (%llu)\n",
						p_node_it->data.mid,
						p_node_it->data.attr.name,
						curr_time - p_node_it->data.time);
				timeout_occured = 1;
			}
			if (p_node_it->data.critical_error == 1) {
				M_DAEMON_PRINT(LOG_ERROR, "#%d %s critical error occured\n",
						p_node_it->data.mid,
						p_node_it->data.attr.name);
				timeout_occured = 1;
				break;
			}
			M_DAEMON_PRINT(LOG_DEBUG, "#%d last: %llu -> curr: %llu\n",
					p_node_it->data.mid, p_node_it->data.time, curr_time);
		}
#ifndef __BIONIC__
		ret = mp_sem_release(semid);
		M_DAEMON_ASSERT(ret == 0);
#endif
		if (timeout_occured == 0) {
			M_DAEMON_PRINT(LOG_DEBUG, "kick off watchdog\n");
			notify_watchdog(M_SM_WD_Kickoff);
		} else {
			M_DAEMON_PRINT(LOG_ERROR, "daemon_thread exit\n");
			thread_run = 0;
		}
		M_OSAL_Task_Sleep(500);
	}
	monitor_exit();
	return;
}
Exemple #8
0
int main(int argc,char **argv)
{
    static struct option longopts[] =
    {
        {"help",no_argument,NULL,'h'},
        {"version",no_argument,NULL,'V'},
        {"verbose",no_argument,NULL,'v'},
        {"foreground",no_argument,NULL,'f'},
        {"evmap",required_argument,NULL,'e'},
        {"socket",required_argument,NULL,'s'},
        {"mode",required_argument,NULL,'m'},
        {"repeat-filter",no_argument,NULL,'R'},
        {"release",required_argument,NULL,'r'},
        {0, 0, 0, 0}
    };
    const char *progname = NULL;
    int verbose = 0;
    bool foreground = false;
    const char *input_device_evmap_dir = EVMAP_DIR;
    const char *lircd_socket_path = LIRCD_SOCKET;
    mode_t lircd_socket_mode = S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH;
    bool input_repeat_filter = false;
    const char *lircd_release_suffix = NULL;
    int opt;

    for (progname = argv[0] ; strchr(progname, '/') != NULL ; progname = strchr(progname, '/') + 1);

    openlog(progname, LOG_CONS | LOG_PERROR | LOG_PID, LOG_DAEMON);

    while((opt = getopt_long(argc, argv, "hVvfe:s:m:Rr:", longopts, NULL)) != -1)
    {
        switch(opt)
        {
            case 'h':
		fprintf(stdout, "Usage: %s [options]\n", progname);
		fprintf(stdout, "    -h --help              print this help message and exit\n");
		fprintf(stdout, "    -V --version           print the program version and exit\n");
		fprintf(stdout, "    -v --verbose           increase the output message verbosity (-v, -vv or -vvv)\n");
		fprintf(stdout, "    -f --foreground        run in the foreground\n");
		fprintf(stdout, "    -e --evmap=<dir>       directory containing input device event map files (default is '%s')\n",
                                                            input_device_evmap_dir);
		fprintf(stdout, "    -s --socket=<socket>   lircd socket (default is '%s')\n",
                                                            lircd_socket_path);
		fprintf(stdout, "    -m --mode=<mode>       lircd socket mode (default is '%04o')\n",
                                                            lircd_socket_mode);
		fprintf(stdout, "    -R --repeat-filter     enable repeat filtering (default is '%s')\n",
                                                            input_repeat_filter ? "false" : "true");
		fprintf(stdout, "    -r --release=<suffix>  generate key release events suffixed with <suffix>\n");
                exit(EX_OK);
                break;
            case 'V':
                fprintf(stdout, PACKAGE_STRING "\n");
                break;
            case 'v':
                if (verbose < 3)
                {
                    verbose++;
                }
                else
                {
                    syslog(LOG_WARNING, "the highest verbosity level is -vvv\n");
                }
            case 'f':
                foreground = true;
                break;
            case 'e':
                input_device_evmap_dir = optarg;
                break;
            case 's':
                lircd_socket_path = optarg;
                break;
            case 'm':
                lircd_socket_mode = (mode_t)atol(optarg);
                break;
            case 'R':
                input_repeat_filter = true;
                break;
            case 'r':
                lircd_release_suffix = optarg;
                break;
            default:
                fprintf(stderr, "error: unknown option: %c\n", opt);
                exit(EX_USAGE);
        }
    }

    if      (verbose == 0)
    {
        setlogmask(0 | LOG_DEBUG | LOG_INFO | LOG_NOTICE);
    }
    else if (verbose == 1)
    {
        setlogmask(0 | LOG_DEBUG | LOG_INFO);
    }
    else if (verbose == 2)
    {
        setlogmask(0 | LOG_DEBUG);
    }
    else
    {
        setlogmask(0);
    }

    signal(SIGPIPE, SIG_IGN);

    if (monitor_init() != 0)
    {
        exit(EXIT_FAILURE);
    }

    /* Initialize the lircd socket before daemonizing in order to ensure that programs
       started after it damonizes will have an lircd socket with which to connect. */
    if (lircd_init(lircd_socket_path, lircd_socket_mode, lircd_release_suffix) != 0)
    {
        monitor_exit();
        exit(EXIT_FAILURE);
    }

    if (foreground != true)
    {
        daemon(0, 0);
    }

    if (input_init(input_device_evmap_dir, input_repeat_filter) != 0)
    {
        monitor_exit();
        lircd_exit();
        exit(EXIT_FAILURE);
    }

    monitor_run();

    if (input_exit() != 0)
    {
        monitor_exit();
        lircd_exit();
        exit(EXIT_FAILURE);
    }

    if (lircd_exit() != 0)
    {
        monitor_exit();
        exit(EXIT_FAILURE);
    }

    if (monitor_exit() != 0)
    {
        exit(EXIT_FAILURE);
    }

    exit(EXIT_SUCCESS);
}