void mMessageHandler(QtMsgType type, const char *msg)
{
    if (type < g_debug_level)
        return;

    if (type == QtDebugMsg || type == QtWarningMsg) {
        if (g_has_debug_whitelist) {
            QString msg_string(msg);
            bool passed(false);

            foreach(const QString & prefix, g_debug_prefixes) {
                if (msg_string.startsWith(prefix)) {
                    passed = true;
                    break;
                }
            }

            if (!passed)
                return;
        } else if (g_has_debug_blacklist) { // black list
            QString msg_string(msg);
            foreach(const QString & prefix, g_debug_prefixes) {
                if (msg_string.startsWith(prefix))
                    return;
            }
        }
    }
Exemplo n.º 2
0
Arquivo: run.c Projeto: ryo/netbsd-src
static void
log_menu_label(menudesc *m, int opt, void *arg)
{
	wprintw(m->mw, "%s: %s",
		msg_string(opt ? MSG_Scripting : MSG_Logging),
		msg_string((opt ? script != NULL : logfp != NULL) ?
		    MSG_On : MSG_Off));
}
Exemplo n.º 3
0
static void
set_config(menudesc *menu, int opt, void *arg)
{
	configinfo	**configp = arg;
	configinfo	*config = configp[opt];
	const char	*optname, *setting;

	optname = config->optname;
	setting = msg_string(config->setting);

	wprintw(menu->mw, "%-50s %-10s", msg_string(optname), setting);
}
Exemplo n.º 4
0
/*
 * Unpacks sets,  clobbering existing contents.
 */
void
do_reinstall_sets(void)
{
    int retcode = 0;

    unwind_mounts();
    msg_display(MSG_reinstallusure);
    if (!ask_noyes(NULL))
        return;

    if (find_disks(msg_string(MSG_reinstall)) < 0)
        return;

    if (mount_disks() != 0)
        return;

    /* Unpack the distribution. */
    process_menu(MENU_distset, &retcode);
    if (retcode == 0)
        return;
    if (get_and_unpack_sets(0, NULL, MSG_unpackcomplete, MSG_abortunpack) != 0)
        return;

    sanity_check();
}
Exemplo n.º 5
0
void
set_sizemultname_meg(void)
{

	sizemult = MEG / sectorsize;
	multname = msg_string(MSG_megname);
}
Exemplo n.º 6
0
void
set_sizemultname_cyl(void)
{

	sizemult = dlcylsize;
	multname = msg_string(MSG_cylname);
}
Exemplo n.º 7
0
static void
disp_sector_count(menudesc *m, msg fmt, uint s)
{
	uint ms = MEG / pm->sectorsize;

	wprintw(m->mw, msg_string(fmt),
		s / ms, s / pm->dlcylsize, s % pm->dlcylsize ? '*' : ' ', s );
}
Exemplo n.º 8
0
/* Ask for a partition offset, check bounds and do the needed roundups */
static uint32_t
getpartoff(uint32_t defpartstart)
{
	char defsize[20], isize[20], maxpartc;
	uint32_t i;
	uint32_t localsizemult;
	int partn;
	const char *errmsg = "\n";

	maxpartc = 'a' + getmaxpartitions() - 1;
	for (;;) {
		snprintf(defsize, sizeof defsize, "%d", defpartstart/sizemult);
		msg_prompt_win(MSG_label_offset, -1, 13, 70, 9,
		    (defpartstart > 0) ? defsize : NULL, isize, sizeof isize,
		    errmsg, maxpartc, maxpartc, multname);
		if (strcmp(defsize, isize) == 0)
			/* Don't do rounding if default accepted */
			return defpartstart;
		if (isize[1] == '\0' && isize[0] >= 'a' &&
		    isize[0] <= maxpartc) {
			partn = isize[0] - 'a';
			i = pm->bsdlabel[partn].pi_size + pm->bsdlabel[partn].pi_offset;
			localsizemult = 1;
		} else if (atoi(isize) == -1) {
			i = pm->ptstart;
			localsizemult = 1;
		} else {
			if (atofsb(isize, &i, &localsizemult)) {
				errmsg = msg_string(MSG_invalid_sector_number);
				continue;
			}
		}
		/* round to cylinder size if localsizemult != 1 */
		i = NUMSEC(i/localsizemult, localsizemult, pm->dlcylsize);
		/* Adjust to start of slice if needed */
		if ((i < pm->ptstart && (pm->ptstart - i) < localsizemult) ||
		    (i > pm->ptstart && (i - pm->ptstart) < localsizemult)) {
			i = pm->ptstart;
		}
		if (i <= pm->dlsize)
			break;
		errmsg = msg_string(MSG_startoutsidedisk);
	}
	return i;
}
Exemplo n.º 9
0
/* Ask for a partition size, check bounds and do the needed roundups */
static uint32_t
getpartsize(uint32_t partstart, uint32_t defpartsize)
{
	char dsize[20], isize[20], maxpartc;
	const char *errmsg = "\n";
	uint32_t i, partend, localsizemult;
	uint32_t fsptend = pm->ptstart + pm->ptsize;
	int partn;

	maxpartc = 'a' + getmaxpartitions() - 1;
	for (;;) {
		snprintf(dsize, sizeof dsize, "%d", defpartsize/sizemult);
		msg_prompt_win(MSG_label_size, -1, 12, 70, 9,
		    (defpartsize != 0) ? dsize : 0, isize, sizeof isize,
		    errmsg, maxpartc, multname);
		if (strcmp(isize, dsize) == 0)
			return defpartsize;
		if (isize[1] == '\0' && isize[0] >= 'a' &&
		    isize[0] <= maxpartc) {
			partn = isize[0] - 'a';
			i = pm->bsdlabel[partn].pi_offset - partstart;
			localsizemult = 1;
		} else if (atoi(isize) == -1) {
			i = fsptend - partstart;
			localsizemult = 1;
		} else {
			if (atofsb(isize, &i, &localsizemult)) {
				errmsg = msg_string(MSG_invalid_sector_number);
				continue;
			}
		}
		/*
		 * partend is aligned to a cylinder if localsizemult
		 * is not 1 sector
		 */
		partend = NUMSEC((partstart + i) / localsizemult,
		    localsizemult, pm->dlcylsize);
		/* Align to end-of-disk or end-of-slice if close enough */
		if (partend > (pm->dlsize - localsizemult)
		    && partend < (pm->dlsize + localsizemult))
			partend = pm->dlsize;
		if (partend > (fsptend - localsizemult)
		    && partend < (fsptend + localsizemult))
			partend = fsptend;
		/* sanity checks */
		if (partend > pm->dlsize) {
			partend = pm->dlsize;
			msg_prompt_win(MSG_endoutsidedisk, -1, 13, 70, 6,
			    NULL, isize, 1,
			    (partend - partstart) / sizemult, multname);
		}
		if (partend < partstart)
			return 0;
		return (partend - partstart);
	}
	/* NOTREACHED */
}
Exemplo n.º 10
0
Arquivo: run.c Projeto: ryo/netbsd-src
static WINDOW *
show_cmd(const char *scmd, struct winsize *win)
{
	int n, m;
	WINDOW *actionwin;
	int nrow;

	wclear(stdscr);
	clearok(stdscr, 1);
	touchwin(stdscr);
	refresh();

	mvaddstr(0, 4, msg_string(MSG_Status));
	standout();
	addstr(msg_string(MSG_Running));
	standend();
	mvaddstr(1, 4, msg_string(MSG_Command));
	standout();
	printw("%s", scmd);
	standend();
	addstr("\n\n");
	for (n = win->ws_col; (m = min(n, 30)) > 0; n -= m)
		addstr( "------------------------------" + 30 - m);
	refresh();

	nrow = getcury(stdscr) + 1;

	actionwin = subwin(stdscr, win->ws_row - nrow, win->ws_col, nrow, 0);
	if (actionwin == NULL) {
		fprintf(stderr, "sysinst: failed to allocate output window.\n");
		exit(1);
	}
	scrollok(actionwin, TRUE);
	if (has_colors()) {
		wbkgd(actionwin, getbkgd(stdscr));
		wattrset(actionwin, getattrs(stdscr));
	}

	wmove(actionwin, 0, 0);
	wrefresh(actionwin);

	return actionwin;
}
Exemplo n.º 11
0
/*
 * hook called after upgrade() or install() has finished setting
 * up the target disk but immediately before the user is given the
 * ``disks are now set up'' message.
 */
int
md_post_newfs(void)
{
    if (!nobootfs) {
        msg_display(msg_string(MSG_copybootloader), diskdev);
        cp_to_target("/usr/mdec/boot", PART_BOOT_FAT12_PI_MOUNT);
    }

    return 0;
}
Exemplo n.º 12
0
/*
 * hook called after writing disklabel to new target disk.
 */
int
md_post_disklabel(void)
{
	/* Sector forwarding / badblocks ... */
	if (*doessf) {
		printf ("%s", msg_string (MSG_dobad144));
		return run_program(RUN_DISPLAY, "/usr/sbin/bad144 %s 0",
		    diskdev);
	}
	return 0;
}
Exemplo n.º 13
0
/*
 * hook called before writing new disklabel.
 */
int
md_pre_disklabel(void)
{
	printf ("%s", msg_string (MSG_dofdisk));

	/* write edited MBR onto disk. */
	if (write_mbr(diskdev, &mbr, 1) != 0) {
		msg_display(MSG_wmbrfail);
		process_menu(MENU_ok, NULL);
		return 1;
	}
	return 0;
}
Exemplo n.º 14
0
/*
 * hook called after upgrade() or install() has finished setting
 * up the target disk but immediately before the user is given the
 * ``disks are now set up'' message.
 *
 * On mipsco, we take this opportuinty to update the bootblocks.
 */
int
md_post_newfs(void)
{

	/* XXX boot blocks ... */
	if (target_already_root()) {
		/* /usr is empty and we must already have bootblocks?*/
		return 0;
	}

	printf(msg_string(MSG_dobootblks), diskdev);
	cp_to_target("/usr/mdec/boot", "/boot");
	if (run_program(RUN_DISPLAY | RUN_NO_CLEAR,
	    "/usr/mdec/installboot /dev/r%sc /usr/mdec/bootxx_ffs", diskdev))
		process_menu(MENU_ok,
			deconst("Warning: disk is probably not bootable"));
	return 0;
}
Exemplo n.º 15
0
void
do_configmenu()
{
	int		menu_no;
	int		opts;
	menu_ent	me[CONFIGOPT_LAST];
	configinfo	*ce[CONFIGOPT_LAST];

        wrefresh(curscr);
        wmove(stdscr, 0, 0);
        wclear(stdscr);
        wrefresh(stdscr);
	
	/* if the target isn't mounted already, figure it out. */
	if (target_mounted() == 0) {
		if (find_disks(msg_string(MSG_configure_prior)) < 0)
			return;

		if (mount_disks() != 0)
			return;
	}

	config_list_init();
	make_url(pkgpath, &pkg, pkg_dir);
	opts = init_config_menu(config_list, me, ce);

	menu_no = new_menu(NULL, me, opts, 0, -4, 0, 70,
		MC_SCROLL | MC_NOBOX | MC_DFLTEXIT,
		configmenu_hdr, set_config, NULL, "XXX Help String",
		MSG_doneconfig);

	process_menu(menu_no, ce);
	free_menu(menu_no);

	sanity_check();

}
Exemplo n.º 16
0
/*
 * Do the system upgrade.
 */
void
do_upgrade(void)
{
    int retcode = 0;
    partman_go = 0;

    msg_display(MSG_upgradeusure);
    if (!ask_noyes(NULL))
        return;

    get_ramsize();

    if (find_disks(msg_string(MSG_upgrade)) < 0)
        return;

    if (set_swap_if_low_ram(pm->diskdev, NULL) < 0)
        return;

    if (md_pre_update() < 0)
        return;

    if (mount_disks() != 0)
        return;


    /*
     * Save X symlink, ...
     */
    if (save_X("/usr/X11R6"))
        return;
    if (save_X("/usr/X11R7"))
        return;

#ifdef AOUT2ELF
    move_aout_libs();
#endif
    /* Do any md updating of the file systems ... e.g. bootblocks,
       copy file systems ... */
    if (!md_update())
        return;

    wrefresh(curscr);
    wmove(stdscr, 0, 0);
    wclear(stdscr);
    wrefresh(stdscr);

    /* Done with disks. Ready to get and unpack tarballs. */
    process_menu(MENU_distset, &retcode);
    if (retcode == 0)
        return;
    if (get_and_unpack_sets(1, MSG_disksetupdoneupdate,
                            MSG_upgrcomplete, MSG_abortupgr) != 0)
        return;

    if (md_post_extract())
        return;

    merge_X("/usr/X11R6");
    merge_X("/usr/X11R7");

    sanity_check();
}
Exemplo n.º 17
0
static int unserialize(struct msg_t *msg, size_t *msg_length)
{
  struct engine_t *engine = NULL;
  size_t effective_msg_length = 0;
  size_t allocated_msg_length = 0;

  ENTER();

  if (!msg || !msg_length) {
    err("LEAVE, args error(%d)",0);
    return EINVAL;
  }

  engine = (struct engine_t*)msg->engine;

  if ((*msg_length < MIN_MSG_SIZE)
      || (msg->id != MSG_TO_ECI_ID)
      || !msg_string(msg->func)
      || (*msg_length < MSG_HEADER_LENGTH + msg->effective_data_length)
      || (engine && !check_engine(engine))) {
    msg("recv erroneous msg");
    memset(msg, 0, MIN_MSG_SIZE);
    msg->id = MSG_TO_APP_ID;
    msg->func = MSG_UNDEFINED;
    *msg_length = MIN_MSG_SIZE;
    msg->res = ECIFalse;
    dbg("send msg '%s', length=%d, res=0x%x (#%d)", msg_string(msg->func), msg->effective_data_length, msg->res, msg->count);
    LEAVE();
    return 0;
  }

  dbg("recv msg '%s', length=%d, engine=%p (#%d)", msg_string(msg->func), msg->effective_data_length, engine, msg->count);

  msg->id = MSG_TO_APP_ID;
  msg->effective_data_length = 0;

  switch(msg->func) {
  case MSG_ADD_TEXT:
    if (msg->data[msg->effective_data_length-1] != 0) {
      err("LEAVE, %s, data error, length=%d, <0x%x 0x%x 0x%x>", msg_string(msg->func), msg->effective_data_length, msg->data[msg->effective_data_length-3], msg->data[msg->effective_data_length-2], msg->data[msg->effective_data_length-1]);
      msg->res = ECIFalse;
    } else {
      dbg("text=%s", (char*)msg->data);
      dbg("eciAddText: handle=%p, data=%s", engine->handle, msg->data);
      msg->res = (uint32_t)eciAddText(engine->handle, msg->data);
    }
    break;

  case MSG_CLEAR_ERRORS:
    dbg("eciClearErrors: handle=%p", engine->handle);
    eciClearErrors(engine->handle);
    break;

  case MSG_CLEAR_INPUT:
    dbg("eciClearInput: handle=%p", engine->handle);
    eciClearInput(engine->handle);
    break;

  case MSG_COPY_VOICE:
    dbg("eciCopyVoice: handle=%p, from %d to %d", engine->handle, msg->args.cv.iVoiceFrom, msg->args.cv.iVoiceTo);
    msg->res = (uint32_t)eciCopyVoice(engine->handle, msg->args.cv.iVoiceFrom, msg->args.cv.iVoiceTo);
    break;

  case MSG_DELETE_DICT:
    dbg("eciDeleteDict: handle=%p, dict=%p", engine->handle, (char*)NULL + msg->args.dd.hDict);
    msg->res = (uint32_t)eciDeleteDict(engine->handle, (char*)NULL + msg->args.dd.hDict);
    break;

  case MSG_ERROR_MESSAGE:
    BUILD_ASSERT(MSG_HEADER_LENGTH + MAX_ERROR_MESSAGE <= PIPE_MAX_BLOCK);
    dbg("eciErrorMessage: handle=%p", engine->handle);
    eciErrorMessage(engine->handle, msg->data);
    msg->effective_data_length = MAX_ERROR_MESSAGE;
    msg("error=%s", (char*)msg->data);
    break;

  case MSG_GET_AVAILABLE_LANGUAGES: {
    struct msg_get_available_languages_t *lang = (struct msg_get_available_languages_t *)msg->data;
    BUILD_ASSERT(MSG_HEADER_LENGTH + sizeof(struct msg_get_available_languages_t) <= PIPE_MAX_BLOCK);
    lang->nb = sizeof(lang->languages)/sizeof(lang->languages[0]);
    dbg("eciGetAvailableLanguages");
    msg->res = eciGetAvailableLanguages(lang->languages, &lang->nb);
    msg->effective_data_length = sizeof(struct msg_get_available_languages_t);
    dbg("nb lang=%d, msg->res=%d", lang->nb, msg->res);
  }
    break;

  case MSG_GET_DEFAULT_PARAM:
    dbg("eciGetDefaultParam: handle=%p", engine->handle);
    msg->res = (uint32_t)eciGetDefaultParam(msg->args.gp.Param);
    break;

  case MSG_GET_DICT:
    dbg("eciGetDict: handle=%p", engine->handle);
    msg->res = (uint32_t)eciGetDict(engine->handle);
    break;

  case MSG_GET_PARAM:
    dbg("eciGetParam: handle=%p, param=%d", engine->handle, msg->args.gp.Param);
    msg->res = (uint32_t)eciGetParam(engine->handle, msg->args.gp.Param);
    break;

  case MSG_GET_VOICE_PARAM:
    dbg("eciGetVoiceParam: handle=%p, voice=%d, param=%d", engine->handle,
	msg->args.gvp.iVoice, msg->args.gp.Param);
    msg->res = (uint32_t)eciGetVoiceParam(engine->handle, msg->args.gvp.iVoice,
					  msg->args.gvp.Param);
    break;

  case MSG_INSERT_INDEX:
    dbg("eciInsertIndex: handle=%p", engine->handle);
    msg->res = (uint32_t)eciInsertIndex(engine->handle, msg->args.ii.iIndex);
    break;

  case MSG_LOAD_DICT:
    dbg("eciLoadDict: handle=%p, hDict=%p, DictVol=0x%x, filename=%s",
	engine->handle,
	(char*)NULL + msg->args.ld.hDict,
	msg->args.ld.DictVol, msg->data);
    msg->res = eciLoadDict(engine->handle, (char*)NULL + msg->args.ld.hDict, msg->args.ld.DictVol, msg->data);
    break;

  case MSG_NEW: {    
    dbg("eciNew");
    ECIHand h = eciNew();
    if (h) {
      engine = calloc(1, sizeof(struct engine_t));
      if (engine) {
	engine->id = ENGINE_ID;
	engine->handle = h;
	dbg("MSG_NEW: engine=%p, handle=%p", engine, h);
      }
    }
    msg->res = (uint32_t)engine;
  }
    break;

  case MSG_NEW_DICT:
    dbg("eciNewDict: handle=%p", engine->handle);
    msg->res = (uint32_t)eciNewDict(engine->handle);
    break;

  case MSG_NEW_EX: {
    dbg("eciNewEx: value=%d", msg->args.ne.Value);
    ECIHand h = eciNewEx(msg->args.ne.Value);
    if (h) {
      engine = calloc(1, sizeof(struct engine_t));
      if (engine) {
	engine->id = ENGINE_ID;
	engine->handle = h;
      }
    }
    msg->res = (uint32_t)engine;
  }
    break;

  case MSG_PAUSE:
    dbg("eciPause: handle=%p", engine->handle);
    msg->res = (uint32_t)eciPause(engine->handle, msg->args.p.On);
    break;

  case MSG_PROG_STATUS:
    dbg("eciProgStatus: handle=%p", engine->handle);
    msg->res = eciProgStatus(engine->handle);
    break;

  case MSG_REGISTER_CALLBACK: {
    ECICallback cb = NULL;
    if (msg->args.rc.Callback)
      cb = my_callback;
    dbg("eciRegisterCallback, engine=%p, handle=%p, cb=%p", engine, engine->handle, cb);
    eciRegisterCallback(engine->handle, cb, engine);
  }
    break;

  case MSG_RESET:
    dbg("eciReset: handle=%p", engine->handle);
    eciReset(engine->handle);
    break;

  case MSG_SET_DEFAULT_PARAM:
    dbg("eciSetDefaultParam: handle=%p, p=%d, v=%d", engine->handle, msg->args.sp.Param, msg->args.sp.iValue);
    msg->res = (uint32_t)eciSetDefaultParam(msg->args.sp.Param, msg->args.sp.iValue);
    break;

  case MSG_SET_DICT:
    dbg("eciSetDict: handle=%p, d=%p", engine->handle, (char*)NULL + msg->args.sd.hDict);
    msg->res = (uint32_t)eciSetDict(engine->handle, (char*)NULL + msg->args.sd.hDict);
    break;

  case MSG_SET_OUTPUT_DEVICE:
    dbg("eciSetOutputDevice: handle=%p, dev=%d", engine->handle, msg->args.sod.iDevNum);
    msg->res = (uint32_t)eciSetOutputDevice(engine->handle, msg->args.sod.iDevNum);
    break;

  case MSG_SET_PARAM:
    dbg("eciSetParam: handle=%p, p=%d, v=%d", engine->handle, msg->args.sp.Param, msg->args.sp.iValue);
    msg->res = (uint32_t)eciSetParam(engine->handle, msg->args.sp.Param, msg->args.sp.iValue);
    break;

  case MSG_SET_VOICE_PARAM:
    dbg("eciSetVoiceParam: handle=%p, p=%d, v=%d", engine->handle, msg->args.svp.iVoice, msg->args.svp.iValue);
    msg->res = (uint32_t)eciSetVoiceParam(engine->handle, msg->args.svp.iVoice, msg->args.svp.Param, msg->args.svp.iValue);
    break;

  case MSG_SET_OUTPUT_BUFFER:
    set_output_buffer(my_voxind, engine, msg);
    break;

  case MSG_SET_OUTPUT_FILENAME:
    dbg("eciSetOutputFilename: handle=%p, d=%s", engine->handle, msg->data);
    msg->res = (uint32_t)eciSetOutputFilename(engine->handle, msg->data);
    break;

  case MSG_SYNTHESIZE:
    dbg("eciSynthesize: handle=%p", engine->handle);
    msg->res = (uint32_t)eciSynthesize(engine->handle);
    break;

  case MSG_SYNCHRONIZE:
    dbg("eciSynchronize: handle=%p", engine->handle);
    msg->res = (uint32_t)eciSynchronize(engine->handle);
    break;

  case MSG_SPEAKING:
    dbg("eciSpeaking: handle=%p", engine->handle);
    msg->res = (uint32_t)eciSpeaking(engine->handle);
    break;

  case MSG_STOP:
    dbg("eciStop: handle=%p", engine->handle);
    msg->res = (uint32_t)eciStop(engine->handle);
    break;

  case MSG_VERSION:
    BUILD_ASSERT(MSG_HEADER_LENGTH + MAX_VERSION <= PIPE_MAX_BLOCK);
    dbg("eciVersion");
    eciVersion(msg->data);
    msg->effective_data_length = MAX_VERSION;
    dbg("version=%s", msg->data);
    break;

  default:
    msg->res = ECIFalse;
    break;
  }

  *msg_length = MSG_HEADER_LENGTH + msg->effective_data_length;

 exit0:
  dbg("send msg '%s', length=%d, res=0x%x (#%d)", msg_string(msg->func), msg->effective_data_length, msg->res, msg->count);
  LEAVE();
  return 0;
}
Exemplo n.º 18
0
static void
set_ptn_label(menudesc *m, int opt, void *arg)
{
	partinfo *p = arg;
	const char *c;

	if (m->opts[opt].opt_flags & OPT_IGNORE
	    && (opt != PTN_MENU_END || p->pi_fstype == FS_UNUSED)) {
		wprintw(m->mw, "            -");
		return;
	}

	switch (opt) {
	case PTN_MENU_FSKIND:
		if (p->pi_fstype == FS_BSDFFS)
			if (p->pi_flags & PIF_FFSv2)
				c = "FFSv2";
			else
				c = "FFSv1";
		else
			c = getfslabelname(p->pi_fstype);
		wprintw(m->mw, msg_string(MSG_fstype_fmt), c);
		break;
	case PTN_MENU_START:
		disp_sector_count(m, MSG_start_fmt, p->pi_offset);
		break;
	case PTN_MENU_SIZE:
		disp_sector_count(m, MSG_size_fmt, p->pi_size);
		break;
	case PTN_MENU_END:
		disp_sector_count(m, MSG_end_fmt, p->pi_offset + p->pi_size);
		break;
	case PTN_MENU_NEWFS:
		wprintw(m->mw, msg_string(MSG_newfs_fmt),
			msg_string(p->pi_flags & PIF_NEWFS ? MSG_Yes : MSG_No));
		break;
	case PTN_MENU_ISIZE:
		wprintw(m->mw, msg_string(p->pi_isize > 0 ?
			MSG_isize_fmt : MSG_isize_fmt_dflt), p->pi_isize);
		break;
	case PTN_MENU_BSIZE:
		wprintw(m->mw, msg_string(MSG_bsize_fmt),
			p->pi_fsize * p->pi_frag);
		break;
	case PTN_MENU_FSIZE:
		wprintw(m->mw, msg_string(MSG_fsize_fmt), p->pi_fsize);
		break;
	case PTN_MENU_MOUNT:
		wprintw(m->mw, msg_string(MSG_mount_fmt),
			msg_string(p->pi_flags & PIF_MOUNT ? MSG_Yes : MSG_No));
		break;
	case PTN_MENU_MOUNTOPT:
		wprintw(m->mw, "%s", msg_string(MSG_mount_options_fmt));
		if (p->pi_flags & PIF_ASYNC)
			wprintw(m->mw, "async ");
		if (p->pi_flags & PIF_NOATIME)
			wprintw(m->mw, "noatime ");
		if (p->pi_flags & PIF_NODEV)
			wprintw(m->mw, "nodev ");
		if (p->pi_flags & PIF_NODEVMTIME)
			wprintw(m->mw, "nodevmtime ");
		if (p->pi_flags & PIF_NOEXEC)
			wprintw(m->mw, "noexec ");
		if (p->pi_flags & PIF_NOSUID)
			wprintw(m->mw, "nosuid ");
		if (p->pi_flags & PIF_LOG)
			wprintw(m->mw, "log ");
		break;
	case PTN_MENU_MOUNTPT:
		wprintw(m->mw, msg_string(MSG_mountpt_fmt), p->pi_mount);
		break;
	}
}
Exemplo n.º 19
0
/*
 * Get the information to configure the network, configure it and
 * make sure both the gateway and the name server are up.
 */
int
config_network(void)
{
	char *tp;
	char *defname;
	const char *prompt;
	char *textbuf;
	int  octet0;
	int  dhcp_config;
	int  nfs_root = 0;
 	int  slip = 0;
 	int  pid, status;
 	char **ap, *slcmd[10], *in_buf;
 	char buffer[STRSIZE];
 	struct statvfs sb;

	int l;
	char dhcp_host[STRSIZE];
#ifdef INET6
	int v6config = 1;
#endif

	FILE *f;
	time_t now;

	if (network_up)
		return (1);

	get_ifconfig_info();

	if (net_up != NULL) {
		/* XXX: some retry loops come here... */
		/* active interfaces found */
		msg_display(MSG_netup, net_up);
		process_menu(MENU_yesno, NULL);
		if (!yesno)
			return 0;
	}

	if (net_devices == NULL) {
		/* No network interfaces found! */
		msg_display(MSG_nonet);
		process_menu(MENU_ok, NULL);
		return (-1);
	}
	network_up = 1;

again:
	tp = strchr(net_devices, ' ');
	asprintf(&defname, "%.*s", (int)(tp - net_devices), net_devices);
	for (prompt = MSG_asknetdev;; prompt = MSG_badnet) {
		msg_prompt(prompt, defname, net_dev, sizeof net_dev - 1,
		    net_devices);
		l = strlen(net_dev);
		net_dev[l] = ' ';
		net_dev[l + 1] = 0;
		tp = strstr(net_devices, net_dev);
		if (tp == NULL)
			continue;
		if (tp != net_devices && tp[-1] != ' ')
			continue;
		net_dev[l] = 0;
		break;
	}
	free(defname);
	if (!handle_license(net_dev))
		goto done;

	slip = net_dev[0] == 's' && net_dev[1] == 'l' &&
	    isdigit((unsigned char)net_dev[2]);

	/* If root is on NFS do not reconfigure the interface. */
	if (statvfs("/", &sb) == 0 && strcmp(sb.f_fstypename, "nfs") == 0) {
		nfs_root = 1;
		dhcp_config = 0;
		get_ifinterface_info();
		get_if6interface_info();
		get_host_info();
	} else if (slip) {
		dhcp_config = 0;
	} else {
		/* Preload any defaults we can find */
		get_ifinterface_info();
		get_if6interface_info();
		get_host_info();

		/* domain and host */
		msg_display(MSG_netinfo);

		/* ethernet medium */
		for (;;) {
			msg_prompt_add(MSG_net_media, net_media, net_media,
					sizeof net_media);

			/*
			 * ifconfig does not allow media specifiers on
			 * IFM_MANUAL interfaces.  Our UI gives no way
			 * to set an option back
			 * to null-string if it gets accidentally set.
			 * Check for plausible alternatives.
			 */
			if (strcmp(net_media, "<default>") == 0 ||
			    strcmp(net_media, "default") == 0 ||
			    strcmp(net_media, "<manual>") == 0 ||
			    strcmp(net_media, "manual") == 0 ||
			    strcmp(net_media, "<none>") == 0 ||
			    strcmp(net_media, "none") == 0 ||
			    strcmp(net_media, " ") == 0) {
				*net_media = '\0';
			}

			if (*net_media == '\0')
				break;
			/*
			 * We must set the media type here - to give dhcp
			 * a chance
			 */
			if (run_program(0, "/sbin/ifconfig %s media %s",
				    net_dev, net_media) == 0)
				break;
			/* Failed to set - output the supported values */
			if (collect(T_OUTPUT, &textbuf, "/sbin/ifconfig -m %s |"
				    "while IFS=; read line;"
				    " do [ \"$line\" = \"${line#*media}\" ] || "
				    "echo $line;"
				    " done", net_dev ) > 0)
				msg_display(textbuf);
			free(textbuf);
		}

		net_dhcpconf = 0;
		/* try a dhcp configuration */
		dhcp_config = config_dhcp(net_dev);
		if (dhcp_config) {
			/* Get newly configured data off interface. */
			get_ifinterface_info();
			get_if6interface_info();
			get_host_info();

			net_dhcpconf |= DHCPCONF_IPADDR;

			/*
			 * Extract default route from output of
			 * 'route -n show'
			 */
			if (collect(T_OUTPUT, &textbuf,
				    "/sbin/route -n show | "
				    "while read dest gateway flags;"
				    " do [ \"$dest\" = default ] && {"
					" echo $gateway; break; };"
				    " done" ) > 0)
				strlcpy(net_defroute, textbuf,
				    sizeof net_defroute);
			free(textbuf);

			/* pull nameserver info out of /etc/resolv.conf */
			if (collect(T_OUTPUT, &textbuf,
				    "cat /etc/resolv.conf 2>/dev/null |"
				    " while read keyword address rest;"
				    " do [ \"$keyword\" = nameserver "
					" -a \"${address#*:}\" = "
					"\"${address}\" ] && {"
					    " echo $address; break; };"
				    " done" ) > 0)
				strlcpy(net_namesvr, textbuf,
				    sizeof net_namesvr);
			free(textbuf);
			if (net_namesvr[0] != '\0')
				net_dhcpconf |= DHCPCONF_NAMESVR;

			/* pull domainname out of leases file */
			get_dhcp_value(net_domain, sizeof(net_domain),
			    "domain-name");
			if (net_domain[0] != '\0')
				net_dhcpconf |= DHCPCONF_DOMAIN;

			/* pull hostname out of leases file */
			dhcp_host[0] = 0;
			get_dhcp_value(dhcp_host, sizeof(dhcp_host),
			    "host-name");
			if (dhcp_host[0] != '\0') {
				net_dhcpconf |= DHCPCONF_HOST;
				strlcpy(net_host, dhcp_host, sizeof net_host);
			}
		}
	}

	msg_prompt_add(MSG_net_domain, net_domain, net_domain,
	    sizeof net_domain);
	msg_prompt_add(MSG_net_host, net_host, net_host, sizeof net_host);

	if (!dhcp_config) {
		/* Manually configure IPv4 */
		if (!nfs_root)
			msg_prompt_add(MSG_net_ip, net_ip, net_ip,
			    sizeof net_ip);
		if (slip)
			msg_prompt_add(MSG_net_srv_ip, net_srv_ip, net_srv_ip,
			    sizeof net_srv_ip);
		else if (!nfs_root) {
			/* We don't want netmasks for SLIP */
			octet0 = atoi(net_ip);
			if (!net_mask[0]) {
				if (0 <= octet0 && octet0 <= 127)
					strlcpy(net_mask, "0xff000000",
				    	sizeof(net_mask));
				else if (128 <= octet0 && octet0 <= 191)
					strlcpy(net_mask, "0xffff0000",
				    	sizeof(net_mask));
				else if (192 <= octet0 && octet0 <= 223)
					strlcpy(net_mask, "0xffffff00",
				    	sizeof(net_mask));
			}
			msg_prompt_add(MSG_net_mask, net_mask, net_mask,
			    sizeof net_mask);
		}
		msg_prompt_add(MSG_net_defroute, net_defroute, net_defroute,
		    sizeof net_defroute);
	}

	if (!dhcp_config || net_namesvr[0] == 0)
		msg_prompt_add(MSG_net_namesrv, net_namesvr, net_namesvr,
		    sizeof net_namesvr);

#ifdef INET6
	/* IPv6 autoconfiguration */
	if (!is_v6kernel())
		v6config = 0;
	else if (v6config) {
		process_menu(MENU_noyes, deconst(MSG_Perform_IPv6_autoconfiguration));
		v6config = yesno ? 1 : 0;
		net_ip6conf |= yesno ? IP6CONF_AUTOHOST : 0;
	}

	if (v6config) {
		process_menu(MENU_namesrv6, NULL);
		if (!yesno)
			msg_prompt_add(MSG_net_namesrv6, net_namesvr6,
			    net_namesvr6, sizeof net_namesvr6);
	}
#endif

	/* confirm the setting */
	if (slip)
		msg_display(MSG_netok_slip, net_domain, net_host, net_dev,
			*net_ip == '\0' ? "<none>" : net_ip,
			*net_srv_ip == '\0' ? "<none>" : net_srv_ip,
			*net_mask == '\0' ? "<none>" : net_mask,
			*net_namesvr == '\0' ? "<none>" : net_namesvr,
			*net_defroute == '\0' ? "<none>" : net_defroute,
			*net_media == '\0' ? "<default>" : net_media);
	else
		msg_display(MSG_netok, net_domain, net_host, net_dev,
			*net_ip == '\0' ? "<none>" : net_ip,
			*net_mask == '\0' ? "<none>" : net_mask,
			*net_namesvr == '\0' ? "<none>" : net_namesvr,
			*net_defroute == '\0' ? "<none>" : net_defroute,
			*net_media == '\0' ? "<default>" : net_media);
#ifdef INET6
	msg_display_add(MSG_netokv6,
		     !is_v6kernel() ? "<not supported>" :
			(v6config ? "yes" : "no"),
		     *net_namesvr6 == '\0' ? "<none>" : net_namesvr6);
#endif
done:
	process_menu(MENU_yesno, deconst(MSG_netok_ok));
	if (!yesno)
		msg_display(MSG_netagain);
	if (!yesno)
		goto again;

	/*
	 * we may want to perform checks against inconsistent configuration,
	 * like IPv4 DNS server without IPv4 configuration.
	 */

	/* Create /etc/resolv.conf if a nameserver was given */
	if (net_namesvr[0] != '\0'
#ifdef INET6
	    || net_namesvr6[0] != '\0'
#endif
		) {
		f = fopen("/etc/resolv.conf", "w");
		if (f == NULL) {
			if (logfp)
				(void)fprintf(logfp,
				    "%s", msg_string(MSG_resolv));
			(void)fprintf(stderr, "%s", msg_string(MSG_resolv));
			exit(1);
		}
		scripting_fprintf(NULL, "cat <<EOF >/etc/resolv.conf\n");
		time(&now);
		/* NB: ctime() returns a string ending in  '\n' */
		scripting_fprintf(f, ";\n; BIND data file\n; %s %s;\n",
		    "Created by NetBSD sysinst on", ctime(&now));
		if (net_domain[0] != '\0')
			scripting_fprintf(f, "search %s\n", net_domain);
		if (net_namesvr[0] != '\0')
			scripting_fprintf(f, "nameserver %s\n", net_namesvr);
#ifdef INET6
		if (net_namesvr6[0] != '\0')
			scripting_fprintf(f, "nameserver %s\n", net_namesvr6);
#endif
		scripting_fprintf(NULL, "EOF\n");
		fflush(NULL);
		fclose(f);
	}

	run_program(0, "/sbin/ifconfig lo0 127.0.0.1");

#ifdef INET6
	if (v6config && !nfs_root) {
		init_v6kernel(1);
		run_program(0, "/sbin/ifconfig %s up", net_dev);
		sleep(get_v6wait() + 1);
		run_program(RUN_DISPLAY, "/sbin/rtsol -D %s", net_dev);
		sleep(get_v6wait() + 1);
	}
#endif

	if (net_ip[0] != '\0') {
		if (slip) {
			/* XXX: needs 'ifconfig sl0 create' much earlier */
			/* Set SLIP interface UP */
			run_program(0, "/sbin/ifconfig %s inet %s %s up",
			    net_dev, net_ip, net_srv_ip);
			strcpy(sl_flags, "-s 115200 -l /dev/tty00");
			msg_prompt_win(MSG_slattach, -1, 12, 70, 0,
				sl_flags, sl_flags, 255);

			/* XXX: wtf isn't run_program() used here? */
			pid = fork();
			if (pid == 0) {
				strcpy(buffer, "/sbin/slattach ");
				strcat(buffer, sl_flags);
				in_buf = buffer;

				for (ap = slcmd; (*ap = strsep(&in_buf, " ")) != NULL;)
				if (**ap != '\0')
					++ap;

				execvp(slcmd[0], slcmd);
			} else
				wait4(pid, &status, WNOHANG, 0);
		} else if (!nfs_root) {
			if (net_mask[0] != '\0') {
				run_program(0, "/sbin/ifconfig %s inet %s netmask %s",
				    net_dev, net_ip, net_mask);
			} else {
				run_program(0, "/sbin/ifconfig %s inet %s",
			    	net_dev, net_ip);
			}
		}
	}

	/* Set host name */
	if (net_host[0] != '\0')
	  	sethostname(net_host, strlen(net_host));

	/* Set a default route if one was given */
	if (!nfs_root && net_defroute[0] != '\0') {
		run_program(RUN_DISPLAY | RUN_PROGRESS,
				"/sbin/route -n flush -inet");
		run_program(RUN_DISPLAY | RUN_PROGRESS,
				"/sbin/route -n add default %s", net_defroute);
	}

	/*
	 * wait a couple of seconds for the interface to go live.
	 */
	if (!nfs_root) {
		msg_display_add(MSG_wait_network);
		sleep(5);
	}

	/*
	 * ping should be verbose, so users can see the cause
	 * of a network failure.
	 */

#ifdef INET6
	if (v6config && network_up) {
		network_up = !run_program(RUN_DISPLAY | RUN_PROGRESS,
		    "/sbin/ping6 -v -c 3 -n -I %s ff02::2", net_dev);

		if (net_namesvr6[0] != '\0')
			network_up = !run_program(RUN_DISPLAY | RUN_PROGRESS,
			    "/sbin/ping6 -v -c 3 -n %s", net_namesvr6);
	}
#endif

	if (net_namesvr[0] != '\0' && network_up)
		network_up = !run_program(RUN_DISPLAY | RUN_PROGRESS,
		    "/sbin/ping -v -c 5 -w 5 -o -n %s", net_namesvr);

	if (net_defroute[0] != '\0' && network_up)
		network_up = !run_program(RUN_DISPLAY | RUN_PROGRESS,
		    "/sbin/ping -v -c 5 -w 5 -o -n %s", net_defroute);
	fflush(NULL);

	return network_up;
}
Exemplo n.º 20
0
Arquivo: run.c Projeto: ryo/netbsd-src
int
run_program(int flags, const char *cmd, ...)
{
	va_list ap;
	struct winsize win;
	int ret;
	WINDOW *actionwin = NULL;
	char *scmd;
	char **args;
	const char *errstr = NULL;

	va_start(ap, cmd);
	vasprintf(&scmd, cmd, ap);
	va_end(ap);
	if (scmd == NULL)
		err(1, "vasprintf(&scmd, \"%s\", ...)", cmd);

	args = make_argv(scmd);

	/* Make curses save tty settings */
	def_prog_mode();

	(void)ioctl(STDIN_FILENO, TIOCGWINSZ, &win);
	/* Apparently, we sometimes get 0x0 back, and that's not useful */
	if (win.ws_row == 0)
		win.ws_row = 24;
	if (win.ws_col == 0)
		win.ws_col = 80;

	if ((flags & RUN_DISPLAY) != 0) {
		if (flags & RUN_FULLSCREEN) {
			wclear(stdscr);
			clearok(stdscr, 1);
			touchwin(stdscr);
			refresh();
			actionwin = stdscr;
		} else
			actionwin = show_cmd(scmd, &win);
	} else
		win.ws_row -= 4;

	ret = launch_subwin(&actionwin, args, &win, flags, scmd, &errstr);
	fpurge(stdin);

	/* If the command failed, show command name */
	if (actionwin == NULL && ret != 0 && !(flags & RUN_ERROR_OK))
		actionwin = show_cmd(scmd, &win);

	if (actionwin != NULL) {
		int y, x;
		getyx(actionwin, y, x);
		if (actionwin != stdscr)
			mvaddstr(0, 4, msg_string(MSG_Status));
		if (ret != 0) {
			if (actionwin == stdscr && x != 0)
				addstr("\n");
			x = 1;	/* force newline below */
			standout();
			addstr(errstr);
			standend();
		} else {
			if (actionwin != stdscr) {
				standout();
				addstr(msg_string(MSG_Finished));
				standend();
			}
		}
		clrtoeol();
		refresh();
		if ((ret != 0 && !(flags & RUN_ERROR_OK)) ||
		    (y + x != 0 && !(flags & RUN_PROGRESS))) {
			if (actionwin != stdscr)
				move(getbegy(actionwin) - 2, 5);
			else if (x != 0)
				addstr("\n");
			addstr(msg_string(MSG_Hit_enter_to_continue));
			refresh();
			getchar();
		} else {
			if (y + x != 0) {
				/* give user 1 second to see messages */
				refresh();
				sleep(1);
			}
		}
	}

	/* restore tty setting we saved earlier */
	reset_prog_mode();

	/* clean things up */
	if (actionwin != NULL) {
		if (actionwin != stdscr)
			delwin(actionwin);
		if (errstr == 0 || !(flags & RUN_NO_CLEAR)) {
			wclear(stdscr);
			touchwin(stdscr);
			clearok(stdscr, 1);
			refresh();
		}
	}

	free(scmd);
	free_argv(args);

	if (ret != 0 && flags & RUN_FATAL)
		exit(ret);
	return ret;
}
Exemplo n.º 21
0
Arquivo: run.c Projeto: ryo/netbsd-src
/*
 * launch a program inside a subwindow, and report its return status when done
 */
static int
launch_subwin(WINDOW **actionwin, char **args, struct winsize *win, int flags,
    const char *scmd, const char **errstr)
{
	int n, i;
	int selectfailed;
	int status, master, slave;
	fd_set active_fd_set, read_fd_set;
	pid_t child, pid;
	char ibuf[MAXBUF];
	char pktdata;
	char *cp, *ncp;
	struct termios rtt, tt;
	struct timeval tmo;
	static int do_tioccons = 2;

	(void)tcgetattr(STDIN_FILENO, &tt);
	if (openpty(&master, &slave, NULL, &tt, win) == -1) {
		*errstr = "openpty() failed";
		return -1;
	}

	rtt = tt;

	/* ignore tty signals until we're done with subprocess setup */
	ttysig_ignore = 1;
	ioctl(master, TIOCPKT, &ttysig_ignore);

	/* Try to get console output into our pipe */
	if (do_tioccons) {
		if (ioctl(slave, TIOCCONS, &do_tioccons) == 0
		    && do_tioccons == 2) {
			/* test our output - we don't want it grabbed */
			write(1, " \b", 2);
			ioctl(master, FIONREAD, &do_tioccons);
			if (do_tioccons != 0) {
				do_tioccons = 0;
				ioctl(slave, TIOCCONS, &do_tioccons);
			} else
				do_tioccons = 1;
		}
	}

	if (logfp)
		fflush(logfp);
	if (script)
		fflush(script);

	child = fork();
	switch (child) {
	case -1:
		ttysig_ignore = 0;
		refresh();
		*errstr = "fork() failed";
		return -1;
	case 0:	/* child */
		(void)close(STDIN_FILENO);
		/* silently stop curses */
		(void)close(STDOUT_FILENO);
		(void)open("/dev/null", O_RDWR, 0);
		dup2(STDIN_FILENO, STDOUT_FILENO);
		endwin();
		(void)close(master);
		rtt = tt;
		rtt.c_lflag |= (ICANON|ECHO);
		(void)tcsetattr(slave, TCSANOW, &rtt);
		login_tty(slave);
		if (logfp) {
			fprintf(logfp, "executing: %s\n", scmd);
			fclose(logfp);
			logfp = NULL;
		}
		if (script) {
			fprintf(script, "%s\n", scmd);
			fclose(script);
			script = NULL;
		}
		if (strcmp(args[0], "cd") == 0 && strcmp(args[2], "&&") == 0) {
			target_chdir_or_die(args[1]);
			args += 3;
		}
		if (flags & RUN_XFER_DIR)
			target_chdir_or_die(xfer_dir);
		/*
		 * If target_prefix == "", the chroot will fail, but
		 * that's ok, since we don't need it then.
		 */
		if (flags & RUN_CHROOT && *target_prefix()
		    && chroot(target_prefix()) != 0)
			warn("chroot(%s) for %s", target_prefix(), *args);
		else {
			execvp(*args, args);
			warn("execvp %s", *args);
		}
		_exit(EXIT_FAILURE);
		// break; /* end of child */
	default:
		/*
		 * parent: we've set up the subprocess.
		 * forward tty signals to its process group.
		 */
		ttysig_forward = child;
		ttysig_ignore = 0;
		break;
	}

	/*
	 * Now loop transferring program output to screen, and keyboard
	 * input to the program.
	 */

	FD_ZERO(&active_fd_set);
	FD_SET(master, &active_fd_set);
	FD_SET(STDIN_FILENO, &active_fd_set);

	for (selectfailed = 0;;) {
		if (selectfailed) {
			const char mmsg[] =
			    "select(2) failed but no child died?";
			if (logfp)
				(void)fprintf(logfp, mmsg);
			errx(1, mmsg);
		}
		read_fd_set = active_fd_set;
		tmo.tv_sec = flags & RUN_SILENT ? 20 : 2;
		tmo.tv_usec = 0;
		i = select(FD_SETSIZE, &read_fd_set, NULL, NULL, &tmo);
		if (i == 0 && *actionwin == NULL && (flags & RUN_SILENT) == 0)
			*actionwin = show_cmd(scmd, win);
		if (i < 0) {
			if (errno != EINTR) {
				warn("select");
				if (logfp)
					(void)fprintf(logfp,
					    "select failure: %s\n",
					    strerror(errno));
				selectfailed = 1;
			}
		} else for (i = 0; i < FD_SETSIZE; ++i) {
			if (!FD_ISSET(i, &read_fd_set))
				continue;
			n = read(i, ibuf, sizeof ibuf - 1);
			if (n <= 0) {
				if (n < 0)
					warn("read");
				continue;
			}
			ibuf[n] = 0;
			cp = ibuf;
			if (i == STDIN_FILENO) {
				(void)write(master, ibuf, (size_t)n);
				if (!(rtt.c_lflag & ECHO))
					continue;
			} else {
				pktdata = ibuf[0];
				if (pktdata != 0) {
					if (pktdata & TIOCPKT_IOCTL)
						memcpy(&rtt, ibuf, sizeof(rtt));
					continue;
				}
				cp += 1;
			}
			if (*cp == 0 || flags & RUN_SILENT)
				continue;
			if (logfp) {
				fprintf(logfp, "%s", cp);
				fflush(logfp);
			}
			if (*actionwin == NULL)
				*actionwin = show_cmd(scmd, win);
			/* posix curses is braindead wrt \r\n so... */
			for (ncp = cp; (ncp = strstr(ncp, "\r\n")); ncp += 2) {
				ncp[0] = '\n';
				ncp[1] = '\r';
			}
			waddstr(*actionwin, cp);
			wrefresh(*actionwin);
		}
		pid = wait4(child, &status, WNOHANG, 0);
 		if (pid == child && (WIFEXITED(status) || WIFSIGNALED(status)))
			break;
	}
	close(master);
	close(slave);
	if (logfp)
		fflush(logfp);

	/* from here on out, we take tty signals ourselves */
	ttysig_forward = 0;

	reset_prog_mode();

	if (WIFEXITED(status)) {
		*errstr = msg_string(MSG_Command_failed);
		return WEXITSTATUS(status);
	}
	if (WIFSIGNALED(status)) {
		*errstr = msg_string(MSG_Command_ended_on_signal);
		return WTERMSIG(status);
	}
	return 0;
}
Exemplo n.º 22
0
/*
 * hook called before writing new disklabel.
 */
int
md_pre_disklabel(void)
{
    int fd;
    char dev_name[100];
    struct disklabel lp;
    Block0 new_block0 = {APPLE_DRVR_MAP_MAGIC, 512,
	 		 0, 0, 0, 0, 0, 0, 0, 0, {0}};

    /*
     * Danger Will Robinson!  We're about to turn that nice MacOS disk
     *  into an expensive doorstop...
     */
    printf ("%s", msg_string (MSG_dodiskmap));

    snprintf (dev_name, sizeof(dev_name), "/dev/r%sc", diskdev);
    /*
     * Open the disk as a raw device
     */
    if ((fd = open(dev_name, O_WRONLY, 0)) < 0) {
	endwin();
	fprintf(stderr, "Can't open %s to rewrite the Disk Map\n", dev_name);
	exit (1);
    }
    /*
     *  First check the pmSigPad field of the first block in the incore
     *  Partition Map.  It should be zero, but if it's 0xa5a5 that means
     *  we need to write out Block0 too.
     */
    if (map.blk[0].pmSigPad == 0xa5a5) {
	if (lseek (fd, (off_t)0 * blk_size, SEEK_SET) < 0) {
	    endwin();
	    fprintf (stderr, "Can't position to write Block0\n");
	    close (fd);
	    exit (1);
	}
	new_block0.sbBlkCount = dlsize;		/* Set disk size */
	if (write (fd, &new_block0, blk_size) != blk_size) {
	    endwin();
	    fprintf (stderr, "I/O error writing Block0\n");
	    close (fd);
	    exit (1);
	}
	map.blk[0].pmSigPad = 0;
    }
    if (lseek (fd, (off_t)1 * blk_size, SEEK_SET) < 0) {
	endwin();
	fprintf (stderr, "Can't position disk to rewrite Disk Map\n");
	close (fd);
	exit (1);
    }
    if (write (fd, map.blk, map.size * blk_size) != (map.size * blk_size)) {
	endwin();
	fprintf(stderr, "I/O error writing Disk Map\n");
	close (fd);
	exit (1);
    }
    fsync(fd);
    /*
     * Well, if we get here the dirty deed has been done.
     *
     * Now we need to force the incore disk table to get updated. This
     * should be done by disklabel -- which is normally called right after
     * we return -- but may be commented out for the mac68k port. We'll
     * instead update the incore table by forcing a dummy write here. This
     * relies on a change in the mac68k-specific writedisklabel() routine.
     * If that change doesn't exist nothing bad happens here. If disklabel
     * properly updates the ondisk and incore labels everything still
     * works. Only if we fail here and if disklabel fails are we in
     * in a state where we've updated the disk but not the incore and
     * a reboot is necessary.
     *
     * First, we grab a copy of the incore label as it existed before
     * we did anything to it. Then we invoke the "write label" ioctl to
     * rewrite it to disk. As a result, the ondisk partition map is
     * re-read and the incore label is reconstructed from it. If
     * disklabel() is then called to update again, either that fails
     * because the mac68k port doesn't support native disklabels, or it
     * succeeds and writes out a new ondisk copy.
     */
    ioctl(fd, DIOCGDINFO, &lp);    /* Get the current disk label */
    ioctl(fd, DIOCWDINFO, &lp);    /* Write it out again */

    close (fd);
    return 0;
}
Exemplo n.º 23
0
/**
 * FUNCTION NAME: checkMessages
 *
 * DESCRIPTION: This function is the message handler of this node.
 * 				This function does the following:
 * 				1) Pops messages from the queue
 * 				2) Handles the messages according to message types
 */
void MP2Node::checkMessages() {
	/*
	 * Implement this. Parts of it are already implemented
	 */
	char * data;
	int size;

	/*
	 * Declare your local variables here
	 */

	// dequeue all messages and handle them
	while ( !memberNode->mp2q.empty() ) {
		/*
		 * Pop a message from the queue
		 */
		data = (char *)memberNode->mp2q.front().elt;
		size = memberNode->mp2q.front().size;
		memberNode->mp2q.pop();

		string msg_string(data, data + size);

		/*
		 * Handle the message types here
		 */
		Message recv_msg = Message(msg_string);
		bool success;
		switch (recv_msg.type) {
			case CREATE:
			{
				success = createKeyValue(recv_msg.key, recv_msg.value, recv_msg.replica);
				if (success)
					log->logCreateSuccess(&memberNode->addr, false, recv_msg.transID, recv_msg.key, recv_msg.value);
				else
					log->logCreateFail(&memberNode->addr, false, recv_msg.transID, recv_msg.key, recv_msg.value);
				//send reply
				Message send_msg = Message(recv_msg.transID, memberNode->addr, REPLY, success);
				emulNet->ENsend(&memberNode->addr, &recv_msg.fromAddr, send_msg.toString());
				break;
			}
			case UPDATE:
			{
				success = updateKeyValue(recv_msg.key, recv_msg.value, recv_msg.replica);
				if (success)
					log->logUpdateSuccess(&memberNode->addr, false, recv_msg.transID, recv_msg.key, recv_msg.value);
				else
					log->logUpdateFail(&memberNode->addr, false, recv_msg.transID, recv_msg.key, recv_msg.value);
				//send reply
				Message send_msg = Message(recv_msg.transID, memberNode->addr, REPLY, success);
				emulNet->ENsend(&memberNode->addr, &recv_msg.fromAddr, send_msg.toString());
				break;
			}
			case READ:
			{
				string ret = readKey(recv_msg.key);
				if ("" != ret)
					log->logReadSuccess(&memberNode->addr, false, recv_msg.transID, recv_msg.key, ret);
				else
					log->logReadFail(&memberNode->addr, false, recv_msg.transID, recv_msg.key);
				//send read reply
				Message send_msg = Message(recv_msg.transID, memberNode->addr, ret);
				emulNet->ENsend(&memberNode->addr, &recv_msg.fromAddr, send_msg.toString());
				break;
			}
			case DELETE:
			{
				success = deletekey(recv_msg.key);
				if (success)
					log->logDeleteSuccess(&memberNode->addr, false, recv_msg.transID, recv_msg.key);
				else
					log->logDeleteFail(&memberNode->addr, false, recv_msg.transID, recv_msg.key);
				//send reply
				Message send_msg = Message(recv_msg.transID, memberNode->addr, REPLY, success);
				emulNet->ENsend(&memberNode->addr, &recv_msg.fromAddr, send_msg.toString());
				break;
			}
			case REPLY:
			{
				for (list<Transaction>::iterator it = buff.begin(); it != buff.end(); ++it) {
					if (it->transID_ == recv_msg.transID) {
						if (it->isStart())
							it->startCount();
						if (recv_msg.success) {
							it->increCount();
						}
						break;
					}
				}
				break;
			}
			case READREPLY:
			{
				for (list<ReadTransaction>::iterator it = buffRead.begin(); it != buffRead.end(); ++it) {
					if (it->transID_ == recv_msg.transID) {
						if (it->isStart()) {
							it->startCount();
						}
						if (recv_msg.value != "") {
							it->increCount();
							it->pushValue(recv_msg.value);
							break;
						}
					}
				}
				break;
			}
		}

	}
	/*
	 * This function should also ensure all READ and UPDATE operation
	 * get QUORUM replies
	 */
	for (list<ReadTransaction>::iterator it = buffRead.begin(); it != buffRead.end(); ) {
		if (it->count_ == -1) {
			it++;
		} else if (it->count_ >= QUORUM) {
			//case READ
			int max = 0;
			string ret;
			for (auto i = it->values_.begin(); i != it->values_.end(); ++i) {
				if (i->second > max)
					ret = i->first;
				//TODO for two euqal max
				//else if (i->second == max) {
				//	log->logReadFail(&memberNode->addr, true, it->transID_, it->key_);
				//}
			}
			log->logReadSuccess(&memberNode->addr, true, it->transID_, it->key_, ret);
			it = buffRead.erase(it);
		} else { //if (it->count_ < QUORUM)
			//case READ
			log->logReadFail(&memberNode->addr, true, it->transID_, it->key_);
			it = buffRead.erase(it);
		}
	}

	for (list<Transaction>::iterator it = buff.begin(); it != buff.end(); ) {
		if (it->count_ == -1) {
			it++;
		} else if (it->count_ >= QUORUM) {
			switch (it->type_) {
				case CREATE:
					log->logCreateSuccess(&memberNode->addr, true, it->transID_, it->key_, it->value_);
					break;
				case UPDATE:
					log->logUpdateSuccess(&memberNode->addr, true, it->transID_, it->key_, it->value_);
					break;
				case DELETE:
					log->logDeleteSuccess(&memberNode->addr, true, it->transID_, it->key_);
					break;
				default:
					//error
					break;
			}
			it = buff.erase(it);
		} else { //if (it->count_ < QUORUM)
			switch (it->type_) {
				case CREATE:
					log->logCreateFail(&memberNode->addr, true, it->transID_, it->key_, it->value_);
					break;
				case UPDATE:
					log->logUpdateFail(&memberNode->addr, true, it->transID_, it->key_, it->value_);
					break;
				case DELETE:
					log->logDeleteFail(&memberNode->addr, true, it->transID_, it->key_);
					break;
				default:
					//error
					break;
			}
			it = buff.erase(it);
		}
	}
}
Exemplo n.º 24
0
void
do_install(void)
{

	msg_display(MSG_installusure);
	process_menu(MENU_noyes, NULL);
	if (!yesno)
		return;

	get_ramsize();

	if (find_disks(msg_string(MSG_install)) < 0)
		return;
	clear();
	refresh();

	if (check_swap(diskdev, 0) > 0) {
		msg_display(MSG_swapactive);
		process_menu(MENU_ok, NULL);
		if (check_swap(diskdev, 1) < 0) {
			msg_display(MSG_swapdelfailed);
			process_menu(MENU_ok, NULL);
			if (!debug)
				return;
		}
	}

	process_menu(MENU_distset, NULL);

	if (!md_get_info()) {
		msg_display(MSG_abort);
		process_menu(MENU_ok, NULL);
		return;
	}

	if (md_make_bsd_partitions() == 0) {
		msg_display(MSG_abort);
		process_menu(MENU_ok, NULL);
		return;
	}

	/* Last chance ... do you really want to do this? */
	clear();
	refresh();
	msg_display(MSG_lastchance, diskdev);
	process_menu(MENU_noyes, NULL);
	if (!yesno)
		return;

	if (md_pre_disklabel() != 0)
		return;

	if (write_disklabel() != 0)
		return;

	if (md_post_disklabel() != 0)
		return;

	if (make_filesystems())
		return;

	if (make_fstab() != 0)
		return;

	if (md_post_newfs() != 0)
		return;

	/* Unpack the distribution. */
	if (get_and_unpack_sets(0, MSG_disksetupdone,
	    MSG_extractcomplete, MSG_abortinst) != 0)
		return;

	if (md_post_extract() != 0)
		return;

	do_configmenu();

	sanity_check();

	md_cleanup_install();

	msg_display(MSG_instcomplete);
	process_menu(MENU_ok, NULL);
}
Exemplo n.º 25
0
static enum ECICallbackReturn my_callback(ECIHand hEngine, enum ECIMessage Msg, long lParam, void *pData)
{
  size_t effective_msg_length = 0;
  size_t allocated_msg_length = 0;
  int res;
  uint32_t func_sav;
  struct engine_t *engine = (struct engine_t*)pData;

  ENTER();

  if (!engine || !engine->cb_msg) {
    err("LEAVE, args error");
    return eciDataAbort;
  }

  if ((Msg < eciWaveformBuffer) || (Msg > eciSynthesisBreak)) {
    err("LEAVE, unknown eci message (%d)", Msg);
    return eciDataAbort;
  }

  allocated_msg_length = engine->cb_msg_length;
  effective_msg_length = MSG_HEADER_LENGTH + 2*lParam;

  if (effective_msg_length > allocated_msg_length) {
    err("LEAVE, samples size error (%d > %d)", effective_msg_length, allocated_msg_length);
    return eciDataAbort;
  }

  engine->cb_msg->func = MSG_CB_WAVEFORM_BUFFER + Msg - eciWaveformBuffer;
  if (!msg_string(engine->cb_msg->func)) {
    err("LEAVE, unknown function (%d)", engine->cb_msg->func);
    return eciDataAbort;
  }
  engine->cb_msg->id = MSG_TO_APP_ID;
  ++engine->cb_msg->count;

  engine->cb_msg->res = 0;
  engine->cb_msg->effective_data_length = 2*lParam;
  dbg("send cb msg '%s', length=%d, engine=%p (#%d)",msg_string(engine->cb_msg->func),
      engine->cb_msg->effective_data_length, engine, engine->cb_msg->count);
  res = pipe_write(my_voxind->pipe_command, engine->cb_msg, &effective_msg_length);
  if (res) {
    err("LEAVE, write error (%d)", res);
    return eciDataAbort;
  }

  effective_msg_length = MIN_MSG_SIZE;
  func_sav = engine->cb_msg->func;
  res = pipe_read(my_voxind->pipe_command, engine->cb_msg, &effective_msg_length);
  if (res) {
    err("LEAVE, read error (%d)",res);
    return eciDataAbort;
  }

  if (engine->cb_msg->func != func_sav) {
    err("LEAVE, received func error (%d, expected=%d)", engine->cb_msg->func, func_sav);
    return eciDataAbort;
  }

  dbg("recv msg '%s', length=%d, res=%d (#%d)", msg_string(engine->cb_msg->func),
      engine->cb_msg->effective_data_length, engine->cb_msg->res, engine->cb_msg->count);

  LEAVE();
  return engine->cb_msg->res;
}
Exemplo n.º 26
0
/*
 * Get the information to configure the network, configure it and
 * make sure both the gateway and the name server are up.
 */
int
config_network(void)
{
	char *textbuf;
	int  octet0;
	int  dhcp_config;
	int  nfs_root = 0;
 	int  slip = 0;
 	int  pid, status;
 	char **ap, *slcmd[10], *in_buf;
 	char buffer[STRSIZE];
 	struct statvfs sb;
	struct net_desc net_devs[MAX_NETS];
	menu_ent net_menu[5];
	int menu_no;
	int num_devs;
	int selected_net;
	int i;
#ifdef INET6
	int v6config = 1, rv;
#endif

	FILE *f;
	time_t now;

	if (network_up)
		return (1);

	num_devs = get_ifconfig_info(net_devs);

	if (num_devs < 1) {
		/* No network interfaces found! */
		msg_display(MSG_nonet);
		process_menu(MENU_ok, NULL);
		return (-1);
	}

	for (i = 0; i < num_devs; i++) {
		net_menu[i].opt_name = net_devs[i].if_dev;
		net_menu[i].opt_menu = OPT_NOMENU;
		net_menu[i].opt_flags = OPT_EXIT;
		net_menu[i].opt_action = set_menu_select;
	}
again:
	selected_net = -1;
	menu_no = new_menu(MSG_netdevs,
		net_menu, num_devs, -1, 4, 0, 0,
		MC_SCROLL,
		NULL, NULL, NULL, NULL, NULL);
	msg_display(MSG_asknetdev, "");
	process_menu(menu_no, &selected_net);
	free_menu(menu_no);
	
	if (selected_net == -1)
	    return 0;

	network_up = 1;
	dhcp_config = 0;

	strncpy(net_dev, net_devs[selected_net].if_dev, STRSIZE);

	if (!handle_license(net_dev))
		goto done;

	slip = net_dev[0] == 's' && net_dev[1] == 'l' &&
	    isdigit((unsigned char)net_dev[2]);

	/* If root is on NFS do not reconfigure the interface. */
	if (statvfs("/", &sb) == 0 && strcmp(sb.f_fstypename, "nfs") == 0) {
		nfs_root = 1;
		get_ifinterface_info();
		get_if6interface_info();
		get_host_info();
	} else if (!slip) {
		/* Preload any defaults we can find */
		get_ifinterface_info();
		get_if6interface_info();
		get_host_info();

		/* domain and host */
		msg_display(MSG_netinfo);

		/* ethernet medium */
		for (;;) {
			msg_prompt_add(MSG_net_media, net_media, net_media,
					sizeof net_media);

			/*
			 * ifconfig does not allow media specifiers on
			 * IFM_MANUAL interfaces.  Our UI gives no way
			 * to set an option back
			 * to null-string if it gets accidentally set.
			 * Check for plausible alternatives.
			 */
			if (strcmp(net_media, "<default>") == 0 ||
			    strcmp(net_media, "default") == 0 ||
			    strcmp(net_media, "<manual>") == 0 ||
			    strcmp(net_media, "manual") == 0 ||
			    strcmp(net_media, "<none>") == 0 ||
			    strcmp(net_media, "none") == 0 ||
			    strcmp(net_media, " ") == 0) {
				*net_media = '\0';
			}

			if (*net_media == '\0')
				break;
			/*
			 * We must set the media type here - to give dhcp
			 * a chance
			 */
			if (run_program(0, "/sbin/ifconfig %s media %s",
				    net_dev, net_media) == 0)
				break;
			/* Failed to set - output the supported values */
			if (collect(T_OUTPUT, &textbuf, "/sbin/ifconfig -m %s |"
				    "while IFS=; read line;"
				    " do [ \"$line\" = \"${line#*media}\" ] || "
				    "echo $line;"
				    " done", net_dev ) > 0)
				msg_display(textbuf);
			free(textbuf);
		}

		net_dhcpconf = 0;
		/* try a dhcp configuration */
		dhcp_config = config_dhcp(net_dev);
		if (dhcp_config) {
			char *nline;

			/* Get newly configured data off interface. */
			get_ifinterface_info();
			get_if6interface_info();
			get_host_info();

			net_dhcpconf |= DHCPCONF_IPADDR;

			/*
			 * Extract default route from output of
			 * 'route -n show'
			 */
			if (collect(T_OUTPUT, &textbuf,
			    "/sbin/route -n show | "
			    "while read dest gateway flags;"
			    " do [ \"$dest\" = default ] && {"
			    " echo \"$gateway\"; break; };"
			    " done" ) > 0)
				strlcpy(net_defroute, textbuf,
				    sizeof net_defroute);
			free(textbuf);
			if ((nline = strchr(net_defroute, '\n')))
				*nline = '\0';

			/* pull nameserver info out of /etc/resolv.conf */
			if (collect(T_OUTPUT, &textbuf,
			    "cat /etc/resolv.conf 2>/dev/null |"
			    " while read keyword address rest;"
			    " do [ \"$keyword\" = nameserver ] &&"
			    " { echo \"$address\"; break; };"
			    " done" ) > 0)
				strlcpy(net_namesvr, textbuf,
				    sizeof net_namesvr);
			free(textbuf);
			if ((nline = strchr(net_namesvr, '\n')))
				*nline = '\0';
			if (net_namesvr[0] != '\0')
				net_dhcpconf |= DHCPCONF_NAMESVR;

			/* pull domain info out of /etc/resolv.conf */
			if (collect(T_OUTPUT, &textbuf,
			    "cat /etc/resolv.conf 2>/dev/null |"
			    " while read keyword domain rest;"
			    " do [ \"$keyword\" = domain ] &&"
			    " { echo \"$domain\"; break; };"
			    " done" ) > 0)
				strlcpy(net_domain, textbuf,
				    sizeof net_domain);
			free(textbuf);
			if (net_domain[0] == '\0') {
				/* pull domain info out of /etc/resolv.conf */
				if (collect(T_OUTPUT, &textbuf,
				    "cat /etc/resolv.conf 2>/dev/null |"
				    " while read keyword search rest;"
				    " do [ \"$keyword\" = search ] &&"
				    " { echo \"$search\"; break; };"
				    " done" ) > 0)
					strlcpy(net_domain, textbuf,
					    sizeof net_domain);
				free(textbuf);
			}
			if ((nline = strchr(net_domain, '\n')))
				*nline = '\0';
			if (net_domain[0] != '\0')
				net_dhcpconf |= DHCPCONF_DOMAIN;

			if (gethostname(net_host, sizeof(net_host)) == 0 &&
			    net_host[0] != 0)
				net_dhcpconf |= DHCPCONF_HOST;
		}
	}

	if (!(net_dhcpconf & DHCPCONF_HOST))
		msg_prompt_add(MSG_net_host, net_host, net_host,
		    sizeof net_host);

	if (!(net_dhcpconf & DHCPCONF_DOMAIN))
		msg_prompt_add(MSG_net_domain, net_domain, net_domain,
		    sizeof net_domain);

	if (!dhcp_config) {
		/* Manually configure IPv4 */
		if (!nfs_root)
			msg_prompt_add(MSG_net_ip, net_ip, net_ip,
			    sizeof net_ip);
		if (slip)
			msg_prompt_add(MSG_net_srv_ip, net_srv_ip, net_srv_ip,
			    sizeof net_srv_ip);
		else if (!nfs_root) {
			/* We don't want netmasks for SLIP */
			octet0 = atoi(net_ip);
			if (!net_mask[0]) {
				if (0 <= octet0 && octet0 <= 127)
					strlcpy(net_mask, "0xff000000",
				    	sizeof(net_mask));
				else if (128 <= octet0 && octet0 <= 191)
					strlcpy(net_mask, "0xffff0000",
				    	sizeof(net_mask));
				else if (192 <= octet0 && octet0 <= 223)
					strlcpy(net_mask, "0xffffff00",
				    	sizeof(net_mask));
			}
			msg_prompt_add(MSG_net_mask, net_mask, net_mask,
			    sizeof net_mask);
		}
		msg_prompt_add(MSG_net_defroute, net_defroute, net_defroute,
		    sizeof net_defroute);
	}

	if (!(net_dhcpconf & DHCPCONF_NAMESVR)) {
#ifdef INET6
		if (v6config) {
			rv = 0;
			process_menu(MENU_namesrv6, &rv);
			if (!rv)
				msg_prompt_add(MSG_net_namesrv, net_namesvr,
				    net_namesvr, sizeof net_namesvr);
		} else
#endif
		msg_prompt_add(MSG_net_namesrv, net_namesvr, net_namesvr,
		    sizeof net_namesvr);
	}

	/* confirm the setting */
	if (slip)
		msg_display(MSG_netok_slip, net_domain, net_host,
		    *net_namesvr == '\0' ? "<none>" : net_namesvr,
		    net_dev,
		    *net_media == '\0' ? "<default>" : net_media,
		    *net_ip == '\0' ? "<none>" : net_ip,
		    *net_srv_ip == '\0' ? "<none>" : net_srv_ip,
		    *net_mask == '\0' ? "<none>" : net_mask,
		    *net_defroute == '\0' ? "<none>" : net_defroute);
	else
		msg_display(MSG_netok, net_domain, net_host,
		    *net_namesvr == '\0' ? "<none>" : net_namesvr,
		    net_dev,
		    *net_media == '\0' ? "<default>" : net_media,
		    *net_ip == '\0' ? "<none>" : net_ip,
		    *net_mask == '\0' ? "<none>" : net_mask,
		    *net_defroute == '\0' ? "<none>" : net_defroute);
#ifdef INET6
	msg_display_add(MSG_netokv6,
		     !is_v6kernel() ? "<not supported>" : net_ip6);
#endif
done:
	if (!ask_yesno(MSG_netok_ok))
		goto again;

	run_program(0, "/sbin/ifconfig lo0 127.0.0.1");

	/* dhcpcd will have configured it all for us */
	if (dhcp_config) {
		fflush(NULL);
		network_up = 1;
		return network_up;
	}

	/*
	 * we may want to perform checks against inconsistent configuration,
	 * like IPv4 DNS server without IPv4 configuration.
	 */

	/* Create /etc/resolv.conf if a nameserver was given */
	if (net_namesvr[0] != '\0') {
		f = fopen("/etc/resolv.conf", "w");
		if (f == NULL) {
			if (logfp)
				(void)fprintf(logfp,
				    "%s", msg_string(MSG_resolv));
			(void)fprintf(stderr, "%s", msg_string(MSG_resolv));
			exit(1);
		}
		scripting_fprintf(NULL, "cat <<EOF >/etc/resolv.conf\n");
		time(&now);
		scripting_fprintf(f, ";\n; BIND data file\n; %s %s;\n",
		    "Created by NetBSD sysinst on", safectime(&now));
		if (net_domain[0] != '\0')
			scripting_fprintf(f, "search %s\n", net_domain);
		if (net_namesvr[0] != '\0')
			scripting_fprintf(f, "nameserver %s\n", net_namesvr);
		scripting_fprintf(NULL, "EOF\n");
		fflush(NULL);
		fclose(f);
	}

	if (net_ip[0] != '\0') {
		if (slip) {
			/* XXX: needs 'ifconfig sl0 create' much earlier */
			/* Set SLIP interface UP */
			run_program(0, "/sbin/ifconfig %s inet %s %s up",
			    net_dev, net_ip, net_srv_ip);
			strcpy(sl_flags, "-s 115200 -l /dev/tty00");
			msg_prompt_win(MSG_slattach, -1, 12, 70, 0,
				sl_flags, sl_flags, 255);

			/* XXX: wtf isn't run_program() used here? */
			pid = fork();
			if (pid == 0) {
				strcpy(buffer, "/sbin/slattach ");
				strcat(buffer, sl_flags);
				in_buf = buffer;

				for (ap = slcmd; (*ap = strsep(&in_buf, " ")) != NULL;)
				if (**ap != '\0')
					++ap;

				execvp(slcmd[0], slcmd);
			} else
				wait4(pid, &status, WNOHANG, 0);
		} else if (!nfs_root) {
			if (net_mask[0] != '\0') {
				run_program(0, "/sbin/ifconfig %s inet %s netmask %s",
				    net_dev, net_ip, net_mask);
			} else {
				run_program(0, "/sbin/ifconfig %s inet %s",
			    	net_dev, net_ip);
			}
		}
	}

	/* Set host name */
	if (net_host[0] != '\0')
	  	sethostname(net_host, strlen(net_host));

	/* Set a default route if one was given */
	if (!nfs_root && net_defroute[0] != '\0') {
		run_program(RUN_DISPLAY | RUN_PROGRESS,
				"/sbin/route -n flush -inet");
		run_program(RUN_DISPLAY | RUN_PROGRESS,
				"/sbin/route -n add default %s", net_defroute);
	}

	/*
	 * wait a couple of seconds for the interface to go live.
	 */
	if (!nfs_root) {
		msg_display_add(MSG_wait_network);
		sleep(5);
	}

	/*
	 * ping should be verbose, so users can see the cause
	 * of a network failure.
	 */
	if (net_defroute[0] != '\0' && network_up)
		network_up = !run_program(RUN_DISPLAY | RUN_PROGRESS,
		    "/sbin/ping -v -c 5 -w 5 -o -n %s", net_defroute);
	if (net_namesvr[0] != '\0' && network_up) {
#ifdef INET6
		if (strchr(net_namesvr, ':'))
			network_up = !run_program(RUN_DISPLAY | RUN_PROGRESS,
			    "/sbin/ping6 -v -c 3 -n %s", net_namesvr);
		else
#endif
			network_up = !run_program(RUN_DISPLAY | RUN_PROGRESS,
			    "/sbin/ping -v -c 5 -w 5 -o -n %s", net_namesvr);
	}
	fflush(NULL);

	return network_up;
}