Eunuchs -- Missing manly parts of UNIX API for Python

Tommi Virtanen [email protected]

What is it?

  • library of Python extensions (C, pyrex)
  • small syscall/libc wrappers
  • where full support for the UNIX API (or the Linux API) is missing from stdlib

Why?

  • instant availability of new wrappers (for me)
  • fast availability of new wrappers (for others)
  • Python APIs not always established

Current contents

  • tuntap

  • fchdir

  • recvmsg, sendmsg

    • IP_PKTINFO support
  • socketpair

Example: fchdir(2)

#include <Python.h>
#include <unistd.h>

/* int fchdir(int fd); */
static PyObject *my_fchdir(PyObject *self,
						   PyObject *args) {
  int fd;
  int ret;

  if (!PyArg_ParseTuple(args, "i", &fd))
	return NULL;
  ret = fchdir(fd);
  if (ret<0) {
	PyErr_SetFromErrno(PyExc_OSError);
	return NULL;
  }
  Py_INCREF(Py_None);
  return Py_None;
}

static PyMethodDef my_methods[] = {
  {
	"fchdir", my_fchdir,
	METH_VARARGS,
	"fchdir(fd)"
  },

  {NULL, NULL, 0, NULL}
};

void initfchdir(void) {
  Py_InitModule("fchdir",
				my_methods);
}

Example: fchdir(2) with pyrex

static PyMethodDef my_methods[] = {
  {
	"fchdir", my_fchdir,
	METH_VARARGS,
	"fchdir(fd)"
  },

  {NULL, NULL, 0, NULL}
};

void initfchdir(void) {
  Py_InitModule("fchdir",
				my_methods);
}

Aspects of the UNIX API

  • low-level
  • dirty
  • absolutely necessary
  • real systems programming

Goal for me

  • have the functions added to mainstream Python libraries
  • what do I need to do?
  • pyrex not acceptable?

Goal for you

  • don't write yet another small library
  • send me a patch

Thank You

For more information

Questions?