[Bug 1851806] Re: 'module' object has no attribute 'O_PATH'

Benjamin Curtiss 1851806 at bugs.launchpad.net
Thu Nov 14 16:00:05 UTC 2019


I'm not exactly sure how to reproduce this bug, but I did encounter the
same issue. It looks like the bug was recently introduced in this
commit:
https://git.launchpad.net/ubuntu/+source/apport/commit/?h=applied/ubuntu
/xenial-security&id=ecd7418b02911c6649b69a592cca74cfbac8813d

```
@@ -510,22 +510,24 @@ class Report(problem_report.ProblemReport):
         - _LogindSession: logind cgroup path, if present (Used for filtering
           out crashes that happened in a session that is not running any more)
         '''
-        if not pid:
-            pid = self.pid or os.getpid()
-        if not self.pid:
-            self.pid = int(pid)
-        pid = str(pid)
+        if not proc_pid_fd:
+            if not pid:
+                pid = self.pid or os.getpid()
+            if not self.pid:
+                self.pid = int(pid)
+            pid = str(pid)
+            proc_pid_fd = os.open('/proc/%s' % pid, os.O_RDONLY | os.O_PATH | os.O_DIRECTORY)
 
         try:
-            self['ProcCwd'] = os.readlink('/proc/' + pid + '/cwd')
+            self['ProcCwd'] = os.readlink('cwd', dir_fd=proc_pid_fd)
         except OSError:
             pass
         self.add_proc_environ(pid, extraenv)
-        self['ProcStatus'] = _read_file('/proc/' + pid + '/status')
-        self['ProcCmdline'] = _read_file('/proc/' + pid + '/cmdline').rstrip('\0')
-        self['ProcMaps'] = _read_maps(int(pid))
+        self['ProcStatus'] = _read_file('status', dir_fd=proc_pid_fd)
+        self['ProcCmdline'] = _read_file('cmdline', dir_fd=proc_pid_fd).rstrip('\0')
+        self['ProcMaps'] = _read_maps(proc_pid_fd)
         try:
-            self['ExecutablePath'] = os.readlink('/proc/' + pid + '/exe')
+            self['ExecutablePath'] = os.readlink('exe', dir_fd=proc_pid_fd)
         except OSError as e:
             if e.errno == errno.ENOENT:
                 raise ValueError('invalid process')
```

The problem is that os.O_PATH does not exist in python2, and only exists
in python3. However, python-apport is a python2 package.

```
bcurtiss at bcurtiss-laptop:~$ python3 -c 'import os; print(os.O_PATH)'
2097152
bcurtiss at bcurtiss-laptop:~$ python -c 'import os; print(os.O_PATH)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'O_PATH'
bcurtiss at bcurtiss-laptop:~$
```

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to apport in Ubuntu.
https://bugs.launchpad.net/bugs/1851806

Title:
  'module' object has no attribute 'O_PATH'

Status in apport package in Ubuntu:
  Incomplete

Bug description:
  I encountered the following exception in python-apport while
  encountering an exception `bup` which uses `python-apport`. I'm sure
  that the exception lies in the responsibility of `python-apport` (the
  `AttributeError` stacktrace is relevant):

  ```
  Traceback (most recent call last):
    File "/usr/lib/bup/cmd/bup-index", line 269, in <module>
      update_index(rp, excluded_paths, exclude_rxs, xdev_exceptions=xexcept)
    File "/usr/lib/bup/cmd/bup-index", line 191, in update_index
      mi.close()
    File "/usr/lib/bup/bup/index.py", line 528, in close
      os.rename(self.tmpname, self.filename)
  OSError: [Errno 13] Permission denied
  Error in sys.excepthook:
  Traceback (most recent call last):
    File "/usr/lib/bup/bup/helpers.py", line 916, in newhook
      return oldhook(exctype, value, traceback)
    File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 109, in apport_excepthook
      pr.add_proc_info(extraenv=['PYTHONPATH', 'PYTHONHOME'])
    File "/usr/lib/python2.7/dist-packages/apport/report.py", line 544, in add_proc_info
      proc_pid_fd = os.open('/proc/%s' % pid, os.O_RDONLY | os.O_PATH | os.O_DIRECTORY)
  AttributeError: 'module' object has no attribute 'O_PATH'

  Original exception was:
  Traceback (most recent call last):
    File "/usr/lib/bup/cmd/bup-index", line 269, in <module>
      update_index(rp, excluded_paths, exclude_rxs, xdev_exceptions=xexcept)
    File "/usr/lib/bup/cmd/bup-index", line 191, in update_index
      mi.close()
    File "/usr/lib/bup/bup/index.py", line 528, in close
      os.rename(self.tmpname, self.filename)
  OSError: [Errno 13] Permission denied
  ```

  ProblemType: Bug
  DistroRelease: Ubuntu 19.10
  Package: python-apport 2.20.11-0ubuntu8.2
  ProcVersionSignature: Ubuntu 5.3.0-19.20-generic 5.3.1
  Uname: Linux 5.3.0-19-generic x86_64
  NonfreeKernelModules: zfs zunicode zavl icp zcommon znvpair
  ApportLog: Error: [Errno 13] Keine Berechtigung: '/var/log/apport.log'
  ApportVersion: 2.20.11-0ubuntu8.2
  Architecture: amd64
  CurrentDesktop: ubuntu:GNOME
  Date: Fri Nov  8 10:43:02 2019
  PackageArchitecture: all
  SourcePackage: apport
  UpgradeStatus: Upgraded to eoan on 2019-10-25 (13 days ago)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/apport/+bug/1851806/+subscriptions



More information about the foundations-bugs mailing list