• linux系统调用kernel code


    linux系统调用kernel code

    kernelincludeuapiasm-genericunistd.h

    kernel/sys.c

    SYSCALL_DEFINE2(setpgid, pid_t, pid, pid_t, pgid)
    {
        struct task_struct *p;
        struct task_struct *group_leader = current->group_leader;
        struct pid *pgrp;
        int err;
    
        if (!pid)
            pid = task_pid_vnr(group_leader);
        if (!pgid)
            pgid = pid;
        if (pgid < 0)
            return -EINVAL;
        rcu_read_lock();
    
        /* From this point forward we keep holding onto the tasklist lock
         * so that our parent does not change from under us. -DaveM
         */
        write_lock_irq(&tasklist_lock);
    
        err = -ESRCH;
        p = find_task_by_vpid(pid);
        if (!p)
            goto out;
    
        err = -EINVAL;
        if (!thread_group_leader(p))
            goto out;
    
        if (same_thread_group(p->real_parent, group_leader)) {
            err = -EPERM;
            if (task_session(p) != task_session(group_leader))
                goto out;
            err = -EACCES;
            if (!(p->flags & PF_FORKNOEXEC))
                goto out;
        } else {
            err = -ESRCH;
            if (p != group_leader)
                goto out;
        }
    
        err = -EPERM;
        if (p->signal->leader)
            goto out;
    
        pgrp = task_pid(p);
        if (pgid != pid) {
            struct task_struct *g;
    
            pgrp = find_vpid(pgid);
            g = pid_task(pgrp, PIDTYPE_PGID);
            if (!g || task_session(g) != task_session(group_leader))
                goto out;
        }
    
        err = security_task_setpgid(p, pgid);
        if (err)
            goto out;
    
        if (task_pgrp(p) != pgrp)
            change_pid(p, PIDTYPE_PGID, pgrp);
    
        err = 0;
    out:
        /* All paths lead to here, thus we are safe. -DaveM */
        write_unlock_irq(&tasklist_lock);
        rcu_read_unlock();
        return err;
    }
  • 相关阅读:
    芯片手冊写错了,非常悲剧
    编程之美读书笔记1.8
    贪心算法
    codeforces Looksery Cup 2015 D. Haar Features
    NS3网络仿真(5): 数据包分析
    hdu1116 Play on Words--并查集
    程序猿生存定律-六个程序猿的故事(2)
    保存Activity的状态
    9月份入读哈工大计算机研究生了
    leetcode第一刷_Same Tree
  • 原文地址:https://www.cnblogs.com/aspirs/p/12541414.html
Copyright © 2020-2023  润新知