Ejemplo n.º 1
0
int msg_send(fmsg_pack *p, int fdto)
{
    if (check_package(p) == -1)
        return -1;
    //lock fdto
    if (lockf(fdto, 1, 0) == -1)
        sys_quit("lock failed");

    if (write(fdto, p, sizeof(fmsg_pack)) < 0)
        sys_quit("error occured while attempted to write :");
    //unlock fdto
    if (lockf(fdto, 0, 0) == -1)
        sys_quit("unlock failed");

    return 0;
}
Ejemplo n.º 2
0
int msg_receive(fmsg_pack *q, int fdself)
{

    if (q == NULL)
        err_common("bad address");

    //lock fdself
    if (lockf(fdself, 1, 0) == -1)
        sys_quit("lock failed");

    if (read(fdself, q, sizeof(fmsg_pack)) < 0)
        sys_quit("error occured while attempted to read :");

    //unlock fdself
    if (lockf(fdself, 0, 0) == -1)
        sys_quit("unlock failed");

    if (check_package(q))
        return -1;

    return 0;
}
Ejemplo n.º 3
0
static void proc_term_func(void *user_data, int status)
{
	log_str("-- proc_term_func %d", status);
	sys_quit();
}
Ejemplo n.º 4
0
int
sys_start(int argc, char *argv[])
{
	int status;
	const char* f;
	lua_State *L;
	
	if (argc<2) {
		printf("%s: <filename.lua>\n", argv[0]);
		return 1;
	}
	
    s_init();
    log_print("sound> initialized\n");
	
	L = lua_open();
	/*luaopen_base(L);*/
	luaL_openlibs(L);
	luaopen_sys(L);
	luaopen_log(L);
	luaopen_mat4(L);
	luaopen_quat(L);
	luaopen_vec3(L);
	luaopen_event(L);
	luaopen_image(L);
	luaopen_render(L);
	luaopen_shader(L);
	luaopen_sound(L);
	luaopen_net(L);
	luaopen_util(L);
	luaopen_font(L);
	luaopen_md2(L);
	//luaopen_blender(L);
	
	lua_getglobal(L, "package");
	if (LUA_TTABLE != lua_type(L, 1)) {
		log_print("lua> 'package' is not a table\n");
		return 1;
	}
	lua_getfield(L, 1, "path");
	if (LUA_TSTRING != lua_type(L, 2)) {
		log_print("lua> 'package.path' is not a string\n");
		lua_pop(L, 1);
		return 1;
	}
	lua_pop(L, 1);
	
#if defined(__IPHONE__)
	f = full_path();
#else
	f = ".";
#endif

	/* package.path = f .. "/?.lua" */
	lua_pushlstring(L, f, strlen(f));
	lua_pushliteral(L, "/?.lua");
	lua_concat(L, 2);
	lua_setfield(L, 1, "path");

	lua_bootstrap(L, f);

#if defined(__IPHONE__)
	f = full_path_to_file(argv[1]);
#else
	f = argv[1];
#endif

	log_print("lua> initialized\n");
	printf("lua> loading %s\n", f);
	
	if (luaL_loadfile(L,f)==0) { 
		/* function runme = file_content */
		lua_setglobal(L, "runme");
		lua_getglobal(L, "runme");

		status = lua_pcall(L,0,LUA_MULTRET,0);
		assert(0 == report(L, status));
        
        if (lua_gettop(L) > 0) {
            status = lua_toboolean(L, -1);
            if (!status) {
                printf("lua> %s returned false\n", f);
                sys_quit();
            }
        }
		
        log_print("lua> loaded\n");
	} else {
		printf("lua> unable to load %s\n",f);
		report(L, status);
		sys_quit();
	}

	lua_state = L;
	
	/* TODO: Double check this stuff some day when bored. */
	return status > 0 ? false : true;	
}
Ejemplo n.º 5
0
void install(const char *path)
{
	if (mkfifo(path, 0666) < 0)
		sys_quit("make fifo error:");
}