syscall sigsuspend返回-ERESTARTNOHAND,我该怎么办?

时间:2019-10-28 08:38:45

标签: android signals system-calls

我在我的应用中调用syscall sigsuspend (API sys_sigsuspend ),错误号为 < em> -ERESTARTNOHAND 。但是我在errno.h中得到了以下信息,看来我 不应 在我的应用程序中得到errno。

 /*
    8  * These should never be seen by user programs.  To return one of ERESTART*
    9  * codes, signal_pending() MUST be set.  Note that ptrace can observe these
   10  * at syscall exit tracing, but they will never be left for the debugged user
   11  * process to see.
   12  */
   13 #define ERESTARTSYS 512
   14 #define ERESTARTNOINTR  513
   15 #define ERESTARTNOHAND  514 /* ***restart if no handler..*** */

然后我检查内核代码,ERESTARTNOHAND将被转换为EINTR,似乎永远不会返回用户空间。

void do_signal(struct pt_regs *regs)
{
    struct ksignal ksig;

    if (get_signal(&ksig)) {
        /* Whee! Actually deliver the signal.  */
        handle_signal(&ksig, regs);
        return;
    }

    /* Did we come from a system call? */
    if (syscall_get_nr(current, regs) >= 0) {
        /* Restart the system call - no handlers present */
        switch (syscall_get_error(current, regs)) {
        case -ERESTARTNOHAND:
        case -ERESTARTSYS:
        case -ERESTARTNOINTR:
            regs->ax = regs->orig_ax;
            regs->ip -= 2;
            break;

        case -ERESTART_RESTARTBLOCK:
            regs->ax = get_nr_restart_syscall(regs);
            regs->ip -= 2;
            break;
        }
    }

    /*
     * If there's no signal to deliver, we just put the saved sigmask
     * back.
     */
    restore_saved_sigmask();
}

handle_signal(struct ksignal *ksig, struct pt_regs *regs)
{
    bool stepping, failed;
    struct fpu *fpu = &current->thread.fpu;

    if (v8086_mode(regs))
        save_v86_state((struct kernel_vm86_regs *) regs, VM86_SIGNAL);

    /* Are we from a system call? */
    if (syscall_get_nr(current, regs) >= 0) {
        /* If so, check system call restarting.. */
        switch (syscall_get_error(current, regs)) {
        case -ERESTART_RESTARTBLOCK:
        case -ERESTARTNOHAND:
            regs->ax = -EINTR;
            break;
        ......
}

我的问题是

  1. 为什么我得到错误号-ERESTARTNOHAND?
  2. 当我收到errno时,我应该怎么做? 重试系统调用还是不执行任何操作

0 个答案:

没有答案