martinpitt / umockdev

Mock hardware devices for creating unit tests and bug reporting
https://launchpad.net/umockdev
GNU Lesser General Public License v2.1
308 stars 55 forks source link

Environment API #186

Closed benzea closed 2 years ago

benzea commented 2 years ago

So, this adds a function returning an char** (same as g_get_environ).

Not sure what makes sense though. In python returning a dictionary would be more convenient. So maybe we should just expose both types of utility functions. This and a GHashtTable return or so.

Or just hash table.

Note that I kind of tried to get things to work using an xattr instead. But, turns out, tmpfs does not allow setting arbitrary values. I did manage to get it to run (except for nix) by setting a special ACL on the file (system.posix_acl_access xattr), but that is just one bit of information, which could probable be done using a sticky bit already ...

Or we could touch a .umockdev file in every device node, and then openat(fd, ".umockdev") to decide on whether to override ...

In conclusion, lets just do this, everything else is complicated and with questionable benefits.

benzea commented 2 years ago

I suppose, python usage would be:

env = os.environ.copy()
env.update(v.split('=', 1) for v in testbed.get_environ())
martinpitt commented 2 years ago

Thanks! TBH I don't really like this, it's sort of giving up on the idea of umockdev. Tomorrow morning I have a few hours in a train and I'll see if it's possible to mock the filesystem stat'ing enough to pacify udev without setting this env variable. If that fails, we can still add this.

benzea commented 2 years ago

@martinpitt, please have a look at my benzea/misc branch then!

benzea commented 2 years ago

Oh, so, I just realised that /proc/self/fd actually shows the path for a file descriptor. So, maybe that is sufficient and much easier to do it then. e.g.

ls -l /proc/self/fd 1000</sys/class/power_supply/BAT0/

martinpitt commented 2 years ago

@benzea : Right, that was my approach. See https://github.com/systemd/systemd/issues/23499#issuecomment-1140855325

martinpitt commented 2 years ago

Let's close this for now, then?