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#pragma ident	"%Z%%M%	%I%	%E% SMI"
13
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18#include <errno.h>
19#include <string.h>
20#include <strings.h>
21#include <ctype.h>
22#include <stdlib.h>
23#include <stdio.h>
24#include <sys/ioctl.h>
25#include <fcntl.h>
26#include <unistd.h>
27#include <sys/acpi_drv.h>
28#include "../../hald/util.h"
29
30int
31main(int argc, char *argv[])
32{
33	char arg[10];
34	int level;
35	int fd = -1;
36	char *udi;
37	char device_file[HAL_PATH_MAX] = "/devices";
38	char *devfs_path;
39
40	if ((udi = getenv("UDI")) == NULL) {
41		return (1);
42	}
43	if ((devfs_path = getenv("HAL_PROP_SOLARIS_DEVFS_PATH")) == NULL) {
44		return (1);
45	}
46	strlcat(device_file, devfs_path, HAL_PATH_MAX);
47	fprintf(stderr, "Setting brightness on %s (udi=%s)",
48	    device_file, udi);
49
50	if ((fd = open(device_file, O_RDONLY | O_NONBLOCK)) < 0) {
51		fprintf(stderr, "Cannot open %s: %s", device_file,
52		    strerror(errno));
53		return (1);
54	}
55	if (fgets(arg, sizeof (arg), stdin)) {
56		level = atoi(arg);
57	}
58	if (ioctl(fd, ACPI_DRV_IOC_SET_BRIGHTNESS, &level) < 0) {
59		close(fd);
60		return (1);
61	} else {
62		close(fd);
63		return (0);
64	}
65}
66