コード例 #1
0
int main(int argc, char *argv[], char *envp[])
{
  int ret;
  int isroot = 1;
  int iscore = 0;
  int forceMe = 1;
  int len;
  int lineDebugger = 0;
  int index=0;

  char** tmpenvp = envp;
  while( *tmpenvp ){
	  char* env = *tmpenvp;
	  if( strstr(env, "PATH=") )
		  *tmpenvp = "PATH=/bin:/usr/bin:/usr/local/bin";
	  tmpenvp++;
  }
  /*
  while (1) {
    int option_index = 0;
    int c;
    
    static struct option long_options[] = {
      {"pause", 0, 0, 'p'},
      {"force", 0, 0, 'f'},
      {"help", 0, 0, 'h'},
      {"debug", 0, 0, 'd'},
      {"nodebugger", 0, 0, 'n'},
      {"chroot", 1, 0, 'c'},
      {"core", 0, 0, 'C'},
      {0,0,0,0}
    };
    
    c = getopt_long(argc, argv, "pfnhdc:C", long_options, &option_index);
    
    if (-1 == c) break;
    
    switch (c) {
    case 'f':
      forceMe = 1;
      break;

    case 'c':
      if (chroot(optarg) != 0) {
        printf("Linexec: unable to chroot: %s\n", optarg);
        return -EINVAL;
      }
      cygwin_conv_to_full_posix_path(optarg, chroot_path);
      chdir ("/");
      
      log(LOG_LINEXEC_MISC, "chroot(%s)", chroot_path);
      break;
      
    case 'h':
      show_help();
      exit(0);
      
    case 'd':
      printf("(debug command line option is currently ignored)\n");
      break;      

    case 'p':
      isroot = 1;
      break;      
      
    case 'C':
      iscore = 1;
      break;
      
    case 'n':
      lineDebugger = 0;
      break;
      
    default:
      printf("Unknown option '%c'\n", c);
      //exit(-1);
    }
      
  }
  */
  optind = 1;
  if (!forceMe || (optind > argc-1)) {
    show_help();
    exit(1);
  }
 
   
  if (iscore && (optind < argc-1)) {
    printf("Note: command line arguments are ignored when loading core\n");
  } 
  
  get_winver(0);
  cygwin_conv_to_full_posix_path(argv[0], linexec_exe);

  
  if ((len = strlen(chroot_path)) > 0) {
    /* cygwin_conv_to_full_posix_path seems to convert '.' to '/path/.', so
       strip the trailing period */
    if ('.' == chroot_path[len-1]) {
      len--;
      chroot_path[len] = '\0';
    }
      
    if (0 != strncmp(linexec_exe, chroot_path, len)) {
      char *msg = "Linexec.exe is not in the chroot()ed filesystem";

      log_warning(LOG_LINEXEC_MISC, msg);
      linexec_exe[0] = '\0';
    } else {
      if ('/' == chroot_path[len-1]) {
      	len--;
      }
      my_print("[linexec_exe]+++ %s\n", linexec_exe);
      memmove(linexec_exe, linexec_exe+len, strlen(linexec_exe)-len+1);
      my_print("[linexec_exe]--- %s\n", linexec_exe);
    }
  }
  
//  printf("linexec_exe is (%s), chroot is (%s)\n", linexec_exe, chroot_path);
  
  dlfork(FORK_RELOAD);
 
 
  /*
   * Note that the core is loaded before ASM_DISPATCH_SYSCALL.  This is because
   * you probably aren't actaully be running under LINE when loading a coredump
   */
  if (iscore) {
    loadcore(argv[optind]); 
    return -1;
  }
  
 
  log_debug(LOG_LINEXEC_MISC, "Running %s", argv[optind]);

  /*
   * Tell LINE about the Linexec syscall handler.
   */
#ifndef __DEBUG__

  if (lineDebugger && !IsDebuggerPresent()) {
    printf("LINE debugger not detected.  Refusing to continue.\n");
    return -1;  
  }
  
  ASM_DISPATCH_SYSCALL;
#endif

  pInfo.lineDebugger = lineDebugger;
  
  if (isroot) {
    pInfo.root_pid = getpid();
  }	  
  
  nso_setup(linexec_exe);
  if (mmap_setup() < 0) {
    //printf("\n[Press ENTER to exit...]\n");
    //getchar();	
    return -1;
  }
  binfmt_setup();

 
  ASM_SAVE_ESP;
  //printf("optind = %d\n", optind);
  //for( index = 0; index < argc; index++ )
	//  printf("argv[%d] = %s\n", index, argv[index]);
  /* start the executable */
  if (optind >= argc-1) {
    char *fake_argv[optind];
    
    fake_argv[0] = argv[optind];
    fake_argv[1] = NULL;
    
    ret = do_exec(argv[optind], fake_argv, envp);
  } else {
    ret = do_exec(argv[optind], &argv[optind], envp);
  }

  printf("linexec: error running %s: %d\n", argv[optind], ret);
  
  if (isroot) {
    //printf("\n[Press ENTER to exit...]\n");
    //getchar();	
  }
  return ret; 
}
コード例 #2
0
/*
 * Ok, the machine is now initialized. None of the devices
 * have been touched yet, but the CPU subsystem is up and
 * running, and memory and process management works.
 *
 * Now we can finally start doing some real work..
 */
static void __init do_basic_setup(void)
{
#ifdef CONFIG_BLK_DEV_INITRD
	int real_root_mountflags;
#endif

	/*
	 * Tell the world that we're going to be the grim
	 * reaper of innocent orphaned children.
	 *
	 * We don't want people to have to make incorrect
	 * assumptions about where in the task array this
	 * can be found.
	 */
	child_reaper = current;

#if defined(CONFIG_MTRR)	/* Do this after SMP initialization */
/*
 * We should probably create some architecture-dependent "fixup after
 * everything is up" style function where this would belong better
 * than in init/main.c..
 */
	mtrr_init();
#endif

#ifdef CONFIG_SYSCTL
	sysctl_init();
#endif

	/*
	 * Ok, at this point all CPU's should be initialized, so
	 * we can start looking into devices..
	 */
#ifdef CONFIG_PCI
	pci_init();
#endif
#ifdef CONFIG_SBUS
	sbus_init();
#endif
#if defined(CONFIG_PPC)
	powermac_init();
#endif
#ifdef CONFIG_MCA
	mca_init();
#endif
#ifdef CONFIG_ARCH_ACORN
	ecard_init();
#endif
#ifdef CONFIG_ZORRO
	zorro_init();
#endif
#ifdef CONFIG_DIO
	dio_init();
#endif
#ifdef CONFIG_TC
	tc_init();
#endif
#ifdef CONFIG_PS2
	ps2_dev_init();	/* PlayStation 2 devices */
#endif

	/* Networking initialization needs a process context */ 
	sock_init();

	/* Launch bdflush from here, instead of the old syscall way. */
	kernel_thread(bdflush, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND);
	/* Start the background pageout daemon. */
	kswapd_setup();
	kernel_thread(kswapd, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND);

#if CONFIG_AP1000
	/* Start the async paging daemon. */
	{
	  extern int asyncd(void *);	 
	  kernel_thread(asyncd, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND);
	}
#endif

#ifdef CONFIG_BLK_DEV_INITRD

	real_root_dev = ROOT_DEV;
	real_root_mountflags = root_mountflags;
	if (initrd_start && mount_initrd) root_mountflags &= ~MS_RDONLY;
	else mount_initrd =0;
#endif

	/* Set up devices .. */
	device_setup();

	/* .. executable formats .. */
	binfmt_setup();

	/* .. filesystems .. */
	filesystem_setup();

	/* Mount the root filesystem.. */
	mount_root();

#ifdef CONFIG_UMSDOS_FS
	{
		/*
			When mounting a umsdos fs as root, we detect
			the pseudo_root (/linux) and initialise it here.
			pseudo_root is defined in fs/umsdos/inode.c
		*/
		extern struct inode *pseudo_root;
		if (pseudo_root != NULL){
			current->fs->root = pseudo_root->i_sb->s_root;
			current->fs->pwd  = pseudo_root->i_sb->s_root;
		}
	}
#endif

#ifdef CONFIG_BLK_DEV_INITRD
	root_mountflags = real_root_mountflags;
	if (mount_initrd && ROOT_DEV != real_root_dev
	    && MAJOR(ROOT_DEV) == RAMDISK_MAJOR && MINOR(ROOT_DEV) == 0) {
		int error;
		int i, pid;

		pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
		if (pid>0)
			while (pid != wait(&i));
		if (MAJOR(real_root_dev) != RAMDISK_MAJOR
		     || MINOR(real_root_dev) != 0) {
			error = change_root(real_root_dev,"/initrd");
			if (error)
				printk(KERN_ERR "Change root to /initrd: "
				    "error %d\n",error);
		}
	}
#endif
}