Пример #1
0
void reset(const std::string &job)
{
  job_statust job_status(job);

  if(job_status.status==job_statust::FAILURE)
  {
    std::cout << "Resetting job " << job_status.id << "\n";
    job_status.status=job_statust::WAITING;
    job_status.write();
  }
}
Пример #2
0
Файл: dsh.c Проект: bsb20/dsh
/* Displays the command strings and status for all current jobs */
void builtin_jobs() {
    job_t* j;
	job_t* prev;                                                        //Previous point needed because need to remove jobs AFTER getting next job in list
	int i;
	for (prev = NULL, j=first_job, i = 1; j; prev = j, j=j->next, i++){ //for each job, print status, then remove if completed
		
		fprintf(stdout, "[%d] %d(%s): %s\n", i, j->pgid, job_status(j), j->commandinfo);
		
		if (prev && job_is_completed(prev))
			remove_job(prev);
	}
	if (prev && job_is_completed(prev)){
		remove_job(prev);
	}
}
Пример #3
0
static void test_exe_submit(void)
{
    int sleep1Result;
    Executor* exe = exe_new();
    Job*      job;
    int       status = exe_submit(exe, sleep1, &sleep1Result, NULL, &job);
    CU_ASSERT_EQUAL_FATAL(status, 0);
    CU_ASSERT_EQUAL(exe_count(exe), 1);
    Job*      completedJob = exe_getCompleted(exe);
    CU_ASSERT_EQUAL_FATAL(status, 0);
    CU_ASSERT_EQUAL(exe_count(exe), 0);
    CU_ASSERT_PTR_EQUAL(completedJob, job);
    CU_ASSERT_FALSE(job_wasStopped(job));
    CU_ASSERT_EQUAL(job_status(job), 0);
    CU_ASSERT_PTR_EQUAL(job_result(job), &sleep1Result);
    job_free(job);
    CU_ASSERT_EQUAL(status, 0);
    status = exe_free(exe);
    CU_ASSERT_EQUAL(status, 0);
}
Пример #4
0
int main(int argc, char *argv[])
{
	int fd, sfd, err, c;
	struct stat sbuf;
	char *host, *file;
	struct addrinfo	*ailist, *aip;
	char *orient;
	long jobid;
	int text;
	int sides;		/* 0=default 1=one-sided */
				/* 2=two-sided-long-edge  3=two-sided-short-edge */
	
	sides = 0;
	text = 0;
	err = 0;
	jobid = -1;
	while ((c = getopt(argc, argv, "is:to:c:h")) != -1) {
		switch (c) {
		case 'h':
			usage();
			exit(0);
		case 'c':
			jobid = atol(optarg);
			break;
		case 'i':
			job_status();
			exit(0);
		case 's':
			sides = atol(optarg);
			if (sides < 1 || sides > 3)
				err_sys("print: invalid sides option");
			break;
		case 'o':
			orient = optarg;
			break;
		case 't':
			text = 1;
			break;

		case '?':
			err = 1;
			break;
		}
	}
	if (err || (optind != argc - 1))
		err_quit("usage: print [-t] filename");
	file = argv[optind];
	if ((fd = open(file, O_RDONLY)) < 0)
		err_sys("print: can't open %s", file);
	if (fstat(fd, &sbuf) < 0)
		err_sys("print: can't stat %s", file);
	if (!S_ISREG(sbuf.st_mode))
		err_quit("print: %s must be a regular file", file);
	/*
	 * Get the hostname of the host acting as the print server.
	 */
	if ((host = get_printserver()) == NULL)
		err_quit("print: no print server defined");
	if ((err = getaddrlist(host, "print", &ailist)) != 0)
		err_quit("print: getaddrinfo error: %s", gai_strerror(err));

	for (aip = ailist; aip != NULL; aip = aip->ai_next) {
		if ((sfd = connect_retry(AF_INET, SOCK_STREAM, 0,
		  aip->ai_addr, aip->ai_addrlen)) < 0) {
			err = errno;
		} else {
			if (jobid != -1) /* cancel job */
				cancel_job(sfd, jobid);
			else 
				submit_file(fd, sfd, file, sbuf.st_size,
					    text, orient, sides);
			exit(0);
		}
	}
	err_exit(err, "print: can't contact %s", host);
}
Пример #5
0
/* execute another program, possibly searching for it first
 * 
 * if the 'exec' argument is set it will never return
 * ----------------------------------------------------------------------- */
int exec_program(char *path, char **argv, int exec, union node *redir) {
  int ret = 0;
  sigset_t nset, oset;
  
  /* if we're gonna execve() a program and 'exec' isn't 
     set or we aren't in the root shell environment we
     have to fork() so we can return */
  if(!exec || sh->parent) {
    pid_t pid;
    struct fdstack io;
    unsigned int n;

    fdstack_push(&io);

    /* buffered fds which have not a real effective file descriptor,
       like here-docs which are read from strallocs and command
       expansions, which write to strallocs can't be shared across
       different process spaces, so we have to establish pipes */
    if((n = fdstack_npipes(FD_HERE|FD_SUBST)))
      fdstack_pipe(n, fdstack_alloc(n));

    /* block child and interrupt signal, so we won't terminate ourselves
       when the child does */
    /*
    sigemptyset(&nset);
    sigaddset(&nset, SIGINT);

#ifdef SIGCHLD
    sigaddset(&nset, SIGCHLD);
#endif
    sigemptyset(&oset);
    sigprocmask(SIG_BLOCK, &nset, &oset);
*/
    sig_block();

    /* in the parent wait for the child to finish and then return 
       or exit, according to the 'exec' argument */
    if((pid = fork())) {
      int status = 1;

      /* this will close child ends of the pipes and read data from the parent end :) */
      fdstack_pop(&io);
      fdstack_data();

      
      job_wait(NULL, pid, &status, 0);
      job_status(pid, status);

      ret = WEXITSTATUS(status);

#ifndef __MINGW32__
      sigprocmask(SIG_SETMASK, &oset, NULL);
#endif
      
      /* exit if 'exec' is set, otherwise return */
      if(exec) sh_exit(ret);
      return ret;
    }

    /* ...in the child we always exit */
    sh_forked();
  }

  fdtable_exec();
  fdstack_flatten();

  /* when there is a path then we gotta execute a command,
     otherwise we exit/return immediately */
  if(path) {
    /* export environment */
    char **envp;
    unsigned long envn = var_count(V_EXPORT) + 1;
    envp = var_export(alloca(envn * sizeof(char *)));

    /* try to execute the program */
    execve(path, argv, envp);

    /* execve() returned so it failed, we're gonna map 
       the error code to the appropriate POSIX errors */
    ret = exec_error();

    /* yield an error message */
    sh_error(path);
  }

  /* we never return at this point! */
  exit(ret);
}