Пример #1
0
static void setacl(int index, int zoom, int x, int y)
{
	LOGI("%i: zoom=%i, x=%i, y=%i", index, zoom, x, y);

	char cmd[256];
	if(g_mode == MODE_NED)
	{
		snprintf(cmd, 256, "gsutil acl set -a public-read gs://goto/ned/%i/%i_%i.nedgz", zoom, x, y);
		runcmd(cmd);
	}
	else if(g_mode == MODE_OSM)
	{
		snprintf(cmd, 256, "gsutil acl set -a public-read gs://goto/osm/%i/%i_%i.pak", zoom, x, y);
		runcmd(cmd);
	}
	else if(g_mode == MODE_HEIGHTMAP)
	{
		snprintf(cmd, 256, "gsutil acl set -a public-read gs://goto/hillshade/%i/%i_%i.pak", zoom, x, y);
		runcmd(cmd);
	}
	else if(g_mode == MODE_BLUEMARBLE)
	{
		int month;
		for(month = 1; month <= 12; ++month)
		{
			snprintf(cmd, 256, "gsutil acl set -a public-read gs://goto/bluemarble/%i/%i/%i_%i.pak", month, zoom, x, y);
			runcmd(cmd);
		}
	}
}
Пример #2
0
static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
	if (!fd || !fd->data) {
		return -1;
	}
	int wordSize = 4;
	ut32 *w = (ut32*)buf;
	int i;
	memset (buf, 0xff, count);
	int words = count / wordSize; // XXX must pad align to 4
	for (i = 0; i < words ; i++) {
		ut64 addr = io->off + (i * wordSize);
		char *cmd = r_str_newf ("x 0x%"PFMT64x, addr);
		char *res = runcmd (cmd);
		sscanf (res, "%x", &w[i]);
		free (res);
		free (cmd);
	}

	int left = count % wordSize;
	if (left > 0) {
		ut32 n = 0xff;
		ut8 *wn = (ut8*)&n;
		ut64 addr = io->off + (i * wordSize);
		char *cmd = r_str_newf ("x 0x%"PFMT64x, addr);
		char *res = runcmd (cmd);
		sscanf (res, "%x", &n);
		free (res);
		free (cmd);
		memcpy (buf + (words * wordSize), wn, left);
	}
	return count;
}
Пример #3
0
void runcmd(struct cmd *cmd)
{
  int p[2];
  struct execcmd *ecmd;
  struct pipecmd *pcmd;
  struct redircmd *rcmd;

  if(cmd == 0)
    exit(1);
  
  switch(cmd->type){
  default:
    printf("runcmd error!\n");

  case 1:
    ecmd = (struct execcmd*)cmd;
    if(ecmd->argv[0] == 0)
      exit(0);
    execvp(ecmd->argv[0], ecmd->argv);
    printf("exec %s failed\n", ecmd->argv[0]);
    break;

  case 2:
    rcmd = (struct redircmd*)cmd;
    close(rcmd->fd);
    if(open(rcmd->file, rcmd->mode) < 0){
      printf("open %s failed\n", rcmd->file);
      exit(0);
    }
    runcmd(rcmd->cmd);
    break;

  case 3:
    pcmd = (struct pipecmd*)cmd;
    if(pipe(p) < 0){
      printf("Errors in pipe!\n");
    }
    if(fork() == 0){
      close(1);
      dup(p[1]);
      close(p[0]);
      close(p[1]);
      runcmd(pcmd->right);
    }
    if(fork() == 0){
      close(0);
      dup(p[0]);
      close(p[0]);
      close(p[1]);
      runcmd(pcmd->left);
    }
    close(p[1]);
    close(p[0]);
    wait(NULL);
    wait(NULL);
    break;
  }
  exit(0);
}
Пример #4
0
void init_judge_environment(int RunID, int language, char *workdir)
{
    sprintf(workdir, "%s/run%d", oj_home, RunID);
    runcmd("rm %s/errmsg/%d.err", oj_home, RunID);
    runcmd("rm -r %s", workdir);
    runcmd("mkdir %s", workdir);   
    runcmd("cp %s/code/%d %s/%s", oj_home, RunID, workdir, codename[language]);
}
Пример #5
0
Файл: sh.c Проект: lishuwnc/Xv6
int
main(void)
{
  static char buf[100];
  static char bufCNM[100];
  int fd;
  
  // Assumes three file descriptors open.
  while((fd = open("console", O_RDWR)) >= 0){
    if(fd >= 3){
      close(fd);
      break;
    }
  }
  
  // Read and run input commands.
  while(getcmd(buf, sizeof(buf)) >= 0){
    if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
      // Clumsy but will have to do for now.
      // Chdir has no effect on the parent if run in the child.
      buf[strlen(buf)-1] = 0;  // chop \n
      if(chdir(buf+3) < 0)
        printf(2, "cannot cd %s\n", buf+3);
      else{
        if((buf + 3)[0] == '.' && (buf + 3)[1] == '.' && (buf + 3)[2] == 0){
            cutChild(currentDir);
            if(currentDir[0] == 0) isRootDir = 1;
            continue;
        }
        if(isRootDir){
            catenate(currentDir, buf + 3);
            isRootDir = 0;
        }
        else{
            append(currentDir, '/');
            catenate(currentDir, buf + 3);
        }
      }
      continue;
    }

    if(fork1() == 0) {
      int i;
      int len = strlen(buf);
      for(i = len + 1; i > 0; i--) {
        bufCNM[i] = buf[i-1];        
      }   
      bufCNM[0] = '/';
      runcmd(parsecmd(buf));
      if(buf[0] != '/') {
        runcmd(parsecmd(bufCNM));
      }
      exit();
    }
    wait();
  }
  exit();
}
Пример #6
0
void preparefiles(char *dname, int len, char *workdir, char *datapath)
{
    char name[MAXLINE+1];
    strncpy(name, dname, len);
    name[len]='\0';
#ifdef DEBUG
    logerrmsg(judgelog, "name:#%s# %d copy %s/%s.in to %s/data.in", dname, len, datapath, name, workdir);
#endif
    runcmd("cp -a %s/%s.in %s/data.in", datapath, name, workdir);
    runcmd("cp -a %s/%s.out %s/data.out", datapath, name, workdir);
}
Пример #7
0
// Execute cmd.  Never returns.
void
runcmd(struct cmd *cmd)
{
    int p[2], r;
    struct execcmd *ecmd;
    struct pipecmd *pcmd;
    struct redircmd *rcmd;
    
    if(cmd == 0)
        exit(0);
    
    switch(cmd->type){
        default:
            fprintf(stderr, "unknown runcmd\n");
            exit(-1);
            
        case ' ':
            ecmd = (struct execcmd*)cmd;
            if(ecmd->argv[0] == 0)
                exit(0);
            execvp(ecmd->argv[0], ecmd->argv);
            break;
        case '>':
        case '<':
            rcmd = (struct redircmd*)cmd;
            int is_out = cmd->type == '>';
            FILE* f = is_out ? freopen(rcmd->file, "w+", stdout) : freopen(rcmd->file, "r", stdin);
            runcmd(rcmd->cmd);
            fclose(f);
            close(fileno(f));
            break;
        case '|':
            pcmd = (struct pipecmd*)cmd;
            pipe(p);
            if (0 == fork()) {
                close(p[1]);
                close(0);
                dup(p[0]);
                runcmd(pcmd->right);
                exit(0);
            } else {
                close(p[0]);
                close(1);
                dup(p[1]);
                runcmd(pcmd->left);
                int r;
                wait(&r);
            }
            break;
    }
    exit(0);
}
Пример #8
0
int
main(void)
{
  static char buf[100];
  int fd, r;

  // Read and run input commands.
  while(getcmd(buf, sizeof(buf)) >= 0){
    if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
      // Clumsy but will have to do for now.
      // Chdir has no effect on the parent if run in the child.
      buf[strlen(buf)-1] = 0;  // chop \n
      if(chdir(buf+3) < 0)
        fprintf(stderr, "cannot cd %s\n", buf+3);
      continue;
    }
    /* also clumsy: can't use exit* programs, but ok since not 
      traversing PATH anyway.*/
    if(!strncmp(buf, "exit", 4)) {
	exit(0);
    }
    if(fork1() == 0)
      runcmd(parsecmd(buf));
    wait(&r);
  }
  exit(0);
}
Пример #9
0
int main(int argc, char* argv[])
{
    static char buf[BUFSIZ];
    int fd;

    whitespace = " \t\r\n\v";
    symbols = "<|>&;()";

    if (argc == 2 && !strcmp(argv[1], "-i"))
        interactive = 1;

    // Assumes three file descriptors open.
    while ((fd = open("/dev/console", O_RDWR)) >= 0) {
        if (fd >= 3) {
            close(fd);
            break;
        }
    }

    // Read and run input commands.
    while (getcmd(buf) >= 0) {
        if (!memcmp(buf, "cd ", 3)) {
            // Clumsy but will have to do for now.
            // Chdir has no effect on the parent if run in the child.
            if (chdir(buf + 3) < 0)
                dprintf(2, "cannot cd %s\n", buf + 3);
            continue;
        } else if (!strcmp(buf, "exit"))
            return 0; // XXX should allow return code (exit [n])
        if (fork1() == 0)
            runcmd(parsecmd(buf));
        wait();
    }
    return 0;
}
Пример #10
0
void
umain(int argc, char **argv)
{
	int r, interactive, echocmds;

	interactive = '?';
	echocmds = 0;
	ARGBEGIN{
	case 'd':
		debug++;
		break;
	case 'i':
		interactive = 1;
		break;
	case 'x':
		echocmds = 1;
		break;
	default:
		usage();
	}ARGEND

	if (argc > 1)
		usage();
	if (argc == 1) {
		close(0);
		if ((r = open(argv[0], O_RDONLY)) < 0)
			panic("open %s: %e", argv[0], r);
		assert(r == 0);
	}
	if (interactive == '?')
		interactive = iscons(0);
	
	while (1) {
		char *buf;

		buf = readline(interactive ? "$ " : NULL);
		if (buf == NULL) {
			if (debug)
				cprintf("EXITING\n");
			exit();	// end of file
		}
		if (debug)
			cprintf("LINE: %s\n", buf);
		if (buf[0] == '#')
			continue;
		if (echocmds)
			printf("# %s\n", buf);
		if (debug)
			cprintf("BEFORE FORK\n");
		if ((r = fork()) < 0)
			panic("fork: %e", r);
		if (debug)
			cprintf("FORK: %d\n", r);
		if (r == 0) {
			runcmd(buf);
			exit();
		} else
			wait(r);
	}
}
Пример #11
0
int
main(void)
{
  static char buf[100];
  int fd, r;

  // Read and run input commands.
  while(getcmd(buf, sizeof(buf)) >= 0){
    if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
      // Clumsy but will have to do for now.
      // Chdir has no effect on the parent if run in the child.
      buf[strlen(buf)-1] = 0;  // chop \n
      if(chdir(buf+3) < 0)
        fprintf(stderr, "cannot cd %s\n", buf+3);
      continue;
    }
    if(strncmp(buf, "exit", 4) == 0) {
      fprintf(stdout, "Exit, good bye.\n");
      exit(0);
    }
    if(fork1() == 0)
      runcmd(parsecmd(buf));
    wait(&r);
  }
  exit(0);
}
Пример #12
0
int
main(void)
{
  static char buf[100];
  int fd;

  // Assumes three file descriptors open.
  while((fd = open("console", O_RDWR)) >= 0) {
    if(fd >= 3){
      close(fd);

      break;
    }
  }

  // Read and run input commands.
  while(getcmd(buf, sizeof(buf)) >= 0) {
    if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
      // Clumsy but will have to do for now.
      // Chdir has no effect on the parent if run in the child.
      buf[strlen(buf)-1] = 0;  // chop \n
      if(chdir(buf+3) < 0)
        printf(2, "cannot cd %s\n", buf+3);
      continue;
    } else if(buf[0] == 'v' && buf[1] == 'e' && buf[2] == 'r' && buf[3] == 's' && buf[4] == 'i' && buf[5] == 'o' && buf[6] == 'n')
    	printf(1, "uNIX Version 0-1 \n Build Version 3");

    if(fork1() == 0)
      runcmd(parsecmd(buf));
    wait();
  }
  exit();
}
Пример #13
0
void
run(void)
{
	fd_set fs;
	int code;
	char **c;
	struct inotify_event ev;

	for (;;) {
		FD_ZERO(&fs);
		FD_SET(notfd, &fs);
		if (select(notfd+1, &fs, 0, 0, 0)==-1) {
			if (errno==EINTR || errno==EAGAIN)
				continue;
			perror("select");
			exit(1);
		}
		read(notfd, &ev, sizeof ev);
		if (ev.mask & IN_IGNORED
		&& inotify_add_watch(notfd, texfile, IN_MODIFY)==-1) {
			perror("inotify_add_watch");
			exit(1);
		}
		for (c=compile; *c; c++)
			if ((code=runcmd(*c))) {
				fprintf(stderr, "Command %s failed (%d)!\n",
					*c, code);
				break;
			}
//		if (code==0 && runcmd(reloadcmd)) {
//		err("Cannot sync xpdf, exiting");
//			exit(1);
//		}
	}
}
Пример #14
0
static struct winedbg_x86_32 regState() {
	struct winedbg_x86_32 r = {0};
	char *res = runcmd ("info reg");
	if (res) {
		char *line = strstr (res, "EIP:");
		if (line) {
			ut32 eip, esp, ebp, eflags;
			(void)sscanf (line, "EIP:%08x ESP:%08x EBP:%08x EFLAGS:%08x",
				&eip, &esp, &ebp, &eflags);
			r.eip = eip;
			r.esp = esp;
			r.ebp = ebp;
			r.eflags = eflags;
			line = strstr (line, "EAX:");
			if (line) {
				ut32 eax, ebx, ecx, edx;
				(void)sscanf (line, "EAX:%08x EBX:%08x ECX:%08x EDX:%08x",
					&eax, &ebx, &ecx, &edx);
				r.eax = eax;
				r.ebx = ebx;
				r.ecx = ecx;
				r.edx = edx;
				line = strstr (line, "ESI:");
				if (line) {
					ut32 esi, edi;
					(void)sscanf (line, "ESI:%08x EDI:%08x", &esi, &edi);
					r.esi = esi;
					r.edi = edi;
				}
			}
		}
		free (res);
	}
	return r;
}
Пример #15
0
/* As from R 2.7.0 we assume file, editor are in UTF-8 */
int R_EditFiles(int nfile, const char **file, const char **title,
		const char *editor)
{
    int   i;
    char  buf[1024];

    if (nfile > 0) {
	if (editor == NULL || strlen(editor) == 0)
	    editor = "internal";
	for (i = 0; i < nfile; i++) {
	    if (!strcmp(editor, "internal")) {
		Rgui_Edit(file[i], CE_UTF8, title[i], 0);
	    } else {
		/* Quote path if necessary */
		if (editor[0] != '"' && Rf_strchr(editor, ' '))
		    snprintf(buf, 1024, "\"%s\" \"%s\"", editor, file[i]);
		else
		    snprintf(buf, 1024, "%s \"%s\"", editor, file[i]);
		runcmd(buf, CE_UTF8, 0, 1, NULL, NULL, NULL);
	    }

	}
	return 0;
    }
    return 1;
}
Пример #16
0
static void
forkcmd(char *cmd, char *p, int reqfd, int datafd, int want_reply)
{
	char *q;

	switch (fork()) {
	case 0:
		if (restdir && chdir(restdir) < 0) {
			syslog(0, "ssh", "can't chdir(%s): %r", restdir);
			exits("can't chdir");
		}
		if (!prevent || (q = getenv("sshsession")) &&
		    strcmp(q, "allow") == 0)
			get_string(p+1, cmd);
		else
			confine(p+1, cmd);
		syslog(0, "ssh", "server running `%s' for %s", cmd, uname);
		/* runcmd doesn't return */
		runcmd(reqfd, datafd, "rx", "/bin/rc", "-lc", cmd);
	case -1:
		REPLY("failure");
		syslog(0, "ssh", "server can't fork: %r");
		exits("fork");
	}
}
Пример #17
0
Файл: sh.c Проект: galmam/OS152
int
main(void)
{
  static char buf[100];
  int fd, status;
  
  // Assumes three file descriptors open.
  while((fd = open("console", O_RDWR)) >= 0){
    if(fd >= 3){
      close(fd);
      break;
    }
  }
  
  // Read and run input commands.
  while(getcmd(buf, sizeof(buf)) >= 0){
    if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
      // Clumsy but will have to do for now.
      // Chdir has no effect on the parent if run in the child.
      buf[strlen(buf)-1] = 0;  // chop \n
      if(chdir(buf+3) < 0)
        printf(2, "cannot cd %s\n", buf+3);
      continue;
    }
    if(fork1() == 0)
      runcmd(parsecmd(buf));
    wait(&status);
  }
  exit(0);
}
Пример #18
0
int
main ()
{
        runner_t runner;
        char buf[80];
        char *wdbuf;;
        int ret;
        long pathmax = pathconf ("/", _PC_PATH_MAX);

        wdbuf = malloc (pathmax);
        assert (wdbuf);
        getcwd (wdbuf, pathmax);

        TBANNER ("basic functionality");
        runcmd ("echo", "a", "b", NULL);

        TBANNER ("argv extension");
        runcmd ("echo", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
                "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
                "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
                "31", "32", "33", "34", "35", "36", "37", "38", "39", "40",
                "41", "42", "43", "44", "45", "46", "47", "48", "49", "50",
                "51", "52", "53", "54", "55", "56", "57", "58", "59", "60",
                "61", "62", "63", "64", "65", "66", "67", "68", "69", "70",
                "71", "72", "73", "74", "75", "76", "77", "78", "79", "80",
                "81", "82", "83", "84", "85", "86", "87", "88", "89", "90",
                "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", NULL);

        TBANNER ("add_args, argprintf, log, and popen-style functionality");
        runinit (&runner);
        runner_add_args (&runner, "echo", "pid:", NULL);
        runner_argprintf (&runner, "%d\n", getpid());
        runner_add_arg (&runner, "wd:");
        runner_add_arg (&runner, wdbuf);
        runner_redir (&runner, 1, RUN_PIPE);
        runner_start (&runner);
        runner_log (&runner, "(x)", LOG_DEBUG, "starting program");
        while (fgets (buf, sizeof(buf), runner_chio (&runner, 1)))
                printf ("got: %s", buf);
        runner_end (&runner);

        TBANNER ("execve error reporting");
        ret = runcmd ("bafflavvitty", NULL);
        printf ("%d %d [%s]\n", ret, errno, strerror (errno));

        return 0;
}
int thread_func(void *arg)
{
	printk("AK47 in  kthread :%d\n", (int)arg);
	msleep_interruptible((int)arg * 1000);
	printk("AK47 in  kthread wakup\n");
	runcmd(1);
	return 0;
}
Пример #20
0
static int sruncmd(cmdint_t *ci, const char *cmdline)
{
    char *cmdnew;
    int ret;

    cmdnew = strnew(cmdline);
    ret = runcmd(ci, cmdnew);
    free(cmdnew);
    return ret;
}
Пример #21
0
/**
 * Prepare for running workunits, get tmpdir stuff set up, divide video
 * fragments between threads and create VideoSegment instances for each video
 * fragment
 */
int Balancer::prepare_work_units() {
    int i, images_per_thread, remainder;
    char cmd[256], message[256];

    // Create video fragments
    sprintf(cmd, "ffmpeg -i %s -r %i -f image2 %s/frame-%%04d.jpg "
            "-loglevel quiet", this->config->input,
            this->config->framerate, this->tmp);
    runcmd(cmd, this->log);

    // Get list of input images
    dirlist(this->tmp, &this->input_images_count, &this->input_image_paths);

    // Figure out what the processed image paths should be
    this->processed_image_paths =
        (char**)malloc(sizeof(char[256]) * this->config->threads);
    for (i = 0; i < this->config->threads; i++) {
        this->processed_image_paths[i] = (char*)malloc(sizeof(char[256]));
        sprintf(this->processed_image_paths[i], "res-%i.jpg", i);
    }

    // How many images is each thread going to handle. Note that the last
    // thread will likely have a couple extra if this division is not even
    images_per_thread = this->input_images_count / this->config->threads;
    
    // Allocate space for workunits and input image counts
    this->workunits = (WorkUnit**)malloc(sizeof(WorkUnit*) *
            this->config->threads);

    // Loop throught this->segments and set up the work units that
    // each thread will be processing. Note that this stops 1 before the end of
    // this->workunits, as the last member of this->workunits will have a
    // different number of images to process
    for (i = 0; i < this->config->threads - 1; i++) {
        // Create workunit
        this->workunits[i] = new WorkUnit(this->config, this->tmp,
                &this->input_image_paths[i * images_per_thread],
                images_per_thread, this->processed_image_paths[i]);
        sprintf(message, "Workunit %i with %i inputs", i, images_per_thread);
        this->log->log(message, DEBUG_V);
    }
    
    // Now we need to find how many input images are left and process them with
    // the last thread
    remainder = this->input_images_count -
        (images_per_thread * (this->config->threads - 1));
    this->workunits[i] = new WorkUnit(this->config, this->tmp,
            &this->input_image_paths[input_images_count - remainder - 1],
            remainder, this->processed_image_paths[this->config->threads - 1]);
    sprintf(message, "Workunit %i with %i inputs",
            this->config->threads - 1, remainder);
    this->log->log(message, DEBUG_V);

    return 0;
}
Пример #22
0
Файл: sh.c Проект: yarivz/os132
int
main(void)
{
  static char buf[100];
  int fd;
  
  // Assumes three file descriptors open.
  while((fd = open("console", O_RDWR)) >= 0){
    if(fd >= 3){
      close(fd);
      break;
    }
  }
  
  // Read and run input commands.
  while(getcmd(buf, sizeof(buf)) >= 0){
    if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
      // Clumsy but will have to do for now.
      // Chdir has no effect on the parent if run in the child.
      buf[strlen(buf)-1] = 0;  // chop \n
      if(chdir(buf+3) < 0)
        printf(2, "cannot cd %s\n", buf+3);
      continue;
    }
    if(!strncmp(buf,"export PATH",11)){		//if export PATH was called
      //buf = buf+12;
      PATH = malloc(10*sizeof(char*));		//allocate memory for the PATH variable
      memset(PATH, 0, 10*sizeof(char*));	//clean alocated memory - 10 paths max
      int i;
      for(i=0;i<10;i++){
	PATH[i] = malloc(100);			//allocate memory for each path in PATH - 100 chars max
	memset(PATH[i],0,100);			//clean allocated memory
      }
      pathInit = 1;				//set flag to 1 - initialized
      int tempIndex = 0;
      int* beginIndex = &tempIndex;
      int length = strlen(&(buf[12]));		//set the starting point to parse after "export PATH"
      char** temp = PATH;
      while(*beginIndex<length-1)		//go over the command string and tokenize by delimiter
      {
	if(strtok(*temp,&(buf[12]),':',beginIndex)) //if tokenizer returned a string
	{
	(temp)++;
	}
      }
      continue;
    }
    if(fork1() == 0)
    {
      runcmd(parsecmd(buf));
    }
    wait();
  }
  exit();
}
Пример #23
0
Файл: sh.c Проект: pLesur/Shell
	int
main(void)
{
	signal(SIGCHLD, backgroundHandler);
	signal(SIGHUP, backgroundHandler);
	signal(SIGINT, foregroundHandler);
	signal(SIGQUIT, foregroundHandler);

	// Read and run input commands.
	char buf[100];
	while(getcmd(buf, sizeof(buf)) >= 0){
		buf[strlen(buf)-1] = 0;  // chop \n
		if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
			if(chdir(buf+3) < 0)
				fprintf(stderr, "cannot cd %s\n", buf+3);
		} else {


			// see if it needs to run in the background
			bool runInBackground = isBackgroundProc(buf, sizeof(buf));
			int pid = fork1();

			if(!runInBackground) { 
				if(pid == 0) {
					runcmd(parsecmd(buf));
				}
				foregroundPid = pid;
				wait(&pid);
				foregroundPid = -1;
			}
			else {
				addPidToList(sizePidsList, pid);
				if(pid == 0) {
					setpgrp();
					runcmd(parsecmd(buf));
				}
			}
		}
	}

	return 0;
}
Пример #24
0
static void test_date_format(void)
{
    DWORD rc;

    rc = runcmd("xcopy /D:20-01-2000 xcopy1 xcopytest");
    ok(rc == 4, "xcopy /D:d-m-y test returned rc=%u\n", rc);
    ok(GetFileAttributesA("xcopytest\\xcopy1") == INVALID_FILE_ATTRIBUTES,
       "xcopy should not have created xcopytest\\xcopy1\n");

    rc = runcmd("xcopy /D:01-20-2000 xcopy1 xcopytest");
    ok(rc == 0, "xcopy /D:m-d-y test failed rc=%u\n", rc);
    ok(GetFileAttributesA("xcopytest\\xcopy1") != INVALID_FILE_ATTRIBUTES,
       "xcopy did not create xcopytest\\xcopy1\n");
    DeleteFileA("xcopytest\\xcopy1");

    rc = runcmd("xcopy /D:1-20-2000 xcopy1 xcopytest");
    ok(rc == 0, "xcopy /D:m-d-y test failed rc=%u\n", rc);
    ok(GetFileAttributesA("xcopytest\\xcopy1") != INVALID_FILE_ATTRIBUTES,
       "xcopy did not create xcopytest\\xcopy1\n");
    DeleteFileA("xcopytest\\xcopy1");
}
Пример #25
0
/**
 *
 * @brief parse la chaine courante de l'interpreteur à la recherche d'une commande, et execute cette commande.
 * @param inter l'interpreteur qui demande l'analyse
 * @return CMD_OK_RETURN_VALUE si la commande s'est exécutée avec succès (0)
 * @return CMD_EXIT_RETURN_VALUE si c'est la commande exit. Dans ce cas, le programme doit se terminer. (-1)
 * @return CMD_UNKOWN_RETURN_VALUE si la commande n'est pas reconnue. (-2)
 * @return tout autre nombre (eg tout nombre positif) si erreur d'execution de la commande
 */
int execute_cmd(interpreteur inter, memory memory) {
    DEBUG_MSG("input '%s'", inter->input);
    char cmdStr[MAX_STR];
    memset( cmdStr, '\0', MAX_STR );

    /* gestion des commandes vides, commentaires, etc*/
    if(strlen(inter->input) == 0
            || sscanf(inter->input, "%s", cmdStr) == 0
            || strlen(cmdStr) == 0
            || cmdStr[0] == '#') { /* ligne commence par # => commentaire*/
        return CMD_OK_RETURN_VALUE;
    }

    /*on identifie la commande avec un premier appel à get_next_token*/
    char * token = get_next_token(inter);

    if(strcmp(token, "exit") == 0) {
        return exitcmd(inter);
    }

    if(strcmp(token, "load") == 0) {
        return loadcmd(inter, memory);
    }
    else if(strcmp(token, "debug") == 0) {
        return debugcmd(inter);
    }
    else if(strcmp(token, "disp") == 0) {
        return dispcmd(inter, memory);
    }
    else if(strcmp(token, "assert") == 0) {
        return assertcmd(inter, memory);
    }
    else if(strcmp(token, "set") == 0) {
        return setcmd(inter, memory);
    }
    else if(strcmp(token, "resume") == 0) {
        return resumecmd(inter);
    }
    else if(strcmp(token, "disasm") == 0) {
        return disasmcmd(inter, memory);
    }
    else if(strcmp(token, "run") == 0) {
        return runcmd(inter, memory);
    }
    else if(strcmp(token, "step") == 0) {
        return stepcmd(inter, memory);
    }
    else if(strcmp(token, "break") == 0) {
        return breakcmd(inter, memory);
    }
    WARNING_MSG("Unknown Command : '%s'\n", cmdStr);
    return CMD_UNKOWN_RETURN_VALUE;
}
Пример #26
0
int R_ShowFiles(int nfile, const char **file, const char **headers,
		const char *wtitle, Rboolean del, const char *pager)
{
    int   i;
    char  buf[1024];

    if (nfile > 0) {
	if (pager == NULL || strlen(pager) == 0)
	    pager = "internal";
	for (i = 0; i < nfile; i++) {
	    if(!access(file[i], R_OK)) {
		if (!strcmp(pager, "internal")) {
		    newpager(wtitle, file[i], CE_NATIVE, headers[i], del);
		} else if (!strcmp(pager, "console")) {
		    size_t len;
		    FILE *f;
		    f = R_fopen(file[i], "rt");
		    if(f) {
			while((len = fread(buf, 1, 1023, f))) {
			    buf[len] = '\0';
			    R_WriteConsole(buf, strlen(buf));
			}
			fclose(f);
			if (del) DeleteFile(file[i]);
			/* add a blank line */
			R_WriteConsole("", 0);
		    }
		    else {
			snprintf(buf, 1024,
				 _("cannot open file '%s': %s"),
				 file[i], strerror(errno));
			warning(buf);
		    }
		} else {
		    /* Quote path if necessary */
		    if(pager[0] != '"' && Rf_strchr(pager, ' '))
			snprintf(buf, 1024, "\"%s\" \"%s\"", pager, file[i]);
		    else
			snprintf(buf, 1024, "%s \"%s\"", pager, file[i]);
		    runcmd(buf, CE_NATIVE, 0, 1, NULL, NULL, NULL);
		}
	    } else {
		snprintf(buf, 1024,
			 _("file.show(): file '%s' does not exist\n"),
			 file[i]);
		warning(buf);
	    }
	}
	return 0;
    }
    return 1;
}
Пример #27
0
// Lurk on the mShellQ and execute a shell script to process requests found.
void *miniGgsnShellServiceLoop(void *arg)
{
	Ggsn *ggsn = (Ggsn*)arg;
	std::string shname = gConfig.getStr("GGSN.ShellScript");
	while (ggsn->active()) {
		ShellRequest *req = ggsn->mShellQ.read(ggsn->mStopTimeout);
		if (! req) continue;
		runcmd("/bin/sh","sh",shname.c_str(), req->msrCommand.c_str(), req->msrArg1.c_str(),
			req->msrArg2.c_str(),req->msrArg3.c_str());
		delete req;
	}
	return 0;
}
Пример #28
0
int
main(void)
{
    unsigned short i;
    char *tmtz, *net, *avgs, *root, *vol, *bat;
    tmtz = net = avgs = root = vol = bat = NULL;
    char *line;
    static unsigned long long rec = 0, sent = 0;

    if (!(dpy = XOpenDisplay(NULL))) {
        fprintf(stderr, "dwmstatus: cannot open display.\n");
        return 1;
    }

    parse_netdev(&rec, &sent);

    for (i = 0;; sleep(1), i++) {
        if (i % 10 == 0) {
            free(bat);
            bat = batstat();
        }
        if (i % 5 == 0) {
            free(avgs);
            free(root);
            free(vol);
            avgs = loadavg();
            root = getfree("/");
            vol = runcmd("amixer get PCM | grep -om1 '[0-9]*%'");
        }
        net = netusage(&rec, &sent);
        tmtz = mktimes("%a %b %d %T");

        line = smprintf("♪ %s ⚡ %s │ %s │ / %s │ %s │ %s",
                        vol, bat, net, root, avgs, tmtz);

        XStoreName(dpy, DefaultRootWindow(dpy), line);
        XSync(dpy, False);

        free(net);
        free(tmtz);
        free(line);

        if (i == 60)
            i = 0;
    }

    XCloseDisplay(dpy);

    return 0;
}
Пример #29
0
void
umain(int argc, char **argv)
{
	int r, interactive, echocmds;

	interactive = '?';
	echocmds = 0;
	ARGBEGIN{
	case 'd':
		debug++;
		break;
	case 'i':
		interactive = 1;
		break;
	case 'x':
		echocmds = 1;
		break;
	default:
		usage();
	}ARGEND

	if(argc > 1)
		usage();
	if(argc == 1){
		close(0);
		if ((r = open(argv[1], O_RDONLY)) < 0)
			panic("open %s: %e", r);
		assert(r==0);
	}
	if(interactive == '?')
		interactive = iscons(0);
	for(;;){
		if (interactive)
			fprintf(1, "$ ");
		readline(buf, sizeof buf);
		if (debug) printf("LINE: %s\n", buf);
		if (buf[0] == '#')
			continue;
		if (echocmds)
			fprintf(1, "# %s\n", buf);
		if ((r = fork()) < 0)
			panic("fork: %e", r);
		if (r == 0) {
			runcmd(buf);
			exit();
		} else
			wait(r);
	}
}
Пример #30
0
void
interact(struct disklabel *lp, int fd)
{
	char	line[BUFSIZ];

	puts("Enter '?' for help");
	for (;;) {
		int i = getinput(line, "partition>");
		if (i == -1)
			return;
		if (i == 0)
			continue;
		if (runcmd(lp, line, fd) == -1)
			return;
	}
}