示例#1
0
文件: task.c 项目: bhutley/pit
static void task_create(POptions po)
{
    pit_db_load();
    PProject pp = (PProject)pit_table_current(projects);

    if (!pp) {
        die("no project selected");
    } else {
        Task t = { 0 }, *pt;

        t.project_id = pp->id;
        if (!po->task.status) po->task.status = "open";
        if (!po->task.priority) po->task.priority = "normal";
        strncpy(t.name,     po->task.name,     sizeof(t.name)     - 1);
        strncpy(t.status,   po->task.status,   sizeof(t.status)   - 1);
        strncpy(t.priority, po->task.priority, sizeof(t.priority) - 1);
        strncpy(t.username, current_user(),    sizeof(t.username) - 1);
        t.date = max(0, po->task.date);
        t.time = max(0, po->task.time);

        pt = (PTask)pit_table_insert(tasks, (char *)&t);
        pit_table_mark(tasks, pt->id);
        pp->number_of_tasks++;
        task_log_create(pt, po);
        pit_db_save();
    }
}
示例#2
0
文件: scm.c 项目: AshishNamdev/linux
static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp)
{
	int *fdp = (int*)CMSG_DATA(cmsg);
	struct scm_fp_list *fpl = *fplp;
	struct file **fpp;
	int i, num;

	num = (cmsg->cmsg_len - sizeof(struct cmsghdr))/sizeof(int);

	if (num <= 0)
		return 0;

	if (num > SCM_MAX_FD)
		return -EINVAL;

	if (!fpl)
	{
		fpl = kmalloc(sizeof(struct scm_fp_list), GFP_KERNEL);
		if (!fpl)
			return -ENOMEM;
		*fplp = fpl;
		fpl->count = 0;
		fpl->max = SCM_MAX_FD;
		fpl->user = NULL;
	}
	fpp = &fpl->fp[fpl->count];

	if (fpl->count + num > fpl->max)
		return -EINVAL;

	/*
	 *	Verify the descriptors and increment the usage count.
	 */

	for (i=0; i< num; i++)
	{
		int fd = fdp[i];
		struct file *file;

		if (fd < 0 || !(file = fget_raw(fd)))
			return -EBADF;
		*fpp++ = file;
		fpl->count++;
	}

	if (!fpl->user)
		fpl->user = get_uid(current_user());

	return num;
}
示例#3
0
文件: note.c 项目: bhutley/pit
static void note_update(int id, POptions po)
{
    PNote pn;

    pit_db_load();
    id = note_find_current(id, &pn);

    strncpy(pn->message,  po->note.message, sizeof(pn->message)  - 1);
    strncpy(pn->username, current_user(),   sizeof(pn->username) - 1);
    pit_table_mark(notes, pn->id);

    note_log_update((PTask)pit_table_find(tasks, pn->task_id), pn, po);
    pit_db_save();
}
示例#4
0
文件: task.c 项目: bhutley/pit
static void task_update(int id, POptions po)
{
    PTask pt;

    pit_db_load();
    id = task_find_current(id, &pt);

    if (po->task.name)     strncpy(pt->name,     po->task.name,     sizeof(pt->name) - 1);
    if (po->task.status)   strncpy(pt->status,   po->task.status,   sizeof(pt->status) - 1);
    if (po->task.priority) strncpy(pt->priority, po->task.priority, sizeof(pt->priority) - 1);
    if (po->task.date) pt->date = max(0, po->task.date);
    if (po->task.time) pt->time = max(0, po->task.time);
    strncpy(pt->username, current_user(), sizeof(pt->username) - 1);
    pit_table_mark(tasks, pt->id);

    task_log_update(pt, po);
    pit_db_save();
}
示例#5
0
文件: note.c 项目: bhutley/pit
static void note_create(POptions po)
{
    pit_db_load();
    PTask pt = (PTask)pit_table_current(tasks);

    if (!pt) {
        die("no task selected");
    } else {
        Note n = { 0 }, *pn;

        n.task_id = pt->id;
        strncpy(n.message,  po->note.message, sizeof(n.message)  - 1);
        strncpy(n.username, current_user(),   sizeof(n.username) - 1);

        pn = (PNote)pit_table_insert(notes, (char *)&n);
        pit_table_mark(notes, pn->id);
        pt->number_of_notes++;
        note_log_create(pt, pn, po);
        pit_db_save();
    }
}
示例#6
0
SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
{
	int class = IOPRIO_PRIO_CLASS(ioprio);
	int data = IOPRIO_PRIO_DATA(ioprio);
	struct task_struct *p, *g;
	struct user_struct *user;
	struct pid *pgrp;
	int ret;

	switch (class) {
		case IOPRIO_CLASS_RT:
			if (!capable(CAP_SYS_ADMIN))
				return -EPERM;
			/* fall through, rt has prio field too */
		case IOPRIO_CLASS_BE:
			if (data >= IOPRIO_BE_NR || data < 0)
				return -EINVAL;

			break;
		case IOPRIO_CLASS_IDLE:
			break;
		case IOPRIO_CLASS_NONE:
			if (data)
				return -EINVAL;
			break;
		default:
			return -EINVAL;
	}

	ret = -ESRCH;
	rcu_read_lock();
	switch (which) {
		case IOPRIO_WHO_PROCESS:
			if (!who)
				p = current;
			else
				p = find_task_by_vpid(who);
			if (p)
				ret = set_task_ioprio(p, ioprio);
			break;
		case IOPRIO_WHO_PGRP:
			if (!who)
				pgrp = task_pgrp(current);
			else
				pgrp = find_vpid(who);
			do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
				ret = set_task_ioprio(p, ioprio);
				if (ret)
					break;
			} while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
			break;
		case IOPRIO_WHO_USER:
			if (!who)
				user = current_user();
			else
				user = find_user(who);

			if (!user)
				break;

			do_each_thread(g, p) {
				if (__task_cred(p)->uid != who)
					continue;
				ret = set_task_ioprio(p, ioprio);
				if (ret)
					goto free_uid;
			} while_each_thread(g, p);
free_uid:
			if (who)
				free_uid(user);
			break;
		default:
			ret = -EINVAL;
	}
示例#7
0
bool TakeOwnership(UserManager *panel,bool selection)
{
  (void)selection;
  return AddOwnerInternal(panel,current_user());
}