[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Git][ftp-team/dak][master] 2 commits: gpg.py: convert waitstatus to exitcode before use



Title: GitLab

Ansgar pushed to branch master at Debian FTP Team / dak

Commits:

  • 4b990139
    by Ansgar at 2022-06-30T11:07:39+02:00
    gpg.py: convert waitstatus to exitcode before use
    
  • a97ee22e
    by Ansgar at 2022-06-30T11:07:58+02:00
    gpg.py: assert that wait4() waited for the expected pid
    

1 changed file:

Changes:

  • daklib/gpg.py
    ... ... @@ -65,6 +65,16 @@ class _Pipe:
    65 65
                 self.w = None
    
    66 66
     
    
    67 67
     
    
    68
    +# Can be replaced with `os.waitstatus_to_exitcode` (Python 3.9)
    
    69
    +def waitstatus_to_exitcode(status):
    
    70
    +    if os.WIFEXITED(status):
    
    71
    +        return os.WEXITSTATUS(status)
    
    72
    +    elif os.WIFSIGNALED(status):
    
    73
    +        return -os.WTERMSIG(status)
    
    74
    +    else:
    
    75
    +        raise ValueError(f"Unexpected status code '{status}'")
    
    76
    +
    
    77
    +
    
    68 78
     class SignedFile:
    
    69 79
         """handle files signed with PGP
    
    70 80
     
    
    ... ... @@ -128,7 +138,10 @@ class SignedFile:
    128 138
                     read = self._do_io([contents.r, stderr.r, status.r], {stdin.w: data})
    
    129 139
                     stdin.w = None # was closed by _do_io
    
    130 140
     
    
    131
    -                (pid_, exit_code, usage_) = os.wait4(pid, 0)
    
    141
    +                (pid_, status_code, usage_) = os.wait4(pid, 0)
    
    142
    +                if pid_ != pid:
    
    143
    +                    raise Exception(f"wait4() waited for pid {pid_}, but we expected {pid}")
    
    144
    +                exit_code = waitstatus_to_exitcode(status_code)
    
    132 145
     
    
    133 146
                     self.contents = read[contents.r]
    
    134 147
                     self.status = read[status.r]
    


  • Reply to: