Using JS to write to file under /sys
- From: Alessandro Crismani <alessandro crismani gmail com>
- To: gnome-shell-list gnome org
- Subject: Using JS to write to file under /sys
- Date: Fri, 27 Jul 2012 01:04:27 +0200
Hi there,
I do not know if this list is the right ML for this question, but I do
not know where exactly it should go. Suggestions are welcomed if I am
out of scope.
I am trying to write a GJS program (which at some point I might turn
into a Gnome Shell extension) that modifies files under /sys.
Particularly, I want to write 0 or 1 into some files that regulate the
behaviour of my Samsung laptop's battery life extender technology,
silent mode and other stuff. These file are under
/sys/devices/platform/samsung and hence require root access. Here come
the questions:
1) Which is the best way to grant root privileges to such a program? I
though about using policykit, but I didn't find much about it when
combined with GJS. Does anybody have a stupid example on how to give
permission to write to such a file to a GJS program? Do I have to run
the program as pkexec program.js, or can I just execute some of its
parts with higher privileges?
2) I tried avoiding the permission thing by running the program as root,
for seeing whether it was working or not. It seems that my way of
writing to a file fails even if I have proper permissions (root can echo
to such file). What I tried is:
const batteryFile = "/sys/devices/platform/samsung/battery_life_extender";
GLib.file_set_contents(batteryFile, "1");
but I get an error that sounds like:
root at alessandro-sammy in /data/Documenti/Linux/SammySettings
# LC_ALL=C gjs SammySettings.js
JS ERROR: !!! Exception was: Error: Error invoking
GLib.file_set_contents: Failed to create file
'/sys/devices/platform/samsung/battery_life_extender.ZTDFIW': No such
file or directory
JS ERROR: !!! lineNumber = '0'
JS ERROR: !!! fileName = '"gjs_throw"'
JS ERROR: !!! stack = '"("Error invoking GLib.file_set_contents:
Failed to create file
'/sys/devices/platform/samsung/battery_life_extender.ZTDFIW': No such
file or directory")@gjs_throw:0
([object _private_Gtk_Switch],[object
_private_GObject_ParamSpec])@SammySettings.js:108
wrapper([object _private_Gtk_Switch],[object
_private_GObject_ParamSpec])@/usr/share/gjs-1.0/lang.js:204
@SammySettings.js:146
"'
JS ERROR: !!! message = '"Error invoking GLib.file_set_contents:
Failed to create file
'/sys/devices/platform/samsung/battery_life_extender.ZTDFIW': No such
file or directory"'
What am I missing? Which is *the* way for modifying such root owned
files (without changing their ownership, obviously)?
Thanks a lot, and sorry if these questions sound stupid, but I am really
new to this kind of things and I do not know where to search/ask.
Cheers,
Alessandro
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]