Exemplo n.º 1
0
int do_diag(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	char *orig_ethact, *orig_ipaddr, ca_ethact[20], ca_ipaddr[20];
	int i;

	switch (argc)
	{
	case 2:
		if (strncmp(argv[1],"cpu-bist", 8) == 0)
		{
			octeon_bist();
			return 0;
		}
		else if (strncmp(argv[1],"ddr", 3) == 0)
		{
			return do_mem_mtest(NULL, 0, 1, "mtest");

		}
		else if (strncmp(argv[1],"pci", 3) == 0)
		{
#define MAX_ADV_PCI_BUS 13
                        char *local_args[4], busno[4];
                        int pci_busno;

                        local_args[0] = "pci";
                        local_args[1] = busno;
			local_args[2] = "short";
                        local_args[3] = NULL;
                        for (pci_busno = 0; pci_busno < MAX_ADV_PCI_BUS; pci_busno++)
                        {
                        	sprintf (busno, "%x", pci_busno);
                                do_pci(NULL, 0, 3, local_args);
                        }
			return 0;
		}
		else if (strncmp(argv[1],"mmc-sensor", 10) == 0)
		{
#define MON_3VSB_ID	"0x02"
#define MON_12V_ID	"0x03"
#define VDD_3V3_ID	"0x06"
#define TMP421_CORE_ID	"0x0B"
#define TMP275_BOARD_ID	"0x0C"

#define MON_3VSB(x)	(0.016*x)
#define MON_12V(x)	((68*x-5)*0.001)
#define VDD_3V3(x)	(0.016*x)
#define TMP421_CORE(x)	(x)
#define TMP275_BOARD(x)	(1.01*x+0.14)

#define COMMAND_SUCCESS_OFFSET  6
#define VALUE_OFFSET		(COMMAND_SUCCESS_OFFSET + 1)
#define VALID_READ_OFFSET	(COMMAND_SUCCESS_OFFSET + 2)
#define INVALID_READ_MASK	0x20
			const uchar *ret_val;
			char *argv[]={"ipmi", "raw", "0x04", "0x2D", "0x00"};
			char *ids[]={MON_3VSB_ID, MON_12V_ID, VDD_3V3_ID, TMP421_CORE_ID, TMP275_BOARD_ID};
			char *ids_name[]={"3.3V standby", "12V", "3.3V", "Core temperature", "Board temperature"};
			int total_ids, argc, i, tmp;
			float fRet;

			total_ids = sizeof(ids) / sizeof(ids[0]);
			argc      = sizeof(argv) / sizeof(argv[0]);

			for (i = 0; i < total_ids; i++)
			{
				sprintf(argv[argc-1], ids[i]);	// replace the sensor ID to read
				ret_val   = mmc_raw_command_access(argc, argv);

				if (ret_val[COMMAND_SUCCESS_OFFSET]) // 0 = success
				{
					printf("!FAIL IPMI Get %s return code 0x%02x\n", ids_name[i], ret_val[6]);
					continue;
				}

				if (ret_val[VALID_READ_OFFSET] & INVALID_READ_MASK) // bit 5: when set, this read is invalid
				{
					printf("%s: %s\n", ids_name[i], "Read failed!");
				}
				else
				{
					switch (i) {
					case 0:
						fRet = MON_3VSB(ret_val[VALUE_OFFSET]);
						break;
					case 1:
						fRet = MON_12V(ret_val[VALUE_OFFSET]);
						break;
					case 2:
						fRet = VDD_3V3(ret_val[VALUE_OFFSET]);
						break;
					case 3:
						fRet = TMP421_CORE(ret_val[VALUE_OFFSET]);
						break;
					case 4:
						fRet = TMP275_BOARD(ret_val[VALUE_OFFSET]);
						break;
					default:
						printf("unkown to calculate\n");
						break;
					}

					/* float to string, only 3 digits after '.'; Note: printf does not support float */
					{
						tmp = fRet;
						printf("%s: %d.", ids_name[i], tmp);
						fRet -= tmp;
						fRet *= 1000;
						tmp = fRet;
						printf("%d\n", tmp);
					}
				}
			}

			return 0;
		}
		else if (strncmp(argv[1],"reset-type", 10) == 0)
		{
			uint8_t cause;

			mmc_get_hw_reset_reason(&cause);
			printf("reset-type: ");
			switch (cause) {
			case 0x1:
				printf("hard reset");
				break;
			case 0x2:
				printf("soft reset");
				break;
			case 0x4:
				printf("watchdog reset");
				break;
			default:
				printf("unknown 0x%02x",cause);
				break;
			}
			printf("\n");

			return 0;
		}
		else if (strncmp(argv[1],"i2c", 3) == 0)
		{
                        char cmd[255], *subcmd[]={"speed", "dev", "probe"};

                        for (i = 0; i < sizeof(subcmd)/sizeof(subcmd[0]); i++)
                        {
				sprintf(cmd, "i2c %s", subcmd[i]);
                                run_command(cmd, 0);
                        }

			return 0;
		}
		else if (strncmp(argv[1],"xaui", 4) == 0)
		{
#define XAUI_INTERFACES	2
#define TEST_IP		"192.168.4.1"
			int default_port[] = {2624, 3136};

			/* save original env vars */
			orig_ethact = getenv("ethact");
			sprintf(ca_ethact, orig_ethact); // save to safety place
			orig_ipaddr = getenv("ipaddr");
			sprintf(ca_ipaddr, orig_ipaddr);

			/* start to test */
			setenv("ipaddr", TEST_IP);
			NetPingIP = string_to_ip(TEST_IP); // ping our self
			for (i = 0; i < XAUI_INTERFACES; i++)
			{
				char *new_ethact = "octeth ";

				sprintf(new_ethact, "octeth%d", i);
				setenv("ethact", new_ethact);

				/* enabling internal loopback */
				if (cvmx_helper_configure_loopback(default_port[i], 1, 0))
				{
					printf("enable %s loopback failed!\n", new_ethact);
					continue;
				}

				if (NetLoop(PING) < 0)
				{
					printf("%s loopback transmission failed!\n", new_ethact);
				}
				else
				{
					printf("%s loopback transmission test pass.\n", new_ethact);
				}

				/* disable loopback */
				if (cvmx_helper_configure_loopback(default_port[i], 0, 0))
					printf("disable %s loopback failed!\n", new_ethact);
			}

			/* restore env vars */
			setenv("ethact", ca_ethact);
			setenv("ipaddr", orig_ipaddr ? ca_ipaddr : orig_ipaddr);

			return 0;
		}
		else if (strncmp(argv[1],"mii", 3) == 0)
		{
			int rc = 0;

			/* save original env vars */
			orig_ethact = getenv("ethact");
			sprintf(ca_ethact, orig_ethact);
			orig_ipaddr = getenv("ipaddr");
			sprintf(ca_ipaddr, orig_ipaddr);

			/* enabling internal loopback */
			run_command("mii write 0 0 6100", 0);

			/* start to test */
			setenv("ethact", "octmgmt0");
			setenv("ipaddr", TEST_IP);
			NetPingIP = string_to_ip(TEST_IP); // ping our self

			if (NetLoop(PING) < 0)
			{
				if (NetLoop(PING) < 0) // give another chance, the octmgmt0 may failed on first try
					rc = -1;
			}

			if (rc < 0)
			{
				printf("octmgmt0 loopback transmission failed!\n");
			}
			else
			{
				printf("octmgmt0 loopback transmission test pass.\n");
			}

			/* disable loopback */
			run_command("mii write 0 0 2100", 0);

			/* restore env vars */
			setenv("ethact", ca_ethact);
			setenv("ipaddr", orig_ipaddr ? ca_ipaddr : orig_ipaddr);

			return 0;
		}
		break;
	}
	return cmd_usage(cmdtp);
}
Exemplo n.º 2
0
int fetch_populated_submodules(const struct argv_array *options,
			       const char *prefix, int command_line_option,
			       int quiet)
{
	int i, result = 0;
	struct child_process cp;
	struct argv_array argv = ARGV_ARRAY_INIT;
	struct string_list_item *name_for_path;
	const char *work_tree = get_git_work_tree();
	if (!work_tree)
		goto out;

	if (read_cache() < 0)
		die("index file corrupt");

	argv_array_push(&argv, "fetch");
	for (i = 0; i < options->argc; i++)
		argv_array_push(&argv, options->argv[i]);
	argv_array_push(&argv, "--recurse-submodules-default");
	/* default value, "--submodule-prefix" and its value are added later */

	memset(&cp, 0, sizeof(cp));
	cp.env = local_repo_env;
	cp.git_cmd = 1;
	cp.no_stdin = 1;

	calculate_changed_submodule_paths();

	for (i = 0; i < active_nr; i++) {
		struct strbuf submodule_path = STRBUF_INIT;
		struct strbuf submodule_git_dir = STRBUF_INIT;
		struct strbuf submodule_prefix = STRBUF_INIT;
		const struct cache_entry *ce = active_cache[i];
		const char *git_dir, *name, *default_argv;

		if (!S_ISGITLINK(ce->ce_mode))
			continue;

		name = ce->name;
		name_for_path = unsorted_string_list_lookup(&config_name_for_path, ce->name);
		if (name_for_path)
			name = name_for_path->util;

		default_argv = "yes";
		if (command_line_option == RECURSE_SUBMODULES_DEFAULT) {
			struct string_list_item *fetch_recurse_submodules_option;
			fetch_recurse_submodules_option = unsorted_string_list_lookup(&config_fetch_recurse_submodules_for_name, name);
			if (fetch_recurse_submodules_option) {
				if ((intptr_t)fetch_recurse_submodules_option->util == RECURSE_SUBMODULES_OFF)
					continue;
				if ((intptr_t)fetch_recurse_submodules_option->util == RECURSE_SUBMODULES_ON_DEMAND) {
					if (!unsorted_string_list_lookup(&changed_submodule_paths, ce->name))
						continue;
					default_argv = "on-demand";
				}
			} else {
				if ((config_fetch_recurse_submodules == RECURSE_SUBMODULES_OFF) ||
				    gitmodules_is_unmerged)
					continue;
				if (config_fetch_recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) {
					if (!unsorted_string_list_lookup(&changed_submodule_paths, ce->name))
						continue;
					default_argv = "on-demand";
				}
			}
		} else if (command_line_option == RECURSE_SUBMODULES_ON_DEMAND) {
			if (!unsorted_string_list_lookup(&changed_submodule_paths, ce->name))
				continue;
			default_argv = "on-demand";
		}

		strbuf_addf(&submodule_path, "%s/%s", work_tree, ce->name);
		strbuf_addf(&submodule_git_dir, "%s/.git", submodule_path.buf);
		strbuf_addf(&submodule_prefix, "%s%s/", prefix, ce->name);
		git_dir = read_gitfile(submodule_git_dir.buf);
		if (!git_dir)
			git_dir = submodule_git_dir.buf;
		if (is_directory(git_dir)) {
			if (!quiet)
				printf("Fetching submodule %s%s\n", prefix, ce->name);
			cp.dir = submodule_path.buf;
			argv_array_push(&argv, default_argv);
			argv_array_push(&argv, "--submodule-prefix");
			argv_array_push(&argv, submodule_prefix.buf);
			cp.argv = argv.argv;
			if (run_command(&cp))
				result = 1;
			argv_array_pop(&argv);
			argv_array_pop(&argv);
			argv_array_pop(&argv);
		}
		strbuf_release(&submodule_path);
		strbuf_release(&submodule_git_dir);
		strbuf_release(&submodule_prefix);
	}
	argv_array_clear(&argv);
out:
	string_list_clear(&changed_submodule_paths, 1);
	return result;
}
Exemplo n.º 3
0
static void write_bcb(const struct bootloader_message * const bcb)
{
	sprintf(buf, "mmcinit 1; fatsave mmc 1:5 0x%08x BCB", bcb);
	run_command(buf, 0);
}
Exemplo n.º 4
0
static const char *unpack(int err_fd, struct shallow_info *si)
{
	struct pack_header hdr;
	struct argv_array av = ARGV_ARRAY_INIT;
	const char *hdr_err;
	int status;
	char hdr_arg[38];
	struct child_process child;
	int fsck_objects = (receive_fsck_objects >= 0
			    ? receive_fsck_objects
			    : transfer_fsck_objects >= 0
			    ? transfer_fsck_objects
			    : 0);

	hdr_err = parse_pack_header(&hdr);
	if (hdr_err) {
		if (err_fd > 0)
			close(err_fd);
		return hdr_err;
	}
	snprintf(hdr_arg, sizeof(hdr_arg),
			"--pack_header=%"PRIu32",%"PRIu32,
			ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries));

	if (si->nr_ours || si->nr_theirs) {
		alt_shallow_file = setup_temporary_shallow(si->shallow);
		argv_array_pushl(&av, "--shallow-file", alt_shallow_file, NULL);
	}

	memset(&child, 0, sizeof(child));
	if (ntohl(hdr.hdr_entries) < unpack_limit) {
		argv_array_pushl(&av, "unpack-objects", hdr_arg, NULL);
		if (quiet)
			argv_array_push(&av, "-q");
		if (fsck_objects)
			argv_array_push(&av, "--strict");
		child.argv = av.argv;
		child.no_stdout = 1;
		child.err = err_fd;
		child.git_cmd = 1;
		status = run_command(&child);
		if (status)
			return "unpack-objects abnormal exit";
	} else {
		int s;
		char keep_arg[256];

		s = sprintf(keep_arg, "--keep=receive-pack %"PRIuMAX" on ", (uintmax_t) getpid());
		if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
			strcpy(keep_arg + s, "localhost");

		argv_array_pushl(&av, "index-pack",
				 "--stdin", hdr_arg, keep_arg, NULL);
		if (fsck_objects)
			argv_array_push(&av, "--strict");
		if (fix_thin)
			argv_array_push(&av, "--fix-thin");
		child.argv = av.argv;
		child.out = -1;
		child.err = err_fd;
		child.git_cmd = 1;
		status = start_command(&child);
		if (status)
			return "index-pack fork failed";
		pack_lockfile = index_pack_lockfile(child.out);
		close(child.out);
		status = finish_command(&child);
		if (status)
			return "index-pack abnormal exit";
		reprepare_packed_git();
	}
	return NULL;
}
Exemplo n.º 5
0
jboolean native_remove_cmd(JNIEnv* env, jclass clazz, jstring name) {
    if (!name)
        return JNI_FALSE;
    const char *path = (*env)->GetStringUTFChars(env, name, NULL);
    return run_command("rm -r %s", path) >= 0;
}
Exemplo n.º 6
0
static int rsync_transport_push(struct transport *transport,
		int refspec_nr, const char **refspec, int flags)
{
	struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT;
	int result = 0, i;
	struct child_process rsync;
	const char *args[10];

	if (flags & TRANSPORT_PUSH_MIRROR)
		return error("rsync transport does not support mirror mode");

	/* first push the objects */

	strbuf_addstr(&buf, rsync_url(transport->url));
	strbuf_addch(&buf, '/');

	memset(&rsync, 0, sizeof(rsync));
	rsync.argv = args;
	rsync.stdout_to_stderr = 1;
	i = 0;
	args[i++] = "rsync";
	args[i++] = "-a";
	if (flags & TRANSPORT_PUSH_DRY_RUN)
		args[i++] = "--dry-run";
	if (transport->verbose > 0)
		args[i++] = "-v";
	args[i++] = "--ignore-existing";
	args[i++] = "--exclude";
	args[i++] = "info";
	args[i++] = get_object_directory();
	args[i++] = buf.buf;
	args[i++] = NULL;

	if (run_command(&rsync))
		return error("Could not push objects to %s",
				rsync_url(transport->url));

	/* copy the refs to the temporary directory; they could be packed. */

	strbuf_addstr(&temp_dir, git_path("rsync-refs-XXXXXX"));
	if (!mkdtemp(temp_dir.buf))
		die ("Could not make temporary directory");
	strbuf_addch(&temp_dir, '/');

	if (flags & TRANSPORT_PUSH_ALL) {
		if (for_each_ref(write_one_ref, &temp_dir))
			return -1;
	} else if (write_refs_to_temp_dir(&temp_dir, refspec_nr, refspec))
		return -1;

	i = 2;
	if (flags & TRANSPORT_PUSH_DRY_RUN)
		args[i++] = "--dry-run";
	if (!(flags & TRANSPORT_PUSH_FORCE))
		args[i++] = "--ignore-existing";
	args[i++] = temp_dir.buf;
	args[i++] = rsync_url(transport->url);
	args[i++] = NULL;
	if (run_command(&rsync))
		result = error("Could not push to %s",
				rsync_url(transport->url));

	if (remove_dir_recursively(&temp_dir, 0))
		warning ("Could not remove temporary directory %s.",
				temp_dir.buf);

	strbuf_release(&buf);
	strbuf_release(&temp_dir);

	return result;
}
Exemplo n.º 7
0
CS_RETCODE
continue_logging_in(CS_CONTEXT ** ctx, CS_CONNECTION ** conn, CS_COMMAND ** cmd, int verbose)
{
	CS_RETCODE ret;
	char query[30];
#ifdef TDS_STATIC_CAST
	TDSCONTEXT *tds_ctx;
#endif

	ret = cs_ctx_alloc(CS_VERSION_100, ctx);
	if (ret != CS_SUCCEED) {
		if (verbose) {
			fprintf(stderr, "Context Alloc failed!\n");
		}
		return ret;
	}

#ifdef TDS_STATIC_CAST
	/* Force default date format, some tests rely on it */
	tds_ctx = (TDSCONTEXT *) (*ctx)->tds_ctx;
	if (tds_ctx && tds_ctx->locale && tds_ctx->locale->date_fmt) {
		free(tds_ctx->locale->date_fmt);
		tds_ctx->locale->date_fmt = strdup("%b %d %Y %I:%M%p");
	}
#endif

	ret = ct_init(*ctx, CS_VERSION_100);
	if (ret != CS_SUCCEED) {
		if (verbose) {
			fprintf(stderr, "Library Init failed!\n");
		}
		return ret;
	}
	if ((ret = ct_callback(*ctx, NULL, CS_SET, CS_CLIENTMSG_CB, 
			       (CS_VOID*) clientmsg_cb)) != CS_SUCCEED) {
		fprintf(stderr, "ct_callback() failed\n");
		return ret;
	}
	if ((ret = ct_callback(*ctx, NULL, CS_SET, CS_SERVERMSG_CB, servermsg_cb)) != CS_SUCCEED) {
		fprintf(stderr, "ct_callback() failed\n");
		return ret;
	}
	ret = ct_con_alloc(*ctx, conn);
	if (ret != CS_SUCCEED) {
		if (verbose) {
			fprintf(stderr, "Connect Alloc failed!\n");
		}
		return ret;
	}
	ret = ct_con_props(*conn, CS_SET, CS_USERNAME, USER, CS_NULLTERM, NULL);
	if (ret != CS_SUCCEED) {
		if (verbose) {
			fprintf(stderr, "ct_con_props() SET USERNAME failed!\n");
		}
		return ret;
	}
	ret = ct_con_props(*conn, CS_SET, CS_PASSWORD, PASSWORD, CS_NULLTERM, NULL);
	if (ret != CS_SUCCEED) {
		if (verbose) {
			fprintf(stderr, "ct_con_props() SET PASSWORD failed!\n");
		}
		return ret;
	}
	
	printf("connecting as %s to %s.%s\n", USER, SERVER, DATABASE);
	
	ret = ct_connect(*conn, SERVER, CS_NULLTERM);
	if (ret != CS_SUCCEED) {
		if (verbose) {
			fprintf(stderr, "Connection failed!\n");
		}
		ct_con_drop(*conn);
		*conn = NULL;
		cs_ctx_drop(*ctx);
		*ctx = NULL;
		return ret;
	}
	ret = ct_cmd_alloc(*conn, cmd);
	if (ret != CS_SUCCEED) {
		if (verbose) {
			fprintf(stderr, "Command Alloc failed!\n");
		}
		ct_con_drop(*conn);
		*conn = NULL;
		cs_ctx_drop(*ctx);
		*ctx = NULL;
		return ret;
	}

	strcpy(query, "use ");
	strncat(query, DATABASE, 20);

	ret = run_command(*cmd, query);
	if (ret != CS_SUCCEED)
		return ret;

	return CS_SUCCEED;
}
Exemplo n.º 8
0
int ifup(const char *name, unsigned flags)
{
	int ret;
	char *cmd, *cmd_discover;
	const char *ip;
	struct stat s;
	int i;
	struct device_d *dev;
	struct eth_device *edev = eth_get_byname(name);

	if (edev && edev->ipaddr && !(flags & IFUP_FLAG_FORCE))
		return 0;

	eth_set_current(edev);

	env_push_context();

	setenv("ip", "");

	for (i = 0; i < ARRAY_SIZE(vars); i++)
		setenv(vars[i], "");

	cmd = asprintf("source /env/network/%s", name);
	cmd_discover = asprintf("/env/network/%s-discover", name);

	ret = run_command(cmd);
	if (ret) {
		pr_err("Running '%s' failed with %d\n", cmd, ret);
		goto out;
	}

	ret = stat(cmd_discover, &s);
	if (!ret) {
		ret = run_command(cmd_discover);
		if (ret) {
			pr_err("Running '%s' failed with %d\n", cmd, ret);
			goto out;
		}
	}

	dev = get_device_by_name(name);
	if (!dev) {
		pr_err("Cannot find device %s\n", name);
		goto out;
	}

	ret = eth_set_param(dev, "ethaddr");
	if (ret)
		goto out;

	ip = getenv("ip");
	if (!strcmp(ip, "dhcp")) {
		ret = run_command("dhcp");
		if (ret)
			goto out;
		ret = eth_set_param(dev, "serverip");
		if (ret)
			goto out;
	} else if (!strcmp(ip, "static")) {
		for (i = 0; i < ARRAY_SIZE(vars); i++) {
			ret = eth_set_param(dev, vars[i]);
			if (ret)
				goto out;
		}
	} else {
		pr_err("unknown ip type: %s\n", ip);
		ret = -EINVAL;
		goto out;
	}

	ret = 0;
out:
	env_pop_context();
	free(cmd);
	free(cmd_discover);

	return ret;
}
Exemplo n.º 9
0
int run_command_v_opt(const char **argv, int opt)
{
	struct child_process cmd;
	prepare_run_command_v_opt(&cmd, argv, opt);
	return run_command(&cmd);
}
Exemplo n.º 10
0
int					/* O - 0 = success, 1 = fail */
make_rpm(int            format,		/* I - Subformat */
         const char     *prodname,	/* I - Product short name */
         const char     *directory,	/* I - Directory for distribution files */
         const char     *platname,	/* I - Platform name */
         dist_t         *dist,		/* I - Distribution information */
	 struct utsname *platform,	/* I - Platform information */
         const char     *setup,		/* I - Setup GUI image */
         const char     *types)		/* I - Setup GUI install types */
{
  int		i;			/* Looping var */
  FILE		*fp;			/* Spec file */
  tarf_t	*tarfile;		/* Distribution tar file */
  char		specname[1024];		/* Spec filename */
  char		name[1024],		/* Product filename */
		filename[1024];		/* Destination filename */
  file_t	*file;			/* Current distribution file */
  char		absdir[1024];		/* Absolute directory */
  char		rpmdir[1024];		/* RPMDIR env var */
  char		release[256];		/* Release: number */
  const char	*build_option;		/* Additional rpmbuild option */


  if (Verbosity)
    puts("Creating RPM distribution...");

  if (directory[0] != '/')
  {
    char	current[1024];		/* Current directory */


    getcwd(current, sizeof(current));

    snprintf(absdir, sizeof(absdir), "%s/%s", current, directory);
  }
  else
    strlcpy(absdir, directory, sizeof(absdir));

 /*
  * Write the spec file for RPM...
  */

  if (Verbosity)
    puts("Creating spec file...");

  snprintf(specname, sizeof(specname), "%s/%s.spec", directory, prodname);

  if ((fp = fopen(specname, "w")) == NULL)
  {
    fprintf(stderr, "epm: Unable to create spec file \"%s\" - %s\n", specname,
            strerror(errno));
    return (1);
  }

  if (dist->release[0])
    strlcpy(release, dist->release, sizeof(release));
  else
    strlcpy(release, "0", sizeof(release));

  fprintf(fp, "Name: %s\n", prodname);
  fprintf(fp, "Version: %s\n", dist->version);
  if (dist->epoch)
    fprintf(fp, "Epoch: %d\n", dist->epoch);
  fprintf(fp, "Release: %s\n", release);
  fprintf(fp, "License: %s\n", dist->copyright);
  fprintf(fp, "Packager: %s\n", dist->packager);
  fprintf(fp, "Vendor: %s\n", dist->vendor);

  if (format == PACKAGE_LSB || format == PACKAGE_LSB_SIGNED)
    fputs("Requires: lsb >= 3.0\n", fp);

 /*
  * Tell RPM to put the distributions in the output directory...
  */

#ifdef EPM_RPMTOPDIR
  fprintf(fp, "%%define _topdir %s\n", absdir);
  strcpy(rpmdir, absdir);
#else
  if (getenv("RPMDIR"))
    strlcpy(rpmdir, getenv("RPMDIR"), sizeof(rpmdir));
  else if (!access("/usr/src/redhat", 0))
    strcpy(rpmdir, "/usr/src/redhat");
  else if (!access("/usr/src/Mandrake", 0))
    strcpy(rpmdir, "/usr/src/Mandrake");
  else
    strcpy(rpmdir, "/usr/src/RPM");
#endif /* EPM_RPMTOPDIR */

  snprintf(filename, sizeof(filename), "%s/RPMS", directory);

  make_directory(filename, 0777, getuid(), getgid());

  snprintf(filename, sizeof(filename), "%s/rpms", directory);
  symlink("RPMS", filename);

  if (!strcmp(platform->machine, "intel"))
    snprintf(filename, sizeof(filename), "%s/RPMS/i386", directory);
  else if (!strcmp(platform->machine, "ppc"))
    snprintf(filename, sizeof(filename), "%s/RPMS/powerpc", directory);
  else
    snprintf(filename, sizeof(filename), "%s/RPMS/%s", directory,
             platform->machine);

  make_directory(filename, 0777, getuid(), getgid());

 /*
  * Now list all of the subpackages...
  */

  write_spec(format, prodname, dist, fp, NULL);
  for (i = 0; i < dist->num_subpackages; i ++)
    write_spec(format, prodname, dist, fp, dist->subpackages[i]);

 /*
  * Close the spec file...
  */

  fclose(fp);

 /*
  * Copy the files over...
  */

  if (Verbosity)
    puts("Copying temporary distribution files...");

  for (i = dist->num_files, file = dist->files; i > 0; i --, file ++)
  {
   /*
    * Copy the file or make the directory or make the symlink as needed...
    */

    switch (tolower(file->type))
    {
      case 'c' :
      case 'f' :
          snprintf(filename, sizeof(filename), "%s/buildroot%s", directory, file->dst);

	  if (Verbosity > 1)
	    printf("%s -> %s...\n", file->src, filename);

	  if (copy_file(filename, file->src, 0, -1, -1))
	    return (1);
          break;
      case 'i' :
          if (format == PACKAGE_LSB || format == PACKAGE_LSB_SIGNED)
	    snprintf(filename, sizeof(filename), "%s/buildroot/etc/init.d/%s",
		     directory, file->dst);
          else
	    snprintf(filename, sizeof(filename), "%s/buildroot%s/init.d/%s",
		     directory, SoftwareDir, file->dst);

	  if (Verbosity > 1)
	    printf("%s -> %s...\n", file->src, filename);

	  if (copy_file(filename, file->src, 0, -1, -1))
	    return (1);
          break;
      case 'd' :
          snprintf(filename, sizeof(filename), "%s/buildroot%s", directory, file->dst);

	  if (Verbosity > 1)
	    printf("Directory %s...\n", filename);

          make_directory(filename, 0755, -1, -1);
          break;
      case 'l' :
          snprintf(filename, sizeof(filename), "%s/buildroot%s", directory, file->dst);

	  if (Verbosity > 1)
	    printf("%s -> %s...\n", file->src, filename);

          make_link(filename, file->src);
          break;
    }
  }

 /*
  * Build the distribution from the spec file...
  */

  if (Verbosity)
    puts("Building RPM binary distribution...");

  if (format == PACKAGE_LSB_SIGNED || format == PACKAGE_RPM_SIGNED)
    build_option = "-signed ";
  else
    build_option = "";

  if (!strcmp(platform->machine, "intel"))
  {
    if (run_command(NULL, EPM_RPMBUILD " -bb --buildroot \"%s/buildroot\" "
                          EPM_RPMARCH "i386 %s%s", absdir, build_option,
			  specname))
      return (1);
  }
  else if (!strcmp(platform->machine, "ppc"))
  {
    if (run_command(NULL, EPM_RPMBUILD " -bb --buildroot \"%s/buildroot\" "
                          EPM_RPMARCH "powerpc %s%s", absdir, build_option,
			  specname))
      return (1);
  }
  else if (run_command(NULL, EPM_RPMBUILD " -bb --buildroot \"%s/buildroot\" "
                       EPM_RPMARCH "%s %s%s", absdir, platform->machine,
		       build_option, specname))
    return (1);

 /*
  * Move the RPMs to the local directory and rename the RPMs using the
  * product name specified by the user...
  */

  move_rpms(prodname, directory, platname, dist, platform, rpmdir, NULL,
            release);

  for (i = 0; i < dist->num_subpackages; i ++)
    move_rpms(prodname, directory, platname, dist, platform, rpmdir,
              dist->subpackages[i], release);

 /*
  * Build a compressed tar file to hold all of the subpackages...
  */

  if (dist->num_subpackages || setup)
  {
   /*
    * Figure out the full name of the distribution...
    */

    if (dist->release[0])
      snprintf(name, sizeof(name), "%s-%s-%s", prodname, dist->version,
               dist->release);
    else
      snprintf(name, sizeof(name), "%s-%s", prodname, dist->version);

    if (platname[0])
    {
      strlcat(name, "-", sizeof(name));
      strlcat(name, platname, sizeof(name));
    }

   /*
    * Create a compressed tar file...
    */

    snprintf(filename, sizeof(filename), "%s/%s.rpm.tgz", directory, name);

    if ((tarfile = tar_open(filename, 1)) == NULL)
      return (1);

   /*
    * Archive the setup and uninst GUIs and their data files...
    */

    if (setup)
    {
     /*
      * Include the ESP Software Installation Wizard (setup)...
      */

      const char	*setup_img;	/* Setup image name */
      struct stat	srcstat;	/* File information */


      if (stat(SetupProgram, &srcstat))
      {
	fprintf(stderr, "epm: Unable to stat GUI setup program %s - %s\n",
		SetupProgram, strerror(errno));
	tar_close(tarfile);
	return (-1);
      }

      if (tar_header(tarfile, TAR_NORMAL, 0555, srcstat.st_size,
	             srcstat.st_mtime, "root", "root", "setup", NULL) < 0)
      {
	fprintf(stderr, "epm: Error writing file header - %s\n",
		strerror(errno));
	tar_close(tarfile);
	return (-1);
      }

      if (tar_file(tarfile, SetupProgram) < 0)
      {
	fprintf(stderr, "epm: Error writing file data for setup -\n    %s\n",
		strerror(errno));
	tar_close(tarfile);
	return (-1);
      }

      if (Verbosity)
	printf("    %7.0fk setup\n", (srcstat.st_size + 1023) / 1024.0);

     /*
      * And the image file...
      */

      stat(setup, &srcstat);

      if (strlen(setup) > 4 && !strcmp(setup + strlen(setup) - 4, ".gif"))
	setup_img = "setup.gif";
      else
	setup_img = "setup.xpm";

      if (tar_header(tarfile, TAR_NORMAL, 0444, srcstat.st_size,
	             srcstat.st_mtime, "root", "root", setup_img, NULL) < 0)
      {
	fprintf(stderr, "epm: Error writing file header - %s\n",
		strerror(errno));
	tar_close(tarfile);
	return (-1);
      }

      if (tar_file(tarfile, setup) < 0)
      {
	fprintf(stderr, "epm: Error writing file data for %s -\n    %s\n",
		setup_img, strerror(errno));
	tar_close(tarfile);
	return (-1);
      }

      if (Verbosity)
	printf("    %7.0fk %s\n", (srcstat.st_size + 1023) / 1024.0, setup_img);

     /*
      * And the types file...
      */

      if (types)
      {
	stat(types, &srcstat);

	if (tar_header(tarfile, TAR_NORMAL, 0444, srcstat.st_size,
		       srcstat.st_mtime, "root", "root", types, NULL) < 0)
	{
	  fprintf(stderr, "epm: Error writing file header - %s\n",
		  strerror(errno));
          tar_close(tarfile);
	  return (-1);
	}

	if (tar_file(tarfile, types) < 0)
	{
	  fprintf(stderr, "epm: Error writing file data for setup.types -\n    %s\n",
		  strerror(errno));
          tar_close(tarfile);
	  return (-1);
	}

	if (Verbosity)
          printf("    %7.0fk setup.types\n", (srcstat.st_size + 1023) / 1024.0);
      }

     /*
      * Include the ESP Software Removal Wizard (uninst)...
      */

      if (stat(UninstProgram, &srcstat))
      {
	fprintf(stderr, "epm: Unable to stat GUI uninstall program %s - %s\n",
		UninstProgram, strerror(errno));
	tar_close(tarfile);
	return (-1);
      }

      if (tar_header(tarfile, TAR_NORMAL, 0555, srcstat.st_size,
	             srcstat.st_mtime, "root", "root", "uninst", NULL) < 0)
      {
	fprintf(stderr, "epm: Error writing file header - %s\n",
		strerror(errno));
	tar_close(tarfile);
	return (-1);
      }

      if (tar_file(tarfile, UninstProgram) < 0)
      {
	fprintf(stderr, "epm: Error writing file data for uninst -\n    %s\n",
		strerror(errno));
	tar_close(tarfile);
	return (-1);
      }

      if (Verbosity)
	printf("    %7.0fk uninst\n", (srcstat.st_size + 1023) / 1024.0);
    }

   /*
    * Archive the main package and subpackages...
    */

    if (tar_package(tarfile, "rpm", prodname, directory, platname, dist, NULL))
    {
      tar_close(tarfile);
      return (1);
    }

    for (i = 0; i < dist->num_subpackages; i ++)
    {
      if (tar_package(tarfile, "rpm", prodname, directory, platname, dist,
                      dist->subpackages[i]))
      {
	tar_close(tarfile);
	return (1);
      }
    }
    
    tar_close(tarfile);
  }

 /*
  * Remove temporary files...
  */

  if (!KeepFiles)
  {
    if (Verbosity)
      puts("Removing temporary distribution files...");

    snprintf(filename, sizeof(filename), "%s/RPMS", directory);
    unlink_directory(filename);

    snprintf(filename, sizeof(filename), "%s/rpms", directory);
    unlink(filename);

    snprintf(filename, sizeof(filename), "%s/buildroot", directory);
    unlink_directory(filename);

    unlink(specname);

    if (dist->num_subpackages)
    {
     /*
      * Remove .rpm files since they are now in a .tgz file...
      */

      unlink_package("rpm", prodname, directory, platname, dist, NULL);

      for (i = 0; i < dist->num_subpackages; i ++)
	unlink_package("rpm", prodname, directory, platname, dist,
                       dist->subpackages[i]);
    }
  }

  return (0);
}
Exemplo n.º 11
0
static int				/* O - 0 = success, 1 = fail */
move_rpms(const char     *prodname,	/* I - Product short name */
          const char     *directory,	/* I - Directory for distribution files */
          const char     *platname,	/* I - Platform name */
          dist_t         *dist,		/* I - Distribution information */
	  struct utsname *platform,	/* I - Platform information */
	  const char     *rpmdir,	/* I - RPM directory */
          const char     *subpackage,	/* I - Subpackage name */
	  const char     *release)	/* I - Release: value */
{
  char		rpmname[1024];		/* RPM name */
  char		prodfull[1024];		/* Full product name */
  struct stat	rpminfo;		/* RPM file info */


 /*
  * Move the RPMs to the local directory and rename the RPMs using the
  * product name specified by the user...
  */

  if (subpackage)
    snprintf(prodfull, sizeof(prodfull), "%s-%s", prodname, subpackage);
  else
    strlcpy(prodfull, prodname, sizeof(prodfull));

  if (dist->release[0])
    snprintf(rpmname, sizeof(rpmname), "%s/%s-%s-%s", directory, prodfull,
             dist->version, dist->release);
  else
    snprintf(rpmname, sizeof(rpmname), "%s/%s-%s", directory, prodfull,
             dist->version);

  if (platname[0])
  {
    strlcat(rpmname, "-", sizeof(rpmname));
    strlcat(rpmname, platname, sizeof(rpmname));
  }

  strlcat(rpmname, ".rpm", sizeof(rpmname));

  if (!strcmp(platform->machine, "intel"))
    run_command(NULL, "/bin/mv %s/RPMS/i386/%s-%s-%s.i386.rpm %s",
		rpmdir, prodfull, dist->version, release,
		rpmname);
  else if (!strcmp(platform->machine, "ppc"))
    run_command(NULL, "/bin/mv %s/RPMS/powerpc/%s-%s-%s.powerpc.rpm %s",
		rpmdir, prodfull, dist->version, release,
		rpmname);
  else
    run_command(NULL, "/bin/mv %s/RPMS/%s/%s-%s-%s.%s.rpm %s",
		rpmdir, platform->machine, prodfull, dist->version,
		release, platform->machine, rpmname);

  if (Verbosity)
  {
    stat(rpmname, &rpminfo);

    printf("    %7.0fk  %s\n", rpminfo.st_size / 1024.0, rpmname);
  }

  return (0);
}
Exemplo n.º 12
0
int main(int argc, char *const argv[])
{
	char tmpdir[] = "/tmp/dirXXXXXX";
	char cmd[128];
	char filepnm[128] = "";
	char *dev;
	struct lr_server_data lsd;
	FILE *filep = NULL;
	int ret;
	int c;
	int opt_client = 0;
	int opt_reply = 0;

	progname = argv[0];
	while ((c = getopt_long(argc, argv, "chr", longopts, NULL)) != -1) {
		switch (c) {
		case 'c':
			opt_client = 1;
			break;
		case 'r':
			opt_reply = 1;
			break;
		case 'h':
		default:
			display_usage();
			return -1;
		}
	}
	dev = argv[optind];
	if (!dev) {
		display_usage();
		return -1;
	}

	/* Make a temporary directory to hold Lustre data files. */
	if (!mkdtemp(tmpdir)) {
		fprintf(stderr, "%s: Can't create temporary directory %s: %s\n",
			progname, tmpdir, strerror(errno));
		return errno;
	}

	memset(cmd, 0, sizeof(cmd));
	snprintf(cmd, sizeof(cmd),
		"%s -c -R 'dump /%s %s/%s' %s",
		DEBUGFS, LAST_RCVD, tmpdir, LAST_RCVD, dev);

	ret = run_command(cmd, sizeof(cmd));
	if (ret) {
		fprintf(stderr, "%s: Unable to dump %s file\n",
			progname, LAST_RCVD);
		goto out_rmdir;
	}

	snprintf(filepnm, 128, "%s/%s", tmpdir, LAST_RCVD);
	filep = fopen(filepnm, "r");
	if (!filep) {
		fprintf(stderr, "%s: Unable to read old data\n",
			progname);
		ret = -errno;
		goto out_rmdir;
	}
	unlink(filepnm);

	/* read lr_server_data structure */
	printf("%s:\n", LAST_RCVD);
	ret = fread(&lsd, 1, sizeof(lsd), filep);
	if (ret < sizeof(lsd)) {
		fprintf(stderr, "%s: Short read (%d of %d)\n",
			progname, ret, (int)sizeof(lsd));
		ret = -ferror(filep);
		if (ret)
			goto out_close;
	}

	/* swab structure fields of interest */
	lsd.lsd_feature_compat = __le32_to_cpu(lsd.lsd_feature_compat);
	lsd.lsd_feature_incompat = __le32_to_cpu(lsd.lsd_feature_incompat);
	lsd.lsd_feature_rocompat = __le32_to_cpu(lsd.lsd_feature_rocompat);
	lsd.lsd_last_transno = __le64_to_cpu(lsd.lsd_last_transno);
	lsd.lsd_osd_index = __le32_to_cpu(lsd.lsd_osd_index);
	lsd.lsd_mount_count = __le64_to_cpu(lsd.lsd_mount_count);

	/* display */
	printf("  uuid: %.40s\n", lsd.lsd_uuid);
	printf("  feature_compat: %#x\n", lsd.lsd_feature_compat);
	printf("  feature_incompat: %#x\n", lsd.lsd_feature_incompat);
	printf("  feature_rocompat: %#x\n", lsd.lsd_feature_rocompat);
	printf("  last_transaction: %llu\n", lsd.lsd_last_transno);
	printf("  target_index: %u\n", lsd.lsd_osd_index);
	printf("  mount_count: %llu\n", lsd.lsd_mount_count);

	/* read client information */
	if (opt_client) {
		lsd.lsd_client_start = __le32_to_cpu(lsd.lsd_client_start);
		lsd.lsd_client_size = __le16_to_cpu(lsd.lsd_client_size);
		printf("  client_area_start: %u\n", lsd.lsd_client_start);
		printf("  client_area_size: %hu\n", lsd.lsd_client_size);

		/* seek to per-client data area */
		ret = fseek(filep, lsd.lsd_client_start, SEEK_SET);
		if (ret) {
			fprintf(stderr, "%s: seek failed. %s\n",
				progname, strerror(errno));
			ret = errno;
			goto out_close;
		}

		/* walk throuh the per-client data area */
		while (true) {
			struct lsd_client_data lcd;

			/* read a per-client data area */
			ret = fread(&lcd, 1, sizeof(lcd), filep);
			if (ret < sizeof(lcd)) {
				if (feof(filep))
					break;
				fprintf(stderr, "%s: Short read (%d of %d)\n",
					progname, ret, (int)sizeof(lcd));
				ret = -ferror(filep);
				goto out_close;
			}

			if (lcd.lcd_uuid[0] == '\0')
				continue;

			/* swab structure fields */
			lcd.lcd_last_transno =
					__le64_to_cpu(lcd.lcd_last_transno);
			lcd.lcd_last_xid = __le64_to_cpu(lcd.lcd_last_xid);
			lcd.lcd_last_result = __le32_to_cpu(lcd.lcd_last_result);
			lcd.lcd_last_data = __le32_to_cpu(lcd.lcd_last_data);
			lcd.lcd_generation = __le32_to_cpu(lcd.lcd_generation);

			/* display per-client data area */
			printf("\n  %.40s:\n", lcd.lcd_uuid);
			printf("    generation: %u\n", lcd.lcd_generation);
			printf("    last_transaction: %llu\n",
			       lcd.lcd_last_transno);
			printf("    last_xid: %llu\n", lcd.lcd_last_xid);
			printf("    last_result: %u\n", lcd.lcd_last_result);
			printf("    last_data: %u\n", lcd.lcd_last_data);

			if (lcd.lcd_last_close_transno != 0 &&
			    lcd.lcd_last_close_xid != 0) {
				lcd.lcd_last_close_transno =
					__le64_to_cpu(lcd.lcd_last_close_transno);
				lcd.lcd_last_close_xid =
					__le64_to_cpu(lcd.lcd_last_close_xid);
				lcd.lcd_last_close_result =
					__le32_to_cpu(lcd.lcd_last_close_result);
				lcd.lcd_last_close_data =
					__le32_to_cpu(lcd.lcd_last_close_data);
				printf("    last_close_transation: %llu\n",
				       lcd.lcd_last_close_transno);
				printf("    last_close_xid: %llu\n",
				       lcd.lcd_last_close_xid);
				printf("    last_close_result: %u\n",
				       lcd.lcd_last_close_result);
				printf("    last_close_data: %u\n",
				       lcd.lcd_last_close_data);
			}
		}
	}
	fclose(filep);
	filep = NULL;

	/* read reply data information */
	if (opt_reply) {
		struct lsd_reply_header lrh;
		struct lsd_reply_data lrd;
		unsigned long long slot;

		snprintf(cmd, sizeof(cmd),
			 "%s -c -R 'dump /%s %s/%s' %s",
			 DEBUGFS, REPLY_DATA, tmpdir, REPLY_DATA, dev);

		ret = run_command(cmd, sizeof(cmd));
		if (ret) {
			fprintf(stderr, "%s: Unable to dump %s file\n",
				progname, REPLY_DATA);
			goto out_rmdir;
		}

		snprintf(filepnm, sizeof(filepnm),
			 "%s/%s", tmpdir, REPLY_DATA);
		filep = fopen(filepnm, "r");
		if (!filep) {
			fprintf(stderr, "%s: Unable to read reply data\n",
				progname);
			ret = -errno;
			goto out_rmdir;
		}
		unlink(filepnm);

		/* read reply_data header */
		printf("\n%s:\n", REPLY_DATA);
		ret = fread(&lrh, 1, sizeof(lrh), filep);
		if (ret < sizeof(lrh)) {
			fprintf(stderr, "%s: Short read (%d of %d)\n",
				progname, ret, (int)sizeof(lrh));
			ret = -ferror(filep);
			if (ret)
				goto out_close;
		}

		/* check header */
		lrh.lrh_magic = __le32_to_cpu(lrh.lrh_magic);
		lrh.lrh_header_size = __le32_to_cpu(lrh.lrh_header_size);
		lrh.lrh_reply_size = __le32_to_cpu(lrh.lrh_reply_size);
		if (lrh.lrh_magic != LRH_MAGIC) {
			fprintf(stderr, "%s: invalid %s header: "
				"lrh_magic=%08x expected %08x\n",
				progname, REPLY_DATA, lrh.lrh_magic, LRH_MAGIC);
			goto out_close;
		}
		if (lrh.lrh_header_size != sizeof(struct lsd_reply_header)) {
			fprintf(stderr, "%s: invalid %s header: "
				"lrh_header_size=%08x expected %08x\n",
				progname, REPLY_DATA, lrh.lrh_header_size,
				(unsigned int)sizeof(struct lsd_reply_header));
			goto out_close;
		}
		if (lrh.lrh_reply_size != sizeof(struct lsd_reply_data)) {
			fprintf(stderr, "%s: invalid %s header: "
				"lrh_reply_size=%08x expected %08x\n",
				progname, REPLY_DATA, lrh.lrh_reply_size,
				(unsigned int)sizeof(struct lsd_reply_data));
			goto out_close;
		}

		/* walk throuh the reply data */
		for (slot = 0; ; slot++) {
			/* read a reply data */
			ret = fread(&lrd, 1, sizeof(lrd), filep);
			if (ret < sizeof(lrd)) {
				if (feof(filep))
					break;
				fprintf(stderr, "%s: Short read (%d of %d)\n",
					progname, ret, (int)sizeof(lrd));
				ret = -ferror(filep);
				goto out_close;
			}

			/* display reply data */
			lrd.lrd_transno = __le64_to_cpu(lrd.lrd_transno);
			lrd.lrd_xid = __le64_to_cpu(lrd.lrd_xid);
			lrd.lrd_data = __le64_to_cpu(lrd.lrd_data);
			lrd.lrd_result = __le32_to_cpu(lrd.lrd_result);
			lrd.lrd_client_gen = __le32_to_cpu(lrd.lrd_client_gen);

			printf("  %lld:\n", slot);
			printf("    client_generation: %u\n",
			       lrd.lrd_client_gen);
			printf("    last_transaction: %llu\n", lrd.lrd_transno);
			printf("    last_xid: %llu\n", lrd.lrd_xid);
			printf("    last_result: %u\n", lrd.lrd_result);
			printf("    last_data: %llu\n\n", lrd.lrd_data);
		}
	}

out_close:
	if (filep != NULL)
		fclose(filep);

out_rmdir:
	rmdir(tmpdir);
	return ret;
}
Exemplo n.º 13
0
bool get_file_method(LSHandle* lshandle, LSMessage *message, void *ctx) {
  LSError lserror;
  LSErrorInit(&lserror);

  char run_command_buffer[MAXBUFLEN];
  char command[MAXLINLEN];

  json_t *object = json_parse_document(LSMessageGetPayload(message));
  json_t *id;

  // Extract the filename argument from the message
  id = json_find_first_label(object, "filename");
  if (!id || (id->child->type != JSON_STRING) ||
      (strlen(id->child->text) >= MAXNAMLEN) ||
      (strspn(id->child->text, ALLOWED_CHARS) != strlen(id->child->text))) {
    if (!LSMessageRespond(message,
			"{\"returnValue\": false, \"errorCode\": -1, "
			"\"errorText\": \"Invalid or missing filename parameter\", "
			"\"stage\": \"failed\"}",
			&lserror)) goto error;
    return true;
  }
  char filename[MAXNAMLEN];
  sprintf(filename, "/media/internal/.temp/%s", id->child->text);

  // Extract the url argument from the message
  id = json_find_first_label(object, "url");               
  if (!id || (id->child->type != JSON_STRING) ||
      (strlen(id->child->text) >= MAXLINLEN)) {
    if (!LSMessageRespond(message,
			"{\"returnValue\": false, \"errorCode\": -1, "
			"\"errorText\": \"Invalid or missing url parameter\", "
			"\"stage\": \"failed\"}",
			&lserror)) goto error;
    return true;
  }
  char url[MAXLINLEN];
  strcpy(url, id->child->text);

  if (!strncmp(url, "file://", 7)) {
    strcpy(filename, url+7);
  }
  else {

    /* Download the package */

    snprintf(command, MAXLINLEN,
	     "/usr/bin/curl --create-dirs --insecure --location --fail --show-error --output %s %s 2>&1", filename, url);

    strcpy(run_command_buffer, "{\"stdOut\": [");
    if (run_command(command, true, run_command_buffer)) {
      strcat(run_command_buffer, "], \"returnValue\": true, \"stage\": \"download\"}");
      if (!LSMessageRespond(message, run_command_buffer, &lserror)) goto error;
    }
    else {
      strcat(run_command_buffer, "]");
      if (!report_command_failure(message, command, run_command_buffer+11, "\"stage\": \"failed\"")) goto end;
      return true;
    }
  }

  return read_file(message, filename, true);

 error:
  LSErrorPrint(&lserror, stderr);
  LSErrorFree(&lserror);
 end:
  return false;
}
Exemplo n.º 14
0
/* update_mmc [dev no] <type> 'mem' 'addr' 'length' [load addr] */
int do_update_mmc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
{
	block_dev_desc_t *desc;
	uint64_t dst_addr = 0, mem_len = 0;
	unsigned int mem_addr = 0;
	unsigned char *p;
	char cmd[32];
	lbaint_t blk, cnt;
	int ret, dev;

	if (6 > argc)
		goto usage;

	ret = get_device("mmc", argv[1], &desc);
	if (0 > ret) {
		printf ("** Not find device mmc.%s **\n", argv[1]);
		return 1;
	}

	dev = simple_strtoul (argv[1], NULL, 10);
	sprintf(cmd, "mmc dev %d", dev);
	if (0 > run_command(cmd, 0))	/* mmc device */
		return -1;

	if (0 != strcmp(argv[2], "2ndboot")  &&
		0 != strcmp(argv[2], "boot") &&
		0 != strcmp(argv[2], "raw")  &&
		0 != strcmp(argv[2], "part"))
		goto usage;

	mem_addr = simple_strtoul (argv[3], NULL, 16);
	dst_addr = simple_strtoull(argv[4], NULL, 16);
	mem_len  = simple_strtoull(argv[5], NULL, 16);

	p   = (unsigned char *)((ulong)mem_addr);
	blk = (dst_addr/MMC_BLOCK_SIZE);
	cnt = (mem_len/MMC_BLOCK_SIZE) + ((mem_len & (MMC_BLOCK_SIZE-1)) ? 1 : 0);

	flush_dcache_all();

	if (! strcmp(argv[2], "2ndboot")) {
		struct boot_dev_head *bh = (struct boot_dev_head *)((ulong)mem_addr);
		struct boot_dev_mmc  *bd = (struct boot_dev_mmc *)&bh->bdi;

		bd->port_no = dev; /* set u-boot device port num */
		printf("head boot dev  = %d\n", bd->port_no);

		goto do_write;
	}

	if (! strcmp(argv[2], "boot")) {
		struct boot_dev_head head;
		struct boot_dev_head *bh = &head;
		struct boot_dev_mmc *bd = (struct boot_dev_mmc *)&bh->bdi;
		int len = sizeof(head);
		unsigned int load = CONFIG_SYS_TEXT_BASE;

		if (argc == 7)
			load = simple_strtoul (argv[6], NULL, 16);

		memset((void*)&head, 0x00, len);

		bh->load_addr = (unsigned int)load;
		bh->jump_addr = bh->load_addr;
		bh->load_size = (unsigned int)mem_len;
		bh->signature = SIGNATURE_ID;
		bd->port_no	  = dev;

		printf("head boot dev  = %d\n", bd->port_no);
		printf("head load addr = 0x%08x\n", bh->load_addr);
		printf("head load size = 0x%08x\n", bh->load_size);
		printf("head gignature = 0x%08x\n", bh->signature);

		p -= len;
		memcpy(p, bh, len);

		mem_len += MMC_BLOCK_SIZE;
		cnt = (mem_len/MMC_BLOCK_SIZE) + ((mem_len & (MMC_BLOCK_SIZE-1)) ? 1 : 0);

		goto do_write;
	}

	if (strcmp(argv[2], "part") == 0) {
		uint64_t parts[4][2] = { {0,0}, };
		uint64_t part_len = 0;
		int partno = (int)dst_addr;
		int num = 0;

		if (0 > mmc_get_part_table(desc, parts, &num))
			return 1;

		if (partno > num || 1 > partno)  {
			printf ("** Invalid mmc.%d partition number %d (1 ~ %d) **\n",
				dev, partno, num);
			return 1;
		}

		dst_addr = parts[partno-1][0];	/* set write addr from part table */
		part_len = parts[partno-1][1];
		blk = (dst_addr/MMC_BLOCK_SIZE);

 		if (0 == check_compress_ext4((char*)p, part_len)) {
			printf("update mmc.%d compressed ext4 = 0x%llx(%d) ~ 0x%llx(%d): ",
				dev, dst_addr, (unsigned int)blk, mem_len, (unsigned int)cnt);

			ret = write_compressed_ext4((char*)p, blk);
			printf("%s\n", ret?"Fail":"Done");
			return 1;
		}
		goto do_write;
	}

do_write:
	if (! blk) {
		printf("-- Fail: start %d block(0x%llx) is in MBR zone (0x200) --\n", (int)blk, dst_addr);
		return -1;
	}

	printf("update mmc.%d type %s = 0x%llx(0x%x) ~ 0x%llx(0x%x): ",
		dev, argv[2], dst_addr, (unsigned int)blk, mem_len, (unsigned int)cnt);

	ret = mmc_bwrite(dev, blk, cnt, (void const*)p);

	printf("%s\n", ret?"Done":"Fail");
	return ret;

usage:
	cmd_usage(cmdtp);
	return 1;
}
Exemplo n.º 15
0
int board_late_init (void)
{
	unsigned int regs;
	char boot_cmd[100];
	unsigned int ps_regs;
	regs = Inp32(INF_REG_BASE + INF_REG3_OFFSET);
	Outp32(0xe02002a0, 0x10000000);
	Outp32(0xe02002c0, 0x1);
#ifdef CONFIG_SILVER210	
	 printf("HCJ:       %s default_boot_mode=%d bootmode-%d   INF_REG3_REG=%d\n",__func__,default_boot_mode,regs,INF_REG3_REG);  	
	//HCJ  PS HOLD
	ps_regs=Inp32(GPH1DAT);
	//printf("pwr sw on =0x%x\n", regs);
	ps_regs=Inp32(GPH0CON);
	//printf("GPH0CON=0x%x\n",ps_regs);
	ps_regs|=(0x1<<16);
	Outp32(GPH0CON,ps_regs);
	//printf("AFTER GPH0CON=0x%x\n",Inp32(GPH0CON));
	ps_regs=Inp32(GPH0DAT);
	//printf("ps regs=0x%x\n",ps_regs);
	ps_regs|=(0x1<<4);
	//printf("after ps high 0x%x\n",ps_regs);
	Outp32(GPH0DAT,ps_regs);
#endif	
	//setenv("bootdelay", "0");  // HCJ

	switch(regs) {
	case BOOT_NAND:
#if 0 // HCJ
		Outp32(0xe02002a4, 0x0);	// LED0 On
		Outp32(0xe02002c4, 0x1);	// LED1 Off
#endif
         	printf("checking mode for fastboot ...\n");
		run_command("mtdparts default", 0);

// [HCJ] if you want to enter fast mode right after boot, un-comment below
#if 0
         	if((~readl(0xE0200C04)) & 0x6) {
         		run_command("fastboot", 0);
                } else
#endif
		if(default_boot_mode) {		// using default environment
			setenv("bootcmd", CONFIG_NAND_BOOTCMD);
			setenv("bootargs", CONFIG_NAND_BOOTARGS);
		}
		break;
	case BOOT_MMCSD:
#if 0 // HCJ
		Outp32(0xe02002a4, 0x80);	// LED1 On
		Outp32(0xe02002c4, 0x0);	// LED0 Off
#endif

// [HCJ] if you want to enter fast mode right after boot, un-comment below
#if 0
		if((~Inp32(0xe0200c04)) & 0x6) { // Linux Recovery Booting Mode
#if 1	// Use Fastboot Mode
			sprintf(boot_cmd, "movi read kernel %08x; bootm %08x"
					, MEMORY_BASE_ADDRESS + 0x8000
					, MEMORY_BASE_ADDRESS + 0x8000);
			setenv("bootcmd", boot_cmd);
			sprintf(boot_cmd, "root=/dev/mmcblk0p2 rootfstype=ext3 console=ttySAC1,115200 rootdelay=10");	// Gnome Booting Mode
			setenv("bootargs", boot_cmd);

         		run_command("fastboot", 0);
#else	// Not Use FastBoot Mode
			sprintf(boot_cmd, "nand erase clean;nand scrub;movi read u-boot %08x;nand write %08x 0 70000;movi read kernel %08x;bootm %08x"
					, MEMORY_BASE_ADDRESS + 0x1000000, MEMORY_BASE_ADDRESS + 0x1000000
					, MEMORY_BASE_ADDRESS + 0x8000, MEMORY_BASE_ADDRESS + 0x8000);
			setenv("bootcmd", boot_cmd);
			sprintf(boot_cmd, "root=/dev/mmcblk0p3 rootfstype=ext3 console=ttySAC1,115200 rootdelay=10 recovery");
			setenv("bootargs", boot_cmd);
			sprintf(boot_cmd, "0");
			setenv("bootdelay", boot_cmd);
#endif
		} else
#endif
		if(default_boot_mode) {	// using default environment
			setenv("bootcmd", CONFIG_MMC_BOOTCMD);
			setenv("bootargs", CONFIG_MMC_BOOTARGS);
		}
		break;
	}

	//LCD_turnon();
	return 0;
}
Exemplo n.º 16
0
void menu_shell(void)
{
    char c;
    char cmd_buf[256];
    static int mode=0;
    while (1)
    {
      /*
      check the download modes 
      0 for usb download
      1 for tftp download
      3 for serial download
      */
	main_menu_usage(mode);
	
        c = awaitkey(-1, NULL);
        printf("%c\n", c);
        switch (c)
        {
        case 'c':
        {
	    mode=!mode;
            break;
	}
        case 's':
        {
	    system_setting_shell();
            break;
	}
        case 'b':
        {
//            strcpy(cmd_buf, "usbslave 1 0x800000; nand erase boot; nand write 0x800000 boot $(filesize)");
            strcpy(cmd_buf, "bootd");
            run_command(cmd_buf, 0);
            break;
        }
        case 'f':
        {
#if 0
	    if (bBootFrmNORFlash == 1)
            strcpy(cmd_buf, "mtdpart default; nand erase;saveenv");
	    else
	    {
	    printf("\nBoot From NAND !\nNot erase bootloader.\n ");
            strcpy(cmd_buf, "mtdpart default; nand erase 0x00080000; saveenv");
	    }
            run_command(cmd_buf, 0);
#else
	  printf("\nNot Supported!\n ");
#endif
            break;
        }
	case 'm':
	  multiboot_shell();
	  break;
        case 'r':
        {
            run_command("reset", 0);
            break;
        }
        case 'v':
        {
#if 0
            strcpy(cmd_buf, "mtdparts");
            run_command(cmd_buf, 0);
	    printf("\nPress any key...\n");
	    awaitkey(-1, NULL);
#else
	  printf("\nNot Supported!\n ");
#endif
            break;
        }
	case 'e':
	{
	    printf("Reset u-boot-env...");
            run_command("env default -f;saveenv;reset",0);
            break;
	}
        case  27:
        case 'q':
        {
            return;
            break;
        }
        case '0':
        {
	  if(bBootFrmNORFlash)
	  {
	    printf("\nWarning!This operation will be brick your board!!!continue?(y/n)");
	    c = awaitkey(-1, NULL);
	    if (c=='n'||c=='N')
	    break;  
	  }
	    printf("\nDownload U-boot Bootloader ... \n");
	    if(download(mode)<0)
	    break;
	    if(chk_image())
	    {
	    strcpy(cmd_buf, "sf probe 0;sf erase 0x0 0x100000;sf write 0x800000 0x0 0x100000");
	    }
	    else
	    {
	      printf("Image is not U-boot SPI image!!!abort!\n");
	    }
	    {
	    if (simple_strtoul(getenv ("filesize"), NULL, 16)>4)
            run_command(cmd_buf, 0);
	    }
            break;
        }
        case '1':
        {
	    printf("\nDownLoad b-boot nand ... \n");
            break;
        }
	case '2': 
	{
	    printf("\nDownLoad Kernel ... \n");
	    break;
	}
        case '3':
        {
	    printf("\nDownLoad Kernel ... \n");
	    download(mode);
	    break;
        }
	case '4': //jffs2
	{
		printf("\nDownLoad rootfs ... \n");
		break;
	}

	case '5': 
	{

		printf("\nDownLoad DDNAS Firmware ... \n");
		download(mode);
		strcpy(cmd_buf, "sf probe 0;sf erase 0x100000 0xf00000;sf write 0x800000 0x100000 0xf00000");
		if(chk_image()==0)
		{
		run_command(cmd_buf, 0);
//		run_command(" bsetenvootargs noinitrd root=/dev/mtdblock3  console=ttySAC0 rootfstype=yaffs2;saveenv", 0);
		}
		else
		  printf("Firmware error!");
		break;
	}
        case '6':
	{
            break;	  
         }
	case '7': 
	{
	    run_command("rescue", 0);
	    break;
	}
        case '8':
        {
	    printf("Current command line:%s\n",getenv("bootargs"));
	    printf("New command line:");
	    memset(console_buffer,NULL,CONFIG_SYS_CBSIZE);
	    readline(NULL);
//	    strcat(cmd_buf, console_buffer);   
	    printf("Save new command line ?(y/n)");
	    c = awaitkey(-1, NULL);
	    
	    if(c=='y'||c=='Y')
	    {setenv("bootargs",console_buffer); run_command("saveenv",0);break;}
	}
        }
    }
}
Exemplo n.º 17
0
static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
{
	struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT;
	struct ref dummy, *tail = &dummy;
	struct child_process rsync;
	const char *args[5];
	int temp_dir_len;

	if (for_push)
		return NULL;

	/* copy the refs to the temporary directory */

	strbuf_addstr(&temp_dir, git_path("rsync-refs-XXXXXX"));
	if (!mkdtemp(temp_dir.buf))
		die ("Could not make temporary directory");
	temp_dir_len = temp_dir.len;

	strbuf_addstr(&buf, rsync_url(transport->url));
	strbuf_addstr(&buf, "/refs");

	memset(&rsync, 0, sizeof(rsync));
	rsync.argv = args;
	rsync.stdout_to_stderr = 1;
	args[0] = "rsync";
	args[1] = (transport->verbose > 0) ? "-rv" : "-r";
	args[2] = buf.buf;
	args[3] = temp_dir.buf;
	args[4] = NULL;

	if (run_command(&rsync))
		die ("Could not run rsync to get refs");

	strbuf_reset(&buf);
	strbuf_addstr(&buf, rsync_url(transport->url));
	strbuf_addstr(&buf, "/packed-refs");

	args[2] = buf.buf;

	if (run_command(&rsync))
		die ("Could not run rsync to get refs");

	/* read the copied refs */

	strbuf_addstr(&temp_dir, "/refs");
	read_loose_refs(&temp_dir, temp_dir_len + 1, &tail);
	strbuf_setlen(&temp_dir, temp_dir_len);

	tail = &dummy;
	strbuf_addstr(&temp_dir, "/packed-refs");
	insert_packed_refs(temp_dir.buf, &tail);
	strbuf_setlen(&temp_dir, temp_dir_len);

	if (remove_dir_recursively(&temp_dir, 0))
		warning ("Error removing temporary directory %s.",
				temp_dir.buf);

	strbuf_release(&buf);
	strbuf_release(&temp_dir);

	return dummy.next;
}
Exemplo n.º 18
0
void multiboot_shell(void)
{
    char c;
    char cmd_buf[256];
    while (1)
    {
      /*
      check the download modes 
      0 for usb download
      1 for tftp download
      3 for serial download
      */
	multiboot_menu_usage();
	
        c = awaitkey(-1, NULL);
        printf("%c\n", c);
        switch (c)
        {
        case '1':
        {
	    printf("Load kernel form USB...\n");
	    run_command("usb start", 0);
	    run_command("fatls usb 0", 0);
            strcpy(cmd_buf, "fatload usb 0 0x30008000 ");
	    printf("filename to load from USB:");
	    memset(console_buffer,NULL,CONFIG_SYS_CBSIZE);
	    readline(NULL);
	    strcat(cmd_buf, console_buffer);
	    run_command(cmd_buf, 0);
	    if (simple_strtoul(getenv ("filesize"), NULL, 16)>16)
            run_command("bootz", 0);	
            break;
	}
        case '2':
        {
	    printf("Load kernel form SD/MMC...\n");
	    run_command("mmc init", 0);
	    run_command("fatls mmc 0", 0);
            strcpy(cmd_buf, "fatload mmc 0 0x30008000 ");
	    printf("filename to load from MMC/SD:");
	    memset(console_buffer,NULL,CONFIG_SYS_CBSIZE);
	    readline(NULL);
	    strcat(cmd_buf, console_buffer);
	    run_command(cmd_buf, 0);
	    if (simple_strtoul(getenv ("filesize"), NULL, 16)>16)
	    run_command("bootz", 0);
            break;
	}
        case '3':
        {
	    setenv("bootcmd","mmc init;fatload mmc 0 0x30008000 zImage;bootz");
	    run_command("saveenv", 0);
            break;
	}
        case '4':
        {
	    setenv("bootcmd","usb start;fatload mmc 0 0x30008000 zImage;bootz");
	    run_command("saveenv", 0);
            break;
	}
	case  27:
        case 'q':
        {
            return;
            
	}
	}
    }
}
Exemplo n.º 19
0
/* Setup a file in the first unused loop_device */
int loop_setup(struct mkfs_opts *mop)
{
	char loop_base[20];
	char l_device[64];
	int i, ret = 0;

	/* Figure out the loop device names */
	if (!access("/dev/loop0", F_OK | R_OK) ||
	    !access("/dev/loop-control", F_OK | R_OK)) {
		strcpy(loop_base, "/dev/loop\0");
	} else if (!access("/dev/loop/0", F_OK | R_OK)) {
		strcpy(loop_base, "/dev/loop/\0");
	} else {
		fprintf(stderr, "%s: can't access loop devices\n", progname);
		return EACCES;
	}

	/* Find unused loop device */
	for (i = 0; i < MAX_LOOP_DEVICES; i++) {
		char cmd[PATH_MAX];
		int cmdsz = sizeof(cmd);

#ifdef LOOP_CTL_GET_FREE
		ret = open("/dev/loop-control", O_RDWR);
		if (ret < 0) {
			fprintf(stderr, "%s: can't access loop control\n", progname);
			return EACCES;
		}
		/* find or allocate a free loop device to use */
		i = ioctl(ret, LOOP_CTL_GET_FREE);
		if (i < 0) {
			fprintf(stderr, "%s: access loop control error\n", progname);
			return EACCES;
		}
		sprintf(l_device, "%s%d", loop_base, i);
#else
		sprintf(l_device, "%s%d", loop_base, i);
		if (access(l_device, F_OK | R_OK))
			break;
#endif
		snprintf(cmd, cmdsz, "losetup %s > /dev/null 2>&1", l_device);
		ret = system(cmd);

		/* losetup gets 1 (ret=256) for non-set-up device */
		if (ret) {
			/* Set up a loopback device to our file */
			snprintf(cmd, cmdsz, "losetup %s %s", l_device,
				 mop->mo_device);
			ret = run_command(cmd, cmdsz);
			if (ret == 256)
				/* someone else picked up this loop device
				 * behind our back */
				continue;
			if (ret) {
				fprintf(stderr, "%s: error %d on losetup: %s\n",
					progname, ret,
					ret >= 0 ? strerror(ret) : "");
				return ret;
			}
			strscpy(mop->mo_loopdev, l_device,
				sizeof(mop->mo_loopdev));
			return ret;
		}
	}

	fprintf(stderr, "%s: out of loop devices!\n", progname);
	return EMFILE;
}
Exemplo n.º 20
0
void system_setting_shell(void)
{
    char c;
    char cmd_buf[256];
    while (1)
    {
      /*
      check the download modes 
      0 for usb download
      1 for tftp download
      3 for serial download
      */
	system_setting_menu_usage();
	
        c = awaitkey(-1, NULL);
        printf("%c\n", c);
        switch (c)
        {
        case '1':
        {
	  strcpy(cmd_buf, "printenv ");
	  printf("Name(enter to view all paramters): ");
	  readline(NULL);
	  strcat(cmd_buf, console_buffer);
	  run_command(cmd_buf, 0);
	   printf("Press any key...");
	    awaitkey(-1, NULL);
            break;
	}
	case '2':
	{
	sprintf(cmd_buf, "setenv ");
	printf("Name: ");
        readline(NULL);
        strcat(cmd_buf, console_buffer);
	printf("Value: ");
	readline(NULL);
	strcat(cmd_buf, " ");
	strcat(cmd_buf, console_buffer);
	run_command(cmd_buf, 0);
        break;
        }
	case '3':
	{
	  matchtype_setting_shell();
	  break;
	}
	case '4':
	{
#if 0
	strcpy(cmd_buf, "nand scrub ");
	run_command(cmd_buf, 0);
#endif
	break;
	}
        case '5':
        {
            strcpy(cmd_buf, "env default -f;saveenv;");
            run_command(cmd_buf, 0);
            break;
        }
	case 's':
	{
	  run_command("saveenv", 0);
	  break;
	}
	case  27:
        case 'q':
        {
            return;
            
	}
	}
    }
}
Exemplo n.º 21
0
FILE *
collect(struct header *hp, int printheaders)
{
	FILE *fbuf;
	int lc, cc, escape, eofcount, fd, c, t;
	char linebuf[LINESIZE], tempname[PATHSIZE], *cp, getsub;
	sigset_t nset;
	int longline, lastlong, rc;	/* So we don't make 2 or more lines
					   out of a long input line. */

	collf = NULL;
	/*
	 * Start catching signals from here, but we're still die on interrupts
	 * until we're in the main loop.
	 */
	(void)sigemptyset(&nset);
	(void)sigaddset(&nset, SIGINT);
	(void)sigaddset(&nset, SIGHUP);
	(void)sigprocmask(SIG_BLOCK, &nset, NULL);
	if ((saveint = signal(SIGINT, SIG_IGN)) != SIG_IGN)
		(void)signal(SIGINT, collint);
	if ((savehup = signal(SIGHUP, SIG_IGN)) != SIG_IGN)
		(void)signal(SIGHUP, collhup);
	savetstp = signal(SIGTSTP, collstop);
	savettou = signal(SIGTTOU, collstop);
	savettin = signal(SIGTTIN, collstop);
	if (setjmp(collabort) || setjmp(colljmp)) {
		(void)rm(tempname);
		goto err;
	}
	(void)sigprocmask(SIG_UNBLOCK, &nset, NULL);

	noreset++;
	(void)snprintf(tempname, sizeof(tempname),
	    "%s/mail.RsXXXXXXXXXX", tmpdir);
	if ((fd = mkstemp(tempname)) == -1 ||
	    (collf = Fdopen(fd, "w+")) == NULL) {
		warn("%s", tempname);
		goto err;
	}
	(void)rm(tempname);

	/*
	 * If we are going to prompt for a subject,
	 * refrain from printing a newline after
	 * the headers (since some people mind).
	 */
	t = GTO|GSUBJECT|GCC|GNL;
	getsub = 0;
	if (hp->h_subject == NULL && value("interactive") != NULL &&
	    (value("ask") != NULL || value("asksub") != NULL))
		t &= ~GNL, getsub++;
	if (printheaders) {
		puthead(hp, stdout, t);
		(void)fflush(stdout);
	}
	if ((cp = value("escape")) != NULL)
		escape = *cp;
	else
		escape = ESCAPE;
	eofcount = 0;
	hadintr = 0;
	lastlong = 0;
	longline = 0;

	if (!setjmp(colljmp)) {
		if (getsub)
			grabh(hp, GSUBJECT);
	} else {
		/*
		 * Come here for printing the after-signal message.
		 * Duplicate messages won't be printed because
		 * the write is aborted if we get a SIGTTOU.
		 */
cont:
		if (hadintr) {
			(void)fflush(stdout);
			fprintf(stderr,
			"\n(Interrupt -- one more to kill letter)\n");
		} else {
			printf("(continue)\n");
			(void)fflush(stdout);
		}
	}
	for (;;) {
		colljmp_p = 1;
		c = readline(stdin, linebuf, LINESIZE);
		colljmp_p = 0;
		if (c < 0) {
			if (value("interactive") != NULL &&
			    value("ignoreeof") != NULL && ++eofcount < 25) {
				printf("Use \".\" to terminate letter\n");
				continue;
			}
			break;
		}
		lastlong = longline;
		longline = c == LINESIZE - 1;
		eofcount = 0;
		hadintr = 0;
		if (linebuf[0] == '.' && linebuf[1] == '\0' &&
		    value("interactive") != NULL && !lastlong &&
		    (value("dot") != NULL || value("ignoreeof") != NULL))
			break;
		if (linebuf[0] != escape || value("interactive") == NULL ||
		    lastlong) {
			if (putline(collf, linebuf, !longline) < 0)
				goto err;
			continue;
		}
		c = linebuf[1];
		switch (c) {
		default:
			/*
			 * On double escape, just send the single one.
			 * Otherwise, it's an error.
			 */
			if (c == escape) {
				if (putline(collf, &linebuf[1], !longline) < 0)
					goto err;
				else
					break;
			}
			printf("Unknown tilde escape.\n");
			break;
		case 'C':
			/*
			 * Dump core.
			 */
			core();
			break;
		case '!':
			/*
			 * Shell escape, send the balance of the
			 * line to sh -c.
			 */
			shell(&linebuf[2]);
			break;
		case ':':
		case '_':
			/*
			 * Escape to command mode, but be nice!
			 */
			execute(&linebuf[2], 1);
			goto cont;
		case '.':
			/*
			 * Simulate end of file on input.
			 */
			goto out;
		case 'q':
			/*
			 * Force a quit of sending mail.
			 * Act like an interrupt happened.
			 */
			hadintr++;
			collint(SIGINT);
			exit(1);
		case 'x':
			/*
			 * Exit, do not save in dead.letter.
			 */
			goto err;
		case 'h':
			/*
			 * Grab a bunch of headers.
			 */
			grabh(hp, GTO|GSUBJECT|GCC|GBCC);
			goto cont;
		case 't':
			/*
			 * Add to the To list.
			 */
			hp->h_to = cat(hp->h_to, extract(&linebuf[2], GTO));
			break;
		case 's':
			/*
			 * Set the Subject line.
			 */
			cp = &linebuf[2];
			while (isspace((unsigned char)*cp))
				cp++;
			hp->h_subject = savestr(cp);
			break;
		case 'R':
			/*
			 * Set the Reply-To line.
			 */
			cp = &linebuf[2];
			while (isspace((unsigned char)*cp))
				cp++;
			hp->h_replyto = savestr(cp);
			break;
		case 'c':
			/*
			 * Add to the CC list.
			 */
			hp->h_cc = cat(hp->h_cc, extract(&linebuf[2], GCC));
			break;
		case 'b':
			/*
			 * Add to the BCC list.
			 */
			hp->h_bcc = cat(hp->h_bcc, extract(&linebuf[2], GBCC));
			break;
		case 'i':
		case 'A':
		case 'a':
			/*
			 * Insert named variable in message.
			 */
			switch(c) {
				case 'i':
					cp = &linebuf[2];
					while(isspace((unsigned char)*cp))
						cp++;
					break;
				case 'a':
					cp = "sign";
					break;
				case 'A':
					cp = "Sign";
					break;
				default:
					goto err;
			}

			if(*cp != '\0' && (cp = value(cp)) != NULL) {
				printf("%s\n", cp);
				if(putline(collf, cp, 1) < 0)
					goto err;
			}

			break;
		case 'd':
			/*
			 * Read in the dead letter file.
			 */
			if (strlcpy(linebuf + 2, getdeadletter(),
				sizeof(linebuf) - 2)
			    >= sizeof(linebuf) - 2) {
				printf("Line buffer overflow\n");
				break;
			}
			/* FALLTHROUGH */
		case 'r':
		case '<':
			/*
			 * Invoke a file:
			 * Search for the file name,
			 * then open it and copy the contents to collf.
			 */
			cp = &linebuf[2];
			while (isspace((unsigned char)*cp))
				cp++;
			if (*cp == '\0') {
				printf("Interpolate what file?\n");
				break;
			}
			cp = expand(cp);
			if (cp == NULL)
				break;
			if (*cp == '!') {
				/*
				 * Insert stdout of command.
				 */
				char *sh;
				int nullfd, tempfd, rc;
				char tempname2[PATHSIZE];

				if ((nullfd = open("/dev/null", O_RDONLY, 0))
				    == -1) {
					warn("/dev/null");
					break;
				}

				(void)snprintf(tempname2, sizeof(tempname2),
				    "%s/mail.ReXXXXXXXXXX", tmpdir);
				if ((tempfd = mkstemp(tempname2)) == -1 ||
				    (fbuf = Fdopen(tempfd, "w+")) == NULL) {
					warn("%s", tempname2);
					break;
				}
				(void)unlink(tempname2);

				if ((sh = value("SHELL")) == NULL)
					sh = _PATH_CSHELL;

				rc = run_command(sh, 0, nullfd, fileno(fbuf),
				    "-c", cp+1, NULL);

				close(nullfd);

				if (rc < 0) {
					(void)Fclose(fbuf);
					break;
				}

				if (fsize(fbuf) == 0) {
					fprintf(stderr,
					    "No bytes from command \"%s\"\n",
					    cp+1);
					(void)Fclose(fbuf);
					break;
				}

				rewind(fbuf);
			} else if (isdir(cp)) {
				printf("%s: Directory\n", cp);
				break;
			} else if ((fbuf = Fopen(cp, "r")) == NULL) {
				warn("%s", cp);
				break;
			}
			printf("\"%s\" ", cp);
			(void)fflush(stdout);
			lc = 0;
			cc = 0;
			while ((rc = readline(fbuf, linebuf, LINESIZE)) >= 0) {
				if (rc != LINESIZE - 1)
					lc++;
				if ((t = putline(collf, linebuf,
					 rc != LINESIZE - 1)) < 0) {
					(void)Fclose(fbuf);
					goto err;
				}
				cc += t;
			}
			(void)Fclose(fbuf);
			printf("%d/%d\n", lc, cc);
			break;
		case 'w':
			/*
			 * Write the message on a file.
			 */
			cp = &linebuf[2];
			while (*cp == ' ' || *cp == '\t')
				cp++;
			if (*cp == '\0') {
				fprintf(stderr, "Write what file!?\n");
				break;
			}
			if ((cp = expand(cp)) == NULL)
				break;
			rewind(collf);
			exwrite(cp, collf, 1);
			break;
		case 'm':
		case 'M':
		case 'f':
		case 'F':
			/*
			 * Interpolate the named messages, if we
			 * are in receiving mail mode.  Does the
			 * standard list processing garbage.
			 * If ~f is given, we don't shift over.
			 */
			if (forward(linebuf + 2, collf, tempname, c) < 0)
				goto err;
			goto cont;
		case '?':
			if ((fbuf = Fopen(_PATH_TILDE, "r")) == NULL) {
				warn("%s", _PATH_TILDE);
				break;
			}
			while ((t = getc(fbuf)) != EOF)
				(void)putchar(t);
			(void)Fclose(fbuf);
			break;
		case 'p':
			/*
			 * Print out the current state of the
			 * message without altering anything.
			 */
			rewind(collf);
			printf("-------\nMessage contains:\n");
			puthead(hp, stdout, GTO|GSUBJECT|GCC|GBCC|GNL);
			while ((t = getc(collf)) != EOF)
				(void)putchar(t);
			goto cont;
		case '|':
			/*
			 * Pipe message through command.
			 * Collect output as new message.
			 */
			rewind(collf);
			mespipe(collf, &linebuf[2]);
			goto cont;
		case 'v':
		case 'e':
			/*
			 * Edit the current message.
			 * 'e' means to use EDITOR
			 * 'v' means to use VISUAL
			 */
			rewind(collf);
			mesedit(collf, c);
			goto cont;
		}
	}
	goto out;
err:
	if (collf != NULL) {
		(void)Fclose(collf);
		collf = NULL;
	}
out:
	if (collf != NULL)
		rewind(collf);
	noreset--;
	(void)sigprocmask(SIG_BLOCK, &nset, NULL);
	(void)signal(SIGINT, saveint);
	(void)signal(SIGHUP, savehup);
	(void)signal(SIGTSTP, savetstp);
	(void)signal(SIGTTOU, savettou);
	(void)signal(SIGTTIN, savettin);
	(void)sigprocmask(SIG_UNBLOCK, &nset, NULL);
	return (collf);
}
Exemplo n.º 22
0
void matchtype_setting_shell(void)
{
    char c;
    char cmd_buf[256];
    
    while (1)
    {	
	machtype_menu_usage();
        c = awaitkey(-1, NULL);
        printf("%c\n", c);
        switch (c)
        {
        case '1':
        {
	      setenv("machid","3381");
            break;
	}
        case '2':
        {
	      setenv("machid","2139");
            break;
	}
	case '3':
        {
 	      setenv("machid","2325");
            break;
	}
	case '4':
        {
 	      setenv("machid","2315");
            break;
	}
	case '5':
        {
 	      setenv("machid","2678");
            break;
	}
	case '6':
        {
 	      setenv("machid","2870");
            break;
	}
	case 'o':
	{
	    printf("Current MACH_TYPE_ID:%s\n",getenv("machid"));
	    printf("New MACH_TYPE_ID:");
	    memset(console_buffer,NULL,CONFIG_SYS_CBSIZE);
	    readline(NULL);
	    setenv("machid",console_buffer);
            break;
	}
	case 's':
	{
	  run_command("saveenv", 0);
	  break;
	}
	case 'q':
	case  27:
        {
            return 0;
            break;
	}
        }
    }
}
Exemplo n.º 23
0
jboolean native_run_shell(JNIEnv* env, jclass clazz, jstring cmdStr) {
    if (!cmdStr)
        return JNI_FALSE;
    const char *cmd = (*env)->GetStringUTFChars(env, cmdStr, NULL);
    return run_command("sh -c \"%s\"", cmd) >= 0;
}
Exemplo n.º 24
0
static inline int splash_umount_ubifs(void)
{
	return run_command("ubifsumount", 0);
}
Exemplo n.º 25
0
int do_eeprom ( cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
{
    MS_U32 addr = 0;
    MS_U32 off = 0;
    MS_U16 cnt = 0;
    char * data = NULL;
    int ret = 0;
    char buffer[CMD_BUF]="\0";

    if (argc < 2) 
    {     
        return cmd_usage(cmdtp);
    }
    if (strncmp (argv[1], "wb", 2) == 0) 
    {
         off=simple_strtoul (argv[2], NULL, 16);
         addr=simple_strtoul (argv[3], NULL, 16);         
         ret = eeprom_WriteByte(off,addr); 

         addr=(MS_U32)eeprom_ReadByte(off);    
         UBOOT_INFO("0x%x\n",(unsigned int)addr);
         
    }
    else if (strncmp (argv[1], "rb", 2) == 0) 
    {
		off  = simple_strtoul (argv[2], NULL, 16);        
        addr=(MS_U32)eeprom_ReadByte(off);    
        UBOOT_INFO("0x%x\n",(unsigned int)addr);
    }
    else if (strncmp (argv[1], "ws", 2) == 0)
    {
		off = simple_strtoul (argv[2], NULL, 16);
		data = (char *)argv[3];       
        ret = eeprom_PageWrite(off,(MS_U8*)data,strlen(data));        
    }
	else if (strncmp (argv[1], "dump", 4) == 0) 
    {        
 		off  = simple_strtoul (argv[2], NULL, 16);
		cnt  = simple_strtoul (argv[3], NULL, 16);       
        data=(char *)malloc(cnt);
        if(data==NULL)
        {
            UBOOT_ERROR("memory allocate fail\n");
            return -1;
        }
        eeprom_PageRead(off,(MS_U8 *)data,cnt);
        snprintf(buffer,CMD_BUF,"md.b %x %x",data,cnt);
        run_command(buffer,0); 
    }    
	else if (strncmp (argv[1], "read", 4) == 0) 
    {        
		addr = simple_strtoul (argv[2], NULL, 16);
		off  = simple_strtoul (argv[3], NULL, 16);
		cnt  = simple_strtoul (argv[4], NULL, 16);
        ret = eeprom_PageRead(off,(MS_U8*)addr,cnt);
    }
    else if (strncmp (argv[1], "write", 5) == 0) 
    {        
		addr = simple_strtoul (argv[2], NULL, 16);
		off  = simple_strtoul (argv[3], NULL, 16);
		cnt  = simple_strtoul (argv[4], NULL, 16);
		ret = eeprom_PageWrite(off,(MS_U8*)addr,cnt);
	}
    else if (strncmp (argv[1], "erase", 5) == 0) 
    {
		cnt  = simple_strtoul (argv[2], NULL, 16);       
        data=(char *)malloc(cnt);
        memset((void *)data,0xFF,cnt);
        ret = eeprom_PageWrite(off,(MS_U8*)data,cnt);
        free(data);
    }    
    else if (strncmp (argv[1], "switch", 5) == 0) 
    {
        EepromID = simple_strtoul (argv[2], NULL, 16);
        EepromID--;        
        UBOOT_INFO("EepromNum : %d\n",EepromID+1);    

    }
    else if (strncmp (argv[1], "list", 4) == 0) 
    {
        UBOOT_INFO("------------------------------------\n");     
        UBOOT_INFO("    Current Eeprom Number : %d \n",(EepromID+1));    
        UBOOT_INFO("------------------------------------\n");    
        showDevInfo();
        UBOOT_INFO("------------------------------------\n");         
    }
    else
    {
        cmd_usage(cmdtp);
    }

	return ret;
}
Exemplo n.º 26
0
void menu_shell(void)
{
	char keyselect;
	char cmd_buf[200];

	while (1)
	{
		main_menu_usage(USE_USB_DOWN);
		keyselect = getc();
		printf("%c\n", keyselect);
		switch (keyselect)
		{
			case '1':
			{

				strcpy(cmd_buf, "dnw 0x20000000; nand erase 0x0 0x80000; nand write 0x20000000 0x0 0x80000");

				run_command(cmd_buf, 0);
				break;
			}
			
			

			case '2':
			{

				strcpy(cmd_buf, "dnw 0x20000000; nand erase 0x300000 0x500000; nand write 0x20000000 0x300000 0x500000");

				run_command(cmd_buf, 0);
				break;
			}


			case '3':
			{
//#ifdef CONFIG_MTD_DEVICE
//				strcpy(cmd_buf, "dnw 0x20000000; nand erase root; nand write.yaffs 0x20000000 root $(filesize)");
//#else
				strcpy(cmd_buf, "dnw 0x20000000; nand erase 0xe00000 0xF8D0000; nand write.yaffs 0x20000000 0xe00000 $(filesize)");
//#endif /* CONFIG_MTD_DEVICE */
				run_command(cmd_buf, 0);
				break;
			}

			case '4':
			{
				char addr_buff[12];
				printf("Enter download address:(eg: 0x20000000)\n");
				readline(NULL);
				strcpy(addr_buff,console_buffer);
				sprintf(cmd_buf, "dnw %s;go %s", addr_buff, addr_buff);
				run_command(cmd_buf, 0);
				break;
			}

			case '5':
			{

				printf("Start Linux ...\n");
//#ifdef CONFIG_MTD_DEVICE
//				strcpy(cmd_buf, "nand read 0x20008000 kernel;bootm 0x20008000");
//#else
				strcpy(cmd_buf, "nand read 0x21000000 0x300000 0x500000;bootm 0x21000000");
//#endif /* CONFIG_MTD_DEVICE */
				run_command(cmd_buf, 0);
				break;
			}

			case '6':
			{
				strcpy(cmd_buf, "nand erase.chip ");
				run_command(cmd_buf, 0);
				break;
			}

			
#ifdef CONFIG_SMART210
			case 'Q':
			case 'q':
			{
				return;	
				break;
			}
#endif
		}
				
	}
}
Exemplo n.º 27
0
static inline int read_bcb(void)
{
	return run_command("mmcinit 1; fatload mmc 1:5 0x81000000 BCB 2048", 0);
}
Exemplo n.º 28
0
/***********************************************************************
*@函数名称: ExecuteCmd
*@功能描述: 执行cmd字符串命令
*@参数:
	cmd:	执行的命令
*@返回:		无
*@备注:	   	无
 **********************************************************************/
static int ExecuteCmd(char *cmd)
{
    return run_command(cmd, 0);
}
Exemplo n.º 29
0
void do_factory_fallback(void)
{
	write_bcb(&factory_bcb);
	run_command("mmcinit 1; booti mmc1 recovery", 0);
}
Exemplo n.º 30
0
int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	return run_command(getenv("bootcmd"), flag);
}