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