I'm trying to learn low level graphics programming on linux using C. I'm fairly new to both linux and C. I'm trying to figure out the most responsible way to manage permissions for /dev/fb0
in my code.
my code:
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
int main(){
int fb_fd = 0;
// Open the file for reading and writing
fb_fd = open("/dev/fb0", O_RDWR);
if (fb_fd == -1) {
perror("Error: cannot open framebuffer device");
exit(1);
}
printf("The framebuffer device was opened successfully.\n");
struct fb_fix_screeninfo finfo;
struct fb_var_screeninfo vinfo;
//Get variable screen information
ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo);
//Get fixed screen information
ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo);
printf("vinfo.bits_per-pixel: %d\n",vinfo.bits_per_pixel);
close(fb_fd);
return(0);
}
My issue: the program only runs using sudo ./my_program
, otherwise it fails to open the frame buffer (permission denied). I'm not sure how permissions for /dev/fb0
are typically managed when writing software that is meant to draw to the frame buffer. How do I "give permission" to my program , to be run by a normal user without special permissions?
Edit: as requested, some console output: setting mode and permisions
~/learning_c/game_0$ ls -l /dev/fb0
crw-rw---- 1 root video 29, 0 Oct 28 08:01 /dev/fb0
~/learning_c/game_0$ ls -l ./bin/game
-rwxrwxr-x 1 logan logan 15160 Oct 29 21:12 ./bin/game
~/learning_c/game_0$ chgrp video ./bin/game
chgrp: changing group of './bin/game': Operation not permitted
~/learning_c/game_0$ sudo chgrp video ./bin/game
[sudo] password for logan:
~/learning_c/game_0$ ls -l ./bin/game
-rwxrwxr-x 1 logan video 15160 Oct 29 21:12 ./bin/game
~/learning_c/game_0$ sudo chmod -v g+s ./bin/game
mode of './bin/game' changed from 0775 (rwxrwxr-x) to 2775 (rwxrwsr-x)
~/learning_c/game_0$ ls -l ./bin/game
-rwxrwsr-x 1 logan video 15160 Oct 29 21:12 ./bin/game
try to run ./bin/game
~/learning_c/game_0$ ./bin/game
Error: cannot open framebuffer device: Permission denied
logan@logan-Aspire-5560:~/learning_c/game_0$ sudo ./bin/game
[sudo] password for logan:
The framebuffer device was opened successfully