Example #1
0
int load_global_context_forindel(global_context_t * context)
{
	char tmp_fname [MAX_FILE_NAME_LENGTH];

	warning_file_limit();
	context -> input_reads.avg_read_length = guess_reads_density_format(context->config.first_read_file , 0, NULL, NULL);
	if(context -> input_reads.avg_read_length<0 )context -> input_reads.avg_read_length = 250;
	if(context -> input_reads.avg_read_length<0 ||geinput_open_sam(context->config.first_read_file, &context->input_reads.first_read_file, context -> input_reads.is_paired_end_reads))
	{
		SUBREADprintf("Unable to open '%s' as a read file. Please check if it exists, you have the permission to read it, and it is in the FASTQ/FASTA/PLAIN format.\n", context->config.first_read_file);
		return -1;
	}


	struct stat ginp1_stat;
	stat(context->config.first_read_file , &ginp1_stat);
	context->input_reads.first_read_file_size = ginp1_stat.st_size;

	sprintf(tmp_fname, "%s.reads", context->config.index_prefix);
	if(!does_file_exist(tmp_fname))
	{
		SUBREADprintf("Unable top open index '%s'. Please make sure that the correct prefix is specified and you have the permission to read these files. For example, if there are files '/opt/my_index.reads', '/opt/my_index.files' and etc, the index prefix should be specified as '/opt/my_index' without any suffix. \n", context->config.index_prefix);
		return -1;
	}


	if(context->config.space_type == GENE_SPACE_COLOR)
		sprintf(tmp_fname, "%s.00.c.tab", context->config.index_prefix);
	else
		sprintf(tmp_fname, "%s.00.b.tab", context->config.index_prefix);
	if(!does_file_exist(tmp_fname))
	{
		SUBREADprintf("Your reads are in the %s space but the index was not built in the same space. Unable to precess the reads.\n", context->config.space_type == GENE_SPACE_COLOR?"color":"base");
		return -1;
	}

	context->index_block_number = 0; 
	while(1)
	{
		sprintf(tmp_fname, "%s.%02d.%c.tab", context->config.index_prefix, context->index_block_number, context->config.space_type == GENE_SPACE_COLOR?'c':'b');
		if(!does_file_exist(tmp_fname))break;
		context->index_block_number ++;
	}

	context->current_index_block_number = 0;
	load_offsets(&context->chromosome_table, context->config.index_prefix);

	
	context->all_processed_reads = 0;
	context->all_mapped_reads = 0;

	memset( context->all_value_indexes , 0 , 100 * sizeof(gene_value_index_t));

	return 0;
}
Example #2
0
bool parameters::init(unsigned _lambda, unsigned _kappa)
{
	lambda = _lambda;
	kappa = _kappa;
	
	pathname = std::string("lambda") + std::to_string(lambda) + std::string("-kappa") + std::to_string(kappa);
	mkdir(pathname.c_str(), 0777);
	pathname += std::string("/");

	if (does_file_exist((pathname + std::string("parameters.mmap")).c_str()))
	{
		std::ifstream parametersFile;
		parametersFile.open((pathname + std::string("parameters.mmap")).c_str(), std::ios::binary);
		parametersFile >> n;
		parametersFile >> rhof;
		parametersFile >> eta;
		parametersFile >> etaq;
		parametersFile >> rho;
		parametersFile >> alpha;
		parametersFile >> xi;
		parametersFile >> beta;
		parametersFile >> nu;
		parametersFile >> ne;
		parametersFile.close();
		delta = floor(sqrt(n));
		return true;
	}
int restore_client(char*ipaddr, int port, char*clientpath, char*auxpath)
/*
Purpose:Restore the path of a specific client. Transmit
the archives from my (the server's) local storage loc.
Params:	clientno - client# in g_clientlist[]
        clientpath - client's path to be restored
Return: result (0=success, nonzero=failure)
*/
{
  struct s_server2client_msg_record rec_to_client;
  int res=0, socket_fd, len, i;
  char tmp[MAX_STR_LEN+1], infile[MAX_STR_LEN+1];
  FILE*fin;

  log_it(info, "%s - restoration of %s commencing", ipaddr, clientpath);
// FIXME - don't assume the latest backup contains the files we want ;)
  sprintf(tmp, "find /var/spool/monitas/%s -type f | sort | tail -n1", ipaddr);
  strcpy(infile, call_program_and_get_last_line_of_output(tmp));
  log_it(debug, "Restoring from data file '%s'", infile);
  if (!does_file_exist(infile)) { log_it(error, "Backup '%s' not found. That should be impossible.", infile); return(1); }
  log_it(debug, "Restoring %s - archive=%s", ipaddr, infile);
  rec_to_client.msg_type = trigger_restore;
  strncpy(rec_to_client.body, clientpath, sizeof(rec_to_client.body));
  strncpy(rec_to_client.bodyAux, auxpath, sizeof(rec_to_client.bodyAux));
  if (send_msg_to_client(&rec_to_client, ipaddr, port, &socket_fd))
    { log_it(error, "restore_client - failed to send msg to client"); return(1); }
  if (!(fin=fopen(infile, "r")))
    { log_it(fatal, "Failed to openin temp data file"); }
  res += transmit_file_to_socket(fin, socket_fd);

  len=read(socket_fd, (char*)&i, sizeof(i));
  if (!len) { res++; log_it(error, "Client hasn't told me the result of its call to mondorestore"); }
  else if (len!=sizeof(i)) { res++; log_it(error, "Client didn't sent _entire_ result of its call to mondorestore"); }
  else if (i) { res++; log_it(error, "Client said, mondorestore returned an error."); }
  else { log_it(debug, "Client said, mondorestore returned OK"); }

  fclose(fin);
  close(socket_fd);
  if (res>0)
    {
      log_it(error, "%s - error(s) occurred while restoring %s", ipaddr, clientpath);
      rec_to_client.msg_type = restore_fail;
      sprintf(rec_to_client.body, "Failed to restore %s", clientpath);
      log_it(debug, rec_to_client.body);
    }
  else
    {
      log_it(info, "%s - restored %s ok", ipaddr, clientpath);
      rec_to_client.msg_type = restore_ok;
      sprintf(rec_to_client.body, "%s - restored ok", clientpath);
      log_it(debug, rec_to_client.body);
    }
  if (send_msg_to_client(&rec_to_client, ipaddr, port, &socket_fd))
    {
      log_it(error, "Unable to notify %s of restore success/failure", ipaddr);
      i = find_client_in_clientlist(ipaddr);
      if (i>=0) { forcibly_logout_client(i); }
    }
  return(res);
}
Example #4
0
File: shell.c Project: Rathcke/uni
int cmd_run(char* prog) {
  if (does_file_exist(prog)) {
    return syscall_join(syscall_exec(prog));
  } else {
    printf("No such program: %s.\n", prog);
    return 1;
  }
}
Example #5
0
int init_ini_file()
{
	char path[MAX_PATH],str[MAX_PATH];
	FILE *f;
	memset(ini_file,0,sizeof(ini_file));
	path[0]=0;
	str[0]=0;
	set_module_dir();
	GetCurrentDirectory(sizeof(path),path);
	_snprintf(str,sizeof(str)-1,"%s\\" APP_NAME ".ini",path);
	if(!does_file_exist(str)){
		path[0]=0;
		get_appdata_folder(path,sizeof(path));
		_snprintf(str,sizeof(str)-1,"%s\\" APP_NAME ".ini",path);
		if(!does_file_exist(str)){
			path[0]=0;
			do_install_dialog(path);
		}
	}
	if(path[0]==0){
		ini_file[0]=0;
		return 0;
	}
	add_trail_slash(path,sizeof(path));
	_snprintf(ini_file,sizeof(ini_file)-1,"%s%s",path,APP_NAME ".ini");
	f=fopen(ini_file,"rb");
	if(f==0){
		f=fopen(ini_file,"wb");
	}
	if(f!=0){
		fclose(f);
	}
	else
	{
		char msg[MAX_PATH+80]={0};
		_snprintf(msg,sizeof(msg),"Unable to access ini file:\r\n%s",ini_file);
		MessageBox(NULL,msg,"Error",MB_OK|MB_SYSTEMMODAL);
	}
	return 0;
}
/**
 * Log the last @p g_noof_log_lines lines of @p filename that match @p
 * grep_for_me to the screen.
 * @param filename The file to give the end of.
 * @param grep_for_me If not "", then only give lines in @p filename that match this regular expression.
 */
	void
	 log_file_end_to_screen(char *filename, char *grep_for_me) {

		/*@ buffers ********************************************************** */
		char *command = NULL;
		char *tmp = NULL;

		/*@ pointers ********************************************************* */
		FILE *fin = NULL;

		/*@ int ************************************************************** */
		int i = 0;
		size_t n = 0;

		assert_string_is_neither_NULL_nor_zerolength(filename);
		assert(grep_for_me != NULL);

		if (!does_file_exist(filename)) {
			return;
		}
		if (grep_for_me[0] != '\0') {
			asprintf(&command, "grep '%s' %s | tail -n%d",
					 grep_for_me, filename, g_noof_log_lines);
		} else {
			asprintf(&command, "tail -n%d %s", g_noof_log_lines, filename);
		}
		fin = popen(command, "r");
		if (!fin) {
			log_OS_error(command);
		} else {
			for (i = 0; i < g_noof_log_lines; i++) {
				for (;
					strlen(err_log_lines[i]) < 2 && !feof(fin);) {
					getline(&(err_log_lines[i]), &n, fin);
					strip_spaces(err_log_lines[i]);
					if (!strncmp(err_log_lines[i], "root:", 5)) {
						asprintf(&tmp, "%s", err_log_lines[i] + 6);
						paranoid_free(err_log_lines[i]);
						err_log_lines[i] = tmp;
					}
					if (feof(fin)) {
						break;
					}
				}
			}
			paranoid_pclose(fin);
		}
		refresh_log_screen();
		paranoid_free(command);
	}
XMondoRestore::XMondoRestore (QWidget *parent, QButtonGroup *mediaType, QLineEdit *device, QLineEdit *nfsRemoteDir, QLineEdit *filelistFilter)
    : QObject (0, 0), rMediaType (mediaType), rDevice (device), rNFSRemoteDir (nfsRemoteDir), rFilter (filelistFilter), ok (true), files (parent), doneSetup (false), th (0)
{
    bkpinfo = new s_bkpinfo;

    char tmp[256];
    strcpy (tmp, "/tmp/xmondo.rstr.XXXXXX");
    mktemp (tmp);
    tempdir = tmp;
    filelistLocation = tempdir + "/filelist.full";
    cfgLocation      = tempdir + "/mondo-restore.cfg";
    cdMountpoint     = "/mnt/cdrom";

    if (!does_file_exist ("/mnt/cdrom")) {
	if (system ("mkdir -p /mnt/cdrom >/dev/null 2>&1") != 0) {
	    popup_and_OK ("Can't create /mnt/cdrom directory. Aborting restore.");
	    ok = false;
	    return;
	}
    }

    QGridLayout *filesGrid;
    filesGrid        = new QGridLayout (files, 3, 2, 5, 5, "filesGrid");
    fStatusMsg       = new QLabel ("", files);
    fList            = new QListView (files);
    fRestoreDirLabel = new QLabel ("Restore to:", files);
    fRestoreDir      = new QLineEdit (files);

    fList->addColumn ("Files to restore:");
    fList->setRootIsDecorated (true);
    fList->setEnabled (false);
    fRestoreDirLabel->setEnabled (false);
    fRestoreDir->setEnabled (false);
    fRestoreDir->setText ("/tmp");
    filesGrid->addMultiCellWidget (fStatusMsg, 0, 0, 0, 1);
    filesGrid->addMultiCellWidget (fList,      1, 1, 0, 1);
    filesGrid->addWidget (fRestoreDirLabel,    2,    0);
    filesGrid->addWidget (fRestoreDir,         2,    1);

    while (system ("mount | grep -q /mnt/cdrom") == 1) {
	if (QMessageBox::warning (0, "XMondo", QString ("CD is mounted. Please unmount it and try again."), "&Retry", "&Cancel") == 1 /* Cancel */) {
	    ok = false;
	    return;
	}
    }

    pthread_create (&preparer_thread, 0, XMondoRestore_preparer_thread, static_cast <void*> (this));
    ok = true;
}
/**
 * Generate the filename of a tarball to verify.
 * @param bkpinfo The backup information structure. @c bkpinfo->zip_suffix is the only field used.
 * @param mountpoint The directory where the CD/DVD/ISO is mounted.
 * @param setno The afioball number to get the location of.
 * @return The absolute path to the afioball.
 * @note The returned string points to static data that will be overwritten with each call.
 * @ingroup stringGroup
 */
char *vfy_tball_fname(struct s_bkpinfo *bkpinfo, char *mountpoint,
					  int setno)
{
	/*@ buffers ******************************************************* */
	static char output[MAX_STR_LEN];

	assert(bkpinfo != NULL);
	assert_string_is_neither_NULL_nor_zerolength(mountpoint);
	sprintf(output, "%s/archives/%d.star.%s", mountpoint, setno,
			bkpinfo->zip_suffix);
	if (!does_file_exist(output)) {
		sprintf(output, "%s/archives/%d.afio.%s", mountpoint, setno,
				bkpinfo->zip_suffix);
	}
	return (output);
}
Example #9
0
File: shell.c Project: Rathcke/uni
int background_run(char* prog) {
  if (background_proc != -1) {
    printf("Error: Can only run one background process at a time.\n");
    printf("Use 'wait' to block until it stops.\n");
    return 1;
  } else {
    if (does_file_exist(prog)) {
      background_proc = syscall_exec(prog);
      printf("Background process spawned with PID %d\n", background_proc);
      return 0;
    } else {
      printf("No such program: %s.\n", prog);
      return 1;
    }
  }
}
/**
 * Verify one afioball from the CD.
 * Checks for existence (calls fatal_error() if it does not exist) and 
 * then calls verify_an_afioball().
 * @param bkpinfo The backup information structure. Passed to verify_an_afioball().
 * @param tarball_fname The filename of the afioball to verify.
 * @return The return value of verify_an_afioball().
 * @see verify_an_afioball
 */
int
verify_an_afioball_from_CD(struct s_bkpinfo *bkpinfo, char *tarball_fname)
{

	/*@ int ************************************************************* */
	int res = 0;

	assert(bkpinfo != NULL);
	assert_string_is_neither_NULL_nor_zerolength(tarball_fname);

	log_msg(1, "Verifying %s", tarball_fname);
	if (!does_file_exist(tarball_fname)) {
		fatal_error("Cannot verify nonexistent afioball");
	}
	res = verify_a_tarball(bkpinfo, tarball_fname);
	return (res);
}
/**
 * Feed @p input_device through ntfsclone to @p output_fname.
 * @param input_device The device to image.
 * @param output_fname The file to write.
 * @return 0 for success, nonzero for failure.
 */
int feed_into_ntfsprog(char *input_device, char *output_fname)
{
// BACKUP
	int res = -1;
	char*command;

	if (!does_file_exist(input_device)) {
		fatal_error("input device does not exist");
	}
	if ( !find_home_of_exe("ntfsclone")) {
		fatal_error("ntfsclone not found");
	}
	malloc_string(command);
	sprintf(command, "ntfsclone --force --save-image --overwrite %s %s", output_fname, input_device);
	res = run_program_and_log_output(command, 5);
	paranoid_free(command);
	unlink(output_fname);
	return (res);
}
/**
 * Compare all data on a cdstream-based backup.
 * @param bkpinfo The backup information structure. Fields used:
 * - @c bkpinfo->disaster_recovery
 * - @c bkpinfo->media_device
 * - @c bkpinfo->restore_path
 * @return 0 for success, nonzero for failure.
 */
int compare_to_cdstream(struct s_bkpinfo *bkpinfo)
{
	int res;

  /** needs malloc **/
	char *dir, *command;

	assert(bkpinfo != NULL);
	malloc_string(dir);
	malloc_string(command);
	getcwd(dir, MAX_STR_LEN);
	chdir(bkpinfo->restore_path);

	sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
			bkpinfo->restore_path);
	run_program_and_log_output(command, FALSE);
	mvaddstr_and_log_it(g_currentY,
						0, "Verifying archives against filesystem");

	if (bkpinfo->disaster_recovery
		&& does_file_exist("/tmp/CDROM-LIVES-HERE")) {
		strcpy(bkpinfo->media_device,
			   last_line_of_file("/tmp/CDROM-LIVES-HERE"));
	} else {
		find_cdrom_device(bkpinfo->media_device, FALSE);
	}
	res = verify_tape_backups(bkpinfo);
	chdir(dir);
	if (length_of_file("/tmp/changed.txt") > 2
		&& length_of_file("/tmp/changed.files") > 2) {
		log_msg(0,
				"Type 'less /tmp/changed.files' to see which files don't match the archives");
		log_msg(2, "Calling popup_changelist_from_file()");
		popup_changelist_from_file("/tmp/changed.files");
		log_msg(2, "Returned from popup_changelist_from_file()");
	}

	mvaddstr_and_log_it(g_currentY++, 74, "Done.");
	paranoid_free(dir);
	paranoid_free(command);
	return (res);
}
void
log_file_end_to_screen (char *filename, char *grep_for_me)
{

	/** buffers ***********************************************************/
  char command[MAX_STR_LEN + 1];
	char tmp[MAX_STR_LEN + 1];

	/** pointers **********************************************************/
  FILE *fin;

	/** int ***************************************************************/
  int i = 0;



  if (!does_file_exist (filename))
    {
      return;
    }
  if (grep_for_me[0] != '\0')
    {
      sprintf (command, "cat %s | grep \"%s\" | tail -n%d", filename,
	       grep_for_me, NOOF_ERR_LINES);
    }
  else
    {
      sprintf (command, "cat %s | tail -n%d", filename, NOOF_ERR_LINES);
    }
  fin = popen (command, "r");
  if (fin)
    {
      for (i = 0; i < NOOF_ERR_LINES; i++)
	  {
	      char tmp[MAX_STR_LEN];
	      fgets (tmp, MAX_STR_LEN, fin);
	      events.insertLine (XMondoLog, tmp);
	  }
    }
  pclose (fin);
}
Example #14
0
int lua_create_default_file(int(*mdi_window)(void *,char *),void *win)
{
	FILE *f;
	char fname[MAX_PATH]={0};
	get_lua_script_fname(fname,sizeof(fname));
	if(does_file_exist(fname)){
		if(mdi_window && win){
			mdi_window(win,"file allready exists:");
			mdi_window(win,fname);
		}
		return FALSE;
	}
	f=fopen(fname,"wb");
	if(f!=0){
		int i;
		fprintf(f,"-- external C functions available:\n");
		for(i=0;i<sizeof(lua_map)/sizeof(LUA_C_FUNC_MAP);i++){
			if(lua_map[i].lua_name==0)
				break;
			fprintf(f,"-- %s %s\n",lua_map[i].lua_name,lua_map[i].descrip);
		}
		fprintf(f,"\n\n-- lua functions that get called after certain events\n"
				" -- session=irc session pointer\n"
				" -- origin=full nick ([email protected])\n"
				" -- nch=nick or channel\n"
				" -- msg=message body\n");
		for(i=0;i<sizeof(lua_funcs)/sizeof(LUA_FUNC_MAP);i++){
			if(lua_funcs[i].event==0)
				break;
			fprintf(f,"\n-- function %s(session,origin,nch,msg%s)\n",lua_funcs[i].lua_func,
				lua_funcs[i].type==USER_FUNC?",win":"");
			fprintf(f,"-- end\n");
		}
		fclose(f);
		if(mdi_window && win){
			mdi_window(win,"created file:");
			mdi_window(win,fname);
		}
	}
	return FALSE;
}
/**
 * Exit Mondo normally.
 * @param signal The exit code (0 indicates a successful backup; 1 for Mondo means the
 * user aborted; 254 means a fatal error occured).
 * @note This function never returns.
 */
	void
	 finish(int signal) {
		char *command = NULL;

		/*  if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */

		/* newtPopHelpLine(); */

		register_pid(0, "mondo");
		chdir("/");
		run_program_and_log_output("umount " MNT_CDROM, FALSE);
		run_program_and_log_output("rm -Rf /mondo.scratch.* /mondo.tmp.*",
								   FALSE);
		if (g_erase_tmpdir_and_scratchdir) {
			run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 1);
		}
		if (g_selfmounted_isodir) {
			asprintf(&command, "umount %s", g_selfmounted_isodir);
			run_program_and_log_output(command, 1);
			asprintf(&command, "rmdir %s", g_selfmounted_isodir);
			run_program_and_log_output(command, 1);
		}
//  iamhere("foo");
		/* system("clear"); */
//  iamhere("About to call newtFinished");
		if (!g_text_mode) {
			if (does_file_exist("/THIS-IS-A-RAMDISK")) {
				log_msg(1, "Calling newtFinished()");
				newtFinished();
			} else {
				log_msg(1, "Calling newtSuspend()");
				newtSuspend();
			}
		}
//  system("clear");
//  iamhere("Finished calling newtFinished");
		printf(_("Execution run ended; result=%d\n"), signal);
		printf(_("Type 'less %s' to see the output log\n"), MONDO_LOGFILE);
		free_libmondo_global_strings();
		exit(signal);
	}
Example #16
0
void register_pid(pid_t pid, char*name_str)
/*
Purpose:Register executable's PID in /var/run/monitas-[name_str].pid;
        store [pid] in data file
Params:	pid - process ID to be stored in data file
        name_str - name (e.g. "client" or "server") to be included
        in the data file name of the PID locking file
Return: None
NB:     Use pid=0 to delete the lock file and unregister the PID
*/
{
  char tmp[MAX_STR_LEN+1], lockfile_fname[MAX_STR_LEN+1];
  int res;
  FILE*fin;

  sprintf(lockfile_fname, "/var/run/monitas-%s.pid", name_str);
  if (!pid)
    {
      log_it(debug, "Unregistering PID");
      if (unlink(lockfile_fname)) { log_it(error, "Error unregistering PID"); }
      return;
    }
  if (does_file_exist(lockfile_fname))
    {
      tmp[0]='\0';
      if ((fin=fopen(lockfile_fname,"r"))) { fgets(tmp, MAX_STR_LEN, fin); fclose(fin); }
      pid = atol(tmp);
      sprintf(tmp, "ps %ld", (long int)pid);
      res = call_program_and_log_output(tmp);
      if (!res)
        {
          sprintf(tmp, "I believe the daemon is already running. If it isn't, please delete %s and try again.", lockfile_fname);
          log_it(fatal, tmp);
        }
    }
  sprintf(tmp, "echo %ld > %s", (long int)getpid(), lockfile_fname);
  if (system(tmp)) { log_it(fatal, "Cannot register PID"); }
}
/**
 * Process mondoarchive's command-line switches.
 * @param bkpinfo The backup information structure to populate.
 * @param flag_val An array of the argument passed to each switch (the letter is the index).
 * If a switch is not set or has no argument, the field in @p flag_val doesn't matter.
 * @param flag_set An array of <tt>bool</tt>s indexed by switch letter: TRUE if it's set,
 * FALSE if it's not.
 * @return The number of problems with the switches, or 0 for success.
 * @bug Maybe include a list of all switches (inc. intentionally undocumented ones not in the manual!) here?
 */
int
process_switches(struct s_bkpinfo *bkpinfo,
				 char flag_val[128][MAX_STR_LEN], bool flag_set[128])
{

	/*@ ints *** */
	int i = 0;
	int retval = 0;
	int percent = 0;

	/*@ buffers ** */
	char *tmp;
	char *tmp1;
	char *psz;
	char *p;
	char *q;

	long itbs;

	struct stat buf;

	malloc_string(tmp);
	malloc_string(psz);

	assert(bkpinfo != NULL);
	assert(flag_val != NULL);
	assert(flag_set != NULL);

	bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;

/* compulsory */
	i = flag_set['c'] + flag_set['i'] + flag_set['n'] +
		flag_set['t'] + flag_set['u'] + flag_set['r'] +
		flag_set['w'] + flag_set['C'];
	if (i == 0) {
		retval++;
		log_to_screen("You must specify the media type\n");
	}
	if (i > 1) {
		retval++;
		log_to_screen("Please specify only one media type\n");
	}
	if (flag_set['K']) {
		g_loglevel = atoi(flag_val['K']);
		if (g_loglevel < 3) {
			g_loglevel = 3;
		}
	}
	if (flag_set['L'] && flag_set['0']) {
		retval++;
		log_to_screen("You cannot have 'no compression' _and_ LZOP.\n");
	}
	bkpinfo->backup_data = flag_set['O'];
	bkpinfo->verify_data = flag_set['V'];
	if (flag_set['I'] && !bkpinfo->backup_data) {
		log_to_screen("-I switch is ignored if just verifying");
	}
	if (flag_set['E'] && !bkpinfo->backup_data) {
		log_to_screen("-E switch is ignored if just verifying");
	}

	if (!find_home_of_exe("afio")) {
		if (find_home_of_exe("star")) {
			flag_set['R'] = TRUE;
			log_msg(1, "Using star instead of afio");
		} else {
			fatal_error
				("Neither afio nor star is installed. Please install at least one.");
		}
	}

	if (flag_set['R']) {
		bkpinfo->use_star = TRUE;
		if (flag_set['L']) {
			fatal_error("You may not use star and lzop at the same time.");
		}
		if (!find_home_of_exe("star")) {
			fatal_error
				("Please install 'star' RPM or tarball if you are going to use -R. Thanks.");
		}
	}
	if (flag_set['W']) {
		bkpinfo->nonbootable_backup = TRUE;
		log_to_screen("Warning - you have opted for non-bootable backup");
		if (flag_set['f'] || flag_set['l']) {
			log_to_screen
				("You don't need to specify bootloader or bootdevice");
		}
	}
	if (flag_set['t'] && flag_set['H']) {
		fatal_error
			("Sorry, you may not nuke w/o warning from tape. Drop -H, please.");
	}
	if (flag_set['I']) {
		if (!strcmp(bkpinfo->include_paths, "/")) {
			log_msg(2, "'/' is pleonastic.");
			bkpinfo->include_paths[0] = '\0';
		}
		if (bkpinfo->include_paths[0]) {
			strcat(bkpinfo->include_paths, " ");
		}
		asprintf(&tmp1, flag_val['I']);
		p = tmp1;
		q = tmp1;

		/* Cut the flag_val['I'] in parts containing all paths to test them */
		while (p != NULL) {
			q = strchr(p, ' ');
			if (q != NULL) {
				*q = '\0';
				if (stat(p, &buf) != 0) {
					log_msg(1, "ERROR ! %s doesn't exist", p);
					fatal_error("ERROR ! You specified a directory to include which doesn't exist");
				}
				p = q+1 ;
			} else {
				if (stat(p, &buf) != 0) {
					log_msg(1, "ERROR ! %s doesn't exist", p);
					fatal_error("ERROR ! You specified a directory to include which doesn't exist");
				}
				p = NULL;
			}
		}
		paranoid_free(tmp1);

		strncpy(bkpinfo->include_paths + strlen(bkpinfo->include_paths),
				flag_val['I'],
				4*MAX_STR_LEN - strlen(bkpinfo->include_paths));
		log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
		if (bkpinfo->include_paths[0] == '-') {
			retval++;
			log_to_screen("Please supply a sensible value with '-I'\n");
		}
	}

	if (g_kernel_version >= 2.6 && !flag_set['d']
		&& (flag_set['c'] || flag_set['w'])) {
		fatal_error
			("If you are using the 2.6.x kernel, please specify the CD-R(W) device.");
	}


	if (flag_set['J']) {
		if (flag_set['I']) {
			retval++;
			log_to_screen
				("Please do not use -J in combination with -I. If you want to make a list of files to backup, that's fine, use -J <filename> but please don't muddy the waters by combining -J with -I. Thanks. :-)");
		}
		bkpinfo->make_filelist = FALSE;
		strcpy(bkpinfo->include_paths, flag_val['J']);
	}
	if (flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) {
		if (!flag_set['r'] && g_kernel_version <= 2.5
			&& strstr(flag_val['d'], "/dev/")) {
			fatal_error
				("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag.");
		}
		if (flag_set['r'] && g_kernel_version <= 2.5
			&& !strstr(flag_val['d'], "/dev/")) {
			fatal_error
				("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag.");
		}
		if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) {
			log_to_screen
				("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk...");
		}

		if (system("which cdrecord > /dev/null 2> /dev/null")
			&& system("which dvdrecord > /dev/null 2> /dev/null")) {
			fatal_error
				("Please install dvdrecord/cdrecord and try again.");
		}
		if (flag_set['C']) {
			bkpinfo->cdrw_speed = atoi(flag_val['C']);
			if (bkpinfo->cdrw_speed < 1) {
				fatal_error
					("You specified a silly speed for a CD-R[W] drive");
			}
			if (!flag_set['L']) {
				log_to_screen
					("You must use -L with -C. Therefore I am setting it for you.");
				flag_set['L'] = 1;
				flag_val['L'][0] = '\0';
			}
		} else {
			log_msg(3, "flag_val['c'] = %s", flag_val['c']);
			log_msg(3, "flag_val['w'] = %s", flag_val['w']);
//    log_msg(3, "flag_set['r'] = %i", flag_set['r'] );
			if (flag_set['c']) {
				bkpinfo->cdrw_speed = atoi(flag_val['c']);
			} else if (flag_set['w']) {
				bkpinfo->cdrw_speed = atoi(flag_val['w']);
			} else if (flag_set['r']) {
				bkpinfo->cdrw_speed = 1;	/*atoi(flag_val['r']); */
			}

			if (bkpinfo->cdrw_speed < 1) {
				fatal_error
					("You specified a silly speed for a CD-R[W] drive");
			}
		}
	}
	if (flag_set['t'] && !flag_set['d']) {
		log_it("Hmm! No tape drive specified. Let's see what we can do.");
		if (find_tape_device_and_size(flag_val['d'], tmp)) {
			fatal_error
				("Tape device not specified. I couldn't find it either.");
		}
		flag_set['d'] = TRUE;
		sprintf(tmp,
				"You didn't specify a tape streamer device. I'm assuming %s",
				flag_val['d']);
		log_to_screen(tmp);
		percent = 0;
	}

	if (flag_set['r'])			// DVD
	{
		if (flag_set['m']) {
			fatal_error
				("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m.");
		}
		if (!flag_set['d']) {
			if (!find_dvd_device(flag_val['d'], FALSE)) {
				flag_set['d'] = TRUE;
				log_to_screen("I guess DVD drive is at %s", flag_val['d']);
			}
		}
		if (!find_home_of_exe("growisofs")) {
			fatal_error
				("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it.");
		}
		if (!find_home_of_exe("dvd+rw-format")) {
			fatal_error
				("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it.");
		}
		if (strchr(flag_val['d'], ',')) {
			fatal_error
				("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
		}
		if (!flag_set['s']) {
			sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE);	// 4.7 salesman's GB = 4.482 real GB = 4582 MB
			strcat(flag_val['s'], "m");
			log_to_screen
				("You did not specify a size (-s) for DVD. I'm guessing %s.",
				 flag_val['s']);
			flag_set['s'] = 1;
		}
/*
      if (flag_set['Z']) {
	  bkpinfo->blank_dvd_first = TRUE;
      }
*/
	}

	if (flag_set['t'] || flag_set['u']) {	/* tape size */
		if (strchr(flag_val['d'], ',')) {
			fatal_error
				("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
		}
		if (flag_set['O']) {
			if (flag_set['s']) {
				if (flag_set['t']) {
					fatal_error
						("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway.");
				}
				if (process_the_s_switch(bkpinfo, flag_val['s'])) {
					fatal_error("Bad -s switch");
				}
			} else if (flag_set['u'] || flag_set['t']) {
				for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
					bkpinfo->media_size[i] = 0;
				}
			} else {
				retval++;
				log_to_screen("Tape size not specified.\n");
			}
		}
	} else {					/* CD size */
		if (flag_set['s']) {
			if (process_the_s_switch(bkpinfo, flag_val['s'])) {
				fatal_error("Bad -s switch");
			}
		}
		if (flag_set['w']) {
			bkpinfo->wipe_media_first = TRUE;
		}						/* CD-RW */
	}
	if (flag_set['n']) {
		strncpy(bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN);
		if (!flag_set['d']) {
			strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN);
		}
		sprintf(tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3",
				bkpinfo->nfs_mount);
		strncpy(bkpinfo->isodir,
				call_program_and_get_last_line_of_output(tmp),
				MAX_STR_LEN / 4);
		if (strlen(bkpinfo->isodir) < 3) {
			retval++;
			log_to_screen("NFS share is not mounted. Please mount it.\n");
		}
		log_msg(3, "mount = %s", bkpinfo->nfs_mount);
		log_msg(3, "isodir= %s", bkpinfo->isodir);
	}
	if (flag_set['c']) {
		bkpinfo->backup_media_type = cdr;
	}
	if (flag_set['C']) {
		bkpinfo->backup_media_type = cdstream;
	}
	if (flag_set['i']) {
		bkpinfo->backup_media_type = iso;
	}
	if (flag_set['n']) {
		bkpinfo->backup_media_type = nfs;
	}
	if (flag_set['r']) {
		bkpinfo->backup_media_type = dvd;
	}
	if (flag_set['t']) {
		bkpinfo->backup_media_type = tape;
	}
	if (flag_set['u']) {
		bkpinfo->backup_media_type = udev;
	}
	if (flag_set['w']) {
		bkpinfo->backup_media_type = cdrw;
	}

/* optional, popular */
	if (flag_set['g']) {
		g_text_mode = FALSE;
	}
	if (flag_set['E']) {
		if (bkpinfo->exclude_paths[0]) {
			strcat(bkpinfo->exclude_paths, " ");
		}
		asprintf(&tmp1, flag_val['E']);
		p = tmp1;
		q = tmp1;

		/* Cut the flag_val['E'] in parts containing all paths to test them */
		while (p != NULL) {
			q = strchr(p, ' ');
			if (q != NULL) {
				*q = '\0';
				if (stat(p, &buf) != 0) {
					log_msg(1, "WARNING ! %s doesn't exist", p);
				}
				p = q+1 ;
			} else {
				if (stat(p, &buf) != 0) {
					log_msg(1, "WARNING ! %s doesn't exist", p);
				}
				p = NULL;
			}
		}
		paranoid_free(tmp1);

		strncpy(bkpinfo->exclude_paths + strlen(bkpinfo->exclude_paths),
				flag_val['E'],
				4*MAX_STR_LEN - strlen(bkpinfo->exclude_paths));
	}
	if (flag_set['e']) {
		bkpinfo->please_dont_eject = TRUE;
	}
	if (flag_set['N'])			// exclude NFS mounts & devices
	{
//      strncpy(psz, list_of_NFS_devices_and_mounts(), MAX_STR_LEN);
		strncpy(psz, list_of_NFS_mounts_only(), MAX_STR_LEN);
		if (bkpinfo->exclude_paths[0]) {
			strncat(bkpinfo->exclude_paths, " ", MAX_STR_LEN);
		}
		strncat(bkpinfo->exclude_paths, psz, MAX_STR_LEN);
		log_msg(3, "-N means we're now excluding %s",
				bkpinfo->exclude_paths);
	}
	if (strlen(bkpinfo->exclude_paths) >= MAX_STR_LEN) {
		fatal_error
			("Your '-E' parameter is too long. Please use '-J'. (See manual.)");
	}
	if (flag_set['b']) {
		strcpy(psz, flag_val['b']);
		log_msg(1, "psz = '%s'", psz);
		if (psz[strlen(psz) - 1] == 'k') {
			psz[strlen(psz) - 1] = '\0';
			itbs = atol(psz) * 1024L;
		} else {
			itbs = atol(psz);
		}
		log_msg(1, "'%s' --> %ld", flag_val['b'], itbs);
		log_msg(1, "Internal tape block size is now %ld bytes", itbs);
		if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) {
			fatal_error
				("Are you nuts? Silly, your internal tape block size is. Abort, I shall.");
		}
		bkpinfo->internal_tape_block_size = itbs;
	}
	if (flag_set['D']) {
		bkpinfo->differential = 1;
//      bkpinfo->differential = atoi (flag_val['D']);
		if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) {
			fatal_error
				("The D option should be between 1 and 9 inclusive");
		}
	}
	if (flag_set['x']) {
		strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4);
		if (run_program_and_log_output("which ntfsclone", 2)) {
			fatal_error("Please install ntfsprogs package/tarball.");
		}
	}
	if (flag_set['m']) {
		bkpinfo->manual_cd_tray = TRUE;
	}
	if (flag_set['k']) {
		strncpy(bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN);
		if (!strcmp(bkpinfo->kernel_path, "failsafe")) {
			strcpy(bkpinfo->kernel_path, "FAILSAFE");
		}
		if (strcmp(bkpinfo->kernel_path, "FAILSAFE")
			&& !does_file_exist(bkpinfo->kernel_path)) {
			retval++;
			sprintf(tmp,
					"You specified kernel '%s', which does not exist\n",
					bkpinfo->kernel_path);
			log_to_screen(tmp);
		}
	}
	if (flag_set['p']) {
		strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4);
	}


	if (flag_set['d']) {		/* backup directory (if ISO/NFS) */
		if (flag_set['i']) {
			strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4);
			sprintf(tmp, "ls -l %s", bkpinfo->isodir);
			if (run_program_and_log_output(tmp, FALSE)) {
				fatal_error
					("output folder does not exist - please create it");
			}
		} else if (flag_set['n']) {
			strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN);
		} else {				/* backup device (if tape/CD-R/CD-RW) */

			strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4);
		}
	}

	if (flag_set['n']) {
		sprintf(tmp, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir,
				bkpinfo->nfs_remote_dir);
		if (run_program_and_log_output(tmp, FALSE)) {
			retval++;
			sprintf(tmp,
					"Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n",
					bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount);
			log_to_screen(tmp);
		}
	}

	if (!flag_set['d']
		&& (flag_set['c'] || flag_set['w'] || flag_set['C'])) {
		if (g_kernel_version >= 2.6) {
			if (popup_and_get_string
				("Device", "Please specify the device",
				 bkpinfo->media_device, MAX_STR_LEN / 4)) {
				retval++;
				log_to_screen("User opted to cancel.");
			}
		} else if (find_cdrw_device(bkpinfo->media_device)) {
			retval++;
			log_to_screen
				("Tried and failed to find CD-R[W] drive automatically.\n");
		} else {
			flag_set['d'] = TRUE;
			strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);
		}
	}

	if (!flag_set['d'] && !flag_set['n'] && !flag_set['C']) {
		retval++;
		log_to_screen("Please specify the backup device/directory.\n");
		fatal_error
			("You didn't use -d to specify the backup device/directory.");
	}
/* optional, obscure */
	for (i = '0'; i <= '9'; i++) {
		if (flag_set[i]) {
			bkpinfo->compression_level = i - '0';
		}						/* not '\0' but '0' */
	}
	if (flag_set['S']) {
		sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'],
				random() % 32768);
	}
	if (flag_set['T']) {
		sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%ld", flag_val['T'],
				random() % 32768);
		sprintf(tmp, "touch %s/.foo.dat", flag_val['T']);
		if (run_program_and_log_output(tmp, 1)) {
			retval++;
			log_to_screen
				("Please specify a tempdir which I can write to. :)");
			fatal_error("I cannot write to the tempdir you specified.");
		}
		sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", flag_val['T'],
				flag_val['T']);
		if (run_program_and_log_output(tmp, 1)) {
			retval++;
			log_to_screen
				("Please don't specify a SAMBA or VFAT or NFS tmpdir.");
			fatal_error("I cannot write to the tempdir you specified.");
		}
	}
	if (flag_set['A']) {
		strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN);
	}
	if (flag_set['B']) {
		strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN);
	}
	if (flag_set['F']) {
		g_skip_floppies = TRUE;
	}
	if (flag_set['H']) {
		g_cd_recovery = TRUE;
	}
	if (flag_set['l']) {
#ifdef __FreeBSD__
#  define BOOT_LOADER_CHARS "GLBMR"
#else
#  ifdef __IA64__
#    define BOOT_LOADER_CHARS "GER"
#  else
#    define BOOT_LOADER_CHARS "GLR"
#  endif
#endif
		if (!strchr
			(BOOT_LOADER_CHARS,
			 (bkpinfo->boot_loader = flag_val['l'][0]))) {
			log_msg(1, "%c? WTF is %c? I need G, L, E or R.",
					bkpinfo->boot_loader, bkpinfo->boot_loader);
			fatal_error
				("Please specify GRUB, LILO, ELILO  or RAW with the -l switch");
		}
#undef BOOT_LOADER_CHARS
	}
	if (flag_set['f']) {
		strncpy(bkpinfo->boot_device,
				resolve_softlinks_to_get_to_actual_device_file(flag_val
															   ['f']),
				MAX_STR_LEN / 4);
	}
	if (flag_set['P']) {
		strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN);
	}
	if (flag_set['Q']) {
		i = which_boot_loader(tmp);
		log_msg(3, "boot loader is %c, residing at %s", i, tmp);
		printf("boot loader is %c, residing at %s\n", i, tmp);
		finish(0);
	}
	if (flag_set['L']) {
		bkpinfo->use_lzo = TRUE;
		if (run_program_and_log_output("which lzop", FALSE)) {
			retval++;
			log_to_screen
				("Please install LZOP. You can't use '-L' until you do.\n");
		}
	}

	if (!flag_set['o']
		&&
		!run_program_and_log_output
		("egrep -i suse /etc/issue.net | egrep '9.0' | grep 64", TRUE)) {
		bkpinfo->make_cd_use_lilo = TRUE;
		log_to_screen
			("Forcing you to use LILO. SuSE 9.0 (64-bit) has a broken mkfs.vfat binary.");
	}
	if (flag_set['o']) {
		bkpinfo->make_cd_use_lilo = TRUE;
	}
#ifndef __FreeBSD__
	else {
		if (!is_this_a_valid_disk_format("vfat")) {
			bkpinfo->make_cd_use_lilo = TRUE;
			log_to_screen
				("Your kernel appears not to support vfat filesystems. I am therefore");
			log_to_screen
				("using LILO instead of SYSLINUX as the CD/floppy's boot loader.");
		}
		if (run_program_and_log_output("which mkfs.vfat", FALSE)) {
			bkpinfo->make_cd_use_lilo = TRUE;
#ifdef __IA32__
			log_to_screen
				("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as");
			log_to_screen
				("your boot loader. I shall therefore use LILO instead.");
#endif
#ifdef __IA64__
			log_to_screen
				("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI");
			log_to_screen("environment correctly. Please install it.");
			fatal_error("Aborting");
#endif
		}
#ifdef __IA64__
		/* We force ELILO usage on IA64 */
		bkpinfo->make_cd_use_lilo = TRUE;
#endif
	}
#endif

	if (bkpinfo->make_cd_use_lilo && !does_file_exist("/boot/boot.b")) {
		paranoid_system("touch /boot/boot.b");
	}

	i = flag_set['O'] + flag_set['V'];
	if (i == 0) {
		retval++;
		log_to_screen("Specify backup (-O), verify (-V) or both (-OV).\n");
	}

/* and finally... */

	paranoid_free(tmp);
	paranoid_free(psz);
	return (retval);
}
/*----------------------------------------------------------------------*/
int daf_service_delete(void)
{

    char cmd[1024];
    char msg[1024];
    char timestamp[16];
    char backup_inittab_filename[64];

#if defined AIX

    print_msg_to_console("Updating /etc/inittab entry\n");

    //--------------------------------------------------------------------------
    // remove any previous entry
    //--------------------------------------------------------------------------

    safecpy(backup_inittab_filename, "/etc/inittab.", sizeof(backup_inittab_filename));
    get_current_time_as_timestamp(timestamp, sizeof(timestamp), '.');
    safecat(backup_inittab_filename, timestamp, sizeof(backup_inittab_filename));
    sprintf(msg, "Backing up /etc/inittab in %s\n", backup_inittab_filename);
    print_msg_to_console(msg);

    if (copy_file("/etc/inittab", backup_inittab_filename) != 0)
    {
        safecpy(msg, "Backup of inittab failed: ", sizeof(msg));
        safecat(msg, cmd, sizeof(msg));
        safecat(msg, "\n", sizeof(msg));
        print_msg_to_console(msg);
        return(1);
    }

    print_msg_to_console("  Removing any previous daf service entry in /etc/inittab\n");
    safecpy(cmd, "cat /etc/inittab | grep \"daf:\"", sizeof(cmd));

    if (run_system_cmd(cmd, 1) == 0)
    {

        safecpy(cmd, "rmitab \"daf\"", sizeof(cmd));

        if (run_system_cmd_and_print_all_output(cmd) != 0)
        {
            safecpy(msg, "Removal of daf service entry in /etc/inittab failed: ", sizeof(msg));
            safecat(msg, cmd, sizeof(msg));
            safecat(msg, "\n", sizeof(msg));
            print_msg_to_console(msg);
            return(1);
        }

    }
    else
    {
        safecpy(msg, "No daf entry found in /etc/inittab so none was removed\n", sizeof(msg));
        print_msg_to_console(msg);
    }

    print_msg_to_console("/etc/inittab entry updated successfully\n");

#elif defined LINUX || defined SOLARIS || defined HPUX

    //--------------------------------------------------------------------------
    // remove any previous entry
    //--------------------------------------------------------------------------

    // This could be Debian/Ubuntu and could be before we have installed DAF so there might not
    // be a /etc/inittab file existing yet - check for this

    if (! does_file_exist("/etc/inittab"))
    {

        if (does_file_exist(DAF_DEBIAN_ETC_INIT_CONF_PATH))
        {
            safecpy(cmd, "rm " DAF_DEBIAN_ETC_INIT_CONF_PATH, sizeof(cmd));

            if (run_system_cmd(cmd, 1) != 0)
            {
                safecpy(msg, "Removal of " DAF_DEBIAN_ETC_INIT_CONF_PATH " failed\n", sizeof(msg));
                print_msg_to_console(msg);
                return(1);
            }
        }

        print_msg_to_console(DAF_DEBIAN_ETC_INIT_CONF_PATH " removed\n");

    }
    else
    {

        print_msg_to_console("Updating /etc/inittab entry\n");

        safecpy(backup_inittab_filename, "/etc/inittab.", sizeof(backup_inittab_filename));
        get_current_time_as_timestamp(timestamp, sizeof(timestamp), '.');
        safecat(backup_inittab_filename, timestamp, sizeof(backup_inittab_filename));
        sprintf(msg, "Backing up /etc/inittab in %s\n", backup_inittab_filename);
        print_msg_to_console(msg);

        if (copy_file ("/etc/inittab", backup_inittab_filename) != 0)
        {
            safecpy(msg, "Backup of inittab failed: ", sizeof(msg));
            safecat(msg, cmd, sizeof(msg));
            safecat(msg, "\n", sizeof(msg));
            print_msg_to_console(msg);
            return(1);
        }

        print_msg_to_console("  Removing any previous daf service entry in /etc/inittab\n");
        safecpy(cmd, "cat ", sizeof(cmd));
        safecat(cmd, backup_inittab_filename, sizeof(cmd));
        safecat(cmd, " | grep -v \""DAF_SERVICE_INVOCATION"\" > /etc/inittab", sizeof(cmd));

        if (run_system_cmd(cmd, 0) != 0)
        {
            safecpy(msg, "Removal of previous daf service in inittab failed: ", sizeof(msg));
            safecat(msg, cmd, sizeof(msg));
            safecat(msg, "\n", sizeof(msg));
            print_msg_to_console(msg);
            return(1);
        }

        print_msg_to_console("/etc/inittab entry updated successfully\n");
    }


#endif

    if (is_daf_service_running())
    {
        print_msg_to_console("daf daemon is running - and will now be stopped\n");

        if (stop_daf_service_running() != 0)
        {
            print_msg_to_console("Problem trying to stop daf daemon\n");
        }
    }

    return(0);

}
void *XMondoRestore_preparer_thread (void *arg) 
{
    XMondoRestore *r = static_cast<XMondoRestore*> (arg);
    int i = 0;
    g_current_media_number = 1;
	    
    r->fStatusMsg->setText ("Retrieving mondo-restore.cfg from archive...");

    struct s_bkpinfo *bkpinfo = r->bkpinfo;
    reset_bkpinfo (bkpinfo);
    switch (r->rMediaType->id (r->rMediaType->selected())) {
    case 0:
	bkpinfo->backup_media_type = cdr;
	break;
    case 1:
	bkpinfo->backup_media_type = cdrw;
	bkpinfo->wipe_media_first  = 1;
	break;
    case 2:
	bkpinfo->backup_media_type = cdstream;
	break;
    case 3:
	bkpinfo->backup_media_type = dvd;
	break;
    case 4:
	bkpinfo->backup_media_type = iso;
	break;
    case 5:
	bkpinfo->backup_media_type = nfs;
	break;
    case 6:
	bkpinfo->backup_media_type = tape;
	break;
    case 7:
	bkpinfo->backup_media_type = udev;
	break;
    }

    strcpy (bkpinfo->media_device, r->rDevice->text());
    if (bkpinfo->backup_media_type == nfs) strcpy (bkpinfo->nfs_mount, r->rDevice->text());
    if (bkpinfo->backup_media_type == nfs) strcpy (bkpinfo->nfs_remote_dir, r->rNFSRemoteDir->text());
    if (bkpinfo->backup_media_type == iso) strcpy (bkpinfo->isodir, r->rDevice->text());
    strcpy (bkpinfo->tmpdir, r->tempdir.ascii());

    setup_MR_global_filenames (bkpinfo);
    
    if (get_cfg_file_from_archive (bkpinfo) != 0) {
	r->fStatusMsg->setText ("Unable to retrieve mondo-restore.cfg. Please choose another archive source.");
	r->ok = false;
	return 0;
    }
    read_cfg_file_into_bkpinfo (g_mondo_cfg_file, bkpinfo);
    if (!does_file_exist (g_mondo_cfg_file)) {
	r->fStatusMsg->setText ("Unable to retrieve mondo-restore.cfg. Internal error.");
	r->ok = false;
	return 0;
    }
    if (!does_file_exist (g_filelist_full)) {
	chdir (bkpinfo->tmpdir);
	r->fStatusMsg->setText ("Retrieving filelist...");
	if ((bkpinfo->backup_media_type == tape) || (bkpinfo->backup_media_type == udev) ||
	    (bkpinfo->backup_media_type == cdstream)) {
	    unlink (g_filelist_full);
	    system (QString ("tar -zxf %1 tmp/filelist.full").arg (bkpinfo->media_device).ascii());
	} else {
	    mount_cdrom (bkpinfo);
	    unlink (g_filelist_full);
	    system ("tar -zxf /mnt/cdrom/images/all.tar.gz tmp/filelist.full");
	}

	if (!does_file_exist (g_filelist_full)) {
	    r->fStatusMsg->setText ("Filelist could not be retrieved!");
	    r->ok = false;
	    return 0;
	}
    }
    if (!r->rFilter->text().isEmpty() && !r->rFilter->text().isNull()) {
	r->fStatusMsg->setText (QString ("Filtering filelist through regexp <tt>%1</tt>...").arg (r->rFilter->text()));
	if (system (QString ("egrep '%2' %1 > %3.FILT").arg (g_filelist_full).arg (r->rFilter->text()).arg (g_filelist_full).ascii()) != 0) {
	    r->fStatusMsg->setText ("Filter failed, using whole filelist");
	    rename (g_filelist_full, QString ("%1.FILT").arg (g_filelist_full).ascii());
	    usleep (500000);
	}   
    } else {
	rename (g_filelist_full, QString ("%1.FILT").arg (g_filelist_full).ascii());
    }

    r->fStatusMsg->setText ("Preparing filelist - 0% done");

    int nlines = atoi (call_program_and_get_last_line_of_output (const_cast<char*> (QString ("wc -l %1.FILT").arg (g_filelist_full).ascii())));
    int curline = 0;
    FILE *fin  = fopen (QString ("%1.FILT").arg (g_filelist_full).ascii(), "r");
    FILE *fout = popen (QString ("sort -u > %1").arg (g_filelist_full).ascii(), "w");

    if (!(fin && fout)) {
	r->fStatusMsg->setText ("Can't open filelist");
	r->ok = false;
	return 0;
    }

    char line[4096], tmp[4096];
    while (fgets (line, 4096, fin)) {
	if (line[strlen (line) - 1] == '\n')
	    line[strlen (line) - 1] = '\0';
	
	for (int pos = 0; line[pos] != '\0'; pos++) {
	    if (line[pos] != '/') continue;
	    strcpy (tmp, line);
	    tmp[pos] = '\0';
	    if (strlen (tmp)) {
		fprintf (fout, "%s\n", tmp);
	    }
	}
	fprintf (fout, "%s\n", line);
	if (!(++curline % 1111)) {
	    r->fStatusMsg->setText (QString ("Preparing filelist - %1% done").arg (curline * 100 / nlines));
	}
    }

    fclose (fin);
    pclose (fout);
    
    if (XM_load_filelist (g_filelist_full, r->fList, r->fStatusMsg) != XMLF_OK) {
	r->fStatusMsg->setText ("Error loading filelist");
	r->ok = false;
	return 0;
    }
    r->fStatusMsg->setText ("Filelist loaded OK");

    r->doneSetup = true;
    r->fList->setEnabled (true);
    r->fRestoreDirLabel->setEnabled (true);
    r->fRestoreDir->setEnabled (true);
    sleep (1);
    r->fStatusMsg->setText ("Please select files and directories to be restored.");
    XMCheckListItem::progressDisplay = r->fStatusMsg;
    XMCheckListItem::doneSetup = &(r->doneSetup);

    return 0;
}
Example #20
0
bool retro_load_game(const struct retro_game_info *info)
{
   int ret;
   struct retro_input_descriptor desc[] = {
      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT,  "D-Pad Left" },
      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP,    "D-Pad Up" },
      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN,  "D-Pad Down" },
      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "B" },
      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L,     "C" },
      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y,     "X" },
      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B,     "A" },
      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X,     "Y" },
      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R,     "Z" },
      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2,    "L" },
      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2,    "R" },
      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
      { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" },
      { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" },

      { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT,  "D-Pad Left" },
      { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP,    "D-Pad Up" },
      { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN,  "D-Pad Down" },
      { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
      { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "B" },
      { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L,     "C" },
      { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y,     "X" },
      { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B,     "A" },
      { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X,     "Y" },
      { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R,     "Z" },
      { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2,    "L" },
      { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2,    "R" },
      { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
      { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" },
      { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" },

      { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT,  "D-Pad Left" },
      { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP,    "D-Pad Up" },
      { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN,  "D-Pad Down" },
      { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
      { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "B" },
      { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L,     "C" },
      { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y,     "X" },
      { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B,     "A" },
      { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X,     "Y" },
      { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R,     "Z" },
      { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2,    "L" },
      { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2,    "R" },
      { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
      { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" },
      { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" },

      { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT,  "D-Pad Left" },
      { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP,    "D-Pad Up" },
      { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN,  "D-Pad Down" },
      { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
      { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "B" },
      { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L,     "C" },
      { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y,     "X" },
      { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B,     "A" },
      { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X,     "Y" },
      { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R,     "Z" },
      { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2,    "L" },
      { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2,    "R" },
      { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
      { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" },
      { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" },

      { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT,  "D-Pad Left" },
      { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP,    "D-Pad Up" },
      { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN,  "D-Pad Down" },
      { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
      { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "B" },
      { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L,     "C" },
      { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y,     "X" },
      { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B,     "A" },
      { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X,     "Y" },
      { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R,     "Z" },
      { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2,    "L" },
      { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2,    "R" },
      { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
      { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" },
      { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" },

      { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT,  "D-Pad Left" },
      { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP,    "D-Pad Up" },
      { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN,  "D-Pad Down" },
      { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
      { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "B" },
      { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L,     "C" },
      { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y,     "X" },
      { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B,     "A" },
      { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X,     "Y" },
      { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R,     "Z" },
      { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2,    "L" },
      { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2,    "R" },
      { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
      { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" },
      { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" },

      { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT,  "D-Pad Left" },
      { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP,    "D-Pad Up" },
      { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN,  "D-Pad Down" },
      { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
      { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "B" },
      { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L,     "C" },
      { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y,     "X" },
      { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B,     "A" },
      { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X,     "Y" },
      { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R,     "Z" },
      { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2,    "L" },
      { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2,    "R" },
      { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
      { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" },
      { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" },

      { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT,  "D-Pad Left" },
      { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP,    "D-Pad Up" },
      { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN,  "D-Pad Down" },
      { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
      { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "B" },
      { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L,     "C" },
      { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y,     "X" },
      { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B,     "A" },
      { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X,     "Y" },
      { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R,     "Z" },
      { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2,    "L" },
      { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2,    "R" },
      { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
      { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" },
      { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" },

      { 8, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT,  "D-Pad Left" },
      { 8, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP,    "D-Pad Up" },
      { 8, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN,  "D-Pad Down" },
      { 8, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
      { 8, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "B" },
      { 8, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L,     "C" },
      { 8, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y,     "X" },
      { 8, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B,     "A" },
      { 8, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X,     "Y" },
      { 8, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R,     "Z" },
      { 8, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2,    "L" },
      { 8, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2,    "R" },
      { 8, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
      { 8, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" },
      { 8, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" },

      { 9, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT,  "D-Pad Left" },
      { 9, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP,    "D-Pad Up" },
      { 9, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN,  "D-Pad Down" },
      { 9, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
      { 9, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "B" },
      { 9, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L,     "C" },
      { 9, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y,     "X" },
      { 9, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B,     "A" },
      { 9, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X,     "Y" },
      { 9, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R,     "Z" },
      { 9, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2,    "L" },
      { 9, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2,    "R" },
      { 9, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
      { 9, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" },
      { 9, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" },

      { 10, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT,  "D-Pad Left" },
      { 10, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP,    "D-Pad Up" },
      { 10, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN,  "D-Pad Down" },
      { 10, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
      { 10, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "B" },
      { 10, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L,     "C" },
      { 10, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y,     "X" },
      { 10, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B,     "A" },
      { 10, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X,     "Y" },
      { 10, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R,     "Z" },
      { 10, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2,    "L" },
      { 10, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2,    "R" },
      { 10, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
      { 10, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" },
      { 10, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" },

      { 11, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT,  "D-Pad Left" },
      { 11, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP,    "D-Pad Up" },
      { 11, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN,  "D-Pad Down" },
      { 11, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
      { 11, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "B" },
      { 11, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L,     "C" },
      { 11, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y,     "X" },
      { 11, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B,     "A" },
      { 11, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X,     "Y" },
      { 11, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R,     "Z" },
      { 11, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2,    "L" },
      { 11, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2,    "R" },
      { 11, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
      { 11, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Analog X" },
      { 11, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Analog Y" },

      { 0 },
   };

   if (!info)
      return false;

   check_variables();

   snprintf(full_path, sizeof(full_path), "%s", info->path);

   environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);

   yinit.cdcoretype      = CDCORE_ISO;
   yinit.cdpath          = full_path;
   /* Emulate BIOS */
   yinit.biospath        = (bios_path[0] != '\0' && does_file_exist(bios_path) && !hle_bios_force) ? bios_path : NULL;
   yinit.percoretype     = PERCORE_LIBRETRO;
#ifdef SH2_DYNAREC
   yinit.sh2coretype     = 2;
#else
   yinit.sh2coretype     = SH2CORE_INTERPRETER;
#endif
   yinit.vidcoretype     = VIDCORE_SOFT;
   yinit.sndcoretype     = SNDCORE_LIBRETRO;
   yinit.m68kcoretype    = M68KCORE_C68K;
   yinit.carttype        = addon_cart_type;
   yinit.regionid        = REGION_AUTODETECT;
   yinit.buppath         = NULL;
   yinit.mpegpath        = NULL;
   yinit.videoformattype = VIDEOFORMATTYPE_NTSC;
   yinit.frameskip       = frameskip_enable;
   yinit.clocksync       = 0;
   yinit.basetime        = 0;
#ifdef HAVE_THREADS
   yinit.usethreads      = 1;
   yinit.numthreads      = numthreads;
#else
   yinit.usethreads      = 0;
#endif

   ret = YabauseInit(&yinit);
   YabauseSetDecilineMode(1);

   return !ret;
}
void
fatal_error_sub (char *error)
{
    static bool already_exiting = false;
    char tmp[MAX_STR_LEN];
    g_exiting = TRUE;

    log_it ("Fatal error received - '%s'", error);
    printf ("Fatal error... %s\n", error);
    if (getpid() == g_mastermind_pid)
	{   
	    log_it ("(FE) mastermind %d is exiting", (int)getpid());   
	    kill (g_main_pid, SIGTERM);
	    finish (1);
	}

    if (getpid() != g_main_pid)
	{   
	    if (g_mastermind_pid != 0 && getpid() != g_mastermind_pid)
		{    
		    log_it ("(FE) non-m/m %d is exiting", (int)getpid());   
		    kill (g_main_pid, SIGTERM);
		    finish (1);
		}

	    if (getpid() != g_main_pid)
		{		    
		    log_it ("(FE) aux pid %d is exiting", (int)getpid());   
		    kill (g_main_pid, SIGTERM);
		    finish (1);
		}
	}

    log_it ("OK, I think I'm the main PID.");
    if (already_exiting)
	{
	    log_it ("...I'm already exiting. Give me time, Julian!");   
	    finish (1);
	}

    already_exiting = TRUE;
    log_it ("I'm going to do some cleaning up now.");
    kill_anything_like_this ("mondoarchive");
    kill_anything_like_this ("/mondo/do-not");
    kill_anything_like_this ("tmp.mondo");
    sync();
    
    sprintf (tmp, "umount %s", g_tmpfs_mountpt);
    chdir ("/");
    for(int i=0; i<10 && run_program_and_log_output (tmp, TRUE); i++)
	{
	    log_it ("Waiting for child processes to terminate");   
	    sleep (1);
	    run_program_and_log_output (tmp, TRUE);
	}

    if (g_erase_tmpdir_and_scratchdir[0])
	{
	    run_program_and_log_output (g_erase_tmpdir_and_scratchdir, TRUE);
	}

    QMessageBox::critical (0, "XMondo", QString ("<font color=\"red\"><b>FATAL ERROR</b></font><br>%1").arg (error),
												 "Quit", 0, 0, 0, 0);
    kapp->quit();
    printf ("---FATAL ERROR--- %s\n", error);
    system ("cat /var/log/mondo-archive.log | gzip -9 > /tmp/MA.log.gz 2> /dev/null");
    printf ("If you require technical support, please contact the mailing list.\n");
    printf ("See http://www.mondorescue.org for details.\n");
    printf ("Log file: %s\n", MONDO_LOGFILE);
    
    if (does_file_exist ("/tmp/MA.log.gz"))
	{
	    printf ("FYI, I have gzipped the log and saved it to /tmp/MA.log.gz\n");
	    printf ("The list's members can help you, if you attach that file to your e-mail.\n");
	}
    
    printf ("Mondo has aborted.\n");
    register_pid (0, "mondo");
    
    if (!g_main_pid) {
	log_it ("FYI - g_main_pid is blank");
    }
    
    finish (254);
    /*NOTREACHED*/
}
Example #22
0
int backup_client(char*ipaddr, int port, char*clientpath)
/*
Purpose:Backup the path of a specific client. Receive
the archives. Store them locally (on me, the server).
Params:	clientno - client# in g_clientlist[]
        clientpath - client's path to be backed up
Return: result (0=success, nonzero=failure)
*/
{
  struct s_server2client_msg_record rec_to_client;
  int res=0, socket_fd, noof_archives, i, len;
  char tmp[MAX_STR_LEN+1], outfile[MAX_STR_LEN+1];
  FILE*fout;

  log_it(info, "%s - backup of %s commencing", ipaddr, clientpath);
  sprintf(outfile, "/var/spool/monitas/%s/%lu.dat", ipaddr, time(NULL));
  if (does_file_exist(outfile)) { log_it(error, "Backup storage location '%s' exists already. That should be impossible.", outfile); return(1); }
  if (make_hole_for_file(outfile))
    { res++; log_it(error, "Cannot write archive to spool dir '%s'", outfile); }
  else if (!(fout=fopen(outfile, "w")))
    { res++; log_it(fatal, "Failed to openout temp data file '%s'", outfile); }
  else
    {
      log_it(debug, "Backing up %s - archive=%s", ipaddr, outfile);
      rec_to_client.msg_type = trigger_backup;
      strncpy(rec_to_client.body, clientpath, sizeof(rec_to_client.body));
      if (send_msg_to_client(&rec_to_client, ipaddr, port, &socket_fd))
        { log_it(error, "backup_client - failed to send msg to client"); return(1); }
      res += receive_file_from_socket(fout, socket_fd);
      len=read(socket_fd, (char*)&i, sizeof(i));
      if (!len) { res++; log_it(error, "Client hasn't told me the result of its call to mondoarchive"); }
      else if (len!=sizeof(i)) { res++; log_it(error, "Client didn't sent _entire_ result of its call to mondoarchive"); }
      else if (i) { res++; log_it(error, "Client said, mondoarchive returned an error."); }
      else { log_it(debug, "Client said, mondoarchive returned OK"); }
      fclose(fout);
      close(socket_fd);
    }
/* Shuffle older backups off the mortal coil. Leave maximum of 4 backup files in /var/spool/monitas/[ipaddr] */
  sprintf(tmp, "find /var/spool/monitas/%s -type f 2> /dev/null | grep -n \"\" | tail -n1 | cut -d':' -f1", ipaddr);
  noof_archives = atoi(call_program_and_get_last_line_of_output(tmp));
  i = noof_archives - 3;
  if (i>0)
    {
      sprintf(tmp, "rm -f `find /var/spool/monitas/%s -type f | sort | head -n%d`", ipaddr, i);
      call_program_and_log_output(tmp);
    }
/* Return success/failure value */
  if (res>0)
    {
      log_it(error, "%s - error(s) occurred while backing up %s", ipaddr, clientpath);
      rec_to_client.msg_type = backup_fail;
      sprintf(rec_to_client.body, "Failed to backup %s", clientpath);
      log_it(debug, rec_to_client.body);
      unlink(outfile);
    }
  else
    {
      log_it(info, "%s - backed up %s ok", ipaddr, clientpath);
      rec_to_client.msg_type = backup_ok;
      sprintf(rec_to_client.body, "%s - backed up ok", clientpath);
      log_it(debug, rec_to_client.body);
    }
  if (send_msg_to_client(&rec_to_client, ipaddr, port, &socket_fd))
    {
      res++;
      log_it(error, "Unable to notify %s of backup success/failure", ipaddr);
      i = find_client_in_clientlist(ipaddr);
      if (i>=0) { forcibly_logout_client(i); }
      log_it(info, "I'm assuming the backup was bad because the client cannot be reached.");
      unlink(outfile);
    }
  return(res);
}
/**
 * Run a program and log its output to the screen.
 * @param basic_call The program to run.
 * @param what_i_am_doing The title of the evalcall form.
 * @return The return value of the command (varies, but 0 almost always means success).
 * @see run_program_and_log_output
 * @see log_to_screen
 */
int run_program_and_log_to_screen(char *basic_call, char *what_i_am_doing)
{
	/*@ int ******************************************************** */
	int retval = 0;
	int res = 0;
	int i;

	/*@ pointers **************************************************** */
	FILE *fin;

	/*@ buffers **************************************************** */
	char tmp[MAX_STR_LEN * 2];
	char command[MAX_STR_LEN * 2];
	char lockfile[MAX_STR_LEN];

	/*@ end vars *************************************************** */

	assert_string_is_neither_NULL_nor_zerolength(basic_call);

	sprintf(lockfile, "/tmp/mojo-jojo.blah.XXXXXX");
	mkstemp(lockfile);
	sprintf(command,
			"echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res",
			lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile);
	open_evalcall_form(what_i_am_doing);
	sprintf(tmp, "Executing %s", basic_call);
	log_msg(2, tmp);
	if (!(fin = popen(command, "r"))) {
		log_OS_error("Unable to popen-in command");
		sprintf(tmp, "Failed utterly to call '%s'", command);
		log_to_screen(tmp);
		return (1);
	}
	if (!does_file_exist(lockfile)) {
		log_to_screen("Waiting for external binary to start");
		for (i = 0; i < 60 && !does_file_exist(lockfile); sleep(1), i++) {
			log_msg(3, "Waiting for lockfile %s to exist", lockfile);
		}
	}
#ifdef _XWIN
	/* This only can update when newline goes into the file,
	   but it's *much* prettier/faster on Qt. */
	while (does_file_exist(lockfile)) {
		while (!feof(fin)) {
			if (!fgets(tmp, 512, fin))
				break;
			log_to_screen(tmp);
		}
		usleep(500000);
	}
#else
	/* This works on Newt, and it gives quicker updates. */
	for (; does_file_exist(lockfile); sleep(1)) {
		log_file_end_to_screen(MONDO_LOGFILE, "");
		update_evalcall_form(1);
	}
#endif
	/* Evaluate the status returned by pclose to get the exit code of the called program. */
	errno = 0;
	res = pclose(fin);
	/* Log actual pclose errors. */
	if (errno) log_msg(5, "pclose err: %d", errno);
	/* Check if we have a valid status. If we do, extract the called program's exit code. */
	/* If we don't, highlight this fact by returning -1. */
	if (WIFEXITED(res)) {
		retval = WEXITSTATUS(res);
	} else {
		retval = -1;
	}
	close_evalcall_form();
	unlink(lockfile);
	return (retval);
}
/**
 * Exit Mondo with a fatal error.
 * @param error_string The error message to present to the user before exiting.
 * @note This function never returns.
 */
	void
	 fatal_error(char *error_string) {
		/*@ buffers ***************************************************** */
		char *fatalstr;
		char *tmp;
		char *command;
		static bool already_exiting = FALSE;
		int i;

		/*@ end vars **************************************************** */

		asprintf(&fatalstr, "-------FATAL ERROR---------");
		set_signals(FALSE);		// link to external func
		g_exiting = TRUE;
		log_msg(1, "%s - '%s'", fatalstr, error_string);
		printf("%s - %s\n", fatalstr, error_string);
		if (getpid() == g_mastermind_pid) {
			log_msg(2, "mastermind %d is exiting", (int) getpid());
			kill(g_main_pid, SIGTERM);
			finish(1);
		}

		if (getpid() != g_main_pid) {
			if (g_mastermind_pid != 0 && getpid() != g_mastermind_pid) {
				log_msg(2, "non-m/m %d is exiting", (int) getpid());
				kill(g_main_pid, SIGTERM);
				finish(1);
			}
		}

		log_msg(3, "OK, I think I'm the main PID.");
		if (already_exiting) {
			log_msg(3, "...I'm already exiting. Give me time, Julian!");
			finish(1);
		}

		already_exiting = TRUE;
		log_msg(2, "I'm going to do some cleaning up now.");
		paranoid_system("killall mindi 2> /dev/null");
		kill_anything_like_this("/mondo/do-not");
		kill_anything_like_this("mondo.tmp");
		kill_anything_like_this("ntfsclone");
		sync();
		asprintf(&tmp, "umount %s", g_tmpfs_mountpt);
		chdir("/");
		for (i = 0; i < 10 && run_program_and_log_output(tmp, 5); i++) {
			log_msg(2, "Waiting for child processes to terminate");
			sleep(1);
			run_program_and_log_output(tmp, 5);
		}
		paranoid_free(tmp);

		if (g_erase_tmpdir_and_scratchdir) {
			run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 5);
		}

		if (g_selfmounted_isodir) {
			asprintf(&command, "umount %s", g_selfmounted_isodir);
			run_program_and_log_output(command, 5);
			asprintf(&command, "rmdir %s", g_selfmounted_isodir);
			run_program_and_log_output(command, 5);
		}

		if (!g_text_mode) {
			log_msg(0, fatalstr);
			log_msg(0, error_string);
			//      popup_and_OK (error_string);
			newtFinished();
		}

		system
			("gzip -9c "MONDO_LOGFILE" > /tmp/MA.log.gz 2> /dev/null");
		printf
				(_("If you require technical support, please contact the mailing list.\n"));
		printf(_("See http://www.mondorescue.org for details.\n"));
		printf
				(_("The list's members can help you, if you attach that file to your e-mail.\n"));
		printf(_("Log file: %s\n"), MONDO_LOGFILE);
		if (does_file_exist("/tmp/MA.log.gz")) {
			printf
				(_("FYI, I have gzipped the log and saved it to /tmp/MA.log.gz\n"));
		}
		printf(_("Mondo has aborted.\n"));
		register_pid(0, "mondo");	// finish() does this too, FYI
		if (!g_main_pid) {
			log_msg(3, "FYI - g_main_pid is blank");
		}
		finish(254);
	}
/**
 * Load @p source_file (a list of files) into @p filelist. There can be no more than
 * @p ARBITRARY_MAXIMUM entries.
 * @param filelist The filelist structure to load @p source_file into.
 * @param source_file The file containing a list of filenames to load into @p filelist.
 */
	int load_filelist_into_array(struct s_filelist *filelist,
								 char *source_file) {
		int i;
		bool done;
		char *reason = NULL;
		char *tmp = NULL;
		size_t n = 0;
		FILE *fin;
		struct s_filelist_entry dummy_fle;

		assert(filelist != NULL);
		assert_string_is_neither_NULL_nor_zerolength(source_file);

		iamhere("entering");
		if (!(fin = fopen(source_file, "r"))) {
			log_OS_error(source_file);
			log_msg(2, "Can't open %s; therefore, cannot popup list",
					source_file);
			return (1);
		}
		log_msg(2, "Loading %s", source_file);
		for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM;
			 filelist->entries++) {
			if (feof(fin)) {
				break;
			}
			(void) getline(&tmp, &n, fin);
			i = (int) strlen(tmp);
			if (i < 2) {
				if (feof(fin)) {
					break;
				}
			}
			if (tmp[i - 1] < 32) {
				tmp[--i] = '\0';
			}
			if (i < 2) {
				if (feof(fin)) {
					break;
				}
			}
			if (!does_file_exist(tmp)) {
				if (feof(fin)) {
					break;
				}
			}
			filelist->el[filelist->entries].severity =
				severity_of_difference(tmp, reason);
			paranoid_free(reason);
			strcpy(filelist->el[filelist->entries].filename, tmp);
			if (feof(fin)) {
				break;
			}
		}
		paranoid_fclose(fin);
		if (filelist->entries >= ARBITRARY_MAXIMUM) {
			log_to_screen(_("Arbitrary limits suck, man!"));
			paranoid_free(tmp);
			return (1);
		}
		paranoid_free(tmp);

		for (done = FALSE; !done;) {
			done = TRUE;
			for (i = 0; i < filelist->entries - 1; i++) {
//          if (strcmp(filelist->el[i].filename, filelist->el[i+1].filename) > 0)
				if (filelist->el[i].severity < filelist->el[i + 1].severity
					|| (filelist->el[i].severity ==
						filelist->el[i + 1].severity
						&& strcmp(filelist->el[i].filename,
								  filelist->el[i + 1].filename) > 0)) {
					memcpy((void *) &dummy_fle,
						   (void *) &(filelist->el[i]),
						   sizeof(struct s_filelist_entry));
					memcpy((void *) &(filelist->el[i]),
						   (void *) &(filelist->el[i + 1]),
						   sizeof(struct s_filelist_entry));
					memcpy((void *) &(filelist->el[i + 1]),
						   (void *) &dummy_fle,
						   sizeof(struct s_filelist_entry));
					log_msg(2, "Swapping %s and %s",
							filelist->el[i].filename,
							filelist->el[i + 1].filename);
					done = FALSE;
				}
			}
		}
		iamhere("leaving");
		return (0);
	}
/**
 * Compare biggiefile number @p bigfileno with the filesystem mounted on @p MNT_RESTORING.
 * @param bkpinfo The backup information structure. Only used in insist_on_this_cd_number().
 * @param bigfileno The biggiefile number (starting from 0) to compare.
 * @note This function uses an MD5 checksum.
 */
int compare_a_biggiefile(struct s_bkpinfo *bkpinfo, long bigfileno)
{

	FILE *fin;
	FILE *fout;

  /** needs malloc *******/
	char *checksum_ptr;
	char *original_cksum_ptr;
	char *bigfile_fname_ptr;
	char *tmp_ptr;
	char *command_ptr;

	char *checksum, *original_cksum, *bigfile_fname, *tmp, *command;

	char *p;
	int i;
	int retval = 0;

	struct s_filename_and_lstat_info biggiestruct;

	malloc_string(checksum);
	malloc_string(original_cksum);
	malloc_string(bigfile_fname);
	malloc_string(tmp);
	malloc_string(command);
	malloc_string(checksum_ptr);
	malloc_string(original_cksum_ptr);
	malloc_string(bigfile_fname_ptr);
	malloc_string(command_ptr);
	malloc_string(tmp_ptr);

  /*********************************************************************
   * allocate memory clear test                sab 16 feb 2003         *
   *********************************************************************/
	assert(bkpinfo != NULL);
	memset(checksum_ptr, '\0', sizeof(checksum));
	memset(original_cksum_ptr, '\0', sizeof(original_cksum));
	memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));
	memset(tmp_ptr, '\0', sizeof(tmp));
	memset(command_ptr, '\0', sizeof(command));
  /** end **/

	if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
		if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
			insist_on_this_cd_number(bkpinfo, (++g_current_media_number));
		} else {
			sprintf(tmp_ptr,
					"No CD's left. No biggiefiles left. No prob, Bob.");
			log_msg(2, tmp_ptr);
			return (0);
		}
	}
	if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
		sprintf(tmp_ptr,
				"Cannot open bigfile %ld (%s)'s info file",
				bigfileno + 1, bigfile_fname_ptr);
		log_to_screen(tmp_ptr);
		return (1);
	}
	fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin);
	paranoid_fclose(fin);

	strcpy(checksum_ptr, biggiestruct.checksum);
	strcpy(bigfile_fname_ptr, biggiestruct.filename);

	log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename);
	log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum);

	sprintf(tmp_ptr, "Comparing %s", bigfile_fname_ptr);

	if (!g_text_mode) {
		newtDrawRootText(0, 22, tmp_ptr);
		newtRefresh();
	}
	if (!checksum[0]) {
		log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr);
	}
	if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) {
		strcpy(original_cksum_ptr, "IGNORE");
	} else {
		sprintf(command_ptr,
				"md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors.txt",
				MNT_RESTORING, bigfile_fname_ptr);
	}
	log_msg(2, command_ptr);
	paranoid_system
		("cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null");
	if (system(command_ptr)) {
		log_OS_error("Warning - command failed");
		original_cksum[0] = '\0';
		return (1);
	} else {
		if (!(fin = fopen("/tmp/md5sum.txt", "r"))) {
			log_msg(2,
					"Unable to open /tmp/md5sum.txt; can't get live checksum");
			original_cksum[0] = '\0';
			return (1);
		} else {
			fgets(original_cksum_ptr, MAX_STR_LEN - 1, fin);
			paranoid_fclose(fin);
			for (i = strlen(original_cksum_ptr);
				 i > 0 && original_cksum[i - 1] < 32; i--);
			original_cksum[i] = '\0';
			p = (char *) strchr(original_cksum_ptr, ' ');
			if (p) {
				*p = '\0';
			}
		}
	}
	sprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1,
			bigfile_fname_ptr);
	if (!strcmp(checksum_ptr, original_cksum_ptr) != 0) {
		strcat(tmp_ptr, " ... OK");
	} else {
		strcat(tmp_ptr, "... changed");
		retval++;
	}
	log_msg(1, tmp_ptr);
	if (retval) {
		if (!(fout = fopen("/tmp/changed.txt", "a"))) {
			fatal_error("Cannot openout changed.txt");
		}
		fprintf(fout, "%s\n", bigfile_fname_ptr);
		paranoid_fclose(fout);
	}

	paranoid_free(original_cksum_ptr);
	paranoid_free(original_cksum);
	paranoid_free(bigfile_fname_ptr);
	paranoid_free(bigfile_fname);
	paranoid_free(checksum_ptr);
	paranoid_free(checksum);
	paranoid_free(command_ptr);
	paranoid_free(command);
	paranoid_free(tmp_ptr);
	paranoid_free(tmp);

	return (retval);
}
int run_external_binary_with_percentage_indicator_OLD(char *tt, char *cmd)
{

	/*@ int *************************************************************** */
	int res = 0;
	int percentage = 0;
	int maxpc = 0;
	int pcno = 0;
	int last_pcno = 0;

	/*@ buffers *********************************************************** */
	char *command;
	char *tempfile;
	char *title;
	/*@ pointers ********************************************************** */
	FILE *pin;

	malloc_string(title);
	malloc_string(command);
	malloc_string(tempfile);
	assert_string_is_neither_NULL_nor_zerolength(cmd);
	assert_string_is_neither_NULL_nor_zerolength(title);

	strcpy(title, tt);
	strcpy(tempfile,
		   call_program_and_get_last_line_of_output
		   ("mktemp -q /tmp/mondo.XXXXXXXX"));
	sprintf(command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
			tempfile);
	log_msg(3, command);
	open_evalcall_form(title);
	if (!(pin = popen(command, "r"))) {
		log_OS_error("fmt err");
		return (1);
	}
	maxpc = 100;
// OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
	for (sleep(1); does_file_exist(tempfile); sleep(1)) {
		pcno = grab_percentage_from_last_line_of_file(MONDO_LOGFILE);
		if (pcno < 0 || pcno > 100) {
			log_msg(5, "Weird pc#");
			continue;
		}
		percentage = pcno * 100 / maxpc;
		if (pcno <= 5 && last_pcno > 40) {
			close_evalcall_form();
			strcpy(title, "Verifying...");
			open_evalcall_form(title);
		}
		last_pcno = pcno;
		update_evalcall_form(percentage);
	}
// OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
	close_evalcall_form();
	if (pclose(pin)) {
		res++;
		log_OS_error("Unable to pclose");
	}
	unlink(tempfile);
	paranoid_free(command);
	paranoid_free(tempfile);
	paranoid_free(title);
	return (res);
}
Example #28
0
void Run(Box& box, int argc, char *argv[])
{
	Real membrane_l_eq = Particle::sigma_m + 13*Particle::A_p*(Particle::repulsion_radius_m - Particle::sigma_m)/(input_membrane_elasticity*Particle::sigma_m + 13*Particle::A_p);
	membrane_l_eq = Particle::repulsion_radius_m;
	int input_Nm = (int) round(M_PI/asin(0.5*membrane_l_eq/input_membrane_radius));
//	int input_Ns = (int) round(input_packing_fraction/( input_chain_length*sin(M_PI/input_Nm)*sin(M_PI/input_Nm) ));
	int input_Ns = (int) round(M_PI * input_cover_fraction * Particle::sigma_p * (1 / sin(M_PI/input_Nm/Particle::repulsion_radius_m)  - 2*Particle::sigma_p ));

	bool FROM_FILE = false;
	string name;
	if (argc == 7)
	{
		name = argv[6];
		FROM_FILE = true;
	}

	Real t_eq,t_sim;

//	Particle::lambda = 0.1; // tumbling rate
//	Particle::t_tumble = 0.1/Particle::lambda; // tumbling duration
//	Particle::torque_tumble = 0.2; // torque strength of a tumble


	Particle::Set_Dr(1.0/8);
	Particle::Set_separation(1.0/(input_chain_length-1));

// The following must be before box.init
	for (int i = 0; i < input_Nm; i++)
	{
		box.particle[i].Set_nb(1);
		box.particle[i].Set_F0(0.0);
		box.particle[i].Set_R0(input_chiral_radius);
	}
	for (int i = input_Nm; i < input_Ns+input_Nm; i++)
	{
		box.particle[i].Set_nb(input_chain_length);
		box.particle[i].Set_F0(1.0);
		box.particle[i].Set_R0(input_chiral_radius);
//		box.particle[i].Set_Parameters(input_chain_length,1.0);
	}

	box.Init(input_Ns, input_Nm);
	box.membrane_elasticity = input_membrane_elasticity;
	box.membrane_radius = input_membrane_radius;
	box.packing_fraction = input_packing_fraction;
	box.cover_fraction = input_cover_fraction;

	box.info.str("");
	box.info << "k="<< box.membrane_elasticity;
	box.info << "-R="<< box.membrane_radius;
	box.info << "-r=" << Particle::R0;
	box.info << "-psi=" << box.cover_fraction;
	box.info << "-Dr=" << Particle::Dr;
	box.info << "-seed=" << input_seed;
	box.info << "-ABP";

	ofstream out_file;
	ofstream variables_file;

	stringstream traj_address;
	traj_address.str("");
	traj_address << "r-v-" << box.info.str() << ".bin";


	stringstream quant_address;
	quant_address.str("");
	quant_address << "quantities-" << box.info.str() << ".dat";


	if (FROM_FILE)
	{
		box.Positioning_Particles(traj_address.str());
		out_file.open(traj_address.str().c_str(), ios::out | ios::app | ios::binary);
		variables_file.open(quant_address.str().c_str(), ios::out | ios::app | ios::binary);
	}
	else
	{
		if (does_file_exist(traj_address.str().c_str()))
		{
			box.Positioning_Particles(traj_address.str());
			out_file.open(traj_address.str().c_str(), ios::out | ios::app | ios::binary);
			variables_file.open(quant_address.str().c_str(), ios::out | ios::app | ios::binary);
		}
		else
		{
			Ring_Membrane(box.particle, Particle::repulsion_radius_m, box.Nm);
			Confined_In_Ring_Membrane(box.particle, Particle::repulsion_radius_m, box.Ns, box.Nm);
			for (int i = 0; i < box.Ns; i++)
				box.particle[i].r_original = box.particle[i].r;
			out_file.open(traj_address.str().c_str());
			variables_file.open(quant_address.str().c_str());
		}
	}

	box.Sync();

	cout << " Box information is: " << box.info.str() << endl;

	cout << box.particle[184].m_parallel << "\t" << box.particle[184].m_perpendicular << "\t" << box.particle[184].k_perpendicular << endl;
	cout << box.particle[184].torque0 << "\t" << box.particle[184].F0 << "\t" << box.particle[184].R0 << endl;

	int quantities_saving_period = ( (int) round(1.0/dt) ) / cell_update_period;
	t_sim = data_gathering(&box, total_step, saving_period, quantities_saving_period, out_file, variables_file);

	cout << " Done in " << (t_sim / 60.0) << " minutes" << endl;
	out_file.close();
}
Example #29
0
int serveconnection(int sockfd)
{
	FILE *in;
	char tempdata[8192], *ptr, *ptr2, *host_ptr1, *host_ptr2;
	char tempstring[8192], mimetype[50];
	char filename[255];
	unsigned int loop=0, flag=0;
	int numbytes=0;
	struct sockaddr_in sa;
	int addrlen = sizeof(struct sockaddr_in);
	t_vhost *thehost;
	
	thehost = &defaulthost;

// tempdata is the full header, tempstring is just the command

	while(!strstr(tempdata, "\r\n\r\n") && !strstr(tempdata, "\n\n"))
	{	
		if((numbytes=recv(sockfd, tempdata+numbytes, 4096-numbytes, 0))==-1)
			return -1;
	}
	for(loop=0; loop<4096 && tempdata[loop]!='\n' && tempdata[loop]!='\r'; loop++)
		tempstring[loop] = tempdata[loop];
	
	tempstring[loop] = '\0';
	ptr = strtok(tempstring, " ");
	if(ptr == 0) return -1;
	if(strcmp(ptr, "GET")) 
	{
		strcpy(filename, SERVERROOT);
		strcat(filename, "/cmderror.html");
		goto sendpage;
	}
	ptr = strtok(NULL, " ");
	if(ptr == NULL)
	{
		strcpy(filename, SERVERROOT);
		strcat(filename, "/cmderror.html");
		goto sendpage;
	}

	host_ptr1 = strstr(tempdata, "Host:");
	if(host_ptr1)
	{
		host_ptr2 = strtok(host_ptr1+6, " \r\n\t");
		
		for(loop=0; loop<no_vhosts; loop++)
			if(!gstricmp(vhosts[loop].host, host_ptr2))
				thehost = &vhosts[loop];
	}	
	else
		thehost = &defaulthost;
	if(strstr(ptr, "/.."))
	{
		strcpy(filename, SERVERROOT);
		strcat(filename, "/404.html");
		goto sendpage;
	}

	getpeername(sockfd, (struct sockaddr *)&sa, &addrlen);
	Log("Connection from %s, request = \"GET %s\"", inet_ntoa(sa.sin_addr), ptr);

	if(!strncmp(ptr, thehost->CGIBINDIR, strlen(thehost->CGIBINDIR)))
	{/* Trying to execute a cgi-bin file ? lets check */
		ptr2 = strstr(ptr, "?");
		if(ptr2!=NULL) { ptr2[0] = '\0'; flag = 1; }

		strcpy(filename, thehost->CGIBINROOT);
		ptr += strlen(thehost->CGIBINDIR);
		strcat(filename, ptr);

		// Filename = program to execute
		// ptr = filename in cgi-bin dir
		// ptr2+1 = parameters

		if(does_file_exist(filename)==TRUE && isDirectory(filename)==FALSE)
		{
			if(send(sockfd, "HTTP/1.1 200 OK\n", 16, 0)==-1)
			{
				fclose(in);
				return -1;
			}
			if(send(sockfd, "Server: "SERVERNAME"\n", strlen("Server: "SERVERNAME"\n"), 0)==-1)
			{
				fclose(in);
				return -1;
			}
			
			// Is a CGI-program that needs executing
			if(0 != dup2(sockfd, 0) || 1 != dup2(sockfd, 1))
				return -1;

			setbuf(stdin, 0);
			setbuf(stdout, 0);
			if(flag==1) setenv("QUERY_STRING", ptr2+1, 1);
			
			chdir(thehost->CGIBINROOT);
			
			execl(filename, "");
		}
		strcpy(filename, SERVERROOT);
		strcat(filename, "/cgierror.html");
		goto sendpage;
	}	

	strcpy(filename, thehost->DOCUMENTROOT);
	strcat(filename, ptr);
	      
	if(does_file_exist(filename)==FALSE)
	{		
		if(filename[strlen(filename)-1] == '/')
			strcat(filename, thehost->DEFAULTPAGE);
		else
		{
			strcat(filename, "/");
			strcat(filename, thehost->DEFAULTPAGE);
		}
		if(does_file_exist(filename) == FALSE)
		{
			filename[strlen(filename)-strlen(thehost->DEFAULTPAGE)-1] = '\0'; // Get rid of the /index.. 
			if(isDirectory(filename) == TRUE) { showdir(filename, sockfd, thehost); return 0; }
	
			// File does not exist, so we need to display the 404 error page..
			strcpy(filename, SERVERROOT);
			strcat(filename, "/404.html");
		}	
	
	}
sendpage:
	if((in = fopen(filename, "rb"))==NULL)
		return -1;
	
	fseek(in, 0, SEEK_END);
	
	if(send(sockfd, "HTTP/1.1 200 OK\n", 16, 0)==-1)
	{
		fclose(in);
		return -1;
	}
	if(send(sockfd, "Server: "SERVERNAME"\n", strlen("Server: "SERVERNAME"\n"), 0)==-1)
	{
		fclose(in);
		return -1;
	}
	sprintf(tempstring, "Content-Length: %d\n", ftell(in));
	if(send(sockfd, tempstring, strlen(tempstring), 0)==-1)
	{
		fclose(in);
		return -1;
	}

	getmimetype(filename, mimetype);
	sprintf(tempstring, "Content-Type: %s\n\n", mimetype);
	if(send(sockfd, tempstring, strlen(tempstring), 0)==-1)
	{
		fclose(in);
		return -1;
	}
	
	fseek(in, 0, SEEK_SET);

	while(!feof(in))
	{
		numbytes = fread(tempdata, 1, 1024, in);
		if(send(sockfd, tempdata, numbytes, 0)==-1)
		{
			fclose(in);
			return -1;
		}
	}
	fclose(in);

	close(sockfd);	
	return 0;
}
/**
 * Compare all afioballs in this backup.
 * @param bkpinfo The backup media structure. Passed to other functions.
 * @return 0 for success, nonzero for failure.
 */
int compare_all_tarballs(struct s_bkpinfo *bkpinfo)
{
	int retval = 0;
	int res;
	int current_tarball_number = 0;

  /**  needs malloc **********/

	char *tarball_fname, *progress_str, *tmp;
	long max_val;

	malloc_string(tarball_fname);
	malloc_string(progress_str);
	malloc_string(tmp);

	assert(bkpinfo != NULL);
	mvaddstr_and_log_it(g_currentY, 0, "Comparing archives");
	read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);

	max_val = atol(tmp);
	sprintf(progress_str, "Comparing with %s #%d ",
			media_descriptor_string(bkpinfo->backup_media_type),
			g_current_media_number);

	open_progress_form("Comparing files",
					   "Comparing tarballs against filesystem.",
					   "Please wait. This may take some time.",
					   progress_str, max_val);

	log_to_screen(progress_str);

	for (;;) {
		insist_on_this_cd_number(bkpinfo, g_current_media_number);
		update_progress_form(progress_str);
		sprintf(tarball_fname,
				MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number);

		if (!does_file_exist(tarball_fname)) {
			sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo",
					current_tarball_number);
		}
		if (!does_file_exist(tarball_fname)) {
			sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.",
					current_tarball_number);
		}
		if (!does_file_exist(tarball_fname)) {
			sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2",
					current_tarball_number);
		}
		if (!does_file_exist(tarball_fname)) {
			sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.",
					current_tarball_number);
		}
		if (!does_file_exist(tarball_fname)) {
			if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST") ||
				system("find " MNT_CDROM
					   "/archives/slice* > /dev/null 2> /dev/null")
				== 0) {
				log_msg(2, "OK, I think I'm done with tarballs...");
				break;
			}
			log_msg(2, "OK, I think it's time for another CD...");
			g_current_media_number++;
			sprintf(progress_str, "Comparing with %s #%d ",
					media_descriptor_string(bkpinfo->backup_media_type),
					g_current_media_number);
			log_to_screen(progress_str);
		} else {
			res = compare_a_tarball(tarball_fname, current_tarball_number);

			g_current_progress++;
			current_tarball_number++;
		}
	}
	close_progress_form();
	if (retval) {
		mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
	} else {
		mvaddstr_and_log_it(g_currentY++, 74, "Done.");
	}
	paranoid_free(tarball_fname);
	paranoid_free(progress_str);
	paranoid_free(tmp);
	return (retval);
}