Re: Using JS to write to file under /sys



Il 27/07/2012 01:04, Alessandro Crismani ha scritto:
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"'

Ok, I guess that file because it tries to create a temp file and then replace the original one with it. That doesn't work under /sys.

I also tried something like:
        let _batteryGFile = Gio.file_new_for_path(batteryFile);
let _batteryOut = _batteryGFile.replace(null, false, Gio.FileCreateFlags.NONE, null); let _batteryStream = new Gio.DataOutputStream({ base_stream: _batteryOut});
        _batteryStream.put_string("1", null);
        _batteryStream.close(null);

But it throws an error too:
JS ERROR: !!! message = '"Error invoking Gio.close: Error writing to file: Invalid argument"'

Both solutions work when I try to write a file in my home, hence they should be ok from the tpo pint of view.

I am thinking of spawning a damn "echo 1" and get the work done, but it seems to be *horribly* bad. Anyone has a better idea? How am I supposed to change such config files according to some good programming rules?

Thanks a lot!
Alessandro




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]