Пример #1
0
void check_permission(char *filename) {
#ifdef _WIN32
	return;
#else
	/* get file-status */
	struct stat filebuf;
	int status=stat(filename, &filebuf);
	if (status == -1) {
		printf ( "Task-file not found.\n" );
		log_task("ERROR", "Task-file not found.");
		exit(EXIT_FAILURE);
	}

	/* check file- vs. os-user */
	uid_t file_uid=filebuf.st_uid;
	uid_t os_uid=geteuid();
	if (file_uid!=os_uid) {
		struct passwd *pw;
		pw=getpwuid(os_uid);
		printf ( "Invalid owner of the task-file (%s).\n", pw->pw_name );
		log_task("ERROR", "Invalid owner of the task-file");
		exit(EXIT_FAILURE);
	}

	/* check file-mode */
	int mode=filebuf.st_mode;
	if ((((mode & S_IWGRP) || (mode & S_IWOTH)) && (mode & S_IWRITE))) {
		printf ( "Invalid permission of the task-file (%o).\nCheck write-permission for 'group' and 'other'.\n", mode );
		log_task("ERROR", "Invalid permission of the task-file");
		exit(EXIT_FAILURE);
	}
#endif
}
Пример #2
0
void execute_task(ITEM now, ITEM item) {
#ifdef _WIN32
	char start[300];
	sprintf(start, "start %s", item.command);

	log_task("START", item.command);

	printf ( "%02d.%02d %02d:%02d\tCOMMAND:\t%s\n", now.monthday, now.month, now.hour, now.minute, item.command );
    system(start);                              /* execute command */
	
	log_task("STOP", item.command);

#else
    pid_t child_pid=fork();                     /* fork program */
	int status;
	switch(child_pid) {
		case -1:
			/* error */
			printf ( "Unable to start process (%s).\n", item.command );
			exit(EXIT_FAILURE);
		case 0:
			/* child */
			log_task("START", item.command);

            int sys_exit=system(item.command);  /* execute command */
			
			log_task("STOP", item.command);
			
            exit(sys_exit);                     /* exit sub-process */
		default:
			/* parent */
			printf ( "%03d.%02d %02d:%02d\tCOMMAND:\t%s\n", now.monthday, now.month, now.hour, now.minute, item.command );
			child_pid = wait(&status);
			
			if ( WIFEXITED(status) != 0 ) {
//				printf ( "Child (%d) has been finished with status %d.\n", child_pid, WEXITSTATUS(status) );
			} else {
				printf ( "Child (%d) has been finished with  error %d.\n", child_pid, WEXITSTATUS(status) );
			}
    }                                           /* switch */
#endif
}
Пример #3
0
int main(void) {

	init_menu();
	
	clear();
	init_motor();
	init_timers();
	encoders_init(IO_D2, IO_D3, IO_C4, IO_C5);

	sei();
	while (1) 
	{
		if(g_pd_release) {
			pd_task();
			g_pd_release = 0;
		}

		if(g_velocity_release) {
			velocity_task();
			g_velocity_release = 0;
		}

		if(g_encoder_release) {
			encoder_task();
			g_encoder_release = 0;
		}

		if(g_log_release) {
			log_task();
			g_log_release = 0;
		}

		if(g_interpolate_release) {
			interoplate_task();
			g_interpolate_release = 0;
		}

		serial_check();
		check_for_new_bytes_received();		
	}
}