コード例 #1
0
ファイル: platform-intel.c プロジェクト: stateman/mdadm
const struct imsm_orom *find_imsm_efi(enum sys_dev_type hba_id)
{
	if (hba_id >= SYS_DEV_MAX)
		return NULL;

	dprintf("EFI CAP: %p,  pid: %d pop: %d\n",
		&imsm_efi[hba_id], (int) getpid(), populated_efi[hba_id]);

	/* it's static data so we only need to read it once */
	if (populated_efi[hba_id]) {
		dprintf("EFI CAP: %p, pid: %d pop: %d\n",
			&imsm_efi[hba_id], (int) getpid(), populated_efi[hba_id]);
		return &imsm_efi[hba_id];
	}
	if (check_env("IMSM_TEST_AHCI_EFI") ||
	    check_env("IMSM_TEST_SCU_EFI")) {
		dprintf("OROM CAP: %p,  pid: %d pop: %d\n",
			&imsm_efi[hba_id], (int) getpid(), populated_efi[hba_id]);
		return imsm_platform_test(hba_id, &populated_efi[hba_id], &imsm_efi[hba_id]);
	}
	/* OROM test is set, return that there is no EFI capabilities */
	if (check_env("IMSM_TEST_OROM"))
		return NULL;

	if (read_efi_variable(&imsm_efi[hba_id], sizeof(imsm_efi[0]), hba_id == SYS_DEV_SAS ? SCU_PROP : AHCI_PROP, VENDOR_GUID)) {
		populated_efi[hba_id] = 0;
		return NULL;
	}

	populated_efi[hba_id] = 1;
	return &imsm_efi[hba_id];
}
コード例 #2
0
ファイル: platform-intel.c プロジェクト: stateman/mdadm
const struct imsm_orom *imsm_platform_test(enum sys_dev_type hba_id, int *populated,
					   struct imsm_orom *imsm_orom)
{
	memset(imsm_orom, 0, sizeof(*imsm_orom));
	imsm_orom->rlc = IMSM_OROM_RLC_RAID0 | IMSM_OROM_RLC_RAID1 |
				IMSM_OROM_RLC_RAID10 | IMSM_OROM_RLC_RAID5;
	imsm_orom->sss = IMSM_OROM_SSS_4kB | IMSM_OROM_SSS_8kB |
				IMSM_OROM_SSS_16kB | IMSM_OROM_SSS_32kB |
				IMSM_OROM_SSS_64kB | IMSM_OROM_SSS_128kB |
				IMSM_OROM_SSS_256kB | IMSM_OROM_SSS_512kB |
				IMSM_OROM_SSS_1MB | IMSM_OROM_SSS_2MB;
	imsm_orom->dpa = IMSM_OROM_DISKS_PER_ARRAY;
	imsm_orom->tds = IMSM_OROM_TOTAL_DISKS;
	imsm_orom->vpa = IMSM_OROM_VOLUMES_PER_ARRAY;
	imsm_orom->vphba = IMSM_OROM_VOLUMES_PER_HBA;
	imsm_orom->attr = imsm_orom->rlc | IMSM_OROM_ATTR_ChecksumVerify;
	*populated = 1;

	if (check_env("IMSM_TEST_OROM_NORAID5")) {
		imsm_orom->rlc = IMSM_OROM_RLC_RAID0 | IMSM_OROM_RLC_RAID1 |
				IMSM_OROM_RLC_RAID10;
	}
	if (check_env("IMSM_TEST_AHCI_EFI_NORAID5") && (hba_id == SYS_DEV_SAS)) {
		imsm_orom->rlc = IMSM_OROM_RLC_RAID0 | IMSM_OROM_RLC_RAID1 |
				IMSM_OROM_RLC_RAID10;
	}
	if (check_env("IMSM_TEST_SCU_EFI_NORAID5") && (hba_id == SYS_DEV_SATA)) {
		imsm_orom->rlc = IMSM_OROM_RLC_RAID0 | IMSM_OROM_RLC_RAID1 |
				IMSM_OROM_RLC_RAID10;
	}

	return imsm_orom;
}
コード例 #3
0
ファイル: platform-intel.c プロジェクト: stateman/mdadm
static const struct imsm_orom *find_imsm_hba_orom(enum sys_dev_type hba_id)
{
	unsigned long align;

	if (hba_id >= SYS_DEV_MAX)
		return NULL;

	/* it's static data so we only need to read it once */
	if (populated_orom[hba_id]) {
		dprintf("OROM CAP: %p, pid: %d pop: %d\n",
			&imsm_orom[hba_id], (int) getpid(), populated_orom[hba_id]);
		return &imsm_orom[hba_id];
	}
	if (check_env("IMSM_TEST_OROM")) {
		dprintf("OROM CAP: %p,  pid: %d pop: %d\n",
                     &imsm_orom[hba_id], (int) getpid(), populated_orom[hba_id]);
		return imsm_platform_test(hba_id, &populated_orom[hba_id], &imsm_orom[hba_id]);
	}
	/* return empty OROM capabilities in EFI test mode */
	if (check_env("IMSM_TEST_AHCI_EFI") ||
	    check_env("IMSM_TEST_SCU_EFI"))
		return NULL;


	if (intel_devices != NULL)
		free_sys_dev(&intel_devices);

	intel_devices = find_intel_devices();

	if (intel_devices == NULL)
		return NULL;

	/* scan option-rom memory looking for an imsm signature */
	if (check_env("IMSM_SAFE_OROM_SCAN"))
		align = 2048;
	else
		align = 512;
	if (probe_roms_init(align) != 0)
		return NULL;
	probe_roms();
	/* ignore return value - True is returned if both adapater roms are found */
	scan_adapter_roms(scan);
	probe_roms_exit();

	if (intel_devices != NULL)
		free_sys_dev(&intel_devices);
	intel_devices = NULL;

	if (populated_orom[hba_id])
		return &imsm_orom[hba_id];
	return NULL;
}
コード例 #4
0
ファイル: init_ncurses.cpp プロジェクト: adrijere/cpp_nibbler
Ncurses::Ncurses(int x, int y)
{
  try
    {
      if (check_env() == -1)
	throw (DisplayException("Environement variable needed"));
    }
  catch (const Exception e)
    {
      std::cerr << e.what() << std::endl;
    }
  initscr();
  start_color();
  curs_set(FALSE);
  keypad(stdscr, TRUE);
  noecho();
  nodelay(stdscr, TRUE);
  _x = x + 2;
  _y = y + 2;
  _dtime = 150000;
  _game = newwin(_y, _x, 0, 0);
  set_color_pair();
  draw_border();
  handle_resize();
  wrefresh(_game);
  
}
コード例 #5
0
ファイル: config-aws.c プロジェクト: dmr41/ncbi-vdb
extern
void add_aws_nodes ( KConfig *self )
{
    char home [ 4096 ] = "";

    size_t num_writ;
    char path [ 4096 ];
    rc_t rc;

    check_env ( self, home, sizeof home );
    /* if home environtment is found, create AWS root node */

    if ( home [ 0 ] != 0 )
    {
        rc = string_printf ( path, sizeof path, &num_writ, "%s/.aws", home );
        if ( rc == 0 && num_writ != 0 )
        {
            KConfigNode *aws_node;
            
            /* create aws node */
            rc = KConfigOpenNodeUpdate ( self, &aws_node, "AWS", NULL );
            if ( rc == 0 )
                rc = aws_find_nodes ( aws_node, path );
            
            rc = KConfigNodeRelease ( aws_node );
        }
    }
}
コード例 #6
0
ファイル: main.c プロジェクト: foo-foo/epitech-projects
/*
**		Check_env: check the TERM environnement variable for tgetent.
**		Init_termios: init terminal settings (!raw mode + !Echo mode).
**		Create a list with arguments given by user.
**		After receving selection from my_select: reinit term settings.
**		Return selection to the shell.
*/
int		main(int ac, char **av, char **env)
{
  int		i;
  t_termios	t;
  t_list	*list;

  i = 1;
  if (ac == 1 || ac == 1)
    return (msg_error("error: to few arguments\n", 1));
  if (check_env(env) == 1)
    return (1);
  if (init_termios(&t) == 1)
    return (1);
  if ((list = my_create_list()) == NULL)
    return (reinit_termios(&t));
  while (i < ac)
    {
      my_put_end_list(list, av[i], i);
      i = i + 1;
    }
  if (my_select(t, list, i - 2) == 1)
    return (reinit_termios(&t));
  my_show_selected_list(list);
  if (reinit_termios(&t) == 1)
    return (msg_error("error: cannot reinit terminal settings\n", 1));
  my_rm_list(list);
  return (0);
}
コード例 #7
0
ファイル: platform-intel.c プロジェクト: Jongil-Park/mdadm
const struct imsm_orom *find_imsm_orom(void)
{
	static int populated = 0;
	unsigned long align;

	/* it's static data so we only need to read it once */
	if (populated)
		return &imsm_orom;

	if (check_env("IMSM_TEST_OROM")) {
		memset(&imsm_orom, 0, sizeof(imsm_orom));
		imsm_orom.rlc = IMSM_OROM_RLC_RAID0 | IMSM_OROM_RLC_RAID1 |
				IMSM_OROM_RLC_RAID10 | IMSM_OROM_RLC_RAID5;
		imsm_orom.sss = IMSM_OROM_SSS_4kB | IMSM_OROM_SSS_8kB |
				IMSM_OROM_SSS_16kB | IMSM_OROM_SSS_32kB |
				IMSM_OROM_SSS_64kB | IMSM_OROM_SSS_128kB |
				IMSM_OROM_SSS_256kB | IMSM_OROM_SSS_512kB |
				IMSM_OROM_SSS_1MB | IMSM_OROM_SSS_2MB;
		imsm_orom.dpa = 6;
		imsm_orom.tds = 6;
		imsm_orom.vpa = 2;
		imsm_orom.vphba = 4;
		imsm_orom.attr = imsm_orom.rlc | IMSM_OROM_ATTR_ChecksumVerify;
		populated = 1;
		return &imsm_orom;
	}

	if (!platform_has_intel_ahci())
		return NULL;

	/* scan option-rom memory looking for an imsm signature */
	if (check_env("IMSM_SAFE_OROM_SCAN"))
		align = 2048;
	else
		align = 512;
	if (probe_roms_init(align) != 0)
		return NULL;
	probe_roms();
	populated = scan_adapter_roms(scan);
	probe_roms_exit();

	if (populated)
		return &imsm_orom;
	return NULL;
}
コード例 #8
0
ファイル: mdmon.c プロジェクト: DanielRussell/mdadm
/* if we are debugging and starting mdmon by hand then don't fork */
static int do_fork(void)
{
	#ifdef DEBUG
	if (check_env("MDADM_NO_MDMON"))
		return 0;
	#endif

	return 1;
}
コード例 #9
0
ファイル: vcma9.c プロジェクト: zipob/OrangePI-Kernel
int board_late_init(void)
{
    /*
     * check if environment is healthy, otherwise restore values
     * from shadow copy
     */
    check_env();
    return 0;
}
コード例 #10
0
ファイル: platform-intel.c プロジェクト: stateman/mdadm
int path_attached_to_hba(const char *disk_path, const char *hba_path)
{
	int rc;

	if (check_env("IMSM_TEST_AHCI_DEV") ||
	    check_env("IMSM_TEST_SCU_DEV")) {
		return 1;
	}

	if (!disk_path || !hba_path)
		return 0;
	dprintf("hba: %s - disk: %s\n", hba_path, disk_path);
	if (strncmp(disk_path, hba_path, strlen(hba_path)) == 0)
		rc = 1;
	else
		rc = 0;

	return rc;
}
コード例 #11
0
ファイル: yaft.c プロジェクト: saitoha/yaft
int main()
{
	uint8_t buf[BUFSIZE];
	ssize_t size;
	fd_set fds;
	struct timeval tv;
	struct framebuffer fb;
	struct terminal term;

	/* init */
	setlocale(LC_ALL, "");
	if (atexit(tty_die) != 0)
		fatal("atexit failed");

	tty_init();
	fb_init(&fb, term.color_palette);
	check_env(&fb);
	term_init(&term, fb.res, fb.rotate);

	/* fork and exec shell */
	eforkpty(&term.fd, term.lines, term.cols);

	/* main loop */
	while (tty.loop_flag) {
		if (tty.redraw_flag) {
			redraw(&term);
			refresh(&fb, &term);
			tty.redraw_flag = false;
		}

		check_fds(&fds, &tv, STDIN_FILENO, term.fd);
		if (FD_ISSET(STDIN_FILENO, &fds)) {
			size = read(STDIN_FILENO, buf, BUFSIZE);
			if (size > 0)
				ewrite(term.fd, buf, size);
		}
		if (FD_ISSET(term.fd, &fds)) {
			size = read(term.fd, buf, BUFSIZE);
			if (size > 0) {
				if (DEBUG)
					ewrite(STDOUT_FILENO, buf, size);
				parse(&term, buf, size);
				if (tty.lazy_draw && size == BUFSIZE)
					continue;
				refresh(&fb, &term);
			}
		}
	}

	/* die */
	term_die(&term);
	fb_die(&fb);

	return EXIT_SUCCESS;
}
コード例 #12
0
ファイル: tst_res.c プロジェクト: kraj/ltp
static void tst_res__(const char *file, const int lineno, int ttype,
                      const char *arg_fmt, ...)
{
	pthread_mutex_lock(&tmutex);

	char tmesg[USERMESG];
	int len = 0;
	int ttype_result = TTYPE_RESULT(ttype);

	if (file && (ttype_result != TPASS && ttype_result != TINFO))
		len = sprintf(tmesg, "%s:%d: ", file, lineno);
	EXPAND_VAR_ARGS(tmesg + len, arg_fmt, USERMESG - len);

	/*
	 * Save the test result type by ORing ttype into the current exit
	 * value (used by tst_exit()).
	 */
	T_exitval |= ttype_result;

	if (ttype_result == TPASS)
		passed_cnt++;

	check_env();

	/*
	 * Set the test case number and print the results, depending on the
	 * display type.
	 */
	if (ttype_result == TWARN || ttype_result == TINFO) {
		tst_print(TCID, 0, ttype, tmesg);
	} else {
		if (tst_count < 0)
			tst_print(TCID, 0, TWARN,
				  "tst_res(): tst_count < 0 is not valid");

		/*
		 * Process each display type.
		 */
		switch (T_mode) {
		case DISCARD:
			break;
		case NOPASS:	/* filtered by tst_print() */
			tst_condense(tst_count + 1, ttype, tmesg);
			break;
		default:	/* VERBOSE */
			tst_print(TCID, tst_count + 1, ttype, tmesg);
			break;
		}

		tst_count++;
	}

	pthread_mutex_unlock(&tmutex);
}
コード例 #13
0
ファイル: vm.c プロジェクト: qnighy/ruby-1.9.2p0
static VALUE
check_env_value(VALUE envval)
{
    rb_env_t *env;
    GetEnvPtr(envval, env);

    if (check_env(env)) {
	return envval;
    }
    rb_bug("invalid env");
    return Qnil;		/* unreachable */
}
コード例 #14
0
ファイル: process.c プロジェクト: Kafei59/epitech-projects
void		my_cmd(t_list *list, char *s, char **env, int i)
{
  char		*epur_s;
  char		**tab;

  epur_s = epur_str(s);
  tab = my_str_to_wordtab(epur_s, &i);
  if ((my_builtin(list, s, tab, env)) == 0 &&		\
      check_redir(epur_s, tab, env, i) == 0)
      my_fork(tab[0], tab, env);
  if (check_env(tab, env) == 1)
    env = env_cpy(list);
  check_recurs(list, s, env, i - 1);
  my_mini_free(epur_s, tab);
}
コード例 #15
0
int main(void)
{
	int nf;

	check_env();

	Suite *s = mapping_engine_suite();
	
	SRunner *sr;
	sr = srunner_create(s);
	srunner_run_all(sr, CK_VERBOSE);
	nf = srunner_ntests_failed(sr);
	srunner_free(sr);
	return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
コード例 #16
0
ファイル: main.c プロジェクト: YliesC/42sh
int		main(int ac, char **av, char **env)
{
  t_utils	utils;
  char		*path_history;

  ac = (int)ac;
  av = (char **)av;
  path_history = create_path_history();
  init_struct(&utils);
  add_history_to_list(&(utils.history));
  check_env(&utils, env);
  my_read(&utils);
  add_history_to_file(path_history, utils.history);
  my_free(&utils);
  return (utils.my_exit);
}
コード例 #17
0
ファイル: bpf.c プロジェクト: AshishNamdev/linux
int test__bpf(int i)
{
	int err;

	if (i < 0 || i >= (int)ARRAY_SIZE(bpf_testcase_table))
		return TEST_FAIL;

	if (geteuid() != 0) {
		pr_debug("Only root can run BPF test\n");
		return TEST_SKIP;
	}

	if (check_env())
		return TEST_SKIP;

	err = __test__bpf(i);
	return err;
}
コード例 #18
0
ファイル: support.c プロジェクト: luizluca/opensync-luizluca
int osync_testsuite(int argc, char **argv, const char *unittest,
		struct osync_testcase_s *tc)
{
	int nf;
	Suite *s = suite_create(unittest);
	SRunner *sr;

	check_env();

	if (!osync_testsuite_selected(s, argc, argv, tc))
		osync_testsuite_all(s, tc);

	sr = srunner_create(s);
	srunner_run_all(sr, CK_VERBOSE);
	nf = srunner_ntests_failed(sr);
	srunner_free(sr);
	return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
コード例 #19
0
ファイル: main.cpp プロジェクト: frarees/rvtmod
int main(int argc, char **argv)
{
  int res;
  World *world;


  check_env();

  if(!appopt.parseArgs(argc,argv))
    return 100;

  if(appopt.inputfname==NULL)
    {
      perror(0,ERROR_NO_IFILE,"No input file specified.");
      return 100;
    };

  welcome();

  world=new World;

  res=processInput(appopt.inputfname, world);

  if(res == 0)
    {
      if(appopt.create_instance)
        {
          world->set_grip();  // vag 2001-06-28
	  world->write_prm(appopt.woutname,appopt.ioutname,appopt.ncpoutname);
        }
      else
	world->write_w(appopt.woutname,appopt.ioutname,appopt.ncpoutname);
    };

  delete world;

  return res;
}
コード例 #20
0
ファイル: abuntix-setup.c プロジェクト: AlexWillisson/abuntix
int
main (int argc, char **argv)
{
	char c;

	while ((c = getopt (argc, argv, "e")) != EOF) {
		switch (c) {
		default:
			usage ();
		}
	}

	if (optind > argc || optind != argc)
		usage ();

	if (!system ("[ `uname -i` = x86_64 ]"))
		arch = "amd64";
	else
		arch = "i386";

	check_sources ();
	check_packages ();
	check_emacs ();
	check_pythonrc ();
	check_xterm ();
	check_fluxbox ();
	check_tex_papersize ();
	check_chrome ();
	check_env ();
	
	check_alternative ("editor", "emacs");
	check_alternative ("x-terminal-emulator", "uxterm");

	if (error_flag == 0)
		printf ("everything ok\n");

	return (0);
}
コード例 #21
0
ファイル: set_env.c プロジェクト: GastaldiRemi/42sh
int			set_env(t_plist *plist, char **cmd, char **env)
{
  char			*new_env;

  (void)env;
  new_env = NULL;
  if (cmd[1] == NULL)
    {
      show_list(plist, NULL, NULL);
      return (0);
    }
  if (cmd[2] == NULL)
    return (set_env_nothing(plist, cmd));
  if (check_env(plist, cmd) == -1)
    {
      new_env = my_strcat(new_env, cmd[1], -1, -1);
      new_env = my_strcat(new_env, "=", -1, -1);
      new_env = my_strcat(new_env, cmd[2], -1, -1);
      env_to_list(plist, new_env);
    }
  free(new_env);
  return (0);
}
コード例 #22
0
ファイル: debuggee.cpp プロジェクト: vadimcn/vscode-lldb
int main(int argc, char* argv[]) {
    if (argc < 2) { // #BP1
        return -1;
    }
    std::string testcase = argv[1];
    if (testcase == "deepstack") {
        deepstack(50);
    } else if (testcase == "threads") {
        threads(15);
    } else if (testcase == "check_env") {
        if (argc < 4) {
            return -1;
        }
        return (int)check_env(argv[2], argv[3]);
    } else if (testcase == "inf_loop") {
        inf_loop();
    } else if (testcase == "echo") {
        echo();
    } else if (testcase == "vars") {
        vars();
    }
    return 0;
}
コード例 #23
0
ファイル: environment.cpp プロジェクト: kusl/unicorn-lib
void check_env(const NativeString& key, const NativeString& value) {
    check_env(key);
    if (value.find(NativeCharacter(0)) != npos)
        throw std::invalid_argument("Invalid environment variable value");
}
コード例 #24
0
ファイル: Manage.c プロジェクト: saschaefer/mdadm-deb-pkg
int Manage_runstop(char *devname, int fd, int runstop, int quiet)
{
	/* Run or stop the array. array must already be configured
	 * required >= 0.90.0
	 * Only print failure messages if quiet == 0;
	 * quiet > 0 means really be quiet
	 * quiet < 0 means we will try again if it fails.
	 */
	mdu_param_t param; /* unused */

	if (runstop == -1 && md_get_version(fd) < 9000) {
		if (ioctl(fd, STOP_MD, 0)) {
			if (quiet == 0) fprintf(stderr,
						Name ": stopping device %s "
						"failed: %s\n",
						devname, strerror(errno));
			return 1;
		}
	}

	if (md_get_version(fd) < 9000) {
		fprintf(stderr, Name ": need md driver version 0.90.0 or later\n");
		return 1;
	}
	/*
	if (ioctl(fd, GET_ARRAY_INFO, &array)) {
		fprintf(stderr, Name ": %s does not appear to be active.\n",
			devname);
		return 1;
	}
	*/
	if (runstop>0) {
		if (ioctl(fd, RUN_ARRAY, &param)) {
			fprintf(stderr, Name ": failed to run array %s: %s\n",
				devname, strerror(errno));
			return 1;
		}
		if (quiet <= 0)
			fprintf(stderr, Name ": started %s\n", devname);
	} else if (runstop < 0){
		struct map_ent *map = NULL;
		struct stat stb;
		struct mdinfo *mdi;
		int devnum;
		int err;
		int count;
		/* If this is an mdmon managed array, just write 'inactive'
		 * to the array state and let mdmon clear up.
		 */
		devnum = fd2devnum(fd);
		/* Get EXCL access first.  If this fails, then attempting
		 * to stop is probably a bad idea.
		 */
		close(fd);
		fd = open(devname, O_RDONLY|O_EXCL);
		if (fd < 0 || fd2devnum(fd) != devnum) {
			if (fd >= 0)
				close(fd);
			fprintf(stderr,
				Name ": Cannot get exclusive access to %s:"
				"Perhaps a running "
				"process, mounted filesystem "
				"or active volume group?\n",
				devname);
			return 1;
		}
		mdi = sysfs_read(fd, -1, GET_LEVEL|GET_VERSION);
		if (mdi &&
		    mdi->array.level > 0 &&
		    is_subarray(mdi->text_version)) {
			int err;
			/* This is mdmon managed. */
			close(fd);

			count = 25;
			while (count &&
			       (err = sysfs_set_str(mdi, NULL,
						    "array_state",
						    "inactive")) < 0
			       && errno == EBUSY) {
				usleep(200000);
				count--;
			}
			if (err && !quiet) {
				fprintf(stderr, Name
					": failed to stop array %s: %s\n",
					devname, strerror(errno));
				return 1;
			}

			/* Give monitor a chance to act */
			ping_monitor(mdi->text_version);

			fd = open_dev_excl(devnum);
			if (fd < 0) {
				fprintf(stderr, Name
					": failed to completely stop %s"
					": Device is busy\n",
					devname);
				return 1;
			}
		} else if (mdi &&
			   mdi->array.major_version == -1 &&
			   mdi->array.minor_version == -2 &&
			   !is_subarray(mdi->text_version)) {
			struct mdstat_ent *mds, *m;
			/* container, possibly mdmon-managed.
			 * Make sure mdmon isn't opening it, which
			 * would interfere with the 'stop'
			 */
			ping_monitor(mdi->sys_name);

			/* now check that there are no existing arrays
			 * which are members of this array
			 */
			mds = mdstat_read(0, 0);
			for (m=mds; m; m=m->next)
				if (m->metadata_version &&
				    strncmp(m->metadata_version, "external:", 9)==0 &&
				    is_subarray(m->metadata_version+9) &&
				    devname2devnum(m->metadata_version+10) == devnum) {
					if (!quiet)
						fprintf(stderr, Name
							": Cannot stop container %s: "
							"member %s still active\n",
							devname, m->dev);
					free_mdstat(mds);
					if (mdi)
						sysfs_free(mdi);
					return 1;
				}
		}

		/* As we have an O_EXCL open, any use of the device
		 * which blocks STOP_ARRAY is probably a transient use,
		 * so it is reasonable to retry for a while - 5 seconds.
		 */
		count = 25; err = 0;
		while (count && fd >= 0
		       && (err = ioctl(fd, STOP_ARRAY, NULL)) < 0
		       && errno == EBUSY) {
			usleep(200000);
			count --;
		}
		if (fd >= 0 && err) {
			if (quiet == 0) {
				fprintf(stderr, Name
					": failed to stop array %s: %s\n",
					devname, strerror(errno));
				if (errno == EBUSY)
					fprintf(stderr, "Perhaps a running "
						"process, mounted filesystem "
						"or active volume group?\n");
			}
			if (mdi)
				sysfs_free(mdi);
			return 1;
		}
		/* prior to 2.6.28, KOBJ_CHANGE was not sent when an md array
		 * was stopped, so We'll do it here just to be sure.  Drop any
		 * partitions as well...
		 */
		if (fd >= 0)
			ioctl(fd, BLKRRPART, 0);
		if (mdi)
			sysfs_uevent(mdi, "change");

		
		if (devnum != NoMdDev &&
		    (stat("/dev/.udev", &stb) != 0 ||
		     check_env("MDADM_NO_UDEV"))) {
			struct map_ent *mp = map_by_devnum(&map, devnum);
			remove_devices(devnum, mp ? mp->path : NULL);
		}


		if (quiet <= 0)
			fprintf(stderr, Name ": stopped %s\n", devname);
		map_lock(&map);
		map_remove(&map, devnum);
		map_unlock(&map);
	}
	return 0;
}
コード例 #25
0
ファイル: creuvuxd.c プロジェクト: Creuvard/Creuvux
/**
 * \fn int main (int argc, char **argv)
 * \brief Fonction principale.
 *
 * \param argv Argument passés en ligne de commande
 * \return -1 en cas d'erreur, et 0 si tout va bien.
 */
int main (int argc, char **argv)
{
  /* extern char *optarg; */
  /* extern int optind; */

  int opt;

	/* update flag: 
	 * '0' -> Don't Create/Update database, 
	 * '1' -> Create/Update database
	 */
	int update = 0;
	
	int result = -1;
	
	/* check options.chroot_directory */
	struct stat st; 
  
	/* Check *.pem files */
	FILE *fd;		   
  char path[SIZE];

  /* Ensure that standart files descriptor 0, 1 and 2 are open or directed to /dev/null */
  crv_sanitise_stdfd();
  
  /* Initialize configuration options to their default values. */
  initialize_server_options(&options);

  while ((opt = getopt(argc, argv, "f:hvsuga")) != -1)
  {
		switch(opt) {
			case 'h': /* Print Help */
				fprintf(stdout, "%s\n", "Help:");
				usage (NULL);
				exit(1);
			case 'v': /* Print version */
				fprintf (stderr, "%s%s\n", "creuvuxd version ", CREUVUX_VERSION);
				fprintf (stderr, "%s\n", 
					"Before reporting bugs ([email protected]) please check "
					"the development CHANGELOG to make sure it hasn't already "
					"been fixed in devel.");
				exit(1);;
			case 'f': /* Config File */
				crv_free(options.config);
				options.config = crv_strdup(optarg);
				break;
			case 'u': /* create Database */
				update = 1;
				break;
			case '?':
			default:
				usage(NULL);
				exit(1);
		}
  }
  argc -= optind;
  argv += optind;

  /* Read configuration file and set options */
  result = read_server_conf (options.config);
  if (result == -1) {
    Free_options();
		return (-1);
	}

	/* Check if passphrase isn't NULL */
	if (options.passphrase == NULL) {
		fprintf(stdout, "%s", "Enter your passphrase:");
		fflush(stdin);
		get_passwd ();
		fprintf(stdout, "%s", "\n");
	}
 
	/* Change user id for options checking */
	result = crv_drop_priv_temp (options.user);
	if (result == -1) {
		fprintf(stderr, "%s", "Change User ID failed\n");
		Free_options();
		return (-1);
	}

  /* Check if files creuvux.log, creuvux.stat and listing.xml exist */
  result = check_env(options.chroot_directory);
  if (result == -1) {
		fprintf( stderr, "%s%s%s\n", "main(): check_env(", options.chroot_directory, ") failed");
		Free_options();
		return (-1);
  }
  
  if (optind < argc) {
		fprintf( stderr, "%s%s\n", "Extra argument ", argv[optind]);
		Free_options();
		exit(EXIT_FAILURE);
  }

  /*
   * Check Configuration 
   */

  /* Chech User */
  if (getpwnam(options.user) == NULL) {
		fprintf(stderr, "Privilege separation user %s does not exist", options.user);
		Free_options();
		exit(1);
  }

  /* Check chroot_directory */
  if ((stat(options.chroot_directory, &st) == -1) || (S_ISDIR(st.st_mode) == 0)) {
		fprintf( stderr, "Missing privilege separation directoty: %s\n", options.chroot_directory);
		Free_options();
		exit(1);
  }

  /* Check upload_directory */
  (void)crv_strncpy(path, options.chroot_directory, sizeof(path));
  (void)crv_strncat(path, options.upload_directory, sizeof(path));
  if ((stat(path, &st) == -1) || (S_ISDIR(st.st_mode) == 0)) {
		fprintf( stderr, "Missing upload directory (in chroot jail ->'%s'): %s\n", options.chroot_directory, options.upload_directory);
		Free_options();
		exit(1);
  }
  memset(path, 0, sizeof(path));

  /* Check public_directory */
  (void)crv_strncpy(path, options.chroot_directory, sizeof(path));
  (void)crv_strncat(path, options.public_directory, sizeof(path));
  if ((stat(path, &st) == -1) || (S_ISDIR(st.st_mode) == 0)) {
		fprintf( stderr, "Missing public directory (in chroot jail): %s\n", options.public_directory);
		Free_options();
		exit(1);
  }
  memset(path, 0, sizeof(path));


  /* Check config directory */
  if ((stat(options.path, &st) == -1) || (S_ISDIR(st.st_mode) == 0)) {
		fprintf( stderr, "Option CREUVUX_PATH is missing: %s\n", options.path);
		Free_options();
		exit(1);
  }

	/* Change directory to options.path (default: /etc/creuvuxd/ ) */
  result = crv_chdir(options.path);
  if (result == -1) {
		fprintf( stderr, "%s%s%s\n", "main(): crv_chdir(", options.path,") failed");
		Free_options();
		exit(1);
  }
  

  /* Check server.pem */
  fd = crv_fopen("server.pem", "r");
  if (fd == NULL) {
		fprintf( stderr, "%s\n", "Missing server.pem.");
		Free_options();
		return (-1);
  }
  fclose(fd);
  
  /* Check rootcert.pem */
  fd = crv_fopen("rootcert.pem", "r");
  if (fd == NULL) {
		fprintf( stderr, "%s\n", "Missing rootcert.pem");
		Free_options();
		return (-1);
  }
  fclose(fd);
  
  /* Check group.conf */
  fd = crv_fopen("group.conf", "r");
  if (fd == NULL) {
		fprintf( stderr, "%s\n", "Missing group");
		Free_options();
		return (-1);
  }
  fclose(fd);

	/* Create database */
  if (update == 1)
  {
		sqlite3 *db = NULL;
		char *zErrMsg = 0;
		int rc = -1;

		/* Restore privilege */
		result = crv_restore_priv();
		if (result == -1) {
			fprintf(stderr, "%s", "Creuvuxd can't restore privilege\n");
			Free_options();
			return (-1);
		}

		/* Drop privilege */
		/* Chroot process */
		/* A décommenter */
		result = crv_drop_priv_perm_and_chroot (options.user , options.chroot_directory );
		if (result == -1) {
			fprintf( stderr, "%s%s%s%s%s", "\nmain(): drop_priv_perm_and_chroot(", 
																	options.user, 
																 ",",
																 options.chroot_directory,
																 ") failed\n");
			fprintf( stderr, "%s", "main(): Please check you are ROOT\n");
			Free_options();
			return (-1);
		}
		
		
		
		fprintf(stdout, "%s", "Sqlite DB creation ");
		fflush(stdout);
		rc = sqlite3_open( ".creuvux.db", &db);
		if( rc ){
			fprintf(stderr, "Can't open database: %s", sqlite3_errmsg(db));
			sqlite3_close(db);
			Free_options();
			return (-1);
		}
		fprintf(stdout, "%s\n", " [Ok] ");
		
		
		fprintf(stdout, "%s\n", "Listing direcory and update database...");
		/*
		 * Multiple TABLE CREATION (Fichiers, Categories, Descr, Grp_User, Grp_Sha1, Descr)
		 */
	
		/*
		 * TABLE Files
		 */
		
		
		rc = sqlite3_exec(db, "create table Files (Sha1 TEXT NOT NULL, Name TEXT NOT NULL, Size NUMERIC NOT NULL, Path TEXT NOT NULL);" , NULL, 0, &zErrMsg);
		if( rc!=SQLITE_OK ){
			fprintf(stderr, "SQL (Table=Files)  error: %s\n", zErrMsg);
			sqlite3_free(zErrMsg);
		}
		
		
		list_directory_and_create_db(options.chroot_directory, db);
		//list_directory_and_create_db( "/", db);
		sqlite3_close(db);
		Free_options();
		return (0);
  }
  
  /* ignore SIGPIPE */
  signal (SIGPIPE, SIG_IGN);

  signal(SIGCHLD, crv_sigchld_handler);
	
	/* Restore privilege */
	result = crv_restore_priv();
	if (result == -1) {
		fprintf(stderr, "%s", "Creuvuxd can't restore privilege\n");
		Free_options();
		return (-1);
	}

  if (options.debug == 1)
  {
		fprintf(stderr, "%s\n", "#################");
		fprintf(stderr, "%s\n", "# MODE DEBUG ON #");
		fprintf(stderr, "%s\n", "#################");
		fprintf(stderr, "# \t| \n");
		fprintf(stderr, "# \t|-> CREUVUX_USER    :'******'\n", options.user);
		fprintf(stderr, "# \t|-> CREUVUX_PATH    :'%s'\n", options.path);
		fprintf(stderr, "# \t|-> CREUVUX_DEBIT   :'%d'\n", options.bandwidth);
		fprintf(stderr, "# \t|-> CREUVUX_PORT    :'%d'\n", options.num_ports);
		fprintf(stderr, "# \t|-> CREUVUX_ADDR    :'%s'\n", options.listen_addrs);
		fprintf(stderr, "# \t|-> CREUVUX_HOST    :'%s'\n", options.host);
		fprintf(stderr, "# \t|-> CREUVUX_PID     :'%s'\n", options.pid);
		fprintf(stderr, "# \t|-> CREUVUX_SEC     :'%d'\n", options.sec);
		fprintf(stderr, "# \t|-> CREUVUX_PWD     :'%s'\n", options.passphrase);
		fprintf(stderr, "# \t|-> CREUVUX_CHROOT  :'%s'\n", options.chroot_directory);
		fprintf(stderr, "# \t|-> CREUVUX_UPDIR   :'%s'\n", options.upload_directory);
		fprintf(stderr, "# \t|-> CREUVUX_PUBLIC  :'%s'\n", options.public_directory);
		fprintf(stderr, "# \t|-> CREUVUX_IPDB    :'%s'\n", options.ipdb);
		fprintf(stderr, "# \t|-> CREUVUX_PORTDB  :'%d'\n", options.portdb);
		fprintf(stderr, "# \t|-> CREUVUX_DBNAME  :'%s'\n", options.dbname);
		fprintf(stderr, "# \t|-> CREUVUX_DBUSER  :'******'\n", options.dbuser);
		fprintf(stderr, "# \t|-> CREUVUX_DBPASSW :'%s'\n", options.dbpassw);
		fprintf(stderr, "# \t|-> CREUVUX_MAX_SIZE:'%lld'\n", options.db_max);
		fprintf(stderr, "# \t`-> CREUVUX_MIN_SIZE:'%lld'\n", options.db_min);
		fprintf(stderr, "%s\n\n", "#################");
  }
  else if (options.debug == -1) {
		int fd_pid;
		char str[12];
		/* Put pid_file */
		if (options.pid == NULL) {
			fprintf(stderr, "%s", "creuvuxd failed, CREUVUXD_PID is NULL\n");
			Free_options();
			exit(EXIT_FAILURE);
		}
		fd_pid = open( options.pid, O_RDWR | O_CREAT, 0640);
		if (fd_pid < 0) {
			fprintf(stderr, "creuvuxd can't open PID file\n");
			Free_options();
			exit(EXIT_FAILURE);
		}

		if (lockf (fd_pid, F_TLOCK, (off_t) 0) < 0) {
			fprintf(stderr, "%s", "creuvuxd is already running\n");
			Free_options();
			exit(EXIT_FAILURE);
		}

		fprintf(stdout, "%s\n", "Mode Daemon");
		crv_daemon_mode();
		snprintf (str, 12, "%d\n", getpid());
		(void)write (fd_pid, str, strlen(str));
  }
 
  server_accept_loop ( );
  Free_options();
	fprintf(stderr, "%s", "Creuvuxd Received terminating signal\n");
  return 0;
}
コード例 #26
0
ファイル: tst_res.c プロジェクト: BelHzy/caliper
static void tst_res__(const char *file, const int lineno, int ttype,
	const char *fname, const char *arg_fmt, ...)
{
	pthread_mutex_lock(&tmutex);

	char tmesg[USERMESG];
	int len = 0;
	int ttype_result = TTYPE_RESULT(ttype);

#if DEBUG
	printf("IN tst_res__; tst_count = %d\n", tst_count);
	fflush(stdout);
#endif

	if (file && (ttype_result != TPASS && ttype_result != TINFO))
		len = sprintf(tmesg, "%s:%d: ", file, lineno);
	EXPAND_VAR_ARGS(tmesg + len, arg_fmt, USERMESG - len);

	/*
	 * Save the test result type by ORing ttype into the current exit
	 * value (used by tst_exit()).
	 */
	T_exitval |= ttype_result;

	/*
	 * Unless T_out has already been set by tst_environ(), make tst_res()
	 * output go to standard output.
	 */
	if (T_out == NULL)
		T_out = stdout;

	/*
	 * Check TOUTPUT environment variable (if first time) and set T_mode
	 * flag.
	 */
	check_env();

	if (fname != NULL && access(fname, F_OK) == 0)
		File = fname;

	/*
	 * Set the test case number and print the results, depending on the
	 * display type.
	 */
	if (ttype_result == TWARN || ttype_result == TINFO) {
		tst_print(TCID, 0, ttype, tmesg);
	} else {
		if (tst_count < 0)
			tst_print(TCID, 0, TWARN,
				  "tst_res(): tst_count < 0 is not valid");

		/*
		 * Process each display type.
		 */
		switch (T_mode) {
		case DISCARD:
			break;
		case NOPASS:	/* filtered by tst_print() */
			tst_condense(tst_count + 1, ttype, tmesg);
			break;
		default:	/* VERBOSE */
			tst_print(TCID, tst_count + 1, ttype, tmesg);
			break;
		}

		tst_count++;
	}

	pthread_mutex_unlock(&tmutex);
}
コード例 #27
0
ファイル: shell.c プロジェクト: hlilje/simple-shell
int main(int argc, const char* argv[])
{
    int status, bg_pipes[2], num_pipes, flags;
    struct sigaction act_bg_term, act_int_old, act_int_new;
    /* Define handler for SIGINT (ignore) */
    act_int_new.sa_handler = SIG_IGN;
    act_int_new.sa_flags = 0;
    if (sigaction(SIGINT, &act_int_new, &act_int_old))
        perror("Failed to change handler for SIGINT");

    /* Define handler for detecting background process termination */
    if (SIGNAL_DETECTION == 1)
    {
        if (sigaction(SIGUSR1, NULL, &act_bg_term))
            perror("Failed to get handler for SIGUSR1");
        act_bg_term.sa_handler = sig_bg_handler;
        act_bg_term.sa_flags = SA_RESTART;
        if (sigaction(SIGUSR1, &act_bg_term, NULL))
            perror("Failed to set handler for SIGUSR1");
    }

    /* Create pipe for printing background process info */
    num_pipes = 1;
    create_pipes(bg_pipes, num_pipes);

    /* Configure pipe to be non-blocking on read end */
    flags = fcntl(bg_pipes[0], F_GETFL, 0);
    fcntl(bg_pipes[0], F_SETFL, flags | O_NONBLOCK);

    while (1)
    {
        char input[80], cmd[80];
        int i;

        /* Wait for all defunct children */
        /* Continue even if no child has exited */
        if (!(SIGNAL_DETECTION == 1))
            while (waitpid(-1, &status, WNOHANG | WUNTRACED) > 0);

        /* Print prompt */
        if (!print_prompt()) continue;

        /* Exit if error occurs */
        if (!fgets(input, 80, stdin))
        {
            perror("Failed to get input");
            continue;
        }

        /* Remove newline, if present */
        i = strlen(input) - 1;
        if (input[i] == '\n') input[i] = '\0';

        /* Read given commands */
        i = 0; /* Input index */
        i = read_cmd(cmd, input, i);

        if (strcmp(cmd, "exit") == 0)
            break;
        else if (strcmp(cmd, "cd") == 0)
            cd(input, cmd, i);
        else if (strcmp(cmd, "checkEnv") == 0)
            check_env(input, i);
        else if (cmd[0] == '\0') {} /* Just print process info */
        else
            general_cmd(input, &act_int_old, bg_pipes);

        /* Print accumulated process information */
        print_process_info(bg_pipes);
    }

    /* Close pipe for printing background process info */
    close_pipes(bg_pipes, num_pipes);

    exit_shell();

    return 0;
}
コード例 #28
0
ファイル: main.cpp プロジェクト: DPMI/marcd
int main(int argc, char *argv[]){
	/* extract program name from path. e.g. /path/to/MArCd -> MArCd */
	const char* separator = strrchr(argv[0], '/');
	if ( separator ){
		program_name = separator + 1;
	} else {
		program_name = argv[0];
	}

	default_env();

	int ret;
	int option_index = 0;
	int op;

#ifdef HAVE_INIPARSER_H
	if ( config::load(argc, argv) != 0 ){ /* passing argv so it can read -f/--config */
		return 1; /* error already shown */
	}
#endif

	while ( (op = getopt_long(argc, argv, shortopts, longopts, &option_index)) != -1 ){
		switch (op){
		case '?': /* error */
			exit(1);

		case 0: /* long opt */
			break;

		case 'b': /* --daemon */
			daemon_mode = 1;
			break;

		case 's': /* --syslog */
			syslog_flag = true;
			break;

		case FLAG_USER: /* --user */
			config::set_drop_username(optarg);
			break;

		case FLAG_GROUP: /* --group */
			config::set_drop_group(optarg);
			break;

		case FLAG_DROP_PRIV: /** --drop */
			drop_priv_flag = true;
			break;

		case FLAG_NODROP_PRIV: /** --no-drop */
			drop_priv_flag = false;
			break;

		case 'f':
#ifndef HAVE_INIPARSER_H
			fprintf(stderr, "%s: configuration files not supported (build with --with-iniparser)\n", program_name);
#endif
			break;

		case 'H':
			strncpy(db_hostname, optarg, sizeof(db_hostname));
			db_hostname[sizeof(db_hostname)-1] = '\0';
			break;

		case 'N':
			strncpy(db_name, optarg, sizeof(db_name));
			db_name[sizeof(db_name)-1] = '\0';
			break;

		case 'u':
			strncpy(db_username, optarg, sizeof(db_username));
			db_username[sizeof(db_username)-1] = '\0';
			break;

		case 'p':
			if ( strcmp(optarg, "-") == 0 ){ /* read password from stdin */
				strncpy(db_password, getpass("mysql password: "******"Invalid port given to --relay: %s. Ignored\n", optarg);
				}
			}

			break;

		case FLAG_DATADIR:
			free(rrdpath);
			rrdpath = strdup(optarg);
			break;

		case FLAG_PIDFILE:
			pidfile = optarg;
			break;

		case 'v': /* --verbose */
			verbose_flag = 1;
			break;

		case 'q': /* --quiet */
			verbose_flag = 0;
			break;

		case 'd': /* --debug */
			debug_flag = 1;
			break;

		case 'h': /* --help */
			show_usage();
			exit(0);

		default:
			if ( option_index >= 0 ){
				fprintf(stderr, "flag --%s declared but not handled\n", longopts[option_index].name);
			} else {
				fprintf(stderr, "flag -%c declared but not handled\n", op);
			}
			abort();
		}
	}

	/* database */
	if ( argc > optind ){
		strncpy(db_name, argv[optind], sizeof(db_name));
		db_name[sizeof(db_name)-1] = '\0';
	}

	setup_output();

	/* test if possible to drop privileges */
	if ( drop_priv_flag && getuid() != 0 ){
		Log::message(MAIN, "Not executing as uid=0, cannot drop privileges.\n");
		drop_priv_flag = 0;
	}

	/* Drop privileges.
	 * Done before forking since unlinking requires write permission to folder so
	 * if it fails to write it will fail unlinking. It is also done before
	 * check_env so it actually check environment for the dropped user instead of
	 * root.
	 */
	if ( drop_priv_flag ){
		privilege_drop();
	}

	/* sanity checks */
	show_env();
	if ( !check_env() ){
		return 1;
	}

	if ( daemon_mode ){
		/* opening file before fork since it will be a fatal error if it fails to write the pid */
		FILE* fp = fopen(pidfile, "w");
		if ( !fp ){
			Log::fatal(MAIN, "failed to open '%s` for writing: %s\n", pidfile, strerror(errno));
			return 1;
		}

		Log::message(MAIN, "Forking to background\n");
		pid_t pid = fork();

		if ( pid ){ /* parent */
			fprintf(fp, "%d\n", pid);
			fclose(fp);

			/* change owner of pidfile */
			if ( drop_priv_flag ){
				if ( chown(pidfile, drop_uid, drop_gid) != 0 ){
					Log::error("failed to change owner of '%s`, will probably fail to unlink it later: %s\n", pidfile, strerror(errno));
				}
			}

			return 0;
		}

		fclose(fp);
	}

	/* initialize daemons */
	pthread_barrier_t barrier;
	int threads = 1;
	threads += (int)have_control_daemon;
	threads += (int)have_relay_daemon;
	pthread_barrier_init(&barrier, NULL, threads);
	control.addr = relay.addr;

	if ( have_control_daemon && (ret=Daemon::instantiate<Control>(2000, &barrier)) != 0 ){
		Log::fatal(MAIN, "Failed to initialize control daemon, terminating.\n");
		if ( daemon_mode && unlink(pidfile) == -1 ){
			Log::fatal(MAIN, "Failed to remove pidfile: %s\n", strerror(errno));
		}
		return ret;
	}

	if ( have_relay_daemon && (ret=Daemon::instantiate<Relay>(2000, &barrier)) != 0 ){
		Log::fatal(MAIN, "Failed to initialize relay daemon, terminating.\n");
		if ( daemon_mode && unlink(pidfile) == -1 ){
			Log::fatal(MAIN, "Failed to remove pidfile: %s\n", strerror(errno));
		}
		return ret;
	}

	/* install signal handler */
	signal(SIGINT, handle_signal);
	signal(SIGTERM, handle_signal);

	/* release all threads and wait for them to finish*/
	pthread_barrier_wait(&barrier);
	if ( daemon_mode ){
		Log::message(MAIN, "Threads started. Going to sleep.\n");
	} else {
		Log::message(MAIN, "Threads started. Going to sleep. Abort with SIGINT\n");
	}
	Daemon::join_all();

	/* cleanup */
	free(rrdpath);
	if ( daemon_mode && unlink(pidfile) == -1 ){
		Log::fatal(MAIN, "Failed to remove pidfile: %s\n", strerror(errno));
	}

	Log::message(MAIN, "%s terminated.\n", program_name);
	return 0;
}