Ejemplo n.º 1
0
ATF_TC_BODY(setdomainname_basic, tc)
{
	char name[MAXHOSTNAMELEN];
	size_t i;

	backup_domain();
	for (i = 0; i < __arraycount(domains); i++) {

		(void)memset(name, 0, sizeof(name));

#ifdef __FreeBSD__
		/*
		 * Sanity checks to ensure that the wrong invariant isn't being
		 * tested for per PR # 181127
		 */
		ATF_REQUIRE_EQ(sizeof(domains[i]), MAXHOSTNAMELEN);
		ATF_REQUIRE_EQ(sizeof(name), MAXHOSTNAMELEN);

		ATF_REQUIRE(setdomainname(domains[i],sizeof(domains[i]) -  1) == 0);
		ATF_REQUIRE(getdomainname(name, sizeof(name) - 1) == 0);
#else
		ATF_REQUIRE(setdomainname(domains[i],sizeof(domains[i])) == 0);
		ATF_REQUIRE(getdomainname(name, sizeof(name)) == 0);
#endif
		ATF_REQUIRE(strcmp(domains[i], name) == 0);
	}

}
Ejemplo n.º 2
0
ATF_TC_BODY(setdomainname_limit, tc)
{
	char name[MAXHOSTNAMELEN + 1];

	(void)memset(name, 0, sizeof(name));

#if defined(__FreeBSD__)
	ATF_REQUIRE(setdomainname(name, MAXHOSTNAMELEN - 1 ) == 0);
	ATF_REQUIRE(setdomainname(name, MAXHOSTNAMELEN) == -1);
#endif
	ATF_REQUIRE(setdomainname(name, sizeof(name)) == -1);
}
Ejemplo n.º 3
0
static int make_nis (char *ifname, dhcp_t *dhcp)
{
  FILE *f;
  address_t *address;
  char prefix[256] = {0};

  if (! (f = fopen(NISFILE, "w")))
    {
      logger (LOG_ERR, "fopen `%s': %m", NISFILE);
      return -1;
    }

  fprintf (f, "# Generated by dhcpcd for interface %s\n", ifname);
  if (dhcp->nisdomain)
    {
      setdomainname (dhcp->nisdomain, strlen (dhcp->nisdomain));

      if (dhcp->nisservers)
	snprintf (prefix, sizeof (prefix), "domain %s server", dhcp->nisdomain);
      else
	fprintf (f, "domain %s broadcast\n", dhcp->nisdomain);
    }
  else
    sprintf(prefix, "ypserver %c", '\0');

  for (address = dhcp->nisservers; address; address = address->next)
    fprintf (f, "%s%s\n", prefix, inet_ntoa (address->address));

  fclose (f);
  
  return 0;
}
Ejemplo n.º 4
0
int main(int ac, char **av)
{

	int lc;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		/*
		 * Call setdomainname(2)
		 */
		TEST(setdomainname(test_domain_name, sizeof(test_domain_name)));

		/* check return code */
		if (TEST_RETURN == -1) {
			tst_resm(TFAIL, "setdomainname() Failed, errno = %d :"
				 " %s", TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			tst_resm(TPASS, "setdomainname() returned %ld, "
				 "Domain name set to \"%s\"", TEST_RETURN,
				 test_domain_name);
		}

	}

	/* cleanup and exit */
	cleanup();
	tst_exit();

}
int main() {
  const char * old_domain_name = get_domain_name();
  const char * old_host_name = get_host_name();

  step("parent: old domainname: %s", old_domain_name);
  step("parent: old hostname: %s", old_host_name);

  step("parent: fork");
  if (fork()) {
    step("parent: wait for child to exit");
    int status = 0;
    do wait(&status); while (!WIFEXITED(status));

    assertStrEquals("parent: domain name", old_domain_name, get_domain_name());
    assertStrEquals("parent: host name", old_host_name, get_host_name());
  } else {
    step("child: create container with separate uts namespace");
    struct slc_create_container_parameters params;
    initialize_default_fs_root(&params.fs_root);
    slc_create_container(&params, 0);

    const char * new_domain_name = "new_domain_name";
    const char * new_host_name = "new_host_name";
    
    step("child: set domain name to '%s'", new_domain_name);
    setdomainname(new_domain_name, strlen(new_domain_name));
    assertStrEquals("child: domain name", new_domain_name, get_domain_name());
    
    step("child: set host name to '%s'", new_host_name);
    sethostname(new_host_name, strlen(new_host_name));
    assertStrEquals("child: host name", new_host_name, get_host_name());
  }

  return 0;
}
Ejemplo n.º 6
0
int
main(int argc, char *argv[])
{
	int ch;
	char domainname[MAXHOSTNAMELEN];

	setprogname(argv[0]);

	while ((ch = getopt(argc, argv, "")) != -1) {
		switch (ch) {
		case '?':
		default:
			usage();
			/* NOTREACHED */
		}
	}
	argc -= optind;
	argv += optind;

	if (argc > 1)
		usage();

	if (*argv) {
		if (setdomainname(*argv, strlen(*argv)))
			err(1, "setdomainname");
	} else {
		if (getdomainname(domainname, sizeof(domainname)))
			err(1, "getdomainname");
		(void)printf("%s\n", domainname);
	}
	exit(EXIT_SUCCESS);
	/* NOTREACHED */
}
Ejemplo n.º 7
0
int
main(int argc, char **argv)
{
	int ch;
	char domainname[MAXHOSTNAMELEN];

	while ((ch = getopt(argc, argv, "")) != -1) {
		switch (ch) {
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (argc > 1)
		usage();

	if (argv[0] != NULL) {
		size_t len = strlen(argv[0]);
		if (len > MAXHOSTNAMELEN)
			errx(1, "domain name too long");

		if (setdomainname(*argv, len))
			err(1, "setdomainname");
	} else {
		if (getdomainname(domainname, sizeof(domainname)))
			err(1, "getdomainname");
		domainname[MAXHOSTNAMELEN-1] = '\0';
		printf("%s\n", domainname);
	}
	exit(0);
}
Ejemplo n.º 8
0
int
main(int argc, char *argv[])
{
	int ch;
	char domainname[MAXHOSTNAMELEN];

	while ((ch = getopt(argc, argv, "")) != -1)
		switch (ch) {
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (argc > 1)
		usage();

	if (*argv) {
		if (setdomainname(*argv, strlen(*argv)))
			err(1, "setdomainname");
	} else {
		if (getdomainname(domainname, sizeof(domainname)))
			err(1, "getdomainname");
		(void)printf("%s\n", domainname);
	}
	exit(0);
}
Ejemplo n.º 9
0
static int make_nis (const char *ifname, const dhcp_t *dhcp)
{
  FILE *f;
  address_t *address;
  char prefix[256] = {0};

  logger (LOG_DEBUG, "writing "NISFILE);
  if (! (f = fopen(NISFILE, "w")))
    {
      logger (LOG_ERR, "fopen `%s': %s", NISFILE, strerror (errno));
      return -1;
    }

  fprintf (f, "# Generated by dhcpcd for interface %s\n", ifname);
  if (dhcp->nisdomain)
    {
      setdomainname (dhcp->nisdomain, strlen (dhcp->nisdomain));

      if (dhcp->nisservers)
	snprintf (prefix, sizeof (prefix), "domain %s server", dhcp->nisdomain);
      else
	fprintf (f, "domain %s broadcast\n", dhcp->nisdomain);
    }
  else
    snprintf (prefix, sizeof (prefix), "%s", "ypserver");

  for (address = dhcp->nisservers; address; address = address->next)
    fprintf (f, "%s %s\n", prefix, inet_ntoa (address->address));

  fclose (f);

  exec_cmd (NISSERVICE, NISRESTARTARGS, NULL);
  return 0;
}
Ejemplo n.º 10
0
ATF_TC_BODY(setdomainname_perm, tc)
{

	errno = 0;

	ATF_REQUIRE_ERRNO(EPERM, setdomainname(domain, sizeof(domain)) == -1);
}
Ejemplo n.º 11
0
ATF_TC_BODY(setdomainname_perm, tc)
{
	char domain[MAXHOSTNAMELEN];

	memset(domain, 0, sizeof(domain));

	errno = 0;
	ATF_REQUIRE_ERRNO(EPERM, setdomainname(domain, sizeof(domain)) == -1);
}
Ejemplo n.º 12
0
/*
 *cleanup() -  performs all ONE TIME cleanup for this test at
 *		completion or premature exit.
 */
void cleanup(void)
{

	/* Restore domain name */
	if ((setdomainname(old_domain_name, strlen(old_domain_name))) < 0) {
		tst_resm(TWARN, "setdomainname() failed while restoring"
			 " domainname to \"%s\"", old_domain_name);
	}

}
Ejemplo n.º 13
0
int container_main(void* arg)
{
    printf("Container - inside the container!\n");
    sethostname("my_hostname",10); /* 设置hostname */
    setdomainname("my_domain",10); /* 设置hostname */
    /* 直接执行一个shell,以便我们观察这个进程空间里的资源是否被隔离了 */
    execv(container_args[0], container_args); 
    printf("Something's wrong!\n");
    return 1;
}
Ejemplo n.º 14
0
Archivo: ct.c Proyecto: mkatkar/libct
static int uname_set(struct container *ct)
{
	int ret = 0;

	if (ct->hostname)
		ret |= sethostname(ct->hostname, strlen(ct->hostname));

	if (ct->domainname)
		ret |= setdomainname(ct->domainname, strlen(ct->domainname));

	return ret;
}
Ejemplo n.º 15
0
int main( int argc, char *argv[] ) {
	int ch;
	char domainname[MAXHOSTNAMELEN];
	while ( ( ch = getopt( argc, argv, "" ) ) != -1 )
		exit( 1 );
	argc -= optind;
	argv += optind;
	if ( argc > 1 ) exit( 1 );
	if ( *argv ) if ( setdomainname( *argv, (int) strlen( *argv ) ) ) err( 1, "setdomainname" );
	else if ( getdomainname( domainname, (int) sizeof( domainname ) ) ) err( 1, "getdomainname" );
	(void) printf( "%s\n", domainname );
	exit( 0 );
}
Ejemplo n.º 16
0
int
nix_setdomainname(char const *domainname, size_t len, nix_env_t *env)
{
	if (domainname == NULL) {
		nix_env_set_errno(env, EFAULT);
		return (-1);
	}

	if (setdomainname (domainname, len) != 0) {
		nix_env_set_errno(env, errno);
		return (-1);
	}

	return (0);
}
Ejemplo n.º 17
0
int
main(int ac, char **av)
{

	int lc;		/* loop counter */
	char *msg;	/* message returned from parse_opts */
    
	/* parse standard options */
	if ((msg=parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
		tst_exit();
	}

	/* perform global setup for test */
	setup();

	/* check looping state if -c option given */
	for (lc=0; TEST_LOOPING(lc); lc++) {

		/* reset Tst_count in case we are looping. */
		Tst_count=0;

		/* 
		 * Call setdomainname(2)
		 */
		TEST(setdomainname(test_domain_name,
				   sizeof(test_domain_name)));
	
		/* check return code */
		if ( TEST_RETURN == -1 ) {
			tst_resm(TFAIL, "setdomainname() Failed, errno = %d :"
				" %s", TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			tst_resm(TPASS, "setdomainname() returned %d, "
				 "Domain name set to \"%s\"", TEST_RETURN,
				 test_domain_name);
		} 


	}	/* End for TEST_LOOPING */

	/* cleanup and exit */
	cleanup();

	/*NOTREACHED*/
	return 0;

}	/* End main */
/*
 *cleanup() -  performs all ONE TIME cleanup for this test at
 *		completion or premature exit.
 */
void cleanup()
{

	/*
	 * print timing stats if that option was specified.
	 * print errno log if that option was specified.
	 */
	TEST_CLEANUP;

	/* Restore domain name */
	if ((setdomainname(old_domain_name, strlen(old_domain_name))) < 0) {
		tst_resm(TWARN, "setdomainname() failed while restoring"
			 " domainname to \"%s\"", old_domain_name);
	}

}
Ejemplo n.º 19
0
void
dns_test(cyg_addrword_t p)
{
    struct in_addr addr;
    struct hostent *hent;
    char dn[256];

    CYG_TEST_INIT();

    init_all_network_interfaces();

    CYG_TEST_INFO("Starting dns2 test");

    getdomainname(dn,sizeof(dn));
    diag_printf("INFO:<DHCP said domain name is %s>\n",dn);
#ifndef USE_HARDCODED_DOMAIN
    // If not hard-coded we can't tell what it's _meant_ to be
    CYG_TEST_CHECK(!strncmp(dn,_LOOKUP_DOMAINNAME,sizeof(_LOOKUP_DOMAINNAME)),
                   "DHCP got the wrong domainname");
#endif //ifdef _LOOKUP_DOMAINNAME
    
    /* Expect _LOOKUP_IP as the answer. This is a CNAME lookup */
    inet_aton(_LOOKUP_IP, &addr);
    hent = gethostbyname(_LOOKUP_FQDN);
    if (hent != NULL) {
        diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
        if (0 != memcmp((void*)&addr, (void*)(hent->h_addr), sizeof(struct in_addr))) {
          diag_printf("FAIL:<expected " _LOOKUP_FQDN " to be " _LOOKUP_IP ">\n");
        }
    } else {
        diag_printf("FAIL:<Asked for " _LOOKUP_FQDN ". No answer: %s>\n", hstrerror(h_errno));
    }

    /* Now just the hostname */
#ifdef USE_HARDCODED_DOMAIN
    // set the domain by hand if required.
    setdomainname(_LOOKUP_DOMAINNAME, sizeof(_LOOKUP_DOMAINNAME));
#endif //ifdef _LOOKUP_DOMAINNAME
    hent = gethostbyname(_LOOKUP_HOSTNAME);
    if (hent != NULL) {
        diag_printf("PASS:<%s is %s>\n", _LOOKUP_HOSTNAME, inet_ntoa(*(struct in_addr *)hent->h_addr));
    } else {
        diag_printf("FAIL:<Asked for " _LOOKUP_HOSTNAME ". No answer: %s>\n", hstrerror(h_errno));
    }

    CYG_TEST_FINISH("dns2 test completed");
}
Ejemplo n.º 20
0
/**
 * BSD-style: \n
 * Expects a "Fully Qualified Domain Name" in `fqdn'.
 * Split at first `.' and extract `hostname' and `def_domain'.
 * Set errno on failure and return -1.
 */
int W32_CALL sethostname (const char *fqdn, int len)
{
  int pos;

  if (!fqdn || !*fqdn || len < 0 || len > MAX_HOSTLEN)
  {
    SOCK_ERRNO (EINVAL);
    return (-1);
  }

#if (DOSX)
  if (!valid_addr((DWORD)fqdn, len))
  {
    SOCK_ERRNO (EFAULT);
    return (-1);
  }
#endif

  pos = 0;
  while (pos < len && fqdn[pos] != '.')
  {
    if (!fqdn[pos]) /* should do complete alpha/digit/underscore check here */
    {
      pos = 0;
      break;
    }
    pos++;
  }
  if (pos == 0) /* leading '.' or invalid char in name */
  {
    SOCK_ERRNO (EINVAL);
    return (-1);
  }
  if (pos >= SIZEOF(hostname))
  {
    SOCK_ERRNO (ERANGE);
    return (-1);
  }
  if (fqdn[pos] == '.') /* a trailing '.' is ok too */
  {
    if (setdomainname(&fqdn[pos+1], len-pos) != 0)
       return (-1);
  }
  memcpy (&hostname[0], fqdn, pos);
  hostname[pos] = '\0';
  return (0);
}
Ejemplo n.º 21
0
int main(int ac, char **av)
{
	int lc, ind;		/* loop counter */
	char *msg;

	if ((msg = parse_opts(ac, av, NULL, NULL))
	    != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
		tst_exit();
	}

	setup();		/* global setup */

	/* The following loop checks looping state if -i option given */

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		/* reset Tst_count in case we are looping */
		Tst_count = 0;

		for (ind = 0; ind < TST_TOTAL; ind++) {

			/*
			 * call the system call with the TEST() macro
			 */
			TEST(setdomainname(test_cases[ind].name,
					   (size_t) test_cases[ind].len));

			if ((TEST_RETURN == -1) &&
			    (TEST_ERRNO == test_cases[ind].exp_errno)) {
				tst_resm(TPASS, "expected failure; Got %s",
					 test_cases[ind].err_desc);
			} else {
				tst_resm(TFAIL, "Call failed to produce "
					 "expected error;  Expected errno: %d "
					 "Got : %d, %s",
					 test_cases[ind].exp_errno,
					 TEST_ERRNO, strerror(TEST_ERRNO));
			}
			TEST_ERROR_LOG(TEST_ERRNO);
		}
	}

	cleanup();

	tst_exit();

}
Ejemplo n.º 22
0
static void setdname(char *dname)
{
    if (opt_v)
	fprintf(stderr, _("Setting domainname to `%s'\n"),
		dname);
    if (setdomainname(dname, strlen(dname))) {
	switch (errno) {
	case EPERM:
	    fprintf(stderr, _("%s: you must be root to change the domain name\n"), program_name);
	    break;
	case EINVAL:
	    fprintf(stderr, _("%s: name too long\n"), program_name);
	    break;
	}
	exit(1);
    };
}
Ejemplo n.º 23
0
static void
restore_domain(void)
{
	char domain[MAXHOSTNAMELEN];
	int fd;
	ssize_t r, n = 0;

	memset(domain, 0, sizeof(domain));
	if ((fd = open(DOMAIN_BACKUP_FILE, O_RDONLY)) < 0)
		err(1, "open");
	while ((r = read(fd, domain + n, sizeof(domain) - n)) > 0)
		n += r;
	if (r < 0)
		err(1, "read");
	if (setdomainname(domain, n) != 0)
		err(1, "setdomainname");
	close(fd);
}
Ejemplo n.º 24
0
/* 
 *cleanup() -  performs all ONE TIME cleanup for this test at
 *		completion or premature exit.
 */
void 
cleanup()
{

	/*
	 * print timing stats if that option was specified.
	 * print errno log if that option was specified.
	 */
	TEST_CLEANUP;

	/* Restore domain name */
	if((setdomainname(old_domain_name, strlen(old_domain_name))) < 0 ) {
		tst_resm(TWARN, "setdomainname() failed while restoring"
				" domainname to \"%s\"", old_domain_name);
	}

	/* exit with return code appropriate for results */
	tst_exit();
}	/* End cleanup() */
Ejemplo n.º 25
0
static int loopback_set_domainname(const char *domainname)
{
	int err, len;

	len = strlen(domainname);

	if (connman_inet_check_hostname(domainname, len) == FALSE)
		return -EINVAL;

	if (setdomainname(domainname, len) < 0) {
		err = -errno;
		connman_error("Failed to set domainname to %s", domainname);
		return err;
	}

	connman_info("Setting domainname to %s", domainname);

	return 0;
}
Ejemplo n.º 26
0
int
main(int argc, char *argv[])
{
	int myerrno = 0;
	errno = 0;

	argc--;
	argv++;
	if (argc) {
		if (setdomainname(*argv, strlen(*argv)) < 0) {
			myerrno = errno;
			perror("setdomainname");
		}
	} else {
		if (getdomainname(domainname, sizeof (domainname)) < 0) {
			myerrno = errno;
			perror("getdomainname");
		} else {
			printf("%s\n", domainname);
		}
	}
	return (myerrno);
}
Ejemplo n.º 27
0
/* Initialise the resolver. Open a socket and bind it to the address
   of the server.  return -1 if something goes wrong, otherwise 0 */
int  
redboot_dns_res_init(void)
{
#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN
  char *dns_domain = NULL;
#endif
    memset((char *)&server, 0, sizeof(server));
    server.sin_len = sizeof(server);
    server.sin_family = AF_INET;
    server.sin_port = htons(DOMAIN_PORT);
    cyg_drv_mutex_init(&dns_mutex);

    /* Set the default DNS domain first, so that it can be overwritten
       latter */
#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_DEFAULT_DOMAIN
        setdomainname(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_DEFAULT_DOMAIN), 
                      strlen(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_DEFAULT_DOMAIN)));
#endif
        /* Set the domain name from flash so that DHCP can later
           overwrite it. */
#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN
        flash_get_config("dns_domain", &dns_domain, CONFIG_STRING);
        if(dns_domain != NULL && dns_domain[0] != '\0')
                setdomainname(dns_domain, strlen(dns_domain));
#endif

    /* If we got a DNS server address from the DHCP/BOOTP, then use
       that address */
    if ( __bootp_dns_set ) {
	memcpy(&server.sin_addr, &__bootp_dns_addr, 
               sizeof(__bootp_dns_addr) );
    
#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_DHCP_DOMAIN        
        if(__bootp_dns_domain_set) 
            setdomainname(__bootp_dns_domain, strlen(__bootp_dns_domain));
#endif
        /* server config is valid */
        s = 0; 
    }
    else {
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
    {
        ip_addr_t dns_ip;

        flash_get_config("dns_ip", &dns_ip, CONFIG_IP);
        if (dns_ip[0] == 0 && dns_ip[1] == 0 && 
            dns_ip[2] == 0 && dns_ip[3] == 0)
            return -1;
        memcpy(&server.sin_addr, &dns_ip, sizeof(dns_ip));
        /* server config is valid */
        s = 0;
    }
#else
    // Use static configuration. If CYGPKG_REDBOOT_NETWORKING_DNS_IP
    // is valid s will set set as a side effect.
    set_dns(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_IP));
#endif
    }

    return 0;
}
Ejemplo n.º 28
0
ATF_TC_CLEANUP(setdomainname_basic, tc)
{
	(void)setdomainname(domain, sizeof(domain));
}
Ejemplo n.º 29
0
int main(int argc, char **argv) {
    pid_t installpid, childpid;
    int waitStatus;
    int fd = -1;
    int doShutdown =0;
    reboot_action shutdown_method = HALT;
    int isSerial = 0;
    int isDevelMode = 0;
    char * console = NULL;
    int doKill = 1;
    char * argvc[15];
    char buf[1024];
    char ** argvp = argvc;
    char twelve = 12;
    struct serial_struct si;
    int i, disable_keys;
    int ret;

    if (!strncmp(basename(argv[0]), "poweroff", 8)) {
        printf("Running poweroff...\n");
        fd = getInitPid();
        if (fd > 0)
            kill(fd, SIGUSR2);
        doExit(0);
    } else if (!strncmp(basename(argv[0]), "halt", 4)) {
        printf("Running halt...\n");
        fd = getInitPid();
        if (fd > 0)
            kill(fd, SIGUSR1);
        doExit(0);
    } else if (!strncmp(basename(argv[0]), "reboot", 6)) {
        printf("Running reboot...\n");
        fd = getInitPid();
        if (fd > 0)
            kill(fd, SIGINT);
        doExit(0);
    }

    /* turn off screen blanking */
    printstr("\033[9;0]");
    printstr("\033[8]");

    umask(022);

    /* set up signal handler */
    setupBacktrace();

    printstr("\nGreetings.\n");

    printf("anaconda installer init version %s starting\n", VERSION);

    printf("mounting /proc filesystem... "); 
    fflush(stdout);
    if (mount("/proc", "/proc", "proc", 0, NULL))
        fatal_error(1);
    printf("done\n");

    /* check for development mode early */
    int fdn;
    if ((fdn = open("/proc/cmdline", O_RDONLY, 0)) != -1) {

        /* get cmdline info */
        int len = read(fdn, buf, sizeof(buf) - 1);
        char *develstart;
        close(fdn);

        /* check the arguments */
        if (len > 0) {
            develstart = buf;
            while (develstart && (*develstart) != '\0') {
                
                /* strip spaces */
		while(*develstart == ' ') develstart++;
		if(*develstart == '\0') break;
                
                /* not the word we are looking for */
                if (strncmp(develstart, "devel", 5)) {
                    develstart = strchr(develstart, ' ');
                    continue;
		}
                
                /* is it isolated? */
                if(((*(develstart+5)) == ' ' || (*(develstart+5)) == '\0')) {
                    printf("Enabling development mode - cores will be dumped\n");
                    isDevelMode++;
                    break;
                }
                
                /* Find next argument */
                develstart = strchr(develstart, ' ');
            }
        }
    }

    /* these args are only for testing from commandline */
    for (i = 1; i < argc; i++) {
        if (!strcmp (argv[i], "serial")) {
            isSerial = 1;
            break;
        }
    }

    printf("creating /dev filesystem... "); 
    fflush(stdout);
    if (mount("/dev", "/dev", "tmpfs", 0, NULL))
        fatal_error(1);
    createDevices();
    printf("done\n");

    printf("starting udev...");
    fflush(stdout);
    if ((childpid = fork()) == 0) {
        execl("/sbin/udevd", "/sbin/udevd", "--daemon", NULL);
        fprintf(stderr, " exec of /sbin/udevd failed.");
        exit(1);
    }

    /* wait at least until the udevd process that we forked exits */
    do {
        pid_t retpid;
        int waitstatus;

        retpid = wait(&waitstatus);
        if (retpid == -1) {
            if (errno == EINTR)
                continue;
            /* if the child exited before we called waitpid, we can get
             * ECHILD without anything really being wrong; we just lost
             * the race.*/
            if (errno == ECHILD)
                break;
            printf("init: error waiting on udevd: %m\n");
            exit(1);
        } else if ((retpid == childpid) && WIFEXITED(waitstatus)) {
            break;
        }
    } while (1);

    if (fork() == 0) {
        execl("/sbin/udevadm", "udevadm", "control", "--env=ANACONDA=1", NULL);
        fprintf(stderr, " exec of /sbin/udevadm failed.");
        exit(1);
    }
    printf("done\n");

    printf("mounting /dev/pts (unix98 pty) filesystem... "); 
    fflush(stdout);
    if (mount("/dev/pts", "/dev/pts", "devpts", 0, NULL))
        fatal_error(1);
    printf("done\n");

    printf("mounting /sys filesystem... "); 
    fflush(stdout);
    if (mount("/sys", "/sys", "sysfs", 0, NULL))
        fatal_error(1);
    printf("done\n");

    /* if anaconda dies suddenly we are doomed, so at least make a coredump */
    struct rlimit corelimit = { RLIM_INFINITY,  RLIM_INFINITY};
    ret = setrlimit(RLIMIT_CORE, &corelimit);
    if (ret) {
        perror("setrlimit failed - no coredumps will be available");
    }

    doKill = getKillPolicy();

#if !defined(__s390__) && !defined(__s390x__)
    static struct termios orig_cmode;
    static int            orig_flags;
    struct termios cmode, mode;
    int cfd;
    
    cfd =  open("/dev/console", O_RDONLY);
    tcgetattr(cfd,&orig_cmode);
    orig_flags = fcntl(cfd, F_GETFL);
    close(cfd);

    cmode = orig_cmode;
    cmode.c_lflag &= (~ECHO);

    cfd = open("/dev/console", O_WRONLY);
    tcsetattr(cfd,TCSANOW,&cmode);
    close(cfd);

    /* handle weird consoles */
#if defined(__powerpc__)
    char * consoles[] = { "/dev/hvc0", /* hvc for JS20 */

                          "/dev/hvsi0", "/dev/hvsi1",
                          "/dev/hvsi2", /* hvsi for POWER5 */
                          NULL };
#elif defined (__ia64__)
    char * consoles[] = { "/dev/ttySG0", "/dev/xvc0", "/dev/hvc0", NULL };
#elif defined (__i386__) || defined (__x86_64__)
    char * consoles[] = { "/dev/xvc0", "/dev/hvc0", NULL };
#else
    char * consoles[] = { NULL };
#endif
    for (i = 0; consoles[i] != NULL; i++) {
        if ((fd = open(consoles[i], O_RDWR)) >= 0 && !tcgetattr(fd, &mode) && !termcmp(&cmode, &mode)) {
            printf("anaconda installer init version %s using %s as console\n",
                   VERSION, consoles[i]);
            isSerial = 3;
            console = strdup(consoles[i]);
            break;
        }
        close(fd);
    }

    cfd = open("/dev/console", O_WRONLY);
    tcsetattr(cfd,TCSANOW,&orig_cmode);
    close(cfd); 

    if ((fd < 0) && (ioctl (0, TIOCLINUX, &twelve) < 0)) {
        isSerial = 2;

        if (ioctl(0, TIOCGSERIAL, &si) == -1) {
            isSerial = 0;
        }
    }

    if (isSerial && (isSerial != 3)) {
        char *device = "/dev/ttyS0";

        printf("anaconda installer init version %s using a serial console\n", 
               VERSION);

        if (isSerial == 2)
            device = "/dev/console";
        fd = open(device, O_RDWR, 0);
        if (fd < 0)
            device = "/dev/tts/0";

        if (fd < 0) {
            printf("failed to open %s\n", device);
            fatal_error(1);
        }

        setupTerminal(fd);
    } else if (isSerial == 3) {
        setupTerminal(fd);
    } else if (fd < 0)  {
        fd = open("/dev/tty1", O_RDWR, 0);
        if (fd < 0)
            fd = open("/dev/vc/1", O_RDWR, 0);

        if (fd < 0) {
            printf("failed to open /dev/tty1 and /dev/vc/1");
            fatal_error(1);
        }
    }

    setsid();
    if (ioctl(0, TIOCSCTTY, NULL)) {
        printf("could not set new controlling tty\n");
    }

    dup2(fd, 0);
    dup2(fd, 1);
    dup2(fd, 2);
    if (fd > 2)
        close(fd);
#else
    dup2(0, 1);
    dup2(0, 2);
#endif

    /* disable Ctrl+Z, Ctrl+C, etc ... but not in rescue mode */
    disable_keys = 1;
    if (argc > 1)
        if (strstr(argv[1], "rescue"))
            disable_keys = 0;

    if (disable_keys) {
        tcgetattr(0, &ts);
        ts.c_iflag &= ~BRKINT;
        ts.c_iflag |= IGNBRK;
        ts.c_iflag &= ~ISIG;
        tcsetattr(0, TCSANOW, &ts);
    }

    ret = sethostname("localhost.localdomain", 21);
    /* the default domainname (as of 2.0.35) is "(none)", which confuses 
     glibc */
    ret = setdomainname("", 0);

    printf("trying to remount root filesystem read write... ");
    fflush(stdout);
    if (mount("/", "/", "ext2", MS_REMOUNT | MS_MGC_VAL, NULL)) {
        fatal_error(1);
    }
    printf("done\n");

    /* we want our /tmp to be tmpfs, but we also want to let people hack
     * their initrds to add things like a ks.cfg, so this has to be a little
     * tricky */
    rename("/tmp", "/oldtmp");
    mkdir("/tmp", 0755);

    printf("mounting /tmp as tmpfs... ");
    fflush(stdout);
    if (mount("none", "/tmp", "tmpfs", 0, "size=250m"))
        fatal_error(1);
    printf("done\n");

    copyDirectory("/oldtmp", "/tmp", copyErrorFn, copyErrorFn);
    unlink("/oldtmp");

    /* Now we have some /tmp space set up, and /etc and /dev point to
       it. We should be in pretty good shape. */
    startSyslog();

    /* write out a pid file */
    if ((fd = open("/var/run/init.pid", O_WRONLY|O_CREAT, 0644)) > 0) {
        char * buf = malloc(10);
        int ret;

        snprintf(buf, 9, "%d", getpid());
        ret = write(fd, buf, strlen(buf));
        close(fd);
        free(buf);
    } else {
        printf("unable to write init.pid (%d): %m\n", errno);
        sleep(2);
    }

    /* D-Bus */
    if (fork() == 0) {
        execl("/sbin/dbus-uuidgen", "/sbin/dbus-uuidgen", "--ensure", NULL);
        fprintf(stderr, "exec of /sbin/dbus-uuidgen failed.");
        doExit(1);
    }

    if (fork() == 0) {
        execl("/sbin/dbus-daemon", "/sbin/dbus-daemon", "--system", NULL);
        fprintf(stderr, "exec of /sbin/dbus-daemon failed.");
        doExit(1);
    }

    sleep(2);

    /* Go into normal init mode - keep going, and then do a orderly shutdown
       when:

       1) /bin/install exits
       2) we receive a SIGHUP 
    */

    printf("running install...\n"); 

    if (!(installpid = fork())) {
        /* child */
        *argvp++ = "/sbin/loader";

        if (isSerial == 3) {
            *argvp++ = "--virtpconsole";
            *argvp++ = console;
        }

        if (isDevelMode) {
            *argvp++ = "--devel";
        }

        *argvp++ = NULL;

        printf("running %s\n", argvc[0]);
        execve(argvc[0], argvc, env);

        shutDown(1, HALT);
    }

    /* signal handlers for halt/poweroff */
    signal(SIGUSR1, sigUsr1Handler);
    signal(SIGUSR2, sigUsr2Handler);

    /* set up the ctrl+alt+delete handler to kill our pid, not pid 1 */
    signal(SIGINT, sigintHandler);
    if ((fd = open("/proc/sys/kernel/cad_pid", O_WRONLY)) != -1) {
        char buf[7];
        size_t count;
        sprintf(buf, "%d", getpid());
        count = write(fd, buf, strlen(buf));
        close(fd);
        /* if we succeeded in writing our pid, turn off the hard reboot
           ctrl-alt-del handler */
        if (count == strlen(buf) &&
            (fd = open("/proc/sys/kernel/ctrl-alt-del", O_WRONLY)) != -1) {
            int ret;

            ret = write(fd, "0", 1);
            close(fd);
        }
    }
    
    while (!doShutdown) {
        pid_t childpid;
        childpid = wait(&waitStatus);

        if (childpid == installpid) {
            doShutdown = 1;
            ioctl(0, VT_ACTIVATE, 1);
        }
    }

#ifdef  ROCKS
    /*
     * ignore child processes that throw error stati when
     * they terminate
     */
    shutdown_method = REBOOT;
#else
    if (!WIFEXITED(waitStatus) ||
        (WIFEXITED(waitStatus) && WEXITSTATUS(waitStatus))) {

        /* Restore terminal */
        cfd =  open("/dev/console", O_RDONLY);
        tcsetattr(cfd, TCSANOW, &orig_cmode);
        fcntl(cfd, F_SETFL, orig_flags);
        close(cfd);

        shutdown_method = DELAYED_REBOOT;
        printf("install exited abnormally [%d/%d] ", WIFEXITED(waitStatus),
                                                     WEXITSTATUS(waitStatus));
        if (WIFSIGNALED(waitStatus)) {
            printf("-- received signal %d", WTERMSIG(waitStatus));
        }
        printf("\n");

        /* If debug mode was requested, spawn shell */
        if(isDevelMode) {
            pid_t shellpid;

            printf("Development mode requested spawning shell...\n");

            if ((shellpid = fork()) == 0) {
                execl("/sbin/bash", "/sbin/bash", NULL);
            }
            else if (shellpid > 0) {
                waitpid(shellpid, NULL, 0);
            }
            else {
                perror("Execution of debug shell failed.");
            }

        }

    } else {
        shutdown_method = REBOOT;
    }
#endif

#ifdef  ROCKS
    while(dontReboot()) {
            sleep(10);
    }
#endif

    shutDown(doKill, shutdown_method);

    return 0;
}
int main(int argc, char **argv) {
    pid_t installpid, childpid;
    int waitStatus;
    int fd = -1;
    int doReboot = 0;
    int doShutdown =0;
    int isSerial = 0;
    char * console = NULL;
    int noKill = 0;
    char * argvc[15];
    char ** argvp = argvc;
    char twelve = 12;
    struct serial_struct si;
    int i, disable_keys;

    if (!strncmp(basename(argv[0]), "poweroff", 8)) {
        printf("Running poweroff...\n");
        fd = getInitPid();
        if (fd > 0)
            kill(fd, SIGUSR2);
        exit(0);
    } else if (!strncmp(basename(argv[0]), "halt", 4)) {
        printf("Running halt...\n");
        fd = getInitPid();
        if (fd > 0)
            kill(fd, SIGUSR1);
        exit(0);
    } else if (!strncmp(basename(argv[0]), "reboot", 6)) {
        printf("Running reboot...\n");
        fd = getInitPid();
        if (fd > 0)
            kill(fd, SIGINT);
        exit(0);
    }

#if !defined(__s390__) && !defined(__s390x__)
    testing = (getppid() != 0) && (getppid() != 1);
#endif

    if (!testing) {
        /* turn off screen blanking */
        printstr("\033[9;0]");
        printstr("\033[8]");
    } else {
        printstr("(running in test mode).\n");
    }

    umask(022);

    printstr("\nGreetings.\n");

    printf("anaconda installer init version %s starting\n", VERSION);

    printf("mounting /proc filesystem... ");
    if (!testing) {
        if (mount("/proc", "/proc", "proc", 0, NULL))
            fatal_error(1);
    }
    printf("done\n");

    printf("creating /dev filesystem... ");
    if (!testing) {
        if (mount("/dev", "/dev", "tmpfs", 0, NULL))
            fatal_error(1);
        createDevices();
    }
    printf("done\n");

    printf("mounting /dev/pts (unix98 pty) filesystem... ");
    if (!testing) {
        if (mount("/dev/pts", "/dev/pts", "devpts", 0, NULL))
            fatal_error(1);
    }
    printf("done\n");

    printf("mounting /sys filesystem... ");
    if (!testing) {
        if (mount("/sys", "/sys", "sysfs", 0, NULL))
            fatal_error(1);
    }
    printf("done\n");

    /* these args are only for testing from commandline */
    for (i = 1; i < argc; i++) {
        if (!strcmp (argv[i], "serial")) {
            isSerial = 1;
            break;
        }
    }

    noKill = getNoKill();

#if !defined(__s390__) && !defined(__s390x__)
    static struct termios orig_cmode;
    struct termios cmode, mode;
    int cfd;

    cfd =  open("/dev/console", O_RDONLY);
    tcgetattr(cfd,&orig_cmode);
    close(cfd);

    cmode = orig_cmode;
    cmode.c_lflag &= (~ECHO);

    cfd = open("/dev/console", O_WRONLY);
    tcsetattr(cfd,TCSANOW,&cmode);
    close(cfd);

    /* handle weird consoles */
#if defined(__powerpc__)
    char * consoles[] = { "/dev/hvc0", /* hvc for JS20 */

                          "/dev/hvsi0", "/dev/hvsi1",
                          "/dev/hvsi2", /* hvsi for POWER5 */
                          NULL
                        };
#elif defined (__ia64__)
    char * consoles[] = { "/dev/ttySG0", "/dev/xvc0", NULL };
#elif defined (__i386__) || defined (__x86_64__)
    char * consoles[] = { "/dev/xvc0", NULL };
#else
    char * consoles[] = { NULL };
#endif
    for (i = 0; consoles[i] != NULL; i++) {
        if ((fd = open(consoles[i], O_RDWR)) >= 0 && !tcgetattr(fd, &mode) && !termcmp(&cmode, &mode)) {
            printf("anaconda installer init version %s using %s as console\n",
                   VERSION, consoles[i]);
            isSerial = 3;
            console = strdup(consoles[i]);
            break;
        }
        close(fd);
    }

    cfd = open("/dev/console", O_WRONLY);
    tcsetattr(cfd,TCSANOW,&orig_cmode);
    close(cfd);

    if ((fd < 0) && (ioctl (0, TIOCLINUX, &twelve) < 0)) {
        isSerial = 2;
        if (ioctl(0, TIOCGSERIAL, &si) == -1) {
            isSerial = 0;
        }
    }

    if (isSerial && (isSerial != 3)) {
        char *device = "/dev/ttyS0";

        printf("anaconda installer init version %s using a serial console\n",
               VERSION);

        if (isSerial == 2)
            device = "/dev/console";
        fd = open(device, O_RDWR, 0);
        if (fd < 0)
            device = "/dev/tts/0";

        if (fd < 0) {
            printf("failed to open %s\n", device);
            fatal_error(1);
        }

        setupTerminal(fd);
    } else if (isSerial == 3) {
        setupTerminal(fd);
    } else if (fd < 0)  {
        fd = open("/dev/tty1", O_RDWR, 0);
        if (fd < 0)
            fd = open("/dev/vc/1", O_RDWR, 0);

        if (fd < 0) {
            printf("failed to open /dev/tty1 and /dev/vc/1");
            fatal_error(1);
        }
    }

    if (testing)
        exit(0);

    setsid();
    if (ioctl(0, TIOCSCTTY, NULL)) {
        printf("could not set new controlling tty\n");
    }

    dup2(fd, 0);
    dup2(fd, 1);
    dup2(fd, 2);
    if (fd > 2)
        close(fd);
#else
    dup2(0, 1);
    dup2(0, 2);
#endif

    /* disable Ctrl+Z, Ctrl+C, etc ... but not in rescue mode */
#ifdef SNAKES_ON_A_PLANE
    disable_keys = 0;
#else
    disable_keys = 1;
    if (argc > 1)
        if (mystrstr(argv[1], "rescue"))
            disable_keys = 0;
#endif

    if (disable_keys) {
        tcgetattr(0, &ts);
        ts.c_iflag &= ~BRKINT;
        ts.c_iflag |= IGNBRK;
        ts.c_iflag &= ~ISIG;
        tcsetattr(0, TCSANOW, &ts);
    }

    if (!testing) {
        int ret;
        ret = sethostname("localhost.localdomain", 21);
        /* the default domainname (as of 2.0.35) is "(none)", which confuses
         glibc */
        ret = setdomainname("", 0);
    }

    printf("trying to remount root filesystem read write... ");
    if (mount("/", "/", "ext2", MS_REMOUNT | MS_MGC_VAL, NULL)) {
        fatal_error(1);
    }
    printf("done\n");

    /* we want our /tmp to be ramfs, but we also want to let people hack
     * their initrds to add things like a ks.cfg, so this has to be a little
     * tricky */
    if (!testing) {
        rename("/tmp", "/oldtmp");
        mkdir("/tmp", 0755);

        printf("mounting /tmp as ramfs... ");
        if (mount("none", "/tmp", "ramfs", 0, NULL))
            fatal_error(1);
        printf("done\n");

        copyDirectory("/oldtmp", "/tmp");
        unlink("/oldtmp");
    }

    /* Now we have some /tmp space set up, and /etc and /dev point to
       it. We should be in pretty good shape. */

    if (!testing)
        doklog("/dev/tty4");

    /* write out a pid file */
    if ((fd = open("/var/run/init.pid", O_WRONLY|O_CREAT, 0644)) > 0) {
        char * buf = malloc(10);
        int ret;

        snprintf(buf, 9, "%d", getpid());
        ret = write(fd, buf, strlen(buf));
        close(fd);
        free(buf);
    } else {
        printf("unable to write init.pid (%d): %s\n", errno, strerror(errno));
        sleep(2);
    }

    /* Go into normal init mode - keep going, and then do a orderly shutdown
       when:

       1) /bin/install exits
       2) we receive a SIGHUP
    */

    printf("running install...\n");

    setsid();

#ifdef SNAKES_ON_A_PLANE
    printf("> Snakes on a Plane <\n");

    /* hack to load core modules for debugging mode */
    char * modvc[15];
    char ** modvp = modvc;
    *modvp++ = "/bin/modprobe";
    *modvp++ = "ehci-hcd";
    *modvp++ = "uhci-hcd";
    *modvp++ = "ohci-hcd";
    *modvp++ = NULL;
    pid_t blah = fork();
    int qux;
    if (blah == 0) {
        printf("loading core debugging modules...\n");
        execve(modvc[0], modvc, env);
    } else {
        waitpid(blah, &qux, WNOHANG);
    }
#endif

    if (!(installpid = fork())) {
        /* child */
#ifdef SNAKES_ON_A_PLANE
        *argvp++ = "/bin/strace";
#endif
        *argvp++ = "/sbin/loader";

        if (isSerial == 3) {
            *argvp++ = "--virtpconsole";
            *argvp++ = console;
        }

        *argvp++ = NULL;

        printf("running %s\n", argvc[0]);
        execve(argvc[0], argvc, env);

        shutDown(1, 0, 0);
    }

    /* signal handlers for halt/poweroff */
    signal(SIGUSR1, sigUsr1Handler);
    signal(SIGUSR2, sigUsr2Handler);

    /* set up the ctrl+alt+delete handler to kill our pid, not pid 1 */
    signal(SIGINT, sigintHandler);
    if ((fd = open("/proc/sys/kernel/cad_pid", O_WRONLY)) != -1) {
        char buf[7];
        size_t count;
        sprintf(buf, "%d", getpid());
        count = write(fd, buf, strlen(buf));
        close(fd);
        /* if we succeeded in writing our pid, turn off the hard reboot
           ctrl-alt-del handler */
        if (count == strlen(buf) &&
                (fd = open("/proc/sys/kernel/ctrl-alt-del", O_WRONLY)) != -1) {
            int ret;

            ret = write(fd, "0", 1);
            close(fd);
        }
    }

    while (!doShutdown) {
        childpid = waitpid(-1, &waitStatus, 0);

        if (childpid == installpid)
            doShutdown = 1;
    }

    if (!WIFEXITED(waitStatus) ||
            (WIFEXITED(waitStatus) && WEXITSTATUS(waitStatus))) {
        printf("install exited abnormally [%d/%d] ", WIFEXITED(waitStatus),
               WEXITSTATUS(waitStatus));
        if (WIFSIGNALED(waitStatus)) {
            printf("-- received signal %d", WTERMSIG(waitStatus));
        }
        printf("\n");
    } else {
        doReboot = 1;
    }

    if (testing)
        exit(0);

    shutDown(noKill, doReboot, 0);

    return 0;
}