コード例 #1
0
ファイル: logger.c プロジェクト: fidoman/binkleyforce
int debug(unsigned long what, const char *str, ...)
{
	char buf[40];
	va_list args;
	
	if( (what == 0 && debug_current_debuglevel)
	 || (debug_current_debuglevel & what) )
	{
		if( debug_fp == NULL && debug_invalid_name == FALSE )
		{
			debug_open();
		}
		
		if( debug_fp )
		{
			fprintf(debug_fp, "%s ", time_string_log(buf, sizeof(buf), 0));
			va_start(args, str);
			vfprintf(debug_fp, str, args);
			va_end(args);
			putc('\n', debug_fp);
			fflush(debug_fp);
		}
	}
	
	return 0;
}
コード例 #2
0
void
debug_mprintf (mchar* fmt, ...)
{
    int was_open = 1;
    va_list argptr;
    int rc;
    mchar mbuf[DEBUG_BUF_LEN];
    char cbuf[DEBUG_BUF_LEN];

    if (!debug_on) return;

    if (!debug_initialized) {
        m_debug_lock = threadlib_create_sem();
        threadlib_signal_sem(&m_debug_lock);
    }
    threadlib_waitfor_sem (&m_debug_lock);

    va_start (argptr, fmt);
    if (!gcsfp) {
	was_open = 0;
	debug_open();
	if (!gcsfp) return;
    }
    if (!debug_initialized) {
	debug_initialized = 1;
	fprintf (gcsfp, "=========================\n");
	fprintf (gcsfp, "STREAMRIPPER " SRPLATFORM " " SRVERSION "\n");
    }

#if defined HAVE_WCHAR_SUPPORT
    rc = vswprintf (mbuf, DEBUG_BUF_LEN, fmt, argptr);
    debug_on = 0;   /* Avoid recursive call which hangs on semaphore */
    rc = string_from_mstring (cbuf, DEBUG_BUF_LEN, mbuf, CODESET_LOCALE);
    debug_on = 1;
#else
    rc = vsnprintf (cbuf, DEBUG_BUF_LEN, fmt, argptr);
#endif

    fwrite (cbuf, 1, rc, gcsfp);

    fflush (gcsfp);

    va_end (argptr);
    if (!was_open) {
	debug_close ();
    }
    threadlib_signal_sem (&m_debug_lock);
}
コード例 #3
0
debug_printf (char* fmt, ...)
#endif
{
    int was_open = 1;
    va_list argptr;

    if (!debug_on) {
	/* Uncomment to debug debug_mprintf() */
#if defined (commentout)
	va_start (argptr, fmt);
        vprintf (fmt, argptr);
	va_end (argptr);
#endif
	return;
    }

    if (!debug_initialized) {
        m_debug_lock = threadlib_create_sem();
        threadlib_signal_sem(&m_debug_lock);
    }
    threadlib_waitfor_sem (&m_debug_lock);

    va_start (argptr, fmt);
    if (!gcsfp) {
	was_open = 0;
	debug_open();
	if (!gcsfp) return;
    }
    if (!debug_initialized) {
	debug_initialized = 1;
	fprintf (gcsfp, "=========================\n");
	fprintf (gcsfp, "STREAMRIPPER " SRPLATFORM " " SRVERSION "\n");
    }

    vfprintf (gcsfp, fmt, argptr);
    fflush (gcsfp);

    va_end (argptr);
    if (!was_open) {
	debug_close ();
    }
    threadlib_signal_sem (&m_debug_lock);
}
コード例 #4
0
ファイル: debug.c プロジェクト: hdijkema/libstreamripper
void debug_printf(char *fmt, ...)
{
	int was_open = 1;
	va_list argptr;

	if (!debug_on) {
		return;
	}

	if (!debug_initialized) {
		m_debug_lock = threadlib_create_sem();
		threadlib_signal_sem(&m_debug_lock);
	}
	threadlib_waitfor_sem(&m_debug_lock);

	va_start(argptr, fmt);
	if (!gcsfp) {
		was_open = 0;
		debug_open();
		if (!gcsfp)
			return;
	}
	if (!debug_initialized) {
		debug_initialized = 1;
		fprintf(gcsfp, "=========================\n");
		fprintf(gcsfp, "STREAMRIPPER " SRPLATFORM " " SRVERSION "\n");
	}

	vfprintf(gcsfp, fmt, argptr);
	fflush(gcsfp);

	va_end(argptr);
	if (!was_open) {
		debug_close();
	}
	threadlib_signal_sem(&m_debug_lock);
}
コード例 #5
0
ファイル: control.c プロジェクト: zdimension/CEmu
/* Write to the 0x0XXX range of ports */
static void control_write(const uint16_t pio, const uint8_t byte, bool poke) {
    unsigned int i;
    uint8_t index = (uint8_t)pio;
    (void)poke;

    switch (index) {
        case 0x00:
            control.ports[index] = byte & 0x93;
            if (byte & (1 << 4)) {
                cpu_crash("writing to bit 4 of port 0");
            }
            /* Setting this bit turns off the calc (not implemented yet) */
            if (byte & (1 << 6)) {
                control.off = true;
            }
            switch (control.readBatteryStatus) {
                case 3: /* Battery Level is 0 */
                    control.readBatteryStatus = control.setBatteryStatus == BATTERY_0 ? 0 : byte & 0x80 ? 5 : 0;
                    break;
                case 5: /* Battery Level is 1 */
                    control.readBatteryStatus = control.setBatteryStatus == BATTERY_1 ? 0 : byte & 0x80 ? 0 : 7;
                    break;
                case 7: /* Battery Level is 2 */
                    control.readBatteryStatus = control.setBatteryStatus == BATTERY_2 ? 0 : byte & 0x80 ? 9 : 0;
                    break;
                case 9: /* Battery Level is 3 (Or 4) */
                    control.readBatteryStatus = control.setBatteryStatus == BATTERY_3 ? 0 : byte & 0x80 ? 0 : 11;
                    break;
            }
            break;
        case 0x01:
            control.ports[index] = byte & 19;
            control.cpuSpeed = byte & 3;
            switch(control.cpuSpeed) {
                case 0:
                    set_cpu_clock(6e6);  /* 6 MHz  */
                    break;
                case 1:
                    set_cpu_clock(12e6); /* 12 MHz */
                    break;
                case 2:
                    set_cpu_clock(24e6); /* 24 MHz */
                    break;
                case 3:
                    set_cpu_clock(48e6); /* 48 MHz */
                    break;
                default:
                    break;
            }
            break;
        case 0x05:
            if (control.ports[index] & (1 << 6) && !(byte & (1 << 6))) {
                cpu_crash("resetting bit 6 of port 5");
            }
            control.ports[index] = byte & 0x1F;
            break;
        case 0x06:
            control.protectedPortsUnlocked = byte & 7;
            if (!protected_ports_unlocked()) {
                control.flashUnlocked &= ~(1 << 3);
            }
            break;
        case 0x07:
            control.readBatteryStatus = (byte & 0x90) ? 1 : 0;
            break;
        case 0x09:
            switch (control.readBatteryStatus) {
                case 1: /* Battery is bad */
                    control.readBatteryStatus = control.setBatteryStatus == BATTERY_DISCHARGED ? 0 : byte & 0x80 ? 0 : 3;
                    break;
            }
            control.ports[index] = byte;

            if (byte == 0xD4) {
                control.ports[0] |= 1 << 6;
                cpu_crash("entering sleep mode");
#ifdef DEBUG_SUPPORT
                if (debug.openOnReset) {
                    debug_open(DBG_MISC_RESET, cpu.registers.PC);
                }
#endif
            }
            break;
        case 0x0A:
            control.readBatteryStatus += (control.readBatteryStatus == 3) ? 1 : 0;
            control.ports[index] = byte;
            break;
        case 0x0B:
        case 0x0C:
            control.readBatteryStatus = 0;
            break;
        case 0x0D:
            /* This bit disables vram and makes it garbage */
            if (!(byte & (1 << 3))) {
                lcd_disable();
                for (i = LCD_RAM_OFFSET; i < LCD_RAM_OFFSET + LCD_BYTE_SIZE; i++) {
                    mem.ram.block[i] = rand();
                }
            } else {
                lcd_update();
            }
            control.ports[index] = (byte & 0xF) << 4 | (byte & 0xF);
            break;
        case 0x0F:
            control.ports[index] = byte & 3;
            break;
        case 0x1D: case 0x1E: case 0x1F:
            write8(control.privileged, (index - 0x1D) << 3, byte);
            break;
        case 0x20: case 0x21: case 0x22:
            write8(control.protectedStart, (index - 0x20) << 3, byte);
            break;
        case 0x23: case 0x24: case 0x25:
            write8(control.protectedEnd, (index - 0x23) << 3, byte);
            break;
        case 0x28:
            control.flashUnlocked = (control.flashUnlocked | 5) & byte;
            break;
        case 0x29:
            control.ports[index] = byte & 1;
            break;
        case 0x3A: case 0x3B: case 0x3C:
            write8(control.stackLimit, (index - 0x3A) << 3, byte);
            break;
        case 0x3E:
            control.protectionStatus &= ~byte;
            break;
        default:
            control.ports[index] = byte;
            break;
    }
}
コード例 #6
0
ファイル: main.c プロジェクト: Alkhliws/projfin-hmip
int main(int argc, char **argv)
{
	pthread_t sigth;
	sigset_t sigblock;
	int logflags = 0;
	int ret = 1;

	debug_init();

	sigemptyset(&sigblock);
	sigaddset(&sigblock, SIGHUP);
	sigaddset(&sigblock, SIGINT);
	sigaddset(&sigblock, SIGTERM);
#ifdef ENABLE_VT
	sigaddset(&sigblock, SIGPIPE);
#endif
	pthread_sigmask(SIG_BLOCK, &sigblock, NULL);

	if (conf_parse(&conf, argc, argv))
		return 1;

	if (conf.debug_level > 0)
		logflags = LOG_PERROR;

	openlog(basename(argv[0]), LOG_PID|logflags, LOG_DAEMON);

	syslog(LOG_INFO, "%s v%s started (%s)", PACKAGE_NAME, PACKAGE_VERSION,
	       entity_string[conf.mip6_entity]);
#ifdef ENABLE_VT
	if (vt_init() < 0)
		goto vt_failed;
#endif

	/* if not debugging, detach from tty */
	if (conf.debug_level == 0)
		daemon_start(1);
	else {
		/* if debugging with debug log file, detach from tty */
		if (conf.debug_log_file) {
			daemon_start(1);

			ret = debug_open(conf.debug_log_file);
			if (ret < 0) {
				fprintf(stderr, "can't init debug log:%s\n",
					strerror(-ret));
				goto debug_failed;
			}
			dbg("%s started in debug mode\n", PACKAGE_NAME);
		} else {
			dbg("%s started in debug mode, not detaching from terminal\n",
			    PACKAGE_NAME);
		}
		conf_show(&conf);
	}

	srandom(time(NULL));

	if (rr_cn_init() < 0)
		goto rr_cn_failed;
	if (policy_init() < 0)
		goto policy_failed;
	if (taskqueue_init() < 0)
		goto taskqueue_failed;
	if (bcache_init() < 0)
		goto bcache_failed;
	if (mh_init() < 0)
		goto mh_failed;
	if (icmp6_init() < 0)
		goto icmp6_failed;
	if (xfrm_init() < 0)
		goto xfrm_failed;
	cn_init();
	if ((is_ha() || is_mn()) && tunnelctl_init() < 0)
		goto tunnelctl_failed;
	if (is_ha() && ha_init() < 0) 
		goto ha_failed;
	if (is_mn() && mn_init() < 0)
		goto mn_failed;
#ifdef ENABLE_VT
	if (vt_start(conf.vt_hostname, conf.vt_service) < 0)
		goto vt_start_failed;
#endif
	if (pthread_create(&sigth, NULL, sigh, NULL))
		goto sigth_failed;
	pthread_join(sigth, NULL);
	ret = 0;
sigth_failed:
#ifdef ENABLE_VT
	vt_fini();
vt_start_failed:
#endif
	if (is_mn())
		mn_cleanup();
mn_failed:
	if (is_ha())
		ha_cleanup();
ha_failed:
	if (is_ha() || is_mn())
		tunnelctl_cleanup();
tunnelctl_failed:
	cn_cleanup();
	xfrm_cleanup();
xfrm_failed:
	icmp6_cleanup();
icmp6_failed:
	mh_cleanup();
mh_failed:
	bcache_cleanup();
bcache_failed:
	taskqueue_destroy();
taskqueue_failed:
	policy_cleanup();
policy_failed:
rr_cn_failed:
	debug_close();
debug_failed:
#ifdef ENABLE_VT
vt_failed:
#endif
	syslog(LOG_INFO, "%s v%s stopped (%s)", PACKAGE_NAME, PACKAGE_VERSION,
	       entity_string[conf.mip6_entity]);
	closelog();
	return ret;
}