Skip to content
Advertisement

Can I use QFile to truncate a write protected file?

I am not running the application itself as root.

Rather than do a convoluted

pkexec sh -c 'echo 50 > /sys/devices/system/cpu/intel_pstate/min_perf_pct'

With QProcess, I would rather simply open /sys/devices/system/cpu/intel_pstate/min_perf_pct and truncate a number into it. It would look something like this:

QFile f("/sys/devices/system/cpu/intel_pstate/min_perf_pct");
if ( f->open( QIODevice::WriteOnly | QIODevice::Truncate ) ) {
        f->write( QByteArray::number(n) )
};

Is there a way to do this without having to start or run any other part of the application as root?
I am using pkexec for sudo prompts.

Thanks.

Advertisement

Answer

Is there a way to do this without having to start or run any other part of the application as root?

No. Otherwise that would defeat the whole purpose of the file permission system.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement