1/*- 2 * Copyright (c) 2008-2011 Stanislav Sedov <stas@FreeBSD.org>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 */ 25 26/* 27 * This utility provides userland access to the cpuctl(4) pseudo-device 28 * features. 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/usr.sbin/cpucontrol/cpucontrol.c 235647 2012-05-19 12:44:27Z gleb $"); |
33 34#include <assert.h> 35#include <stdio.h> 36#include <stdlib.h> 37#include <string.h> 38#include <unistd.h> 39#include <fcntl.h> 40#include <err.h> --- 246 unchanged lines hidden (view full) --- 287static int 288do_update(const char *dev) 289{ 290 int fd; 291 unsigned int i; 292 int error; 293 struct ucode_handler *handler; 294 struct datadir *dir; |
295 DIR *dirp; |
296 struct dirent *direntry; 297 char buf[MAXPATHLEN]; 298 299 fd = open(dev, O_RDONLY); 300 if (fd < 0) { 301 WARN(0, "error opening %s for reading", dev); 302 return (1); 303 } --- 12 unchanged lines hidden (view full) --- 316 return (1); 317 } 318 close(fd); 319 320 /* 321 * Process every image in specified data directories. 322 */ 323 SLIST_FOREACH(dir, &datadirs, next) { |
324 dirp = opendir(dir->path); 325 if (dirp == NULL) { |
326 WARNX(1, "skipping directory %s: not accessible", dir->path); 327 continue; 328 } |
329 while ((direntry = readdir(dirp)) != NULL) { |
330 if (direntry->d_namlen == 0) 331 continue; 332 error = snprintf(buf, sizeof(buf), "%s/%s", dir->path, 333 direntry->d_name); 334 if ((unsigned)error >= sizeof(buf)) 335 WARNX(0, "skipping %s, buffer too short", 336 direntry->d_name); 337 if (isdir(buf) != 0) { 338 WARNX(2, "skipping %s: is a directory", buf); 339 continue; 340 } 341 handler->update(dev, buf); 342 } |
343 error = closedir(dirp); |
344 if (error != 0) 345 WARN(0, "closedir(%s)", dir->path); 346 } 347 return (0); 348} 349 350/* 351 * Add new data directory to the search list. --- 79 unchanged lines hidden --- |