mirror of
https://github.com/X11Libre/xf86-video-intel.git
synced 2026-03-24 01:24:12 +00:00
Since the helper is a standalone app, the usual xserver rules of not using stdio because of signal handling don't apply. And since the helper does run with elevated rights, it is important to keep the code KISS so that it can be audited easily. This commit replaces the hard to read "raw" read loop with a much simpler loop using fgets, improving readability of the code. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
37 lines
745 B
C
37 lines
745 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
struct stat st;
|
|
char buf[1024];
|
|
int len, fd;
|
|
|
|
if (argc != 2) {
|
|
fprintf(stderr, "Usage: %s <iface>\n", argv[0]);
|
|
return 1;
|
|
}
|
|
|
|
snprintf(buf, sizeof(buf), "/sys/class/backlight/%s/brightness", argv[1]);
|
|
fd = open(buf, O_RDWR);
|
|
if (fd < 0 || fstat(fd, &st) || major(st.st_dev)) {
|
|
fprintf(stderr, "Cannot access backlight interface '%s'\n", argv[1]);
|
|
return 1;
|
|
}
|
|
|
|
while (fgets(buf, sizeof(buf), stdin)) {
|
|
len = strlen(buf);
|
|
if (write(fd, buf, len) != len) {
|
|
fprintf(stderr, "Failed to update backlight interface '%s'\n", argv[1]);
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|