Exemple #1
0
struct pathnode *
strtopath(char *pathstr)
{
	struct pathnode *root;
	struct pathnode *p;
	char *w;
	char *aux;	
	
	initpath(root);

	for (p = root; p != NULL; p = p->next) {
		my_strtok(pathstr,aux,w);
		p->next = NULL;
		while (w != NULL && !(strcmp(".",w) && strcmp("..",w)) ) {
			if (strcmp("..",w) == 0) {
				p = p->prev;
				if (p->next != NULL)
					freenode(p->next);
			}
			free(w);
			my_strtok(pathstr,aux,w);
		}
	
		if (w != NULL) {
			p->next = palloc();
			(p->next)->name = w;
			(p->next)->prev = p; 
		}		
	}
	
	return root;
}
Exemple #2
0
void worker_init(upstreams *upstr_ptr, mqd_t msgq_id) {
	char msgcontent[MAX_MSG_LEN_CH];
	int msgsz;
	unsigned int sender;
	struct mq_attr msgq_attr;
	struct timespec tm;
	const config_setting_t *upstr_setting;

	upstr_setting = config_lookup(&cfg, "upstreams");
	upstream_count = config_setting_length(upstr_setting);

	while (running) {
		sleep(1);
		mq_getattr(msgq_id, &msgq_attr);
		error_log(DEBUG,
				"Queue \"%s\":\n\t- stores at most %ld messages\n\t- large at most %ld bytes each\n\t- currently holds %ld messages\n",
				QUEUE, msgq_attr.mq_maxmsg, msgq_attr.mq_msgsize,
				msgq_attr.mq_curmsgs);

		/* getting a message */
		clock_gettime(CLOCK_REALTIME, &tm);
		tm.tv_sec += 1;

		msgsz = mq_timedreceive(msgq_id, msgcontent, MAX_MSG_LEN_CH, &sender,
				&tm);
		if (msgsz == -1) {
			if (errno == ETIMEDOUT) {
				continue;
			}
			error_log(ERROR, "mq_receive error: %s", strerror(errno));
			exit(EXIT_FAILURE);
		}

		/* Ok, we got file to download */
		if (initpath(msgcontent) != 0) {
			error_log(ERROR, "Initpath failed");
		} else if (download(msgcontent) != 0) {
			error_log(ERROR, "Failed to download file");
		}
	}
	error_log(ERROR, "Exiting");
}
Exemple #3
0
/*
 * main - The shell's main routine 
 *
 * Requires:
 *   argc should be less than MAXARGS arguments.
 *   argv should contain less than MAXARGS arguments.
 *
 * Effects:
 *   Runs an interactive command-line interpreter that runs programs on
 *   behalf of the user. It waits for a command line and then carries out
 *   the action of that command line. The shell executes built-in commands
 *   immediately, but also can execute user programs by forking child 
 *   processes. It manages jobs running the foreground and background.
 */
int
main(int argc, char **argv) 
{
	int c;
	char cmdline[MAXLINE];
	char *path = NULL;
	bool emit_prompt = true;	// Emit a prompt by default.

	/*
	 * Redirect stderr to stdout (so that driver will get all output
	 * on the pipe connected to stdout).
	 */
	dup2(1, 2);
	// Parse the command line.
	while ((c = getopt(argc, argv, "hvp")) != -1) {
		switch (c) {
		case 'h':             // Print a help message.
			usage();
			break;
		case 'v':             // Emit additional diagnostic info.
			verbose = true;
			break;
		case 'p':             // Don't print a prompt.
			// This is handy for automatic testing.
			emit_prompt = false;
			break;
		default:
			usage();
		}
	}
	// Install the signal handlers.

	// These are the ones you will need to implement:
	Signal(SIGINT,  sigint_handler);   // ctrl-c
	Signal(SIGTSTP, sigtstp_handler);  // ctrl-z
	Signal(SIGCHLD, sigchld_handler);  // Terminated or stopped child

	// This one provides a clean way to kill the shell.
	Signal(SIGQUIT, sigquit_handler); 

	// Initialize the search path.
	path = getenv("PATH");
	initpath(path);

	// Initialize the jobs list.
	initjobs(jobs);

	// Execute the shell's read/eval loop.
	while (true) {
		// Read the command line.
		if (emit_prompt) {
			printf("%s", prompt);
			fflush(stdout);
		}
		if ((fgets(cmdline, MAXLINE, stdin) == NULL) && ferror(stdin)){
			app_error("fgets error");}
		if (feof(stdin)) { // End of file (ctrl-d)
			fflush(stdout);
			exit(0);
		}
		
		// Evaluate the command line.
		eval(cmdline);
		fflush(stdout);
		fflush(stdout);
	}

	// Control never reaches here.
	assert(false);
}