cloudshell lcd script for rootless lcd toggling

Moderators: mdrjr, odroid

cloudshell lcd script for rootless lcd toggling

Unread postby yysh12 » Sun Apr 29, 2018 4:43 am

Nothing fancy just though I'd post if for anyone who doesn't want to do it themselves and wants a quick solution. Basically a shell script that requires root status to toggle lcd is executed through a compiled c program with setgid to root. note I was told this is dangerous since anyone with access to the shell script can modify it and run it as root (which is the whole reason I think linux doesn't allow for setgid root on shell scripts). make sure to adjust filepaths in c program and adjust permissions and setgid on your own.

c code:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <iostream>

//need a better solution to this someday

using namespace std;

int main(int argc, char* argv[])
if ( argv[1][1] == 'f') {
cout<<"turning off"<<endl;
system("/home/Bin/ off"); //path to shell script
} else if ( argv[1][1] == 'n' ) {
cout<<"turning on"<<endl;
system("/home/Bin/ on"); //path to shell script
else {
return 0;

shell script
Code: Select all

if [ $1 = "off" ]
echo 1 > /sys/class/backlight/*/bl_power
elif [ $1 = "on" ]
echo 0 > /sys/class/backlight/*/bl_power
echo "parameters must be either 'on' or 'off'"

lastly setgid to root and adjust bin paths and permissions
Posts: 8
Joined: Mon Dec 18, 2017 2:37 am
languages_spoken: english
ODROIDs: Odroid XU and now also XU4

Re: cloudshell lcd script for rootless lcd toggling

Unread postby rooted » Sun Apr 29, 2018 5:32 am

You can run a shell script like it's an executable, why the C file?

I missed the setgid
User avatar
Posts: 5297
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1, C1+, C2
XU3 Lite, XU4
HiFi Shield 2
Smart Power (original)

Return to CloudShell

Who is online

Users browsing this forum: No registered users and 0 guests