Beispiel #1
0
bool retro_load_game(const struct retro_game_info *game)
{ 
   int loaded;
   struct retro_memory_map map;

   init_descriptors();
   memorydesc_c = 0;
   map.descriptors    = memorydesc + MAX_MAPS - memorydesc_c;
   map.num_descriptors = memorydesc_c;

   /* Hack. S9x cannot do stuff from RAM. <_< */
   memstream_set_buffer((uint8_t*)game->data, game->size);

   loaded = LoadROM("");
   if (!loaded)
   {
      if (log_cb)
         log_cb(RETRO_LOG_ERROR, "ROM loading failed...\n");
      return FALSE;
   }

   check_variables();


   environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map);

   return TRUE;
}
Beispiel #2
0
bool retro_load_game_special(
  unsigned game_type,
  const struct retro_game_info *info, size_t num_info
)
{
   init_descriptors();
   return false;
}
int usb_interface_init(struct usb_interface_init_data *init_data) {
	static_data->usb_ep_complete = init_data->ep_complete;
	init_descriptors(init_data->dev_desc,
			 init_data->conf_desc, init_data->conf_desc_size,
			 init_data->strings_desc, init_data->num_strings);
	static_data->usb_class_handler = init_data->class_handler;
	static_data->usb_endpoints = init_data->eps;
	static_data->usb_num_endpoints = init_data->num_eps;
	static_data->usb_event_cb = init_data->usb_evt_cb;
	static_data->ep0_buffer = init_data->ep0_buffer;
	static_data->ep0_buffer_size = init_data->ep0_buffer_size;
	return 0;
}
Beispiel #4
0
bool retro_load_game(const struct retro_game_info* game)
{
   init_descriptors();
   check_variables();

   uint8_t bios_data[256];
   char bios_path[PATH_MAX_LENGTH];
   char* system_dir;
   if(environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_dir) && system_dir)
      strncpy(bios_path, system_dir, sizeof(bios_path));
   else if (game->path)
      strncpy(bios_path, game->path, sizeof(bios_path));
   else
      strncpy(bios_path, ".", sizeof(bios_path));
#if defined(_WIN32)
   char slash = '\\';
#else
   char slash = '/';
#endif
   char* tmp = strrchr(bios_path, slash);
   if(!tmp)
      tmp = strrchr(bios_path, '\0');
   *tmp++ = slash;
   strcpy(tmp, "gbbios.gb");

   retro_sleep(10);
   fflush(stdout);
   gbemu_printf("romd info\n");
   gbemu_printf("path : %s\n", game->path);
   gbemu_printf("size : %u\n", game->size);
   fflush(stdout);

   gbemu_printf("loading bios from : %s\n", bios_path);
   FILE* fp = fopen(bios_path, "rb");
   if(fp)
   {
      fread(bios_data, 1, sizeof(bios_data), fp);
      fclose(fp);
   }
   else
      gbemu_printf("bios not found !\n");

   gbemu_load_game(game->data, game->size, fp? bios_data: NULL);

   return true;
}
Beispiel #5
0
bool retro_load_game(const struct retro_game_info *game)
{ 
   int loaded;
   struct retro_memory_map map;

   init_descriptors();
   memorydesc_c = 0;
   map.descriptors    = memorydesc + MAX_MAPS - memorydesc_c;
   map.num_descriptors = memorydesc_c;

   /* Hack. S9x cannot do stuff from RAM. <_< */
   memstream_set_buffer((uint8_t*)game->data, game->size);

   loaded = LoadROM("");
   if (!loaded)
   {
      struct retro_message msg; 
      char msg_local[256];

      snprintf(msg_local,
            sizeof(msg_local), "ROM loading failed...");
      if (log_cb)
         log_cb(RETRO_LOG_ERROR, "ROM loading failed...\n");
      msg.msg    = msg_local;
      msg.frames = 360;
      if (environ_cb)
         environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, (void*)&msg);
      return FALSE;
   }

   check_variables();


   environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map);

   return TRUE;
}
Beispiel #6
0
void kmain() {
    init_descriptors();
    putsk("Loaded succesfully\n");
}
Beispiel #7
0
/**
 *
 * @param argc
 * @param argv
 * @return
 */
int main(int argc, char** argv) {

    if (0 != getuid()) {
        printf("%s", INSUFF_PRIV);
        exit(EXIT_FAILURE);
    }
    start_time = time(NULL);
    char *host = NULL;
    int opt = 0;
    int longIndex = 0;

    memset(globals.routes, 0, ROUTES_MAX_COUNT);
    //
    curl_global_init(CURL_GLOBAL_ALL);
    //
    watchdog_stop_flag = false;
    sheduler_stop_flag = false;
    pbuffer_stop_flag = false;
    rotate_stop_flag = false;
    listen_stop_flag = false;

    /* Initialize arguments before we get to work. */
    char * argument = NULL;

    argument = "/var/run/arewik.pid";
    arguments.pidfile = xmalloc(sizeof (char) * strlen(argument) + 1);
    strcpy(arguments.pidfile, argument);

    argument = "/var/log/arewik";
    arguments.logdir = xmalloc(sizeof (char) * strlen(argument) + 1);
    strcpy(arguments.logdir, argument);

    argument = "/var/arewik";
    arguments.storagedir = xmalloc(sizeof (char) * strlen(argument) + 1);
    strcpy(arguments.storagedir, argument);

    argument = "/var/arewik/buffers";
    arguments.bufferdir = xmalloc(sizeof (char) * strlen(argument) + 1);
    strcpy(arguments.bufferdir, argument);

    argument = "/etc/arewik/arewik.conf";
    arguments.configfile = xmalloc(sizeof (char) * strlen(argument) + 1);
    strcpy(arguments.configfile, argument);

    argument = "arewik";
    arguments.user = xmalloc(sizeof (char) * strlen(argument) + 1);
    strcpy(arguments.user, argument);

    argument = "arewik";
    arguments.group = xmalloc(sizeof (char) * strlen(argument) + 1);
    strcpy(arguments.group, argument);

    argument = "/tmp";
    arguments.wdir = xmalloc(sizeof (char) * strlen(argument) + 1);
    strcpy(arguments.wdir, argument);

    argument = DEFAULT_LISTEN_IP;
    arguments.listen_host = xmalloc(sizeof (char) * strlen(argument) + 1);
    strcpy(arguments.listen_host, argument);

    arguments.listen_port = DEFAULT_LISTEN_PORT;
    arguments.verbosity = 0;
    arguments.foreground = 0;
    arguments.debuginfo = 0;

    argument = "custom.log";
    globals.custom_logfile_name = xmalloc(sizeof (char) * strlen(argument) + 1);
    strcpy(globals.custom_logfile_name, argument);

    argument = "debug.log";
    globals.debug_logfile_name = xmalloc(sizeof (char) * strlen(argument) + 1);
    strcpy(globals.debug_logfile_name, argument);

    argument = "connections.log";
    globals.connections_logfile_name = xmalloc(sizeof (char) * strlen(argument) + 1);
    strcpy(globals.connections_logfile_name, argument);

    argument = "access.log";
    globals.access_logfile_name = xmalloc(sizeof (char) * strlen(argument) + 1);
    strcpy(globals.access_logfile_name, argument);

    globals.maxcon = 4096; // routes max * 64
    globals.proxymode = false; //todo
    globals.routes_cnt = 1;
    globals.watchdog_interval = WATCHDOG_T;
    globals.ping_interval = 30;
    globals.autoreconfigure = false;
    globals.reconfigure_interval = 60;
    globals.use_resolver = 0;
    globals.use_syslog = 0;
    globals.socktimeout = 10000;
    globals.epolltimeout = EPOLL_RUN_TIMEOUT;
    globals.workers = POSSIBLE_FHNDL;

    sprintf(globals.identline, "%s", ident);
    //
    globals.modules[0].id = 0;
    globals.modules[0].enabled = true;
    globals.modules[0].name = "plain";
    globals.modules[0].process_function = &process_plain;
    globals.modules[0].init_function = NULL;

    globals.modules[1].id = 1;
    globals.modules[1].enabled = false;
    globals.modules[1].name = "riak";
    globals.modules[1].process_function = &process_riak;
    globals.modules[1].init_function = &init_riak_module;
    globals.modules[1].close_function = &close_riak;

    globals.modules[2].id = 2;
    globals.modules[2].enabled = false;
    globals.modules[2].name = "esearch";
    globals.modules[2].process_function = &process_esearch;
    globals.modules[2].init_function = &init_esearch_module;
    globals.modules[2].close_function = &close_esearch;


    globals.modules[3].id = 3;
    globals.modules[3].enabled = false;
    globals.modules[3].name = "webhdfs";
    globals.modules[3].process_function = &process_webhdfs;
    globals.modules[3].init_function = &init_webhdfs_module;
    globals.modules[3].close_function = &close_webhdfs;


    CPRESS_FUNCT[0].type = SNAPPY;
    CPRESS_FUNCT[0].compress_function = &compress_snappy;

    CPRESS_FUNCT[1].type = GZIP;
    CPRESS_FUNCT[1].compress_function = &compress_gzip;


    set_sig_handler();
    static const char *optString = "s:D:B:u:g:p:l:c:H:P:vfhd?";
    opt = getopt_long(argc, argv, optString, longOpts, &longIndex);

    while (opt != -1) {
        switch (opt) {
            case 'p':
                if (!is_valid_opt(optarg)) {
                    print_usage();
                }
                arguments.pidfile = xrealloc(arguments.pidfile, (sizeof (char) * strlen(optarg) + 1));
                strcpy(arguments.pidfile, optarg);

                break;

            case 'l':
                if (!is_valid_opt(optarg)) {
                    print_usage();
                }
                arguments.logdir = xrealloc(arguments.pidfile, (sizeof (char) * strlen(optarg) + 1));
                strcpy(arguments.logdir, optarg);
                break;

            case 'c':
                if (!is_valid_opt(optarg)) {
                    print_usage();
                }
                arguments.configfile = xrealloc(arguments.configfile, (sizeof (char) * strlen(optarg) + 1));
                strcpy(arguments.configfile, optarg);
                break;

            case 'H':
                if (!isValidIP(optarg)) {
                    print_usage();
                }
                if (NULL != (host = nslookup(optarg))) {
                    arguments.listen_host = xrealloc(arguments.listen_host, (sizeof (char) * strlen(optarg) + 1));
                    strcpy(arguments.listen_host, host);
                } else {
                    printf("%s\n", hstrerror(h_errno));
                    exit(EXIT_FAILURE);
                }
                break;
            case 'u':
                if (!is_valid_opt(optarg)) {
                    print_usage();
                }
                arguments.user = xrealloc(arguments.user, (sizeof (char) * strlen(optarg) + 1));
                strcpy(arguments.user, optarg);
                break;
            case 'g':
                arguments.group = xrealloc(arguments.group, (sizeof (char) * strlen(optarg) + 1));
                strcpy(arguments.group, optarg);
                break;
            case 'D':
                if (!is_valid_opt(optarg)) {
                    print_usage();
                }
                arguments.wdir = xrealloc(arguments.wdir, (sizeof (char) * strlen(optarg) + 1));
                strcpy(arguments.wdir, optarg);
                break;
            case 's':
                if (!is_valid_opt(optarg)) {
                    print_usage();
                }
                arguments.storagedir = xrealloc(arguments.storagedir, (sizeof (char) * strlen(optarg) + 1));
                strcpy(arguments.storagedir, optarg);
                break;
            case 'B':
                if (!is_valid_opt(optarg)) {
                    print_usage();
                }
                arguments.bufferdir = xrealloc(arguments.bufferdir, (sizeof (char) * strlen(optarg) + 1));
                strcpy(arguments.bufferdir, optarg);
                break;
            case 'P':
                arguments.listen_port = atoi(optarg);
                break;
            case 'v':
                arguments.verbosity++;
                break;
            case 'f':
                arguments.foreground++;
                break;
            case 'h':
                print_usage();
                break;
            case 'd':
                arguments.debuginfo++;
                arguments.verbosity++;
                break;
            default:
                if (!is_valid_opt(optarg)) {
                    print_usage();
                }
                break;
        }

        opt = getopt_long(argc, argv, optString, longOpts, &longIndex);
    }

    if (false == DirectoryExists(arguments.storagedir)) {
        printf("Specified storage directory '%s' does not exists\n", arguments.storagedir);
        printf("Creating new one\n");
        if (0 > mkdir(arguments.storagedir, 0755)) {
            printf("Can not create storage directory - %s\n", strerror(errno));
            exit(EXIT_FAILURE);
        } else {
            setRightOwner(arguments.storagedir);
        }
    }
    setRightOwner(arguments.storagedir);

    if (false == DirectoryExists(arguments.bufferdir)) {
        printf("Specified buffer directory '%s' does not exists\n", arguments.bufferdir);
        printf("Creating new one\n");
        if (0 > mkdir(arguments.bufferdir, 0755)) {
            printf("Can not create buffer directory - %s\n", strerror(errno));
            exit(EXIT_FAILURE);
        } else {
            setRightOwner(arguments.bufferdir);
        }
    }
    setRightOwner(arguments.bufferdir);

    if (true == DirectoryExists(arguments.pidfile)) {
        printf("Specified pid file '%s' is a directory\n", arguments.pidfile);
        exit(EXIT_FAILURE);
    }

    if (false == DirectoryExists(arguments.wdir)) {
        printf("Specified working directory '%s' does not exists or not a directory\n", arguments.wdir);
        exit(EXIT_FAILURE);
    }

    if (arguments.foreground == 1) {
        printf("Running in foreground mode...\n");
        setbuf(stdout, 0);
        setbuf(stdin, 0);
        setbuf(stderr, 0);
    }

    if (arguments.verbosity == 1) {
        printf("Verbosity enabled\n");
    }

    if (false == FileExists(arguments.configfile)) {
        printf("Specified file '%s' does not exists\n", arguments.configfile);
        exit(EXIT_FAILURE);
    } else if (true == DirectoryExists(arguments.configfile)) {
        printf("Specified file '%s' is a directory\n", arguments.configfile);
        exit(EXIT_FAILURE);
    } else {
        setRightOwner(arguments.configfile);
        if (true != hasRightOwner(arguments.configfile)) {
            printf("The file '%s' has invalid owner/group\nMust be %s:%s\n", arguments.configfile, arguments.user, arguments.group);
            exit(EXIT_FAILURE);
        }
    }

    if (false == DirectoryExists(arguments.logdir)) {
        printf("Specified log directory '%s' does not exists\n", arguments.logdir);
        printf("Creating new one\n");
        if (0 > mkdir(arguments.logdir, 0755)) {
            printf("Can not create log directory - %s\n", strerror(errno));
            exit(EXIT_FAILURE);
        } else {
            setRightOwner(arguments.logdir);
        }
    }
    setRightOwner(arguments.logdir);

    if (true != hasRightOwner(arguments.logdir)) {
        printf("The file '%s' has invalid owner/group\nMust be %s:%s\n", arguments.logdir, arguments.user, arguments.group);
        exit(EXIT_FAILURE);
    }


    glob = readConfig(arguments.configfile);
    checkPid();

    openCustomLog();
    openDebugLog();
    openConLog();
    openAccessLog();

    if (!(pwd = getpwnam(arguments.user))) {
        snprintf(TMP_MSG, MAXLINE, "No such user: %s. Quitting!", arguments.user);
        writeToCustomLog(TMP_MSG);

        exit(EXIT_FAILURE);
    } else my_uid = pwd->pw_uid;

    if (!(grp = getgrnam(arguments.group))) {
        snprintf(TMP_MSG, MAXLINE, "No such group: %s. Quitting!", arguments.group);
        writeToCustomLog(TMP_MSG);
        exit(EXIT_FAILURE);
    } else my_gid = grp->gr_gid;

    if (arguments.foreground == 0) {

        pid = fork();

        if (pid < 0) {
            snprintf(TMP_MSG, MAXLINE, "%s", "Can not fork! [Invalid PID]");
            writeToCustomLog(TMP_MSG);
            removePid();
            exit(EXIT_FAILURE);
        }
        /* If we got a good PID, then
           we can exit the parent process. */
        if (pid > 0) {
            exit(EXIT_SUCCESS);
        }
        //
        snprintf(TMP_MSG, MAXLINE, "%s", "Forked successfully");
        writeToCustomLog(TMP_MSG);
        /* Change the file mode mask */
        umask(027);
        /* Create a new SID for the child process */
        sid = setsid();
        if (sid < 0) {
            snprintf(TMP_MSG, MAXLINE, "%s", "Can not create child process");
            writeToCustomLog(TMP_MSG);
            /* Log the failure */
            removePid();
            exit(EXIT_FAILURE);
        }
        snprintf(TMP_MSG, MAXLINE, "%s", "Daemonizing");
        writeToCustomLog(TMP_MSG);

        /* Change the current working directory */
        if ((chdir(arguments.wdir)) < 0) {
            snprintf(TMP_MSG, MAXLINE, "%s", "Can not change current directory");
            writeToCustomLog(TMP_MSG);
            /* Log the failure */
            exit(EXIT_FAILURE);
        }
        snprintf(TMP_MSG, MAXLINE, "%s", "Working directory changed");
        writeToCustomLog(TMP_MSG);
    }
    savePid();

    if ((setgid(my_gid)) < 0) {
        snprintf(TMP_MSG, MAXLINE, "ERROR: setgid(%d) failed: %s", my_gid, strerror(errno));
        writeToCustomLog(TMP_MSG);
        halt();
    }
    snprintf(TMP_MSG, MAXLINE, "Group ID changed to %d", my_gid);
    writeToCustomLog(TMP_MSG);

    if ((setuid(my_uid)) < 0) {
        snprintf(TMP_MSG, MAXLINE, "ERROR: setuid(%d) failed: %s", my_uid, strerror(errno));
        writeToCustomLog(TMP_MSG);
        halt();
    }
    snprintf(TMP_MSG, MAXLINE, "User ID changed to %d", my_gid);
    writeToCustomLog(TMP_MSG);


    if (arguments.foreground == 0) {
        snprintf(TMP_MSG, MAXLINE, "%s", "Closing descriptors & disabling verbosity.\nEnsure you have set right permissions for your log file.\nWatch your log file for further information\n");
        VERBOSE(TMP_MSG);
        arguments.verbosity = 0;
        /* Close out the standard file descriptors */
        close(STDIN_FILENO);
        close(STDOUT_FILENO);
        close(STDERR_FILENO);
    }
    ////////////////////////////////////////////////////////////////////////////////

    //
    init_arrays();

    init_webhdfs_arrays();

    init_active_c_table();
    init_descriptors();
    scan_connections();
    //
    ////////////////////////////////////////////////////////////////////////////////
    spawn_threads();
    do_listen();

    ////////////////////////////////////////////////////////////////////////////////
    /* This never happens */
    return 0;
}