[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

rpms/udev/devel firmware_helper.c, NONE, 1.1 udev.rules, 1.29, 1.30 udev.spec, 1.94, 1.95



Author: notting

Update of /cvs/dist/rpms/udev/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv5011

Modified Files:
	udev.rules udev.spec 
Added Files:
	firmware_helper.c 
Log Message:
obsolete firmware.agent too



--- NEW FILE firmware_helper.c ---
/*
 * A simple firmware helper program.
 * 
 * Copyright 2005 Red Hat, Inc.
 *
 * This software may be freely redistributed under the terms of the GNU
 * public license.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>

#include <sys/stat.h>

#define FIRMWARE_PATH	"/lib/firmware"


void log_err(char *firmware, int err) {
	char *driver;
	
	driver = getenv("PHYSDEVDRIVER");
	if (!driver)
		driver = "(unknown)";
	openlog("firmware_helper",LOG_PID,LOG_USER);
	syslog(LOG_ERR,"Loading of %s for %s driver failed: %s",firmware, driver, strerror(err));
	closelog();
}

/* Set the 'loading' attribute for a firmware device.
 * 1 == currently loading
 * 0 == done loading
 * -1 == error
 */
int set_loading(char *device, int value) {
	char *path;
	int rc;
	FILE *f;
	
	path = alloca(strlen(device)+15);
	sprintf(path,"/sys/%s/loading", device);
	f = fopen(path, "w");
	if (!f)
		return 1;
	rc = fprintf(f, "%d", value);
	fclose(f);
	if (rc < 0)
		return rc;
	return 0;
}
	

int main(int argc, char **argv) {
	char *devpath, *firmware, *action;
	struct stat sbuf;
	int fw_fd, count;
	int rc;
	char *fw_path, *data_path;
	char *fw_buffer;
	
	devpath = getenv("DEVPATH");
	if (!devpath) return 0;
	
	firmware = getenv("FIRMWARE");
	if (!firmware) return 0;
	
	action = getenv("ACTION");
	if (strcmp(action,"add"))
		return 0;

	set_loading(devpath, 1);
	
	fw_path = malloc(strlen(FIRMWARE_PATH) + strlen(firmware) + 2);
	if (!fw_path) {
		rc = errno;
		goto out_err;
	}
	
	sprintf(fw_path,"%s/%s", FIRMWARE_PATH, firmware);
	fw_fd = open(fw_path, O_RDONLY);
	if (fw_fd == -1) {
		rc = errno;
		goto out_err;
	}
	
	fstat(fw_fd, &sbuf);
	fw_buffer = malloc(sbuf.st_size);
	if (!fw_buffer) {
		rc = errno;
		goto out_err;
	}
	if (read(fw_fd, fw_buffer, sbuf.st_size) != sbuf.st_size) {
		rc = errno;
		goto out_err;
	}
	close(fw_fd);
	
	data_path = malloc(strlen(devpath) + 12);
	if (!data_path) {
		rc = errno;
		goto out_err;
	}
	
	sprintf(data_path,"/sys/%s/data", devpath);
	
	fw_fd = open(data_path, O_RDWR);
	if (fw_fd == -1) {
		rc = errno;
		goto out_err;
	}
	
	count = 0;
	while (count < sbuf.st_size) {
		int c;
		
		c = write(fw_fd,fw_buffer+count,sbuf.st_size-count);
		if (c <= 0) {
			rc = errno;
			goto out_err;
		}
		count += c;
	}
	close(fw_fd);
	set_loading(devpath, 0);
	return 0;
out_err:
	close(fw_fd);
	set_loading(devpath, -1);
	log_err(fw_path, rc);
	return rc;
}


Index: udev.rules
===================================================================
RCS file: /cvs/dist/rpms/udev/devel/udev.rules,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- udev.rules	19 Jul 2005 20:03:37 -0000	1.29
+++ udev.rules	19 Jul 2005 23:59:03 -0000	1.30
@@ -254,3 +254,8 @@
 	RUN+="/sbin/modprobe st"
 ACTION=="add", SUBSYSTEM=="scsi", SYSFS{type}=="[23689]", \
 	RUN+="/sbin/modprobe sg"
+
+ACTION=="add", SUBSYSTEM=="firmware", FIRMWARE="*", \
+        RUN+="/sbin/firmware_helper"
+
+	
\ No newline at end of file


Index: udev.spec
===================================================================
RCS file: /cvs/dist/rpms/udev/devel/udev.spec,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -r1.94 -r1.95
--- udev.spec	14 Jul 2005 04:05:11 -0000	1.94
+++ udev.spec	19 Jul 2005 23:59:03 -0000	1.95
@@ -36,6 +36,8 @@
 
 Source23: udevpermconv.sh
 
+Source30: firmware_helper.c
+
 Patch1: udev-062-build.patch
 Patch50: udev-039-scsi_id-tmp_dir.patch
 
@@ -111,6 +113,8 @@
 	"
         #extras/volume_id  
 
+%{__cc} %{optflags} -o firmware_helper %{SOURCE30}
+
 %install
 rm -rf $RPM_BUILD_ROOT
 
@@ -175,7 +179,7 @@
 done
 install -m 0755 %{SOURCE5} $RPM_BUILD_ROOT%{_sysconfdir}/udev/scripts/
 
-
+install -m 0755 firmware_helper $RPM_BUILD_ROOT/sbin
 
 %preun
 if [ $1 = 0 -a -f %{_initrddir}/udev ]; then
@@ -228,6 +232,7 @@
 %attr(755,root,root) /sbin/ata_id
 %attr(755,root,root) /sbin/ata_id.static
 %attr(755,root,root) /sbin/usb_id
+%attr(755,root,root) /sbin/firmware_helper
 
 %attr(0755,root,root) %{_bindir}/udevtest
 %attr(0755,root,root) %{_bindir}/udevinfo


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]