1 /*************************************************************************** 2 * 3 * hal-system-lcd-set-brightness-sunos.c : Set LCD brightness 4 * 5 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 6 * Use is subject to license terms. 7 * 8 * Licensed under the Academic Free License version 2.1 9 * 10 **************************************************************************/ 11 12 #ifdef HAVE_CONFIG_H 13 #include <config.h> 14 #endif 15 16 #include <errno.h> 17 #include <string.h> 18 #include <strings.h> 19 #include <ctype.h> 20 #include <stdlib.h> 21 #include <stdio.h> 22 #include <sys/ioctl.h> 23 #include <fcntl.h> 24 #include <unistd.h> 25 #include <sys/acpi_drv.h> 26 #include "../../hald/util.h" 27 28 int 29 main(int argc, char *argv[]) 30 { 31 char arg[10]; 32 int level; 33 int fd = -1; 34 char *udi; 35 char device_file[HAL_PATH_MAX] = "/devices"; 36 char *devfs_path; 37 38 if ((udi = getenv("UDI")) == NULL) { 39 return (1); 40 } 41 if ((devfs_path = getenv("HAL_PROP_SOLARIS_DEVFS_PATH")) == NULL) { 42 return (1); 43 } 44 strlcat(device_file, devfs_path, HAL_PATH_MAX); 45 fprintf(stderr, "Setting brightness on %s (udi=%s)", 46 device_file, udi); 47 48 if ((fd = open(device_file, O_RDONLY | O_NONBLOCK)) < 0) { 49 fprintf(stderr, "Cannot open %s: %s", device_file, 50 strerror(errno)); 51 return (1); 52 } 53 if (fgets(arg, sizeof (arg), stdin)) { 54 level = atoi(arg); 55 } 56 if (ioctl(fd, ACPI_DRV_IOC_SET_BRIGHTNESS, &level) < 0) { 57 close(fd); 58 return (1); 59 } else { 60 close(fd); 61 return (0); 62 } 63 } 64