Ejemplo n.º 1
0
int main(int argc , char ** argv) {
  char * cwd     = util_alloc_cwd( );
  char * path1   = argv[1];
  char * path2   = argv[2];
  {
    path_stack_type * path_stack = path_stack_alloc();

    path_stack_push_cwd( path_stack );
    
    if (path_stack_push( path_stack , "NotExist-1111"))
      test_error_exit("Pushed unexisting path\n");
    
    if (!path_stack_push( path_stack, path1 ))
      test_error_exit("Failed to push:%s \n",path1 );
    
    util_chdir( path2 );
    if (util_is_cwd( path1 ))
      test_error_exit("Failed to chdir(%s) \n",path2 );
    
    {
      if (path_stack_size( path_stack ) != 2)
        test_error_exit("Wrong stack size");
    
      if (strcmp( path1 , path_stack_peek( path_stack )) != 0)
        test_error_exit("peek error");
    }
    
    path_stack_pop( path_stack );
    printf("After pop: cwd:%s   path1:%s  \n",util_alloc_cwd() , path1);
    if (!util_is_cwd( path1 ))
      test_error_exit("path_stack_pop failed \n");

    path_stack_pop( path_stack );
    if (!util_is_cwd( cwd ))
      test_error_exit("path_stack_pop failed \n");

    if (path_stack_size( path_stack ) != 0)
      test_error_exit("Wrong stack size");
    
    if (!path_stack_push(path_stack , NULL))
      test_error_exit("Hmmm - push(NULL) failed \n");

    if (path_stack_size( path_stack ) != 1)
      test_error_exit("Wrong stack size");
    
    path_stack_pop( path_stack );
    path_stack_free( path_stack);
  }
  exit(0);
}
Ejemplo n.º 2
0
int
imap4d_session_setup0 ()
{
  real_homedir = mu_normalize_path (mu_strdup (auth_data->dir));
  if (imap4d_check_home_dir (real_homedir, auth_data->uid, auth_data->gid))
    return 1;

  if (modify_homedir)
    {
      int rc;
      mu_vartab_t vtab;
      char *expr = mu_tilde_expansion (modify_homedir, "/", real_homedir);

      mu_vartab_create (&vtab);
      mu_vartab_define (vtab, "user", auth_data->name, 0);
      mu_vartab_define (vtab, "home", real_homedir, 0);
      rc = mu_vartab_expand (vtab, expr, &imap4d_homedir);
      mu_vartab_destroy (&vtab);
      free (expr);
      if (rc)
	{
	  free (real_homedir);
	  mu_diag_funcall (MU_DIAG_ERROR, "mu_vartab_expand",
			   modify_homedir, rc);
	  return 1;
	}
    }
  else
    imap4d_homedir = strdup (real_homedir);

  if (strcmp (imap4d_homedir, real_homedir)
      && imap4d_check_home_dir (imap4d_homedir,
				auth_data->uid, auth_data->gid))
    {
      free (imap4d_homedir);
      free (real_homedir);
      return 1;
    }
  
  if (auth_data->change_uid)
    setuid (auth_data->uid);

  util_chdir (imap4d_homedir);
  namespace_init_session (imap4d_homedir);
  mu_diag_output (MU_DIAG_INFO,
		  _("user `%s' logged in (source: %s)"), auth_data->name,
		  auth_data->source);
  return 0;
}
Ejemplo n.º 3
0
static int dir_removebusy(const char *basepath)
{
	char path[MAXSIZ_PATH];
	sprintf (path,"%s/dir",basepath);
	Rdir_spcent.verbose ("Creating directory %s\n",path);
	/* #Specification: utstgen / removing a busy directory
		A check is done that a busy directory can't be removed.
		Here is the sequence we test. It must fail with EBUSY.
		
		mkdir dir
		cd dir
		rm ../dir
	*/
	if (util_mkdir(path,0777,Rdir_removebusy,0)!=-1){
		char curdir[MAXSIZ_PATH];
		getcwd(curdir,sizeof(curdir)-1);
		if (util_chdir(path,Rdir_removebusy,0)!=-1){
			util_rmdir (path,Rdir_removebusy,EBUSY);
			util_chdir (curdir,Rdir_removebusy,0);
		}
		util_rmdir (path,Rdir_removebusy,0);
	}
	return Rdir_removebusy.getnberr();
}
Ejemplo n.º 4
0
Archivo: main.c Proyecto: pgdr/ert
int main (int argc, char ** argv) {
  text_splash();
  init_debug(argv[0]);
  printf("\n");
  printf("Documentation : %s \n","http://ert.nr.no");
  printf("git commit    : %s \n",ert_version_get_git_commit( ));
  printf("compile time  : %s \n",ert_version_get_build_time( ));
  printf("site config   : %s \n", site_config_get_location());

  enkf_main_install_SIGNALS();                     /* Signals common to both tui and gui. */
  signal(SIGINT, util_abort_signal);              /* Control C - tui only.               */
  if (argc < 2) {
    enkf_usage();
    exit(1);
  } else {
    const char * model_config_file = argv[1];
    stringlist_type * workflow_list = stringlist_alloc_new();

    parse_workflows(argc, argv, workflow_list);
    if (!(util_entry_readable(model_config_file) && util_is_file(model_config_file)))
      util_exit("Can not read file %s - exiting \n", model_config_file);

    {
      char * abs_config = util_alloc_realpath(model_config_file);
      printf("model config  : %s \n\n", abs_config);
      free(abs_config);
    }
    enkf_welcome(model_config_file);
    {
      res_config_type * res_config = res_config_alloc_load(model_config_file);
      util_chdir( res_config_get_config_directory( res_config ));
      {
        enkf_main_type * enkf_main = enkf_main_alloc(res_config, true, true);
        enkf_main_run_workflows(enkf_main, workflow_list);
        enkf_tui_main_menu(enkf_main);
        enkf_main_free(enkf_main);
        res_config_free(res_config);
      }
    }

    stringlist_free(workflow_list);
    util_abort_free_version_info(); /* No f*****g leaks ... */
  }
  exit(0);
}
Ejemplo n.º 5
0
int main(int argc , char ** argv) {
#ifdef ERT_LINUX
  const char * rel_path = "rel/path";
  const char * rel_true = "rel/path/XXX";
  const char * path_true1 = "rel/path/XXX";
  
  
#endif
  test_work_area_type * work_area = test_work_area_alloc( "config_path_elm" );
  const char * root = test_work_area_get_cwd( work_area );
  char * abs_path = util_alloc_filename( root , "rel/path" , NULL);
  char * abs_true = util_alloc_filename( root , "rel/path/XXX" , NULL);
  char * path_true2 = util_alloc_filename( root , "rel/path/XXX" , NULL);

  util_chdir( test_work_area_get_original_cwd( work_area ));
  config_root_path_type * root_path = config_root_path_alloc( root );
  {
    config_path_elm_type * path_elm = config_path_elm_alloc( root_path , rel_path );
    
    test_assert_string_equal( config_path_elm_get_relpath( path_elm ) , rel_path );
    test_assert_string_equal( config_path_elm_get_abspath( path_elm ) , abs_path );

    test_assert_string_equal( config_path_elm_alloc_relpath( path_elm , "XXX" ) , rel_true);
    test_assert_string_equal( config_path_elm_alloc_abspath( path_elm , "XXX" ) , abs_true);
    test_assert_string_equal( config_path_elm_alloc_path( path_elm , "XXX" ) , path_true2 );

    
    config_path_elm_free( path_elm );
  }
  {
    config_path_elm_type * path_elm = config_path_elm_alloc( root_path , abs_path );
  
    test_assert_string_equal( config_path_elm_get_relpath( path_elm ) , rel_path );
    test_assert_string_equal( config_path_elm_get_abspath( path_elm ) , abs_path );

    test_assert_string_equal( config_path_elm_alloc_relpath( path_elm , "XXX" ) , rel_true);
    test_assert_string_equal( config_path_elm_alloc_abspath( path_elm , "XXX" ) , abs_true);
    test_assert_string_equal( config_path_elm_alloc_path( path_elm , "XXX" ) , path_true2 );
    
    config_path_elm_free( path_elm );
  }
  config_root_path_free( root_path );

  util_chdir( root );
  root_path = config_root_path_alloc( NULL );
  {
    config_path_elm_type * path_elm = config_path_elm_alloc( root_path , rel_path );
    
    test_assert_string_equal( config_path_elm_get_relpath( path_elm ) , rel_path );
    test_assert_string_equal( config_path_elm_get_abspath( path_elm ) , abs_path );

    test_assert_string_equal( config_path_elm_alloc_relpath( path_elm , "XXX" ) , rel_true);
    test_assert_string_equal( config_path_elm_alloc_abspath( path_elm , "XXX" ) , abs_true);
    test_assert_string_equal( config_path_elm_alloc_path( path_elm , "XXX" ) , path_true1 );

    
    config_path_elm_free( path_elm );
  }
  
  exit(0);
}
Ejemplo n.º 6
0
pid_t util_fork_exec(const char * executable , int argc , const char ** argv , 
                     bool blocking , const char * target_file , const char  * run_path , 
                     const char * stdin_file , const char * stdout_file , const char * stderr_file) {
  const char  ** __argv = NULL;
  pid_t child_pid;
  
  if (target_file != NULL && blocking == false) 
    util_abort("%s: When giving a target_file != NULL - you must use the blocking semantics. \n",__func__);

  child_pid = fork();
  if (child_pid == -1) {
    fprintf(stderr,"Error: %s(%d) \n",strerror(errno) , errno);
    util_abort("%s: fork() failed when trying to run external command:%s \n",__func__ , executable);
  }
  
  if (child_pid == 0) {
    /* This is the child */
    int iarg;

    nice(19);    /* Remote process is run with nice(19). */
    if (run_path != NULL) {
      if (util_chdir(run_path) != 0) 
        util_abort("%s: failed to change to directory:%s  %s \n",__func__ , run_path , strerror(errno));
    }

    if (stdout_file != NULL) 
      __util_redirect(1 , stdout_file , O_WRONLY | O_TRUNC | O_CREAT);
    
    if (stderr_file != NULL) 
      __util_redirect(2 , stderr_file , O_WRONLY | O_TRUNC | O_CREAT);
    
    if (stdin_file  != NULL) 
      __util_redirect(0 , stdin_file  , O_RDONLY);
    
    __argv        = util_malloc((argc + 2) * sizeof * __argv );  
    __argv[0]     = executable;
    for (iarg = 0; iarg < argc; iarg++)
      __argv[iarg+1] = argv[iarg];
    __argv[argc + 1] = NULL;

    /* 
       If executable is an absolute path, it is invoked directly, 
       otherwise PATH is used to locate the executable.
    */
    execvp( executable , (char **) __argv);
    /* 
       Exec should *NOT* return - if this code is executed
       the exec??? function has indeed returned, and this is
       an error.
    */
    util_abort("%s: failed to execute external command: \'%s\': %s \n",__func__ , executable , strerror(errno));
    
  }  else  {
    /* Parent */
    
    if (blocking) {
      waitpid(child_pid , NULL , 0);
      
      if (target_file != NULL)
        if (!util_file_exists(target_file))
          util_abort("%s: %s failed to produce target_file:%s aborting \n",__func__ , executable , target_file);
    }
  }
  
  util_safe_free( __argv );
  return child_pid;
}