[arch-general] Get netctl status from C?
I run dwm with a custom C program to update the status bar. So far I can check everything without needing to exec(), e.g. through libmpd, parsing /proc/meminfo, and so on. Is there a way to interface with the netctl profile system from C? I really just want to find the currently actively profile. I pulled down the code for netctl with abs and it seems to amount largely to shell scripts that will with stuff in /sys. It doesn't look too daunting, but I'd prefer a native interface if one exists. Thanks, Daniel
On Sun, Dec 15, 2013 at 7:01 AM, Daniel Bryan <danbryan@gmail.com> wrote:
I run dwm with a custom C program to update the status bar.
So far I can check everything without needing to exec(), e.g. through libmpd, parsing /proc/meminfo, and so on.
Is there a way to interface with the netctl profile system from C? I really just want to find the currently actively profile.
I think there isn't explicitly any process running after netctl is done configuring the network configuration. So you should either get more specific about the kind of information you want, so whether you are talking about network state or netctl's opinion about it (not that these are likely to diverge, but there's my point)... Uhm... a glance into netctl's source just revealed it's a bash script. You'll need exec anyway. I'd be interested in the features you added, have you considered githubbing your customizations? cheers! mar77i
On Sun, Dec 15, 2013 at 12:32 PM, Martti Kühne <mysatyre@gmail.com> wrote:
I think there isn't explicitly any process running after netctl is done configuring the network configuration. So you should either get more specific about the kind of information you want, so whether you are talking about network state or netctl's opinion about it (not that these are likely to diverge, but there's my point)...
Uhm... a glance into netctl's source just revealed it's a bash script. You'll need exec anyway.
wait. so: https://github.com/joukewitteveen/netctl/blob/master/src/lib/globals#L6 char *statefile = getenv("NETCTL_STATE_FILE"); FILE *f; if(!statefile) statefile = "/var/lib/netctl/netctl.state"; // from /usr/lib/network/globals f = fopen(statefile, "r"); if(f) { // parse whatever you find there... } but... I think the point in running netctl is that running it would update said state file. So, the state file might be there and all. That's how I believe these diverge. You'd have to analyze what netctl does there and replicate that in c, but ... no really, use exec(). cheers! mar77i
On Sun, Dec 15, 2013 at 7:01 AM, Daniel Bryan <danbryan@gmail.com> wrote:
I run dwm with a custom C program to update the status bar.
So far I can check everything without needing to exec(), e.g. through libmpd, parsing /proc/meminfo, and so on.
Is there a way to interface with the netctl profile system from C? I really just want to find the currently actively profile.
I pulled down the code for netctl with abs and it seems to amount largely to shell scripts that will with stuff in /sys. It doesn't look too daunting, but I'd prefer a native interface if one exists.
Thanks,
Daniel
netctl profiles are actually systemd units: if the profile is "foo" then the unit is "netctl@foo.service". And systemd has a C interface by using dbus, I think... HTH -- Rodrigo
participants (3)
-
Daniel Bryan
-
Martti Kühne
-
Rodrigo Rivas