$(udev_common_CFLAGS)
udevd_LDADD = \
- $(udev_common_LDADD)
+ $(udev_common_LDADD) \
+ libsystemd-basic.la
udevd_CPPFLAGS = \
$(udev_common_CPPFLAGS)
$(udev_common_CFLAGS)
udevadm_LDADD = \
- $(udev_common_LDADD)
+ $(udev_common_LDADD) \
+ libsystemd-basic.la
udevadm_CPPFLAGS = \
$(udev_common_CPPFLAGS)
src/udev/ata_id/ata_id.c
ata_id_LDADD = \
- libudev-private.la
+ libudev-private.la \
+ libsystemd-basic.la
udevlibexec_PROGRAMS += \
ata_id
src/udev/cdrom_id/cdrom_id.c
cdrom_id_LDADD = \
- libudev-private.la
+ libudev-private.la \
+ libsystemd-basic.la
udevlibexec_PROGRAMS += \
cdrom_id
src/udev/scsi_id/scsi_id.h
scsi_id_LDADD = \
- libudev-private.la
+ libudev-private.la \
+ libsystemd-basic.la
udevlibexec_PROGRAMS += \
scsi_id
src/udev/accelerometer/accelerometer.c
accelerometer_LDADD = \
- libudev-private.la -lm
+ libudev-private.la -lm \
+ libsystemd-basic.la
udevlibexec_PROGRAMS += \
accelerometer
Bugfixes:
+* do not link selinux and attr against all binaries
* swap units that are activated by one name but shown in the kernel under another are semi-broken
if (udev == NULL)
return 1;
- udev_log_init("input_id");
+ log_open();
udev_set_log_fn(udev, log_fn);
/* CLI argument parsing */
return 0;
}
- info(udev, "Opening accelerometer device %s\n", devnode);
+ log_debug("opening accelerometer device %s\n", devnode);
test_orientation(udev, dev, devnode);
free(devnode);
-
+ log_close();
return 0;
}
#include "libudev.h"
#include "libudev-private.h"
+#include "log.h"
#define COMMAND_TIMEOUT_MSEC (30 * 1000)
if (udev == NULL)
goto exit;
- udev_log_init("ata_id");
+ log_open();
udev_set_log_fn(udev, log_fn);
while (1) {
node = argv[optind];
if (node == NULL) {
- err(udev, "no node specified\n");
+ log_error("no node specified\n");
rc = 1;
goto exit;
}
fd = open(node, O_RDONLY|O_NONBLOCK);
if (fd < 0) {
- err(udev, "unable to open '%s'\n", node);
+ log_error("unable to open '%s'\n", node);
rc = 1;
goto exit;
}
} else {
/* If this fails, then try HDIO_GET_IDENTITY */
if (ioctl(fd, HDIO_GET_IDENTITY, &id) != 0) {
- info(udev, "HDIO_GET_IDENTITY failed for '%s': %m\n", node);
+ log_info("HDIO_GET_IDENTITY failed for '%s': %m\n", node);
rc = 2;
goto close;
}
close(fd);
exit:
udev_unref(udev);
- udev_log_close();
+ log_close();
return rc;
}
static void info_scsi_cmd_err(struct udev *udev, const char *cmd, int err)
{
if (err == -1) {
- info(udev, "%s failed\n", cmd);
+ log_debug("%s failed\n", cmd);
return;
}
- info(udev, "%s failed with SK=%Xh/ASC=%02Xh/ACQ=%02Xh\n", cmd, SK(err), ASC(err), ASCQ(err));
+ log_debug("%s failed with SK=%Xh/ASC=%02Xh/ACQ=%02Xh\n", cmd, SK(err), ASC(err), ASCQ(err));
}
struct scsi_cmd {
/* disable the kernel's lock logic */
err = ioctl(fd, CDROM_CLEAR_OPTIONS, CDO_LOCK);
if (err < 0)
- info(udev, "CDROM_CLEAR_OPTIONS, CDO_LOCK failed\n");
+ log_debug("CDROM_CLEAR_OPTIONS, CDO_LOCK failed\n");
err = ioctl(fd, CDROM_LOCKDOOR, lock ? 1 : 0);
if (err < 0)
- info(udev, "CDROM_LOCKDOOR failed\n");
+ log_debug("CDROM_LOCKDOOR failed\n");
return err;
}
capability = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
if (capability < 0) {
- info(udev, "CDROM_GET_CAPABILITY failed\n");
+ log_debug("CDROM_GET_CAPABILITY failed\n");
return -1;
}
static int cd_media_compat(struct udev *udev, int fd)
{
if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) != CDS_DISC_OK) {
- info(udev, "CDROM_DRIVE_STATUS != CDS_DISC_OK\n");
+ log_debug("CDROM_DRIVE_STATUS != CDS_DISC_OK\n");
return -1;
}
cd_media = 1;
}
if ((inq[0] & 0x1F) != 5) {
- info(udev, "not an MMC unit\n");
+ log_debug("not an MMC unit\n");
return -1;
}
- info(udev, "INQUIRY: [%.8s][%.16s][%.4s]\n", inq + 8, inq + 16, inq + 32);
+ log_debug("INQUIRY: [%.8s][%.16s][%.4s]\n", inq + 8, inq + 16, inq + 32);
return 0;
}
case 0x03:
case 0x04:
case 0x05:
- info(udev, "profile 0x%02x \n", cur_profile);
+ log_debug("profile 0x%02x \n", cur_profile);
cd_media = 1;
cd_media_mo = 1;
break;
case 0x08:
- info(udev, "profile 0x%02x media_cd_rom\n", cur_profile);
+ log_debug("profile 0x%02x media_cd_rom\n", cur_profile);
cd_media = 1;
cd_media_cd_rom = 1;
break;
case 0x09:
- info(udev, "profile 0x%02x media_cd_r\n", cur_profile);
+ log_debug("profile 0x%02x media_cd_r\n", cur_profile);
cd_media = 1;
cd_media_cd_r = 1;
break;
case 0x0a:
- info(udev, "profile 0x%02x media_cd_rw\n", cur_profile);
+ log_debug("profile 0x%02x media_cd_rw\n", cur_profile);
cd_media = 1;
cd_media_cd_rw = 1;
break;
case 0x10:
- info(udev, "profile 0x%02x media_dvd_ro\n", cur_profile);
+ log_debug("profile 0x%02x media_dvd_ro\n", cur_profile);
cd_media = 1;
cd_media_dvd_rom = 1;
break;
case 0x11:
- info(udev, "profile 0x%02x media_dvd_r\n", cur_profile);
+ log_debug("profile 0x%02x media_dvd_r\n", cur_profile);
cd_media = 1;
cd_media_dvd_r = 1;
break;
case 0x12:
- info(udev, "profile 0x%02x media_dvd_ram\n", cur_profile);
+ log_debug("profile 0x%02x media_dvd_ram\n", cur_profile);
cd_media = 1;
cd_media_dvd_ram = 1;
break;
case 0x13:
- info(udev, "profile 0x%02x media_dvd_rw_ro\n", cur_profile);
+ log_debug("profile 0x%02x media_dvd_rw_ro\n", cur_profile);
cd_media = 1;
cd_media_dvd_rw = 1;
cd_media_dvd_rw_ro = 1;
break;
case 0x14:
- info(udev, "profile 0x%02x media_dvd_rw_seq\n", cur_profile);
+ log_debug("profile 0x%02x media_dvd_rw_seq\n", cur_profile);
cd_media = 1;
cd_media_dvd_rw = 1;
cd_media_dvd_rw_seq = 1;
break;
case 0x1B:
- info(udev, "profile 0x%02x media_dvd_plus_r\n", cur_profile);
+ log_debug("profile 0x%02x media_dvd_plus_r\n", cur_profile);
cd_media = 1;
cd_media_dvd_plus_r = 1;
break;
case 0x1A:
- info(udev, "profile 0x%02x media_dvd_plus_rw\n", cur_profile);
+ log_debug("profile 0x%02x media_dvd_plus_rw\n", cur_profile);
cd_media = 1;
cd_media_dvd_plus_rw = 1;
break;
case 0x2A:
- info(udev, "profile 0x%02x media_dvd_plus_rw_dl\n", cur_profile);
+ log_debug("profile 0x%02x media_dvd_plus_rw_dl\n", cur_profile);
cd_media = 1;
cd_media_dvd_plus_rw_dl = 1;
break;
case 0x2B:
- info(udev, "profile 0x%02x media_dvd_plus_r_dl\n", cur_profile);
+ log_debug("profile 0x%02x media_dvd_plus_r_dl\n", cur_profile);
cd_media = 1;
cd_media_dvd_plus_r_dl = 1;
break;
case 0x40:
- info(udev, "profile 0x%02x media_bd\n", cur_profile);
+ log_debug("profile 0x%02x media_bd\n", cur_profile);
cd_media = 1;
cd_media_bd = 1;
break;
case 0x41:
case 0x42:
- info(udev, "profile 0x%02x media_bd_r\n", cur_profile);
+ log_debug("profile 0x%02x media_bd_r\n", cur_profile);
cd_media = 1;
cd_media_bd_r = 1;
break;
case 0x43:
- info(udev, "profile 0x%02x media_bd_re\n", cur_profile);
+ log_debug("profile 0x%02x media_bd_re\n", cur_profile);
cd_media = 1;
cd_media_bd_re = 1;
break;
case 0x50:
- info(udev, "profile 0x%02x media_hddvd\n", cur_profile);
+ log_debug("profile 0x%02x media_hddvd\n", cur_profile);
cd_media = 1;
cd_media_hddvd = 1;
break;
case 0x51:
- info(udev, "profile 0x%02x media_hddvd_r\n", cur_profile);
+ log_debug("profile 0x%02x media_hddvd_r\n", cur_profile);
cd_media = 1;
cd_media_hddvd_r = 1;
break;
case 0x52:
- info(udev, "profile 0x%02x media_hddvd_rw\n", cur_profile);
+ log_debug("profile 0x%02x media_hddvd_rw\n", cur_profile);
cd_media = 1;
cd_media_hddvd_rw = 1;
break;
default:
- info(udev, "profile 0x%02x <ignored>\n", cur_profile);
+ log_debug("profile 0x%02x <ignored>\n", cur_profile);
break;
}
}
case 0x03:
case 0x04:
case 0x05:
- info(udev, "profile 0x%02x mo\n", profile);
+ log_debug("profile 0x%02x mo\n", profile);
cd_mo = 1;
break;
case 0x08:
- info(udev, "profile 0x%02x cd_rom\n", profile);
+ log_debug("profile 0x%02x cd_rom\n", profile);
cd_cd_rom = 1;
break;
case 0x09:
- info(udev, "profile 0x%02x cd_r\n", profile);
+ log_debug("profile 0x%02x cd_r\n", profile);
cd_cd_r = 1;
break;
case 0x0A:
- info(udev, "profile 0x%02x cd_rw\n", profile);
+ log_debug("profile 0x%02x cd_rw\n", profile);
cd_cd_rw = 1;
break;
case 0x10:
- info(udev, "profile 0x%02x dvd_rom\n", profile);
+ log_debug("profile 0x%02x dvd_rom\n", profile);
cd_dvd_rom = 1;
break;
case 0x12:
- info(udev, "profile 0x%02x dvd_ram\n", profile);
+ log_debug("profile 0x%02x dvd_ram\n", profile);
cd_dvd_ram = 1;
break;
case 0x13:
case 0x14:
- info(udev, "profile 0x%02x dvd_rw\n", profile);
+ log_debug("profile 0x%02x dvd_rw\n", profile);
cd_dvd_rw = 1;
break;
case 0x1B:
- info(udev, "profile 0x%02x dvd_plus_r\n", profile);
+ log_debug("profile 0x%02x dvd_plus_r\n", profile);
cd_dvd_plus_r = 1;
break;
case 0x1A:
- info(udev, "profile 0x%02x dvd_plus_rw\n", profile);
+ log_debug("profile 0x%02x dvd_plus_rw\n", profile);
cd_dvd_plus_rw = 1;
break;
case 0x2A:
- info(udev, "profile 0x%02x dvd_plus_rw_dl\n", profile);
+ log_debug("profile 0x%02x dvd_plus_rw_dl\n", profile);
cd_dvd_plus_rw_dl = 1;
break;
case 0x2B:
- info(udev, "profile 0x%02x dvd_plus_r_dl\n", profile);
+ log_debug("profile 0x%02x dvd_plus_r_dl\n", profile);
cd_dvd_plus_r_dl = 1;
break;
case 0x40:
cd_bd = 1;
- info(udev, "profile 0x%02x bd\n", profile);
+ log_debug("profile 0x%02x bd\n", profile);
break;
case 0x41:
case 0x42:
cd_bd_r = 1;
- info(udev, "profile 0x%02x bd_r\n", profile);
+ log_debug("profile 0x%02x bd_r\n", profile);
break;
case 0x43:
cd_bd_re = 1;
- info(udev, "profile 0x%02x bd_re\n", profile);
+ log_debug("profile 0x%02x bd_re\n", profile);
break;
case 0x50:
cd_hddvd = 1;
- info(udev, "profile 0x%02x hddvd\n", profile);
+ log_debug("profile 0x%02x hddvd\n", profile);
break;
case 0x51:
cd_hddvd_r = 1;
- info(udev, "profile 0x%02x hddvd_r\n", profile);
+ log_debug("profile 0x%02x hddvd_r\n", profile);
break;
case 0x52:
cd_hddvd_rw = 1;
- info(udev, "profile 0x%02x hddvd_rw\n", profile);
+ log_debug("profile 0x%02x hddvd_rw\n", profile);
break;
default:
- info(udev, "profile 0x%02x <ignored>\n", profile);
+ log_debug("profile 0x%02x <ignored>\n", profile);
break;
}
}
if ((err != 0)) {
info_scsi_cmd_err(udev, "READ DISC INFORMATION", err);
if (cd_media == 1) {
- info(udev, "no current profile, but disc is present; assuming CD-ROM\n");
+ log_debug("no current profile, but disc is present; assuming CD-ROM\n");
cd_media_cd_rom = 1;
return 0;
} else {
- info(udev, "no current profile, assuming no media\n");
+ log_debug("no current profile, assuming no media\n");
return -1;
}
};
if (header[2] & 16) {
cd_media_cd_rw = 1;
- info(udev, "profile 0x0a media_cd_rw\n");
+ log_debug("profile 0x0a media_cd_rw\n");
} else if ((header[2] & 3) < 2 && cd_cd_r) {
cd_media_cd_r = 1;
- info(udev, "profile 0x09 media_cd_r\n");
+ log_debug("profile 0x09 media_cd_r\n");
} else {
cd_media_cd_rom = 1;
- info(udev, "profile 0x08 media_cd_rom\n");
+ log_debug("profile 0x08 media_cd_rom\n");
}
return 0;
}
info_scsi_cmd_err(udev, "GET CONFIGURATION", err);
/* handle pre-MMC2 drives which do not support GET CONFIGURATION */
if (SK(err) == 0x5 && ASC(err) == 0x20) {
- info(udev, "drive is pre-MMC2 and does not support 46h get configuration command\n");
- info(udev, "trying to work around the problem\n");
+ log_debug("drive is pre-MMC2 and does not support 46h get configuration command\n");
+ log_debug("trying to work around the problem\n");
ret = cd_profiles_old_mmc(udev, fd);
}
goto out;
cur_profile = features[6] << 8 | features[7];
if (cur_profile > 0) {
- info(udev, "current profile 0x%02x\n", cur_profile);
+ log_debug("current profile 0x%02x\n", cur_profile);
feature_profile_media (udev, cur_profile);
ret = 0; /* we have media */
} else {
- info(udev, "no current profile, assuming no media\n");
+ log_debug("no current profile, assuming no media\n");
}
len = features[0] << 24 | features[1] << 16 | features[2] << 8 | features[3];
- info(udev, "GET CONFIGURATION: size of features buffer 0x%04x\n", len);
+ log_debug("GET CONFIGURATION: size of features buffer 0x%04x\n", len);
if (len > sizeof(features)) {
- info(udev, "can not get features in a single query, truncating\n");
+ log_debug("can not get features in a single query, truncating\n");
len = sizeof(features);
} else if (len <= 8) {
len = sizeof(features);
/* parse the length once more, in case the drive decided to have other features suddenly :) */
len = features[0] << 24 | features[1] << 16 | features[2] << 8 | features[3];
- info(udev, "GET CONFIGURATION: size of features buffer 0x%04x\n", len);
+ log_debug("GET CONFIGURATION: size of features buffer 0x%04x\n", len);
if (len > sizeof(features)) {
- info(udev, "can not get features in a single query, truncating\n");
+ log_debug("can not get features in a single query, truncating\n");
len = sizeof(features);
}
switch (feature) {
case 0x00:
- info(udev, "GET CONFIGURATION: feature 'profiles', with %i entries\n", features[i+3] / 4);
+ log_debug("GET CONFIGURATION: feature 'profiles', with %i entries\n", features[i+3] / 4);
feature_profiles(udev, &features[i]+4, features[i+3]);
break;
default:
- info(udev, "GET CONFIGURATION: feature 0x%04x <ignored>, with 0x%02x bytes\n", feature, features[i+3]);
+ log_debug("GET CONFIGURATION: feature 0x%04x <ignored>, with 0x%02x bytes\n", feature, features[i+3]);
break;
}
}
};
cd_media = 1;
- info(udev, "disk type %02x\n", header[8]);
- info(udev, "hardware reported media status: %s\n", media_status[header[2] & 3]);
+ log_debug("disk type %02x\n", header[8]);
+ log_debug("hardware reported media status: %s\n", media_status[header[2] & 3]);
/* exclude plain CDROM, some fake cdroms return 0 for "blank" media here */
if (!cd_media_cd_rom)
}
if (dvdstruct[4] & 0x02) {
cd_media_state = media_status[2];
- info(udev, "write-protected DVD-RAM media inserted\n");
+ log_debug("write-protected DVD-RAM media inserted\n");
goto determined;
}
len = format[3];
if (len & 7 || len < 16) {
- info(udev, "invalid format capacities length\n");
+ log_debug("invalid format capacities length\n");
return -1;
}
switch(format[8] & 3) {
case 1:
- info(udev, "unformatted DVD-RAM media inserted\n");
+ log_debug("unformatted DVD-RAM media inserted\n");
/* This means that last format was interrupted
* or failed, blank dvd-ram discs are factory
* formatted. Take no action here as it takes
goto determined;
case 2:
- info(udev, "formatted DVD-RAM media inserted\n");
+ log_debug("formatted DVD-RAM media inserted\n");
break;
case 3:
cd_media = 0; //return no media
- info(udev, "format capacities returned no media\n");
+ log_debug("format capacities returned no media\n");
return -1;
}
}
if (!result) {
cd_media_state = media_status[0];
- info(udev, "no data in blocks 0 or 16, assuming blank\n");
+ log_debug("no data in blocks 0 or 16, assuming blank\n");
} else {
- info(udev, "data in blocks 0 or 16, assuming complete\n");
+ log_debug("data in blocks 0 or 16, assuming complete\n");
}
}
}
len = (header[0] << 8 | header[1]) + 2;
- info(udev, "READ TOC: len: %d, start track: %d, end track: %d\n", len, header[2], header[3]);
+ log_debug("READ TOC: len: %d, start track: %d, end track: %d\n", len, header[2], header[3]);
if (len > sizeof(toc))
return -1;
if (len < 2)
is_data_track = (p[1] & 0x04) != 0;
block = p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7];
- info(udev, "track=%u info=0x%x(%s) start_block=%u\n",
+ log_debug("track=%u info=0x%x(%s) start_block=%u\n",
p[2], p[1] & 0x0f, is_data_track ? "data":"audio", block);
if (is_data_track)
return -1;
}
len = header[4+4] << 24 | header[4+5] << 16 | header[4+6] << 8 | header[4+7];
- info(udev, "last track %u starts at block %u\n", header[4+2], len);
+ log_debug("last track %u starts at block %u\n", header[4+2], len);
cd_media_session_last_offset = (unsigned long long int)len * 2048;
return 0;
}
if (udev == NULL)
goto exit;
- udev_log_init("cdrom_id");
+ log_open();
udev_set_log_fn(udev, log_fn);
while (1) {
node = argv[optind];
if (!node) {
- err(udev, "no device\n");
+ log_error("no device\n");
fprintf(stderr, "no device\n");
rc = 1;
goto exit;
nanosleep(&duration, NULL);
}
if (fd < 0) {
- info(udev, "unable to open '%s'\n", node);
+ log_debug("unable to open '%s'\n", node);
fprintf(stderr, "unable to open '%s'\n", node);
rc = 1;
goto exit;
}
- info(udev, "probing: '%s'\n", node);
+ log_debug("probing: '%s'\n", node);
/* same data as original cdrom_id */
if (cd_capability_compat(udev, fd) < 0) {
work:
/* lock the media, so we enable eject button events */
if (lock && cd_media) {
- info(udev, "PREVENT_ALLOW_MEDIUM_REMOVAL (lock)\n");
+ log_debug("PREVENT_ALLOW_MEDIUM_REMOVAL (lock)\n");
media_lock(udev, fd, true);
}
if (unlock && cd_media) {
- info(udev, "PREVENT_ALLOW_MEDIUM_REMOVAL (unlock)\n");
+ log_debug("PREVENT_ALLOW_MEDIUM_REMOVAL (unlock)\n");
media_lock(udev, fd, false);
}
if (eject) {
- info(udev, "PREVENT_ALLOW_MEDIUM_REMOVAL (unlock)\n");
+ log_debug("PREVENT_ALLOW_MEDIUM_REMOVAL (unlock)\n");
media_lock(udev, fd, false);
- info(udev, "START_STOP_UNIT (eject)\n");
+ log_debug("START_STOP_UNIT (eject)\n");
media_eject(udev, fd);
}
if (fd >= 0)
close(fd);
udev_unref(udev);
- udev_log_close();
+ log_close();
return rc;
}
fclose(f);
rename(filename_tmp, filename);
- info(udev, "created %s file '%s' for '%s'\n", has_info ? "db" : "empty",
+ dbg(udev, "created %s file '%s' for '%s'\n", has_info ? "db" : "empty",
filename, udev_device_get_devpath(udev_device));
return 0;
}
f = fopen(dbfile, "re");
if (f == NULL) {
- info(udev_device->udev, "no db file to read %s: %m\n", dbfile);
+ dbg(udev_device->udev, "no db file to read %s: %m\n", dbfile);
return -1;
}
udev_device->is_initialized = true;
}
fclose(f);
- info(udev_device->udev, "device %p filled with db file data\n", udev_device);
+ dbg(udev_device->udev, "device %p filled with db file data\n", udev_device);
return 0;
}
udev_device_add_property(udev_device,
udev_list_entry_get_name(list_entry),
udev_list_entry_get_value(list_entry));
- dbg(udev_device->udev, "udev_device: %p created\n", udev_device);
return udev_device;
}
/* path starts in sys */
len = strlen(udev_get_sys_path(udev));
if (strncmp(syspath, udev_get_sys_path(udev), len) != 0) {
- info(udev, "not in sys :%s\n", syspath);
+ dbg(udev, "not in sys :%s\n", syspath);
return NULL;
}
/* path is not a root directory */
subdir = &syspath[len+1];
pos = strrchr(subdir, '/');
- if (pos == NULL || pos[1] == '\0' || pos < &subdir[2]) {
- dbg(udev, "not a subdir :%s\n", syspath);
+ if (pos == NULL || pos[1] == '\0' || pos < &subdir[2])
return NULL;
- }
/* resolve possible symlink to real path */
util_strscpy(path, sizeof(path), syspath);
/* all "devices" require a "uevent" file */
util_strscpyl(file, sizeof(file), path, "/uevent", NULL);
- if (stat(file, &statbuf) != 0) {
- dbg(udev, "not a device: %s\n", syspath);
+ if (stat(file, &statbuf) != 0)
return NULL;
- }
} else {
/* everything else just needs to be a directory */
- if (stat(path, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) {
- dbg(udev, "directory not found: %s\n", syspath);
+ if (stat(path, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode))
return NULL;
- }
}
udev_device = udev_device_new(udev);
return NULL;
udev_device_set_syspath(udev_device, path);
- info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device));
+ dbg(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device));
return udev_device;
}
udev_device_add_property_from_string_parse(udev_device, environ[i]);
if (udev_device_add_property_from_string_parse_finish(udev_device) < 0) {
- info(udev, "missing values, invalid device\n");
+ dbg(udev, "missing values, invalid device\n");
udev_device_unref(udev_device);
udev_device = NULL;
}
udev_device->parent_set = true;
udev_device->parent_device = device_new_from_parent(udev_device);
}
- if (udev_device->parent_device != NULL)
- dbg(udev_device->udev, "returning existing parent %p\n", udev_device->parent_device);
return udev_device->parent_device;
}
free(udev_device->id_filename);
free(udev_device->envp);
free(udev_device->monitor_buf);
- dbg(udev_device->udev, "udev_device: %p released\n", udev_device);
free(udev_device);
}
/* look for possibly already cached result */
list_entry = udev_list_get_entry(&udev_device->sysattr_value_list);
list_entry = udev_list_entry_get_by_name(list_entry, sysattr);
- if (list_entry != NULL) {
- dbg(udev_device->udev, "got '%s' (%s) from cache\n",
- sysattr, udev_list_entry_get_value(list_entry));
+ if (list_entry != NULL)
return udev_list_entry_get_value(list_entry);
- }
util_strscpyl(path, sizeof(path), udev_device_get_syspath(udev_device), "/", sysattr, NULL);
if (lstat(path, &statbuf) != 0) {
- dbg(udev_device->udev, "no attribute '%s', keep negative entry\n", path);
udev_list_entry_add(&udev_device->sysattr_value_list, sysattr, NULL);
goto out;
}
if (util_get_sys_core_link_value(udev_device->udev, sysattr,
udev_device->syspath, value, sizeof(value)) < 0)
return NULL;
- dbg(udev_device->udev, "cache '%s' with link value '%s'\n", sysattr, value);
list_entry = udev_list_entry_add(&udev_device->sysattr_value_list, sysattr, value);
val = udev_list_entry_get_value(list_entry);
goto out;
/* read attribute value */
fd = open(path, O_RDONLY|O_CLOEXEC);
- if (fd < 0) {
- dbg(udev_device->udev, "attribute '%s' can not be opened\n", path);
+ if (fd < 0)
goto out;
- }
size = read(fd, value, sizeof(value));
close(fd);
if (size < 0)
/* got a valid value, store it in cache and return it */
value[size] = '\0';
util_remove_trailing_chars(value, '\n');
- dbg(udev_device->udev, "'%s' has attribute value '%s'\n", path, value);
list_entry = udev_list_entry_add(&udev_device->sysattr_value_list, sysattr, value);
val = udev_list_entry_get_value(list_entry);
out:
return 0;
dir = opendir(udev_device_get_syspath(udev_device));
- if (!dir) {
- dbg(udev_device->udev, "sysfs dir '%s' can not be opened\n",
- udev_device_get_syspath(udev_device));
+ if (!dir)
return -1;
- }
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
char path[UTIL_PATH_SIZE];
}
closedir(dir);
- dbg(udev_device->udev, "found %d sysattrs for '%s'\n", num, udev_device_get_syspath(udev_device));
udev_device->sysattr_list_read = true;
return num;
udev_device->envp[i] = NULL;
udev_device->monitor_buf_len = s - udev_device->monitor_buf;
udev_device->envp_uptodate = true;
- dbg(udev_device->udev, "filled envp/monitor buffer, %u properties, %zu bytes\n",
- i, udev_device->monitor_buf_len);
return 0;
}
len = strlen(udev_get_sys_path(udev));
for (i = 0; delay_device_list[i] != NULL; i++) {
- if (strstr(&syspath[len], delay_device_list[i]) != NULL) {
- dbg(udev, "delaying: %s\n", syspath);
+ if (strstr(&syspath[len], delay_device_list[i]) != NULL)
return true;
- }
}
return false;
}
util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem", NULL);
if (stat(base, &statbuf) == 0) {
/* we have /subsystem/, forget all the old stuff */
- dbg(udev, "searching '/subsystem/*/devices/*' dir\n");
scan_dir(udev_enumerate, "subsystem", "devices", NULL);
} else {
- dbg(udev, "searching '/bus/*/devices/*' dir\n");
scan_dir(udev_enumerate, "bus", "devices", NULL);
- dbg(udev, "searching '/class/*' dir\n");
scan_dir(udev_enumerate, "class", NULL, NULL);
}
return 0;
return -EINVAL;
/* all kernel modules */
- if (match_subsystem(udev_enumerate, "module")) {
- dbg(udev, "searching 'modules/*' dir\n");
+ if (match_subsystem(udev_enumerate, "module"))
scan_dir_and_add_devices(udev_enumerate, "module", NULL, NULL);
- }
util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem", NULL);
if (stat(base, &statbuf) == 0)
subsysdir = "bus";
/* all subsystems (only buses support coldplug) */
- if (match_subsystem(udev_enumerate, "subsystem")) {
- dbg(udev, "searching '%s/*' dir\n", subsysdir);
+ if (match_subsystem(udev_enumerate, "subsystem"))
scan_dir_and_add_devices(udev_enumerate, subsysdir, NULL, NULL);
- }
/* all subsystem drivers */
- if (match_subsystem(udev_enumerate, "drivers")) {
- dbg(udev, "searching '%s/*/drivers/*' dir\n", subsysdir);
+ if (match_subsystem(udev_enumerate, "drivers"))
scan_dir(udev_enumerate, subsysdir, "drivers", "drivers");
- }
return 0;
}
if (i >= 0) {
entry = list->entries[i];
- dbg(list->udev, "'%s' is already in the list\n", name);
free(entry->value);
if (value == NULL) {
entry->value = NULL;
- dbg(list->udev, "'%s' value unset\n", name);
return entry;
}
entry->value = strdup(value);
if (entry->value == NULL)
return NULL;
- dbg(list->udev, "'%s' value replaced with '%s'\n", name, value);
return entry;
}
}
udev_list_entry_append(entry, list);
}
- dbg(list->udev, "'%s=%s' added\n", entry->name, entry->value);
return entry;
}
return NULL;
}
- dbg(udev, "monitor %p created with '%s'\n", udev_monitor, socket_path);
return udev_monitor;
}
udev_monitor->snl_destination.nl_family = AF_NETLINK;
udev_monitor->snl_destination.nl_groups = UDEV_MONITOR_UDEV;
- dbg(udev, "monitor %p created with NETLINK_KOBJECT_UEVENT (%u)\n", udev_monitor, group);
return udev_monitor;
}
close(udev_monitor->sock);
udev_list_cleanup(&udev_monitor->filter_subsystem_list);
udev_list_cleanup(&udev_monitor->filter_tag_list);
- dbg(udev_monitor->udev, "monitor %p released\n", udev_monitor);
free(udev_monitor);
}
buflen = recvmsg(udev_monitor->sock, &smsg, 0);
if (buflen < 0) {
if (errno != EINTR)
- info(udev_monitor->udev, "unable to receive message\n");
+ dbg(udev_monitor->udev, "unable to receive message\n");
return NULL;
}
if (buflen < 32 || (size_t)buflen >= sizeof(buf)) {
- info(udev_monitor->udev, "invalid message length\n");
+ dbg(udev_monitor->udev, "invalid message length\n");
return NULL;
}
/* unicast message, check if we trust the sender */
if (udev_monitor->snl_trusted_sender.nl_pid == 0 ||
snl.nl_pid != udev_monitor->snl_trusted_sender.nl_pid) {
- info(udev_monitor->udev, "unicast netlink message ignored\n");
+ dbg(udev_monitor->udev, "unicast netlink message ignored\n");
return NULL;
}
} else if (snl.nl_groups == UDEV_MONITOR_KERNEL) {
if (snl.nl_pid > 0) {
- info(udev_monitor->udev, "multicast kernel netlink message from pid %d ignored\n",
+ dbg(udev_monitor->udev, "multicast kernel netlink message from pid %d ignored\n",
snl.nl_pid);
return NULL;
}
cmsg = CMSG_FIRSTHDR(&smsg);
if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) {
- info(udev_monitor->udev, "no sender credentials received, message ignored\n");
+ dbg(udev_monitor->udev, "no sender credentials received, message ignored\n");
return NULL;
}
cred = (struct ucred *)CMSG_DATA(cmsg);
if (cred->uid != 0) {
- info(udev_monitor->udev, "sender uid=%d, message ignored\n", cred->uid);
+ dbg(udev_monitor->udev, "sender uid=%d, message ignored\n", cred->uid);
return NULL;
}
/* kernel message with header */
bufpos = strlen(buf) + 1;
if ((size_t)bufpos < sizeof("a@/d") || bufpos >= buflen) {
- info(udev_monitor->udev, "invalid message length\n");
+ dbg(udev_monitor->udev, "invalid message length\n");
return NULL;
}
/* check message header */
if (strstr(buf, "@/") == NULL) {
- info(udev_monitor->udev, "unrecognized message header\n");
+ dbg(udev_monitor->udev, "unrecognized message header\n");
return NULL;
}
}
}
if (udev_device_add_property_from_string_parse_finish(udev_device) < 0) {
- info(udev_monitor->udev, "missing values, invalid device\n");
+ dbg(udev_monitor->udev, "missing values, invalid device\n");
udev_device_unref(udev_device);
return NULL;
}
smsg.msg_name = &udev_monitor->sun;
smsg.msg_namelen = udev_monitor->addrlen;
count = sendmsg(udev_monitor->sock, &smsg, 0);
- info(udev_monitor->udev, "passed %zi bytes to socket monitor %p\n", count, udev_monitor);
+ dbg(udev_monitor->udev, "passed %zi bytes to socket monitor %p\n", count, udev_monitor);
return count;
}
smsg.msg_name = &udev_monitor->snl_destination;
smsg.msg_namelen = sizeof(struct sockaddr_nl);
count = sendmsg(udev_monitor->sock, &smsg, 0);
- info(udev_monitor->udev, "passed %zi bytes to netlink monitor %p\n", count, udev_monitor);
+ dbg(udev_monitor->udev, "passed %zi bytes to netlink monitor %p\n", count, udev_monitor);
return count;
}
/*
* libudev - interface to udev device information
*
- * Copyright (C) 2008-2010 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2008-2012 Kay Sievers <kay.sievers@vrfy.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include "libudev.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#define READ_END 0
-#define WRITE_END 1
-
-static inline void __attribute__((always_inline, format(printf, 2, 3)))
-udev_log_null(struct udev *udev, const char *format, ...) {}
+#define READ_END 0
+#define WRITE_END 1
+/* avoid (sometimes expensive) calculations of parameters for debug output */
#define udev_log_cond(udev, prio, arg...) \
do { \
if (udev_get_log_priority(udev) >= prio) \
udev_log(udev, prio, __FILE__, __LINE__, __FUNCTION__, ## arg); \
} while (0)
-#ifdef ENABLE_DEBUG
-# define dbg(udev, arg...) udev_log_cond(udev, LOG_DEBUG, ## arg)
-#else
-# define dbg(udev, arg...) udev_log_null(udev, ## arg)
-#endif
+#define dbg(udev, arg...) udev_log_cond(udev, LOG_DEBUG, ## arg)
#define info(udev, arg...) udev_log_cond(udev, LOG_INFO, ## arg)
#define err(udev, arg...) udev_log_cond(udev, LOG_ERR, ## arg)
-static inline void udev_log_init(const char *program_name)
-{
- openlog(program_name, LOG_PID | LOG_CONS, LOG_DAEMON);
-}
-
-static inline void udev_log_close(void)
-{
- closelog();
-}
-
/* libudev.c */
void udev_log(struct udev *udev,
int priority, const char *file, int line, const char *fn,
/* read old queue file */
if (udev_queue_export->queue_file != NULL) {
- dbg(udev_queue_export->udev, "compacting queue file, freeing %d bytes\n",
- udev_queue_export->waste_bytes);
-
devpaths = build_index(udev_queue_export);
if (devpaths != NULL)
udev_queue_export->seqnum_max += devpaths->devpaths_first;
}
if (devpaths == NULL) {
- dbg(udev_queue_export->udev, "creating empty queue file\n");
udev_queue_export->queued_count = 0;
udev_queue_export->seqnum_max = udev_queue_export->seqnum_min;
}
{
unsigned short len;
- if (udev_queue_export->queue_file == NULL) {
- dbg(udev_queue_export->udev, "can't record event: queue file not available\n");
+ if (udev_queue_export->queue_file == NULL)
return -1;
- }
if (fwrite(&seqnum, sizeof(unsigned long long int), 1, udev_queue_export->queue_file) != 1)
goto write_error;
return -EINVAL;
seqnum = udev_get_kernel_seqnum(udev_queue->udev);
- dbg(udev_queue->udev, "seqnum=%llu\n", seqnum);
return seqnum;
}
}
}
- if (queued > 0) {
- dbg(udev_queue->udev, "queue is not empty\n");
+ if (queued > 0)
goto out;
- }
seqnum_kernel = udev_queue_get_kernel_seqnum(udev_queue);
- if (seqnum_udev < seqnum_kernel) {
- dbg(udev_queue->udev, "queue is empty but kernel events still pending [%llu]<->[%llu]\n",
- seqnum_kernel, seqnum_udev);
+ if (seqnum_udev < seqnum_kernel)
goto out;
- }
- dbg(udev_queue->udev, "queue is empty\n");
is_empty = 1;
out:
if (!udev_queue_get_seqnum_sequence_is_finished(udev_queue, seqnum, seqnum))
return 0;
- dbg(udev_queue->udev, "seqnum: %llu finished\n", seqnum);
return 1;
}
{
/* record the present security context */
selinux_enabled = (is_selinux_enabled() > 0);
- info(udev, "selinux=%i\n", selinux_enabled);
+ dbg(udev, "selinux=%i\n", selinux_enabled);
if (!selinux_enabled)
return;
matchpathcon_init_prefix(NULL, udev_get_dev_path(udev));
return 0;
pos[0] = '\0';
- dbg(udev, "stat '%s'\n", p);
if (stat(p, &stats) == 0) {
if ((stats.st_mode & S_IFMT) == S_IFDIR)
return 0;
if (err != 0)
return err;
- dbg(udev, "mkdir '%s'\n", p);
if (selinux)
udev_selinux_setfscreatecon(udev, p, S_IFDIR|0755);
err = mkdir(p, 0755);
util_strscpy(result, maxsize, val);
else
result[0] = '\0';
- info(udev, "value '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result);
+ dbg(udev, "value '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result);
} else {
size_t l;
char *s;
l = util_strpcpyl(&s, maxsize, udev_device_get_syspath(dev), NULL);
if (attr != NULL)
util_strpcpyl(&s, l, "/", attr, NULL);
- info(udev, "path '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result);
+ dbg(udev, "path '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result);
}
udev_device_unref(dev);
return 0;
if (pos == NULL)
return -1;
pos = &pos[1];
- dbg(udev, "resolved link to: '%s'\n", pos);
return util_strscpy(value, size, pos);
}
if (len <= 0 || len == (ssize_t)sizeof(link_target))
return -1;
link_target[len] = '\0';
- dbg(udev, "path link '%s' points to '%s'\n", syspath, link_target);
for (back = 0; strncmp(&link_target[back * 3], "../", 3) == 0; back++)
;
- dbg(udev, "base '%s', tail '%s', back %i\n", syspath, &link_target[back * 3], back);
for (i = 0; i <= back; i++) {
base = strrchr(syspath, '/');
if (base == NULL)
}
if (base == NULL)
return -EINVAL;
- dbg(udev, "after moving back '%s'\n", syspath);
util_strscpyl(base, size - (base - syspath), "/", &link_target[back * 3], NULL);
return 0;
}
udev->rules_path_count = 3;
}
- dbg(udev, "context %p created\n", udev);
- dbg(udev, "log_priority=%d\n", udev->log_priority);
- dbg(udev, "config_file='%s'\n", config_file);
- dbg(udev, "dev_path='%s'\n", udev->dev_path);
- dbg(udev, "sys_path='%s'\n", udev->sys_path);
- dbg(udev, "run_path='%s'\n", udev->run_path);
- dbg(udev, "rules_path='%s':'%s':'%s'\n", udev->rules_path[0], udev->rules_path[1], udev->rules_path[2]);
free(config_file);
return udev;
err:
free(udev->rules_path[1]);
free(udev->rules_path[2]);
free(udev->run_path);
- dbg(udev, "context %p released\n", udev);
free(udev);
}
const char *format, va_list args))
{
udev->log_fn = log_fn;
- info(udev, "custom logging function %p registered\n", log_fn);
+ dbg(udev, "custom logging function %p registered\n", log_fn);
}
/**
int c;
int retval = 0;
- dbg(udev, "vendor='%s'; model='%s'\n", vendor, model);
fd = fopen(config_file, "r");
if (fd == NULL) {
- dbg(udev, "can't open %s\n", config_file);
if (errno == ENOENT) {
return 1;
} else {
- err(udev, "can't open %s: %s\n", config_file, strerror(errno));
+ log_error("can't open %s: %s\n", config_file, strerror(errno));
return -1;
}
}
buffer = malloc(MAX_BUFFER_LEN);
if (!buffer) {
fclose(fd);
- err(udev, "can't allocate memory\n");
+ log_error("can't allocate memory\n");
return -1;
}
break;
lineno++;
if (buf[strlen(buffer) - 1] != '\n') {
- err(udev, "Config file line %d too long\n", lineno);
+ log_error("Config file line %d too long\n", lineno);
break;
}
if (*buf == '#')
continue;
- dbg(udev, "lineno %d: '%s'\n", lineno, buf);
str1 = strsep(&buf, "=");
if (str1 && strcasecmp(str1, "VENDOR") == 0) {
str1 = get_value(&buf);
}
options_in = str1;
}
- dbg(udev, "config file line %d:\n"
- " vendor '%s'; model '%s'; options '%s'\n",
- lineno, vendor_in, model_in, options_in);
+
/*
* Only allow: [vendor=foo[,model=bar]]options=stuff
*/
if (!options_in || (!vendor_in && model_in)) {
- err(udev, "Error parsing config file line %d '%s'\n", lineno, buffer);
+ log_error("Error parsing config file line %d '%s'\n", lineno, buffer);
retval = -1;
break;
}
if (vendor == NULL) {
- if (vendor_in == NULL) {
- dbg(udev, "matched global option\n");
+ if (vendor_in == NULL)
break;
- }
} else if ((vendor_in && strncmp(vendor, vendor_in,
strlen(vendor_in)) == 0) &&
(!model_in || (strncmp(model, model_in,
* give a partial match (that is FOO
* matches FOOBAR).
*/
- dbg(udev, "matched vendor/model\n");
break;
- } else {
- dbg(udev, "no match\n");
}
}
c = argc_count(buffer) + 2;
*newargv = calloc(c, sizeof(**newargv));
if (!*newargv) {
- err(udev, "can't allocate memory\n");
+ log_error("can't allocate memory\n");
retval = -1;
} else {
*argc = c;
if (option == -1)
break;
- if (optarg)
- dbg(udev, "option '%c' arg '%s'\n", option, optarg);
- else
- dbg(udev, "option '%c'\n", option);
-
switch (option) {
case 'b':
all_good = 0;
} else if (strcmp(optarg, "pre-spc3-83") == 0) {
default_page_code = PAGE_83_PRE_SPC3;
} else {
- err(udev, "Unknown page code '%s'\n", optarg);
+ log_error("Unknown page code '%s'\n", optarg);
return -1;
}
break;
case 's':
sg_version = atoi(optarg);
if (sg_version < 3 || sg_version > 4) {
- err(udev, "Unknown SG version '%s'\n", optarg);
+ log_error("Unknown SG version '%s'\n", optarg);
return -1;
}
break;
if (option == -1)
break;
- if (optarg)
- dbg(udev, "option '%c' arg '%s'\n", option, optarg);
- else
- dbg(udev, "option '%c'\n", option);
-
switch (option) {
case 'b':
*good_bad = 0;
} else if (strcmp(optarg, "pre-spc3-83") == 0) {
*page_code = PAGE_83_PRE_SPC3;
} else {
- err(udev, "Unknown page code '%s'\n", optarg);
+ log_error("Unknown page code '%s'\n", optarg);
retval = -1;
}
break;
default:
- err(udev, "Unknown or bad option '%c' (0x%x)\n", option, option);
+ log_error("Unknown or bad option '%c' (0x%x)\n", option, option);
retval = -1;
break;
}
/* get per device (vendor + model) options from the config file */
per_dev_options(udev, &dev_scsi, &good_dev, &page_code);
- dbg(udev, "per dev options: good %d; page code 0x%x\n", good_dev, page_code);
if (!good_dev) {
retval = 1;
goto out;
if (udev == NULL)
goto exit;
- udev_log_init("scsi_id");
+ log_open();
udev_set_log_fn(udev, log_fn);
/*
exit(1);
if (!dev_specified) {
- err(udev, "no device specified\n");
+ log_error("no device specified\n");
retval = 1;
goto exit;
}
exit:
udev_unref(udev);
- udev_log_close();
+ log_close();
return retval;
}
* we'll retry the command.
*/
- dbg(udev, "got check condition\n");
-
if (sb_len < 1) {
- info(udev, "%s: sense buffer empty\n", dev_scsi->kernel);
+ log_debug("%s: sense buffer empty\n", dev_scsi->kernel);
return -1;
}
*/
s = sense_buffer[7] + 8;
if (sb_len < s) {
- info(udev, "%s: sense buffer too small %d bytes, %d bytes too short\n",
+ log_debug("%s: sense buffer too small %d bytes, %d bytes too short\n",
dev_scsi->kernel, sb_len, s - sb_len);
return -1;
}
/*
* Possible?
*/
- info(udev, "%s: sense result too" " small %d bytes\n",
+ log_debug("%s: sense result too" " small %d bytes\n",
dev_scsi->kernel, s);
return -1;
}
asc = sense_buffer[2];
ascq = sense_buffer[3];
} else {
- info(udev, "%s: invalid sense code 0x%x\n",
+ log_debug("%s: invalid sense code 0x%x\n",
dev_scsi->kernel, code);
return -1;
}
- info(udev, "%s: sense key 0x%x ASC 0x%x ASCQ 0x%x\n",
+ log_debug("%s: sense key 0x%x ASC 0x%x ASCQ 0x%x\n",
dev_scsi->kernel, sense_key, asc, ascq);
} else {
if (sb_len < 4) {
- info(udev, "%s: sense buffer too small %d bytes, %d bytes too short\n",
+ log_debug("%s: sense buffer too small %d bytes, %d bytes too short\n",
dev_scsi->kernel, sb_len, 4 - sb_len);
return -1;
}
if (sense_buffer[0] < 15)
- info(udev, "%s: old sense key: 0x%x\n", dev_scsi->kernel, sense_buffer[0] & 0x0f);
+ log_debug("%s: old sense key: 0x%x\n", dev_scsi->kernel, sense_buffer[0] & 0x0f);
else
- info(udev, "%s: sense = %2x %2x\n",
+ log_debug("%s: sense = %2x %2x\n",
dev_scsi->kernel, sense_buffer[0], sense_buffer[2]);
- info(udev, "%s: non-extended sense class %d code 0x%0x\n",
+ log_debug("%s: non-extended sense class %d code 0x%0x\n",
dev_scsi->kernel, sense_class, code);
}
#ifdef DUMP_SENSE
for (i = 0, j = 0; (i < s) && (j < 254); i++) {
- dbg(udev, "i %d, j %d\n", i, j);
out_buffer[j++] = hex_str[(sense_buffer[i] & 0xf0) >> 4];
out_buffer[j++] = hex_str[sense_buffer[i] & 0x0f];
out_buffer[j++] = ' ';
}
out_buffer[j] = '\0';
- info(udev, "%s: sense dump:\n", dev_scsi->kernel);
- info(udev, "%s: %s\n", dev_scsi->kernel, out_buffer);
+ log_debug("%s: sense dump:\n", dev_scsi->kernel);
+ log_debug("%s: %s\n", dev_scsi->kernel, out_buffer);
#endif
return -1;
/*
* Impossible, should not be called.
*/
- info(udev, "%s: called with no error\n", __FUNCTION__);
+ log_debug("%s: called with no error\n", __FUNCTION__);
return -1;
}
- info(udev, "%s: sg_io failed status 0x%x 0x%x 0x%x 0x%x\n",
+ log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x 0x%x\n",
dev_scsi->kernel, io->driver_status, io->host_status, io->msg_status, io->status);
if (io->status == SCSI_CHECK_CONDITION)
return scsi_dump_sense(udev, dev_scsi, io->sbp, io->sb_len_wr);
/*
* Impossible, should not be called.
*/
- info(udev, "%s: called with no error\n", __FUNCTION__);
+ log_debug("%s: called with no error\n", __FUNCTION__);
return -1;
}
- info(udev, "%s: sg_io failed status 0x%x 0x%x 0x%x\n",
+ log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x\n",
dev_scsi->kernel, io->driver_status, io->transport_status,
io->device_status);
if (io->device_status == SCSI_CHECK_CONDITION)
int retval;
if (buflen > SCSI_INQ_BUFF_LEN) {
- info(udev, "buflen %d too long\n", buflen);
+ log_debug("buflen %d too long\n", buflen);
return -1;
}
resend:
- dbg(udev, "%s evpd %d, page 0x%x\n", dev_scsi->kernel, evpd, page);
-
if (dev_scsi->use_sg == 4) {
memset(&io_v4, 0, sizeof(struct sg_io_v4));
io_v4.guard = 'Q';
dev_scsi->use_sg = 3;
goto resend;
}
- info(udev, "%s: ioctl failed: %s\n", dev_scsi->kernel, strerror(errno));
+ log_debug("%s: ioctl failed: %s\n", dev_scsi->kernel, strerror(errno));
goto error;
}
if (!retval) {
retval = buflen;
} else if (retval > 0) {
- if (--retry > 0) {
- dbg(udev, "%s: Retrying ...\n", dev_scsi->kernel);
+ if (--retry > 0)
goto resend;
- }
retval = -1;
}
error:
if (retval < 0)
- info(udev, "%s: Unable to get INQUIRY vpd %d page 0x%x.\n",
+ log_debug("%s: Unable to get INQUIRY vpd %d page 0x%x.\n",
dev_scsi->kernel, evpd, page);
return retval;
return 1;
if (buffer[1] != 0) {
- info(udev, "%s: page 0 not available.\n", dev_scsi->kernel);
+ log_debug("%s: page 0 not available.\n", dev_scsi->kernel);
return 1;
}
if (buffer[3] > len) {
- info(udev, "%s: page 0 buffer too long %d\n", dev_scsi->kernel, buffer[3]);
+ log_debug("%s: page 0 buffer too long %d\n", dev_scsi->kernel, buffer[3]);
return 1;
}
* invalid.
*/
if (!strncmp((char *)&buffer[VENDOR_LENGTH], dev_scsi->vendor, VENDOR_LENGTH)) {
- info(udev, "%s: invalid page0 data\n", dev_scsi->kernel);
+ log_debug("%s: invalid page0 data\n", dev_scsi->kernel);
return 1;
}
}
* above, ind will never be too large.
*/
if (ind != (VENDOR_LENGTH + MODEL_LENGTH)) {
- info(udev, "%s: expected length %d, got length %d\n",
+ log_debug("%s: expected length %d, got length %d\n",
dev_scsi->kernel, (VENDOR_LENGTH + MODEL_LENGTH), ind);
return -1;
}
len += VENDOR_LENGTH + MODEL_LENGTH;
if (max_len < len) {
- info(udev, "%s: length %d too short - need %d\n",
+ log_debug("%s: length %d too short - need %d\n",
dev_scsi->kernel, max_len, len);
return 1;
}
* included in the identifier.
*/
if (id_search->id_type == SCSI_ID_VENDOR_SPECIFIC)
- if (prepend_vendor_model(udev, dev_scsi, &serial[1]) < 0) {
- dbg(udev, "prepend failed\n");
+ if (prepend_vendor_model(udev, dev_scsi, &serial[1]) < 0)
return 1;
- }
i = 4; /* offset to the start of the identifier */
s = j = strlen(serial);
{
int i, j;
- dbg(udev, "using pre-spc3-83 for %s\n", dev_scsi->kernel);
serial[0] = hex_str[id_search->id_type];
/* serial has been memset to zero before */
j = strlen(serial); /* j = 1; */
return 1;
if (page_83[1] != PAGE_83) {
- info(udev, "%s: Invalid page 0x83\n", dev_scsi->kernel);
+ log_debug("%s: Invalid page 0x83\n", dev_scsi->kernel);
return 1;
}
serial, serial_short, len,
wwn, wwn_vendor_extension,
tgpt_group);
- dbg(udev, "%s id desc %d/%d/%d\n", dev_scsi->kernel,
- id_search_list[id_ind].id_type,
- id_search_list[id_ind].naa_type,
- id_search_list[id_ind].code_set);
- if (!retval) {
- dbg(udev, " used\n");
+ if (!retval)
return retval;
- } else if (retval < 0) {
- dbg(udev, " failed\n");
+ else if (retval < 0)
return retval;
- } else {
- dbg(udev, " not used\n");
- }
}
}
return 1;
return 1;
if (page_83[1] != PAGE_83) {
- info(udev, "%s: Invalid page 0x83\n", dev_scsi->kernel);
+ log_debug("%s: Invalid page 0x83\n", dev_scsi->kernel);
return 1;
}
/*
serial[j++] = hex_str[page_83[i] & 0x0f];
i++;
}
- dbg(udev, "using pre-spc3-83 for %s\n", dev_scsi->kernel);
return 0;
}
return retval;
if (buf[1] != PAGE_80) {
- info(udev, "%s: Invalid page 0x80\n", dev_scsi->kernel);
+ log_debug("%s: Invalid page 0x80\n", dev_scsi->kernel);
return 1;
}
len = 1 + VENDOR_LENGTH + MODEL_LENGTH + buf[3];
if (max_len < len) {
- info(udev, "%s: length %d too short - need %d\n",
+ log_debug("%s: length %d too short - need %d\n",
dev_scsi->kernel, max_len, len);
return 1;
}
struct stat statbuf;
int err = 0;
- dbg(udev, "opening %s\n", devname);
fd = open(devname, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
- info(udev, "scsi_id: cannot open %s: %s\n",
+ log_debug("scsi_id: cannot open %s: %s\n",
devname, strerror(errno));
return 1;
}
if (fstat(fd, &statbuf) < 0) {
- info(udev, "scsi_id: cannot stat %s: %s\n",
+ log_debug("scsi_id: cannot stat %s: %s\n",
devname, strerror(errno));
err = 2;
goto out;
int retval;
memset(dev_scsi->serial, 0, len);
- dbg(udev, "opening %s\n", devname);
srand((unsigned int)getpid());
for (cnt = 20; cnt > 0; cnt--) {
struct timespec duration;
goto completed;
}
} else if (page_code != 0x00) {
- info(udev, "%s: unsupported page code 0x%d\n", dev_scsi->kernel, page_code);
+ log_debug("%s: unsupported page code 0x%d\n", dev_scsi->kernel, page_code);
return 1;
}
goto completed;
}
- dbg(udev, "%s: Checking page0\n", dev_scsi->kernel);
-
for (ind = 4; ind <= page0[3] + 3; ind++)
if (page0[ind] == PAGE_83)
if (!do_scsi_page83_inquiry(udev, dev_scsi, fd,
udev = udev_new();
if (udev == NULL)
exit(1);
- info(udev, "version %s\n", VERSION);
+ log_debug("version %s\n", VERSION);
udev_selinux_init(udev);
sigprocmask(SIG_SETMASK, NULL, &sigmask_orig);
action = argv[1];
if (action == NULL) {
- err(udev, "action missing\n");
+ log_error("action missing\n");
goto out;
}
devpath = argv[2];
if (devpath == NULL) {
- err(udev, "devpath missing\n");
+ log_error("devpath missing\n");
goto out;
}
util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), devpath, NULL);
dev = udev_device_new_from_syspath(udev, syspath);
if (dev == NULL) {
- info(udev, "unknown device '%s'\n", devpath);
+ log_debug("unknown device '%s'\n", devpath);
goto out;
}
if (err < 0)
goto out;
- info(udev, "probe %s %sraid offset=%llu\n",
- udev_device_get_devnode(dev),
- noraid ? "no" : "", (unsigned long long) offset);
+ log_debug("probe %s %sraid offset=%llu\n",
+ udev_device_get_devnode(dev),
+ noraid ? "no" : "", (unsigned long long) offset);
err = probe_superblocks(pr);
if (err < 0)
ldfile = fopen(loadpath, "we");
if (ldfile == NULL) {
- err(udev, "error: can not open '%s'\n", loadpath);
+ log_error("error: can not open '%s'\n", loadpath);
return false;
};
fprintf(ldfile, "%s\n", state);
buf = malloc(size);
if (buf == NULL) {
- err(udev,"No memory available to load firmware file");
+ log_error("No memory available to load firmware file");
return false;
}
- info(udev, "writing '%s' (%zi) to '%s'\n", source, size, target);
+ log_debug("writing '%s' (%zi) to '%s'\n", source, size, target);
fsource = fopen(source, "re");
if (fsource == NULL)
firmware = udev_device_get_property_value(dev, "FIRMWARE");
if (firmware == NULL) {
- err(udev, "firmware parameter missing\n\n");
+ log_error("firmware parameter missing\n\n");
rc = EXIT_FAILURE;
goto exit;
}
uname(&kernel);
for (i = 0; i < ARRAY_SIZE(searchpath); i++) {
util_strscpyl(fwpath, sizeof(fwpath), searchpath[i], kernel.release, "/", firmware, NULL);
- dbg(udev, "trying %s\n", fwpath);
fwfile = fopen(fwpath, "re");
if (fwfile != NULL)
break;
util_strscpyl(fwpath, sizeof(fwpath), searchpath[i], firmware, NULL);
- dbg(udev, "trying %s\n", fwpath);
fwfile = fopen(fwpath, "re");
if (fwfile != NULL)
break;
int err;
/* This link indicates the missing firmware file and the associated device */
- info(udev, "did not find firmware file '%s'\n", firmware);
+ log_debug("did not find firmware file '%s'\n", firmware);
do {
err = util_create_path(udev, misspath);
if (err != 0 && err != -ENOENT)
util_strscpyl(datapath, sizeof(datapath), udev_device_get_syspath(dev), "/data", NULL);
if (!copy_firmware(udev, fwpath, datapath, statbuf.st_size)) {
- err(udev, "error sending firmware '%s' to device\n", firmware);
+ log_error("error sending firmware '%s' to device\n", firmware);
set_loading(udev, loadpath, "-1");
rc = EXIT_FAILURE;
goto exit;
unsigned long val;
snprintf(text, sizeof(text), "%s", udev_device_get_sysattr_value(pdev, attr));
- info(udev, "%s raw kernel attribute: %s\n", attr, text);
+ log_debug("%s raw kernel attribute: %s\n", attr, text);
memset (bitmask, 0, bitmask_size);
i = 0;
if (i < bitmask_size/sizeof(unsigned long))
bitmask[i] = val;
else
- info(udev, "ignoring %s block %lX which is larger than maximum size\n", attr, val);
+ log_debug("ignoring %s block %lX which is larger than maximum size\n", attr, val);
*word = '\0';
++i;
}
if (i < bitmask_size / sizeof(unsigned long))
bitmask[i] = val;
else
- info(udev, "ignoring %s block %lX which is larger than maximum size\n", attr, val);
+ log_debug("ignoring %s block %lX which is larger than maximum size\n", attr, val);
if (test) {
/* printf pattern with the right unsigned long number of hex chars */
snprintf(text, sizeof(text), " bit %%4u: %%0%zilX\n", 2 * sizeof(unsigned long));
- info(udev, "%s decoded bit map:\n", attr);
+ log_debug("%s decoded bit map:\n", attr);
val = bitmask_size / sizeof (unsigned long);
/* skip over leading zeros */
while (bitmask[val-1] == 0 && val > 0)
--val;
for (i = 0; i < val; ++i)
- info(udev, text, i * BITS_PER_LONG, bitmask[i]);
+ log_debug(text, i * BITS_PER_LONG, bitmask[i]);
}
}
/* do we have any KEY_* capability? */
if (!test_bit (EV_KEY, bitmask_ev)) {
- info(udev, "test_key: no EV_KEY capability\n");
+ log_debug("test_key: no EV_KEY capability\n");
return;
}
found = 0;
for (i = 0; i < BTN_MISC/BITS_PER_LONG; ++i) {
found |= bitmask_key[i];
- info(udev, "test_key: checking bit block %lu for any keys; found=%i\n", i*BITS_PER_LONG, found > 0);
+ log_debug("test_key: checking bit block %lu for any keys; found=%i\n", i*BITS_PER_LONG, found > 0);
}
/* If there are no keys in the lower block, check the higher block */
if (!found) {
for (i = KEY_OK; i < BTN_TRIGGER_HAPPY; ++i) {
if (test_bit (i, bitmask_key)) {
- info(udev, "test_key: Found key %x in high block\n", i);
+ log_debug("test_key: Found key %x in high block\n", i);
found = 1;
break;
}
return err;
if (list == NULL)
- info(udev, "no module matches '%s'\n", alias);
+ log_debug("no module matches '%s'\n", alias);
kmod_list_foreach(l, list) {
struct kmod_module *mod = kmod_module_get_module(l);
err = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST, NULL, NULL, NULL, NULL);
if (err == KMOD_PROBE_APPLY_BLACKLIST)
- info(udev, "module '%s' is blacklisted\n", kmod_module_get_name(mod));
+ log_debug("module '%s' is blacklisted\n", kmod_module_get_name(mod));
else if (err == 0)
- info(udev, "inserted '%s'\n", kmod_module_get_name(mod));
+ log_debug("inserted '%s'\n", kmod_module_get_name(mod));
else
- info(udev, "failed to insert '%s'\n", kmod_module_get_name(mod));
+ log_debug("failed to insert '%s'\n", kmod_module_get_name(mod));
kmod_module_unref(mod);
}
if (!ctx)
return -ENOMEM;
- info(udev, "load module index\n");
+ log_debug("load module index\n");
kmod_set_log_fn(ctx, udev_kmod_log, udev);
kmod_load_resources(ctx);
}
if (argc < 3 || strcmp(argv[1], "load")) {
- err(udev, "expect: %s load <module>\n", argv[0]);
+ log_error("expect: %s load <module>\n", argv[0]);
return EXIT_FAILURE;
}
for (i = 2; argv[i]; i++) {
- info(udev, "execute '%s' '%s'\n", argv[1], argv[i]);
+ log_debug("execute '%s' '%s'\n", argv[1], argv[i]);
load_module(udev, argv[i]);
}
if (!ctx)
return -ENOMEM;
- info(udev, "load module index\n");
+ log_debug("load module index\n");
kmod_set_log_fn(ctx, udev_kmod_log, udev);
kmod_load_resources(ctx);
return 0;
/* called on udev shutdown and reload request */
static void builtin_kmod_exit(struct udev *udev)
{
- info(udev, "unload module index\n");
+ log_debug("unload module index\n");
ctx = kmod_unref(ctx);
}
/* called every couple of seconds during event activity; 'true' if config has changed */
static bool builtin_kmod_validate(struct udev *udev)
{
- info(udev, "validate module index\n");
+ log_debug("validate module index\n");
if (kmod_validate_resources(ctx) != KMOD_RESOURCES_OK)
return true;
return false;
type_str[0] = '\0';
instance_str[0] = '\0';
- dbg(udev, "syspath %s\n", udev_device_get_syspath(dev));
-
/* shortcut, if we are called directly for a "usb_device" type */
if (udev_device_get_devtype(dev) != NULL && strcmp(udev_device_get_devtype(dev), "usb_device") == 0) {
dev_if_packed_info(dev, packed_if_str, sizeof(packed_if_str));
/* usb interface directory */
dev_interface = udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_interface");
if (dev_interface == NULL) {
- info(udev, "unable to access usb_interface device of '%s'\n",
+ log_debug("unable to access usb_interface device of '%s'\n",
udev_device_get_syspath(dev));
return EXIT_FAILURE;
}
if_class = udev_device_get_sysattr_value(dev_interface, "bInterfaceClass");
if (!if_class) {
- info(udev, "%s: cannot get bInterfaceClass attribute\n",
+ log_debug("%s: cannot get bInterfaceClass attribute\n",
udev_device_get_sysname(dev));
return EXIT_FAILURE;
}
set_usb_iftype(type_str, if_class_num, sizeof(type_str)-1);
}
- info(udev, "%s: if_class %d protocol %d\n",
+ log_debug("%s: if_class %d protocol %d\n",
udev_device_get_syspath(dev_interface), if_class_num, protocol);
/* usb device directory */
dev_usb = udev_device_get_parent_with_subsystem_devtype(dev_interface, "usb", "usb_device");
if (!dev_usb) {
- info(udev, "unable to find parent 'usb' device of '%s'\n",
+ log_debug("unable to find parent 'usb' device of '%s'\n",
udev_device_get_syspath(dev));
return EXIT_FAILURE;
}
/* get scsi device */
dev_scsi = udev_device_get_parent_with_subsystem_devtype(dev, "scsi", "scsi_device");
if (dev_scsi == NULL) {
- info(udev, "unable to find parent 'scsi' device of '%s'\n",
+ log_debug("unable to find parent 'scsi' device of '%s'\n",
udev_device_get_syspath(dev));
goto fallback;
}
if (sscanf(udev_device_get_sysname(dev_scsi), "%d:%d:%d:%d", &host, &bus, &target, &lun) != 4) {
- info(udev, "invalid scsi device '%s'\n", udev_device_get_sysname(dev_scsi));
+ log_debug("invalid scsi device '%s'\n", udev_device_get_sysname(dev_scsi));
goto fallback;
}
/* Generic SPC-2 device */
scsi_vendor = udev_device_get_sysattr_value(dev_scsi, "vendor");
if (!scsi_vendor) {
- info(udev, "%s: cannot get SCSI vendor attribute\n",
+ log_debug("%s: cannot get SCSI vendor attribute\n",
udev_device_get_sysname(dev_scsi));
goto fallback;
}
scsi_model = udev_device_get_sysattr_value(dev_scsi, "model");
if (!scsi_model) {
- info(udev, "%s: cannot get SCSI model attribute\n",
+ log_debug("%s: cannot get SCSI model attribute\n",
udev_device_get_sysname(dev_scsi));
goto fallback;
}
scsi_type = udev_device_get_sysattr_value(dev_scsi, "type");
if (!scsi_type) {
- info(udev, "%s: cannot get SCSI type attribute\n",
+ log_debug("%s: cannot get SCSI type attribute\n",
udev_device_get_sysname(dev_scsi));
goto fallback;
}
scsi_rev = udev_device_get_sysattr_value(dev_scsi, "rev");
if (!scsi_rev) {
- info(udev, "%s: cannot get SCSI revision attribute\n",
+ log_debug("%s: cannot get SCSI revision attribute\n",
udev_device_get_sysname(dev_scsi));
goto fallback;
}
if (!usb_vendor)
usb_vendor = vendor_id;
if (!usb_vendor) {
- info(udev, "No USB vendor information available\n");
+ log_debug("No USB vendor information available\n");
return EXIT_FAILURE;
}
udev_util_encode_string(usb_vendor, vendor_str_enc, sizeof(vendor_str_enc));
usb_model = udev_device_get_sysattr_value(dev_usb, "product");
if (!usb_model)
usb_model = product_id;
- if (!usb_model) {
- dbg(udev, "No USB model information available\n");
+ if (!usb_model)
return EXIT_FAILURE;
- }
udev_util_encode_string(usb_model, model_str_enc, sizeof(model_str_enc));
util_replace_whitespace(usb_model, model_str, sizeof(model_str)-1);
util_replace_chars(model_str, NULL);
if (key[0] != '.')
udev_list_entry_set_num(entry, true);
- info(udev_device_get_udev(dev), "%s=%s\n", key, val);
+ log_debug("%s=%s\n", key, val);
if (test)
printf("%s=%s\n", key, val);
return 0;
if (fd < 0) {
uctrl->sock = socket(AF_LOCAL, SOCK_SEQPACKET|SOCK_NONBLOCK|SOCK_CLOEXEC, 0);
if (uctrl->sock < 0) {
- err(udev, "error getting socket: %m\n");
+ log_error("error getting socket: %m\n");
udev_ctrl_unref(uctrl);
return NULL;
}
if (err < 0) {
err = -errno;
- err(uctrl->udev, "bind failed: %m\n");
+ log_error("bind failed: %m\n");
return err;
}
err = listen(uctrl->sock, 0);
if (err < 0) {
err = -errno;
- err(uctrl->udev, "listen failed: %m\n");
+ log_error("listen failed: %m\n");
return err;
}
conn->sock = accept4(uctrl->sock, NULL, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK);
if (conn->sock < 0) {
if (errno != EINTR)
- err(uctrl->udev, "unable to receive ctrl connection: %m\n");
+ log_error("unable to receive ctrl connection: %m\n");
goto err;
}
/* check peer credential of connection */
slen = sizeof(ucred);
if (getsockopt(conn->sock, SOL_SOCKET, SO_PEERCRED, &ucred, &slen) < 0) {
- err(uctrl->udev, "unable to receive credentials of ctrl connection: %m\n");
+ log_error("unable to receive credentials of ctrl connection: %m\n");
goto err;
}
if (ucred.uid > 0) {
- err(uctrl->udev, "sender uid=%i, message ignored\n", ucred.uid);
+ log_error("sender uid=%i, message ignored\n", ucred.uid);
goto err;
}
continue;
goto err;
} else if (r == 0) {
- err(udev, "timeout waiting for ctrl message\n");
+ log_error("timeout waiting for ctrl message\n");
goto err;
} else {
if (!(pfd[0].revents & POLLIN)) {
- err(udev, "ctrl connection error: %m\n");
+ log_error("ctrl connection error: %m\n");
goto err;
}
}
smsg.msg_controllen = sizeof(cred_msg);
size = recvmsg(conn->sock, &smsg, 0);
if (size < 0) {
- err(udev, "unable to receive ctrl message: %m\n");
+ log_error("unable to receive ctrl message: %m\n");
goto err;
}
cmsg = CMSG_FIRSTHDR(&smsg);
cred = (struct ucred *) CMSG_DATA(cmsg);
if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) {
- err(udev, "no sender credentials received, message ignored\n");
+ log_error("no sender credentials received, message ignored\n");
goto err;
}
if (cred->uid != 0) {
- err(udev, "sender uid=%i, message ignored\n", cred->uid);
+ log_error("sender uid=%i, message ignored\n", cred->uid);
goto err;
}
if (uctrl_msg->ctrl_msg_wire.magic != UDEV_CTRL_MAGIC) {
- err(udev, "message magic 0x%08x doesn't match, ignore it\n", uctrl_msg->ctrl_msg_wire.magic);
+ log_error("message magic 0x%08x doesn't match, ignore it\n", uctrl_msg->ctrl_msg_wire.magic);
goto err;
}
- dbg(udev, "created ctrl_msg %p (%i)\n", uctrl_msg, uctrl_msg->ctrl_msg_wire.type);
return uctrl_msg;
err:
udev_ctrl_msg_unref(uctrl_msg);
ctrl_msg->refcount--;
if (ctrl_msg->refcount > 0)
return ctrl_msg;
- dbg(ctrl_msg->conn->uctrl->udev, "release ctrl_msg %p\n", ctrl_msg);
udev_ctrl_connection_unref(ctrl_msg->conn);
free(ctrl_msg);
return NULL;
event->fd_signal = -1;
event->birth_usec = now_usec();
event->timeout_usec = 30 * 1000 * 1000;
- dbg(event->udev, "allocated event %p\n", event);
return event;
}
udev_list_cleanup(&event->run_list);
free(event->program_result);
free(event->name);
- dbg(event->udev, "free event %p\n", event);
free(event);
}
if (strncmp(&from[1], map[i].name, strlen(map[i].name)) == 0) {
type = map[i].type;
from += strlen(map[i].name)+1;
- dbg(event->udev, "will substitute format name '%s'\n", map[i].name);
goto subst;
}
}
if (from[1] == map[i].fmt) {
type = map[i].type;
from += 2;
- dbg(event->udev, "will substitute format char '%c'\n", map[i].fmt);
goto subst;
}
}
from++;
for (i = 0; from[i] != '}'; i++) {
if (from[i] == '\0') {
- err(event->udev, "missing closing brace for format '%s'\n", src);
+ log_error("missing closing brace for format '%s'\n", src);
goto out;
}
}
switch (type) {
case SUBST_DEVPATH:
l = util_strpcpy(&s, l, udev_device_get_devpath(dev));
- dbg(event->udev, "substitute devpath '%s'\n", udev_device_get_devpath(dev));
break;
case SUBST_KERNEL:
l = util_strpcpy(&s, l, udev_device_get_sysname(dev));
- dbg(event->udev, "substitute kernel name '%s'\n", udev_device_get_sysname(dev));
break;
case SUBST_KERNEL_NUMBER:
if (udev_device_get_sysnum(dev) == NULL)
break;
l = util_strpcpy(&s, l, udev_device_get_sysnum(dev));
- dbg(event->udev, "substitute kernel number '%s'\n", udev_device_get_sysnum(dev));
break;
case SUBST_ID:
if (event->dev_parent == NULL)
break;
l = util_strpcpy(&s, l, udev_device_get_sysname(event->dev_parent));
- dbg(event->udev, "substitute id '%s'\n", udev_device_get_sysname(event->dev_parent));
break;
case SUBST_DRIVER: {
const char *driver;
if (driver == NULL)
break;
l = util_strpcpy(&s, l, driver);
- dbg(event->udev, "substitute driver '%s'\n", driver);
break;
}
case SUBST_MAJOR: {
sprintf(num, "%d", major(udev_device_get_devnum(dev)));
l = util_strpcpy(&s, l, num);
- dbg(event->udev, "substitute major number '%s'\n", num);
break;
}
case SUBST_MINOR: {
sprintf(num, "%d", minor(udev_device_get_devnum(dev)));
l = util_strpcpy(&s, l, num);
- dbg(event->udev, "substitute minor number '%s'\n", num);
break;
}
case SUBST_RESULT: {
char tmp[UTIL_PATH_SIZE];
char *cpos;
- dbg(event->udev, "request part #%d of result string\n", i);
util_strscpy(result, sizeof(result), event->program_result);
cpos = result;
while (--i) {
cpos++;
}
if (i > 0) {
- err(event->udev, "requested part of result string not found\n");
+ log_error("requested part of result string not found\n");
break;
}
util_strscpy(tmp, sizeof(tmp), cpos);
cpos[0] = '\0';
}
l = util_strpcpy(&s, l, tmp);
- dbg(event->udev, "substitute part of result string '%s'\n", tmp);
} else {
l = util_strpcpy(&s, l, event->program_result);
- dbg(event->udev, "substitute result string '%s'\n", event->program_result);
}
break;
}
int count;
if (attr == NULL) {
- err(event->udev, "missing file parameter for attr\n");
+ log_error("missing file parameter for attr\n");
break;
}
vbuf[len] = '\0';
count = util_replace_chars(vbuf, UDEV_ALLOWED_CHARS_INPUT);
if (count > 0)
- info(event->udev, "%i character(s) replaced\n" , count);
+ log_debug("%i character(s) replaced\n" , count);
l = util_strpcpy(&s, l, vbuf);
- dbg(event->udev, "substitute sysfs value '%s'\n", vbuf);
break;
}
case SUBST_PARENT: {
size_t devlen = strlen(udev_get_dev_path(event->udev))+1;
l = util_strpcpy(&s, l, &devnode[devlen]);
- dbg(event->udev, "found parent '%s', got node name '%s'\n",
- udev_device_get_syspath(dev_parent), &devnode[devlen]);
}
break;
}
case SUBST_NAME: {
if (event->name != NULL) {
l = util_strpcpy(&s, l, event->name);
- dbg(event->udev, "substitute custom node name '%s'\n", event->name);
} else if (udev_device_get_devnode(dev) != NULL) {
size_t devlen = strlen(udev_get_dev_path(event->udev))+1;
l = util_strpcpy(&s, l, &udev_device_get_devnode(dev)[devlen]);
- dbg(event->udev, "substitute node name'%s'\n", &udev_device_get_devnode(dev)[devlen]);
} else {
l = util_strpcpy(&s, l, udev_device_get_sysname(dev));
- dbg(event->udev, "substitute device name'%s'\n", udev_device_get_sysname(dev));
}
break;
}
}
case SUBST_ROOT:
l = util_strpcpy(&s, l, udev_get_dev_path(event->udev));
- dbg(event->udev, "substitute udev_root '%s'\n", udev_get_dev_path(event->udev));
break;
case SUBST_SYS:
l = util_strpcpy(&s, l, udev_get_sys_path(event->udev));
- dbg(event->udev, "substitute sys_path '%s'\n", udev_get_sys_path(event->udev));
break;
case SUBST_ENV:
if (attr == NULL) {
- dbg(event->udev, "missing attribute\n");
break;
} else {
const char *value;
value = udev_device_get_property_value(event->dev, attr);
if (value == NULL)
break;
- dbg(event->udev, "substitute env '%s=%s'\n", attr, value);
l = util_strpcpy(&s, l, value);
break;
}
default:
- err(event->udev, "unknown substitution type=%i\n", type);
+ log_error("unknown substitution type=%i\n", type);
break;
}
}
out:
s[0] = '\0';
- dbg(event->udev, "'%s' -> '%s' (%zu)\n", src, dest, l);
return l;
}
dup2(fd, STDERR_FILENO);
close(fd);
} else {
- err(udev, "open /dev/null failed: %m\n");
+ log_error("open /dev/null failed: %m\n");
}
/* connect pipes to std{out,err} */
/* exec failed */
err = -errno;
- err(udev, "failed to execute '%s' '%s': %m\n", argv[0], cmd);
+ log_error("failed to execute '%s' '%s': %m\n", argv[0], cmd);
return err;
}
fd_ep = epoll_create1(EPOLL_CLOEXEC);
if (fd_ep < 0) {
- err(udev, "error creating epoll fd: %m\n");
+ log_error("error creating epoll fd: %m\n");
goto out;
}
ep_outpipe.events = EPOLLIN;
ep_outpipe.data.ptr = &fd_stdout;
if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_stdout, &ep_outpipe) < 0) {
- err(udev, "fail to add fd to epoll: %m\n");
+ log_error("fail to add fd to epoll: %m\n");
goto out;
}
}
ep_errpipe.events = EPOLLIN;
ep_errpipe.data.ptr = &fd_stderr;
if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_stderr, &ep_errpipe) < 0) {
- err(udev, "fail to add fd to epoll: %m\n");
+ log_error("fail to add fd to epoll: %m\n");
goto out;
}
}
age_usec = now_usec() - event->birth_usec;
if (age_usec >= event->timeout_usec) {
- err(udev, "timeout '%s'\n", cmd);
+ log_error("timeout '%s'\n", cmd);
goto out;
}
timeout = ((event->timeout_usec - age_usec) / 1000) + 1000;
if (fdcount < 0) {
if (errno == EINTR)
continue;
- err(udev, "failed to poll: %m\n");
+ log_error("failed to poll: %m\n");
goto out;
}
if (fdcount == 0) {
- err(udev, "timeout '%s'\n", cmd);
+ log_error("timeout '%s'\n", cmd);
goto out;
}
memcpy(&result[respos], buf, count);
respos += count;
} else {
- err(udev, "'%s' ressize %zd too short\n", cmd, ressize);
+ log_error("'%s' ressize %zd too short\n", cmd, ressize);
}
}
pos = buf;
while ((line = strsep(&pos, "\n"))) {
if (pos != NULL || line[0] != '\0')
- info(udev, "'%s'(%s) '%s'\n", cmd, *fd == fd_stdout ? "out" : "err" , line);
+ log_debug("'%s'(%s) '%s'\n", cmd, *fd == fd_stdout ? "out" : "err" , line);
}
}
} else if (ev[i].events & EPOLLHUP) {
if (epoll_ctl(fd_ep, EPOLL_CTL_DEL, *fd, NULL) < 0) {
- err(udev, "failed to remove fd from epoll: %m\n");
+ log_error("failed to remove fd from epoll: %m\n");
goto out;
}
*fd = -1;
}
/* return the child's stdout string */
- if (result != NULL) {
+ if (result != NULL)
result[respos] = '\0';
- dbg(udev, "result='%s'\n", result);
- }
out:
if (fd_ep >= 0)
close(fd_ep);
if (errno == EINTR)
continue;
err = -errno;
- err(udev, "failed to poll: %m\n");
+ log_error("failed to poll: %m\n");
goto out;
}
if (fdcount == 0) {
- err(udev, "timeout: killing '%s' [%u]\n", cmd, pid);
+ log_error("timeout: killing '%s' [%u]\n", cmd, pid);
kill(pid, SIGKILL);
}
if (waitpid(pid, &status, WNOHANG) < 0)
break;
if (WIFEXITED(status)) {
- info(udev, "'%s' [%u] exit with return code %i\n", cmd, pid, WEXITSTATUS(status));
+ log_debug("'%s' [%u] exit with return code %i\n", cmd, pid, WEXITSTATUS(status));
if (WEXITSTATUS(status) != 0)
err = -1;
} else if (WIFSIGNALED(status)) {
- err(udev, "'%s' [%u] terminated by signal %i (%s)\n", cmd, pid, WTERMSIG(status), strsignal(WTERMSIG(status)));
+ log_error("'%s' [%u] terminated by signal %i (%s)\n", cmd, pid, WTERMSIG(status), strsignal(WTERMSIG(status)));
err = -1;
} else if (WIFSTOPPED(status)) {
- err(udev, "'%s' [%u] stopped\n", cmd, pid);
+ log_error("'%s' [%u] stopped\n", cmd, pid);
err = -1;
} else if (WIFCONTINUED(status)) {
- err(udev, "'%s' [%u] continued\n", cmd, pid);
+ log_error("'%s' [%u] continued\n", cmd, pid);
err = -1;
} else {
- err(udev, "'%s' [%u] exit with status 0x%04x\n", cmd, pid, status);
+ log_error("'%s' [%u] exit with status 0x%04x\n", cmd, pid, status);
err = -1;
}
pid = 0;
while (pos[0] == ' ')
pos++;
}
- dbg(udev, "argv[%i] '%s'\n", i, argv[i]);
i++;
}
out:
if (result != NULL || udev_get_log_priority(udev) >= LOG_INFO) {
if (pipe2(outpipe, O_NONBLOCK) != 0) {
err = -errno;
- err(udev, "pipe failed: %m\n");
+ log_error("pipe failed: %m\n");
goto out;
}
}
if (udev_get_log_priority(udev) >= LOG_INFO) {
if (pipe2(errpipe, O_NONBLOCK) != 0) {
err = -errno;
- err(udev, "pipe failed: %m\n");
+ log_error("pipe failed: %m\n");
goto out;
}
}
errpipe[READ_END] = -1;
}
- info(udev, "starting '%s'\n", cmd);
+ log_debug("starting '%s'\n", cmd);
err = spawn_exec(event, cmd, argv, envp, sigmask,
outpipe[WRITE_END], errpipe[WRITE_END]);
_exit(2 );
case -1:
- err(udev, "fork of '%s' failed: %m\n", cmd);
+ log_error("fork of '%s' failed: %m\n", cmd);
err = -1;
goto out;
default:
int loop;
int err;
- info(event->udev, "changing net interface name from '%s' to '%s'\n",
- udev_device_get_sysname(dev), event->name);
+ log_debug("changing net interface name from '%s' to '%s'\n",
+ udev_device_get_sysname(dev), event->name);
sk = socket(PF_INET, SOCK_DGRAM, 0);
if (sk < 0) {
err = -errno;
- err(event->udev, "error opening socket: %m\n");
+ log_error("error opening socket: %m\n");
return err;
}
while (loop--) {
const struct timespec duration = { 0, 1000 * 1000 * 1000 / 20 };
- dbg(event->udev, "wait for netif '%s' to become free, loop=%i\n",
- event->name, (90 * 20) - loop);
nanosleep(&duration, NULL);
err = ioctl(sk, SIOCSIFNAME, &ifr);
out:
if (err < 0)
- err(event->udev, "error changing net interface name %s to %s: %m\n", ifr.ifr_name, ifr.ifr_newname);
+ log_error("error changing net interface name %s to %s: %m\n", ifr.ifr_name, ifr.ifr_newname);
close(sk);
return err;
}
err = rename_netif(event);
if (err == 0) {
- info(event->udev, "renamed netif to '%s'\n", event->name);
+ log_debug("renamed netif to '%s'\n", event->name);
/* remember old name */
udev_device_add_property(dev, "INTERFACE_OLD", udev_device_get_sysname(dev));
util_strscpy(pos, sizeof(syspath) - (pos - syspath), event->name);
udev_device_set_syspath(event->dev, syspath);
udev_device_add_property(dev, "INTERFACE", udev_device_get_sysname(dev));
- info(event->udev, "changed devpath to '%s'\n", udev_device_get_devpath(dev));
+ log_debug("changed devpath to '%s'\n", udev_device_get_devpath(dev));
}
}
}
struct udev_list_entry *list_entry;
int err = 0;
- dbg(event->udev, "executing run list\n");
udev_list_entry_foreach(list_entry, udev_list_get_entry(&event->run_list)) {
const char *cmd = udev_list_entry_get_name(list_entry);
char **envp;
if (event->exec_delay > 0) {
- info(event->udev, "delay execution of '%s'\n", program);
+ log_debug("delay execution of '%s'\n", program);
sleep(event->exec_delay);
}
if (S_ISBLK(stats.st_mode) || S_ISCHR(stats.st_mode)) {
struct stat stats2;
- info(udev, "found existing node instead of symlink '%s'\n", slink);
+ log_debug("found existing node instead of symlink '%s'\n", slink);
if (lstat(node, &stats2) == 0) {
if ((stats.st_mode & S_IFMT) == (stats2.st_mode & S_IFMT) &&
stats.st_rdev == stats2.st_rdev && stats.st_ino != stats2.st_ino) {
- info(udev, "replace device node '%s' with symlink to our node '%s'\n",
+ log_debug("replace device node '%s' with symlink to our node '%s'\n",
slink, node);
} else {
- err(udev, "device node '%s' already exists, "
+ log_error("device node '%s' already exists, "
"link to '%s' will not overwrite it\n",
slink, node);
goto exit;
char buf[UTIL_PATH_SIZE];
int len;
- dbg(udev, "found existing symlink '%s'\n", slink);
len = readlink(slink, buf, sizeof(buf));
if (len > 0 && len < (int)sizeof(buf)) {
buf[len] = '\0';
if (strcmp(target, buf) == 0) {
- info(udev, "preserve already existing symlink '%s' to '%s'\n",
- slink, target);
+ log_debug("preserve already existing symlink '%s' to '%s'\n", slink, target);
udev_selinux_lsetfilecon(udev, slink, S_IFLNK);
utimensat(AT_FDCWD, slink, NULL, AT_SYMLINK_NOFOLLOW);
goto exit;
}
}
} else {
- info(udev, "creating symlink '%s' to '%s'\n", slink, target);
+ log_debug("creating symlink '%s' to '%s'\n", slink, target);
do {
err = util_create_path_selinux(udev, slink);
if (err != 0 && err != -ENOENT)
goto exit;
}
- info(udev, "atomically replace '%s'\n", slink);
+ log_debug("atomically replace '%s'\n", slink);
util_strscpyl(slink_tmp, sizeof(slink_tmp), slink, TMP_FILE_EXT, NULL);
unlink(slink_tmp);
do {
udev_selinux_resetfscreatecon(udev);
} while (err == -ENOENT);
if (err != 0) {
- err(udev, "symlink '%s' '%s' failed: %m\n", target, slink_tmp);
+ log_error("symlink '%s' '%s' failed: %m\n", target, slink_tmp);
goto exit;
}
err = rename(slink_tmp, slink);
if (err != 0) {
- err(udev, "rename '%s' '%s' failed: %m\n", slink_tmp, slink);
+ log_error("rename '%s' '%s' failed: %m\n", slink_tmp, slink);
unlink(slink_tmp);
}
exit:
if (dent->d_name[0] == '.')
continue;
- info(udev, "found '%s' claiming '%s'\n", dent->d_name, stackdir);
+ log_debug("found '%s' claiming '%s'\n", dent->d_name, stackdir);
/* did we find ourself? */
if (strcmp(dent->d_name, udev_device_get_id_filename(dev)) == 0)
devnode = udev_device_get_devnode(dev_db);
if (devnode != NULL) {
- dbg(udev, "compare priority of '%s'(%i) > '%s'(%i)\n", target, priority,
- udev_device_get_devnode(dev_db), udev_device_get_devlink_priority(dev_db));
if (target == NULL || udev_device_get_devlink_priority(dev_db) > priority) {
- info(udev, "'%s' claims priority %i for '%s'\n",
- udev_device_get_syspath(dev_db), udev_device_get_devlink_priority(dev_db), stackdir);
+ log_debug("'%s' claims priority %i for '%s'\n",
+ udev_device_get_syspath(dev_db), udev_device_get_devlink_priority(dev_db), stackdir);
priority = udev_device_get_devlink_priority(dev_db);
util_strscpy(buf, bufsize, devnode);
target = buf;
const char *target;
char buf[UTIL_PATH_SIZE];
- dbg(udev, "update symlink '%s' of '%s'\n", slink, udev_device_get_syspath(dev));
-
util_path_encode(&slink[strlen(udev_get_dev_path(udev))+1], name_enc, sizeof(name_enc));
util_strscpyl(dirname, sizeof(dirname), udev_get_run_path(udev), "/links/", name_enc, NULL);
util_strscpyl(filename, sizeof(filename), dirname, "/", udev_device_get_id_filename(dev), NULL);
- if (!add) {
- dbg(udev, "removing index: '%s'\n", filename);
- if (unlink(filename) == 0)
- rmdir(dirname);
- }
+ if (!add && unlink(filename) == 0)
+ rmdir(dirname);
target = link_find_prioritized(dev, add, dirname, buf, sizeof(buf));
if (target == NULL) {
- info(udev, "no reference left, remove '%s'\n", slink);
+ log_debug("no reference left, remove '%s'\n", slink);
if (unlink(slink) == 0)
util_delete_path(udev, slink);
} else {
- info(udev, "creating link '%s' to '%s'\n", slink, target);
+ log_debug("creating link '%s' to '%s'\n", slink, target);
node_symlink(udev, target, slink);
}
if (add) {
int err;
- dbg(udev, "creating index: '%s'\n", filename);
do {
int fd;
if (found)
continue;
- info(udev, "update old name, '%s' no longer belonging to '%s'\n",
+ log_debug("update old name, '%s' no longer belonging to '%s'\n",
name, udev_device_get_devpath(dev));
link_update(dev, name, 0);
}
if (lstat(devnode, &stats) != 0) {
err = -errno;
- info(udev, "can not stat() node '%s' (%m)\n", devnode);
+ log_debug("can not stat() node '%s' (%m)\n", devnode);
goto out;
}
if (((stats.st_mode & S_IFMT) != (mode & S_IFMT)) || (stats.st_rdev != devnum)) {
err = -EEXIST;
- info(udev, "found node '%s' with non-matching devnum %s, skip handling\n",
- udev_device_get_devnode(dev), udev_device_get_id_filename(dev));
+ log_debug("found node '%s' with non-matching devnum %s, skip handling\n",
+ udev_device_get_devnode(dev), udev_device_get_id_filename(dev));
goto out;
}
if ((stats.st_mode & 0777) != (mode & 0777) || stats.st_uid != uid || stats.st_gid != gid) {
- info(udev, "set permissions %s, %#o, uid=%u, gid=%u\n", devnode, mode, uid, gid);
+ log_debug("set permissions %s, %#o, uid=%u, gid=%u\n", devnode, mode, uid, gid);
chmod(devnode, mode);
chown(devnode, uid, gid);
} else {
- info(udev, "preserve permissions %s, %#o, uid=%u, gid=%u\n", devnode, mode, uid, gid);
+ log_debug("preserve permissions %s, %#o, uid=%u, gid=%u\n", devnode, mode, uid, gid);
}
/*
struct udev_list_entry *list_entry;
int err = 0;
- info(udev, "handling device node '%s', devnum=%s, mode=%#o, uid=%d, gid=%d\n",
- udev_device_get_devnode(dev), udev_device_get_id_filename(dev), mode, uid, gid);
+ log_debug("handling device node '%s', devnum=%s, mode=%#o, uid=%d, gid=%d\n",
+ udev_device_get_devnode(dev), udev_device_get_id_filename(dev), mode, uid, gid);
if (node_fixup(dev, mode, uid, gid) < 0)
return;
unsigned int token_cur;
};
-#ifdef ENABLE_DEBUG
+#ifdef DEBUG
static const char *operation_str(enum operation_type type)
{
static const char *operation_strs[] = {
const char *tk_ptr = (char *)token;
unsigned int idx = (tk_ptr - tks_ptr) / sizeof(struct token);
- dbg(rules->udev, "* RULE %s:%u, token: %u, count: %u, label: '%s'\n",
- &rules->buf[token->rule.filename_off], token->rule.filename_line,
- idx, token->rule.token_count,
- &rules->buf[token->rule.label_off]);
+ log_debug("* RULE %s:%u, token: %u, count: %u, label: '%s'\n",
+ &rules->buf[token->rule.filename_off], token->rule.filename_line,
+ idx, token->rule.token_count,
+ &rules->buf[token->rule.label_off]);
break;
}
case TK_M_ACTION:
case TK_A_GROUP:
case TK_A_MODE:
case TK_A_RUN:
- dbg(rules->udev, "%s %s '%s'(%s)\n",
- token_str(type), operation_str(op), value, string_glob_str(glob));
+ log_debug("%s %s '%s'(%s)\n",
+ token_str(type), operation_str(op), value, string_glob_str(glob));
break;
case TK_M_IMPORT_BUILTIN:
- dbg(rules->udev, "%s %i '%s'\n", token_str(type), token->key.builtin_cmd, value);
+ log_debug("%s %i '%s'\n", token_str(type), token->key.builtin_cmd, value);
break;
case TK_M_ATTR:
case TK_M_ATTRS:
case TK_M_ENV:
case TK_A_ATTR:
case TK_A_ENV:
- dbg(rules->udev, "%s %s '%s' '%s'(%s)\n",
- token_str(type), operation_str(op), attr, value, string_glob_str(glob));
+ log_debug("%s %s '%s' '%s'(%s)\n",
+ token_str(type), operation_str(op), attr, value, string_glob_str(glob));
break;
case TK_M_TAG:
case TK_A_TAG:
- dbg(rules->udev, "%s %s '%s'\n", token_str(type), operation_str(op), value);
+ log_debug("%s %s '%s'\n", token_str(type), operation_str(op), value);
break;
case TK_A_STRING_ESCAPE_NONE:
case TK_A_STRING_ESCAPE_REPLACE:
case TK_A_DB_PERSIST:
- dbg(rules->udev, "%s\n", token_str(type));
+ log_debug("%s\n", token_str(type));
break;
case TK_M_TEST:
- dbg(rules->udev, "%s %s '%s'(%s) %#o\n",
- token_str(type), operation_str(op), value, string_glob_str(glob), token->key.mode);
+ log_debug("%s %s '%s'(%s) %#o\n",
+ token_str(type), operation_str(op), value, string_glob_str(glob), token->key.mode);
break;
case TK_A_INOTIFY_WATCH:
- dbg(rules->udev, "%s %u\n", token_str(type), token->key.watch);
+ log_debug("%s %u\n", token_str(type), token->key.watch);
break;
case TK_A_DEVLINK_PRIO:
- dbg(rules->udev, "%s %u\n", token_str(type), token->key.devlink_prio);
+ log_debug("%s %u\n", token_str(type), token->key.devlink_prio);
break;
case TK_A_OWNER_ID:
- dbg(rules->udev, "%s %s %u\n", token_str(type), operation_str(op), token->key.uid);
+ log_debug("%s %s %u\n", token_str(type), operation_str(op), token->key.uid);
break;
case TK_A_GROUP_ID:
- dbg(rules->udev, "%s %s %u\n", token_str(type), operation_str(op), token->key.gid);
+ log_debug("%s %s %u\n", token_str(type), operation_str(op), token->key.gid);
break;
case TK_A_MODE_ID:
- dbg(rules->udev, "%s %s %#o\n", token_str(type), operation_str(op), token->key.mode);
+ log_debug("%s %s %#o\n", token_str(type), operation_str(op), token->key.mode);
break;
case TK_A_STATIC_NODE:
- dbg(rules->udev, "%s '%s'\n", token_str(type), value);
+ log_debug("%s '%s'\n", token_str(type), value);
break;
case TK_M_EVENT_TIMEOUT:
- dbg(rules->udev, "%s %u\n", token_str(type), token->key.event_timeout);
+ log_debug("%s %u\n", token_str(type), token->key.event_timeout);
break;
case TK_A_GOTO:
- dbg(rules->udev, "%s '%s' %u\n", token_str(type), value, token->key.rule_goto);
+ log_debug("%s '%s' %u\n", token_str(type), value, token->key.rule_goto);
break;
case TK_END:
- dbg(rules->udev, "* %s\n", token_str(type));
+ log_debug("* %s\n", token_str(type));
break;
case TK_M_PARENTS_MIN:
case TK_M_PARENTS_MAX:
case TK_M_MAX:
case TK_UNSET:
- dbg(rules->udev, "unknown type %u\n", type);
+ log_debug("unknown type %u\n", type);
break;
}
}
{
unsigned int i;
- dbg(rules->udev, "dumping %u (%zu bytes) tokens, %u (%zu bytes) strings\n",
- rules->token_cur,
- rules->token_cur * sizeof(struct token),
- rules->buf_count,
- rules->buf_cur);
+ log_debug("dumping %u (%zu bytes) tokens, %u (%zu bytes) strings\n",
+ rules->token_cur,
+ rules->token_cur * sizeof(struct token),
+ rules->buf_count,
+ rules->buf_cur);
for(i = 0; i < rules->token_cur; i++)
dump_token(rules, &rules->tokens[i]);
}
static inline const char *token_str(enum token_type type) { return NULL; }
static inline void dump_token(struct udev_rules *rules, struct token *token) {}
static inline void dump_rules(struct udev_rules *rules) {}
-#endif /* ENABLE_DEBUG */
+#endif /* DEBUG */
static int add_new_string(struct udev_rules *rules, const char *str, size_t bytes)
{
buf = realloc(rules->buf, rules->buf_max + add);
if (buf == NULL)
return -1;
- dbg(rules->udev, "extend buffer from %zu to %zu\n", rules->buf_max, rules->buf_max + add);
rules->buf = buf;
rules->buf_max += add;
}
nodes = realloc(rules->trie_nodes, (rules->trie_nodes_max + add) * sizeof(struct trie_node));
if (nodes == NULL)
return -1;
- dbg(rules->udev, "extend trie nodes from %u to %u\n",
- rules->trie_nodes_max, rules->trie_nodes_max + add);
rules->trie_nodes = nodes;
rules->trie_nodes_max += add;
}
tokens = realloc(rules->tokens, (rules->token_max + add ) * sizeof(struct token));
if (tokens == NULL)
return -1;
- dbg(rules->udev, "extend tokens from %u to %u\n", rules->token_max, rules->token_max + add);
rules->tokens = tokens;
rules->token_max += add;
}
off = rules->uids[i].name_off;
if (strcmp(&rules->buf[off], owner) == 0) {
uid = rules->uids[i].uid;
- dbg(rules->udev, "return existing %u for '%s'\n", uid, owner);
return uid;
}
}
uids = realloc(rules->uids, (rules->uids_max + add ) * sizeof(struct uid_gid));
if (uids == NULL)
return uid;
- dbg(rules->udev, "extend uids from %u to %u\n", rules->uids_max, rules->uids_max + add);
rules->uids = uids;
rules->uids_max += add;
}
off = rules->gids[i].name_off;
if (strcmp(&rules->buf[off], group) == 0) {
gid = rules->gids[i].gid;
- dbg(rules->udev, "return existing %u for '%s'\n", gid, group);
return gid;
}
}
gids = realloc(rules->gids, (rules->gids_max + add ) * sizeof(struct uid_gid));
if (gids == NULL)
return gid;
- dbg(rules->udev, "extend gids from %u to %u\n", rules->gids_max, rules->gids_max + add);
rules->gids = gids;
rules->gids_max += add;
}
/* unquote */
if (val[0] == '"' || val[0] == '\'') {
if (val[len-1] != val[0]) {
- info(udev, "inconsistent quoting: '%s', skip\n", line);
+ log_debug("inconsistent quoting: '%s', skip\n", line);
return -1;
}
val[len-1] = '\0';
val++;
}
- dbg(udev, "adding '%s'='%s'\n", key, val);
-
/* handle device, renamed by external tool, returning new path */
if (strcmp(key, "DEVPATH") == 0) {
char syspath[UTIL_PATH_SIZE];
- info(udev, "updating devpath from '%s' to '%s'\n",
- udev_device_get_devpath(dev), val);
+ log_debug("updating devpath from '%s' to '%s'\n",
+ udev_device_get_devpath(dev), val);
util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), val, NULL);
udev_device_set_syspath(dev, syspath);
} else {
if (dev_parent == NULL)
return -1;
- dbg(udev, "found parent '%s', get the node name\n", udev_device_get_syspath(dev_parent));
udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(dev_parent)) {
const char *key = udev_list_entry_get_name(list_entry);
const char *val = udev_list_entry_get_value(list_entry);
if (fnmatch(filter, key, 0) == 0) {
struct udev_list_entry *entry;
- dbg(udev, "import key '%s=%s'\n", key, val);
entry = udev_device_add_property(dev, key, val);
/* store in db, skip private keys */
if (key[0] != '.')
file = filepath;
}
- dbg(udev, "will wait %i sec for '%s'\n", timeout, file);
while (--loop) {
const struct timespec duration = { 0, 1000 * 1000 * 1000 / WAIT_LOOP_PER_SECOND };
/* lookup file */
if (stat(file, &stats) == 0) {
- info(udev, "file '%s' appeared after %i loops\n", file, (timeout * WAIT_LOOP_PER_SECOND) - loop-1);
+ log_debug("file '%s' appeared after %i loops\n", file, (timeout * WAIT_LOOP_PER_SECOND) - loop-1);
return 0;
}
/* make sure, the device did not disappear in the meantime */
if (devicepath[0] != '\0' && stat(devicepath, &stats) != 0) {
- info(udev, "device disappeared while waiting for '%s'\n", file);
+ log_debug("device disappeared while waiting for '%s'\n", file);
return -2;
}
- info(udev, "wait for '%s' for %i mseconds\n", file, 1000 / WAIT_LOOP_PER_SECOND);
+ log_debug("wait for '%s' for %i mseconds\n", file, 1000 / WAIT_LOOP_PER_SECOND);
nanosleep(&duration, NULL);
}
- info(udev, "waiting for '%s' failed\n", file);
+ log_debug("waiting for '%s' failed\n", file);
return -1;
}
return -1;
temp[0] = '\0';
temp++;
- dbg(udev, "%s '%s'-'%s'\n", operation_str(*op), *key, *value);
/* move line to next key */
*line = temp;
attr++;
pos = strchr(attr, '}');
if (pos == NULL) {
- err(udev, "missing closing brace for format\n");
+ log_error("missing closing brace for format\n");
return NULL;
}
pos[0] = '\0';
- dbg(udev, "attribute='%s'\n", attr);
return attr;
}
return NULL;
case TK_M_MAX:
case TK_END:
case TK_UNSET:
- err(rule_tmp->rules->udev, "wrong type %u\n", type);
+ log_error("wrong type %u\n", type);
return -1;
}
token->key.op = op;
rule_tmp->token_cur++;
if (rule_tmp->token_cur >= ARRAY_SIZE(rule_tmp->token)) {
- err(rule_tmp->rules->udev, "temporary rule array too small\n");
+ log_error("temporary rule array too small\n");
return -1;
}
return 0;
if (strcmp(key, "ACTION") == 0) {
if (op > OP_MATCH_MAX) {
- err(rules->udev, "invalid ACTION operation\n");
+ log_error("invalid ACTION operation\n");
goto invalid;
}
rule_add_key(&rule_tmp, TK_M_ACTION, op, value, NULL);
if (strcmp(key, "DEVPATH") == 0) {
if (op > OP_MATCH_MAX) {
- err(rules->udev, "invalid DEVPATH operation\n");
+ log_error("invalid DEVPATH operation\n");
goto invalid;
}
rule_add_key(&rule_tmp, TK_M_DEVPATH, op, value, NULL);
if (strcmp(key, "KERNEL") == 0) {
if (op > OP_MATCH_MAX) {
- err(rules->udev, "invalid KERNEL operation\n");
+ log_error("invalid KERNEL operation\n");
goto invalid;
}
rule_add_key(&rule_tmp, TK_M_KERNEL, op, value, NULL);
if (strcmp(key, "SUBSYSTEM") == 0) {
if (op > OP_MATCH_MAX) {
- err(rules->udev, "invalid SUBSYSTEM operation\n");
+ log_error("invalid SUBSYSTEM operation\n");
goto invalid;
}
/* bus, class, subsystem events should all be the same */
strcmp(value, "bus") == 0 ||
strcmp(value, "class") == 0) {
if (strcmp(value, "bus") == 0 || strcmp(value, "class") == 0)
- err(rules->udev, "'%s' must be specified as 'subsystem' \n"
+ log_error("'%s' must be specified as 'subsystem' \n"
"please fix it in %s:%u", value, filename, lineno);
rule_add_key(&rule_tmp, TK_M_SUBSYSTEM, op, "subsystem|class|bus", NULL);
} else
if (strcmp(key, "DRIVER") == 0) {
if (op > OP_MATCH_MAX) {
- err(rules->udev, "invalid DRIVER operation\n");
+ log_error("invalid DRIVER operation\n");
goto invalid;
}
rule_add_key(&rule_tmp, TK_M_DRIVER, op, value, NULL);
if (strncmp(key, "ATTR{", sizeof("ATTR{")-1) == 0) {
attr = get_key_attribute(rules->udev, key + sizeof("ATTR")-1);
if (attr == NULL) {
- err(rules->udev, "error parsing ATTR attribute\n");
+ log_error("error parsing ATTR attribute\n");
goto invalid;
}
if (op < OP_MATCH_MAX) {
if (strcmp(key, "KERNELS") == 0) {
if (op > OP_MATCH_MAX) {
- err(rules->udev, "invalid KERNELS operation\n");
+ log_error("invalid KERNELS operation\n");
goto invalid;
}
rule_add_key(&rule_tmp, TK_M_KERNELS, op, value, NULL);
if (strcmp(key, "SUBSYSTEMS") == 0) {
if (op > OP_MATCH_MAX) {
- err(rules->udev, "invalid SUBSYSTEMS operation\n");
+ log_error("invalid SUBSYSTEMS operation\n");
goto invalid;
}
rule_add_key(&rule_tmp, TK_M_SUBSYSTEMS, op, value, NULL);
if (strcmp(key, "DRIVERS") == 0) {
if (op > OP_MATCH_MAX) {
- err(rules->udev, "invalid DRIVERS operation\n");
+ log_error("invalid DRIVERS operation\n");
goto invalid;
}
rule_add_key(&rule_tmp, TK_M_DRIVERS, op, value, NULL);
if (strncmp(key, "ATTRS{", sizeof("ATTRS{")-1) == 0) {
if (op > OP_MATCH_MAX) {
- err(rules->udev, "invalid ATTRS operation\n");
+ log_error("invalid ATTRS operation\n");
goto invalid;
}
attr = get_key_attribute(rules->udev, key + sizeof("ATTRS")-1);
if (attr == NULL) {
- err(rules->udev, "error parsing ATTRS attribute\n");
+ log_error("error parsing ATTRS attribute\n");
goto invalid;
}
if (strncmp(attr, "device/", 7) == 0)
- err(rules->udev, "the 'device' link may not be available in a future kernel, "
+ log_error("the 'device' link may not be available in a future kernel, "
"please fix it in %s:%u", filename, lineno);
else if (strstr(attr, "../") != NULL)
- err(rules->udev, "do not reference parent sysfs directories directly, "
+ log_error("do not reference parent sysfs directories directly, "
"it may break with a future kernel, please fix it in %s:%u", filename, lineno);
rule_add_key(&rule_tmp, TK_M_ATTRS, op, value, attr);
continue;
if (strcmp(key, "TAGS") == 0) {
if (op > OP_MATCH_MAX) {
- err(rules->udev, "invalid TAGS operation\n");
+ log_error("invalid TAGS operation\n");
goto invalid;
}
rule_add_key(&rule_tmp, TK_M_TAGS, op, value, NULL);
if (strncmp(key, "ENV{", sizeof("ENV{")-1) == 0) {
attr = get_key_attribute(rules->udev, key + sizeof("ENV")-1);
if (attr == NULL) {
- err(rules->udev, "error parsing ENV attribute\n");
+ log_error("error parsing ENV attribute\n");
goto invalid;
}
if (op < OP_MATCH_MAX) {
for (i = 0; i < ARRAY_SIZE(blacklist); i++)
if (strcmp(attr, blacklist[i]) == 0) {
- err(rules->udev, "invalid ENV attribute, '%s' can not be set %s:%u\n", attr, filename, lineno);
+ log_error("invalid ENV attribute, '%s' can not be set %s:%u\n", attr, filename, lineno);
continue;
}
if (rule_add_key(&rule_tmp, TK_A_ENV, op, value, attr) != 0)
if (strcmp(key, "RESULT") == 0) {
if (op > OP_MATCH_MAX) {
- err(rules->udev, "invalid RESULT operation\n");
+ log_error("invalid RESULT operation\n");
goto invalid;
}
rule_add_key(&rule_tmp, TK_M_RESULT, op, value, NULL);
if (strncmp(key, "IMPORT", sizeof("IMPORT")-1) == 0) {
attr = get_key_attribute(rules->udev, key + sizeof("IMPORT")-1);
if (attr == NULL) {
- err(rules->udev, "IMPORT{} type missing, ignoring IMPORT %s:%u\n", filename, lineno);
+ log_error("IMPORT{} type missing, ignoring IMPORT %s:%u\n", filename, lineno);
continue;
}
if (strstr(attr, "program")) {
cmd = udev_builtin_lookup(value);
if (cmd < UDEV_BUILTIN_MAX) {
- info(rules->udev, "IMPORT found builtin '%s', replacing %s:%u\n",
- value, filename, lineno);
+ log_debug("IMPORT found builtin '%s', replacing %s:%u\n",
+ value, filename, lineno);
rule_add_key(&rule_tmp, TK_M_IMPORT_BUILTIN, op, value, &cmd);
continue;
}
}
- dbg(rules->udev, "IMPORT will be executed\n");
rule_add_key(&rule_tmp, TK_M_IMPORT_PROG, op, value, NULL);
} else if (strstr(attr, "builtin")) {
enum udev_builtin_cmd cmd = udev_builtin_lookup(value);
- dbg(rules->udev, "IMPORT execute builtin\n");
if (cmd < UDEV_BUILTIN_MAX)
rule_add_key(&rule_tmp, TK_M_IMPORT_BUILTIN, op, value, &cmd);
else
- err(rules->udev, "IMPORT{builtin}: '%s' unknown %s:%u\n", value, filename, lineno);
+ log_error("IMPORT{builtin}: '%s' unknown %s:%u\n", value, filename, lineno);
} else if (strstr(attr, "file")) {
- dbg(rules->udev, "IMPORT will be included as file\n");
rule_add_key(&rule_tmp, TK_M_IMPORT_FILE, op, value, NULL);
} else if (strstr(attr, "db")) {
- dbg(rules->udev, "IMPORT will include db values\n");
rule_add_key(&rule_tmp, TK_M_IMPORT_DB, op, value, NULL);
} else if (strstr(attr, "cmdline")) {
- dbg(rules->udev, "IMPORT will include db values\n");
rule_add_key(&rule_tmp, TK_M_IMPORT_CMDLINE, op, value, NULL);
} else if (strstr(attr, "parent")) {
- dbg(rules->udev, "IMPORT will include the parent values\n");
rule_add_key(&rule_tmp, TK_M_IMPORT_PARENT, op, value, NULL);
}
continue;
mode_t mode = 0;
if (op > OP_MATCH_MAX) {
- err(rules->udev, "invalid TEST operation\n");
+ log_error("invalid TEST operation\n");
goto invalid;
}
attr = get_key_attribute(rules->udev, key + sizeof("TEST")-1);
if (strcmp(key, "RUN") == 0) {
if (strncmp(value, "socket:", 7) == 0)
- err(rules->udev, "RUN+=\"socket:...\" support will be removed from a future udev release. "
+ log_error("RUN+=\"socket:...\" support will be removed from a future udev release. "
"Please remove it from: %s:%u and use libudev to subscribe to events.\n", filename, lineno);
rule_add_key(&rule_tmp, TK_A_RUN, op, value, NULL);
continue;
rule_add_key(&rule_tmp, TK_M_NAME, op, value, NULL);
} else {
if (strcmp(value, "%k") == 0) {
- err(rules->udev, "NAME=\"%%k\" is ignored, because it breaks kernel supplied names, "
+ log_error("NAME=\"%%k\" is ignored, because it breaks kernel supplied names, "
"please remove it from %s:%u\n", filename, lineno);
continue;
}
if (value[0] == '\0') {
- info(rules->udev, "NAME=\"\" is ignored, because udev will not delete any device nodes, "
- "please remove it from %s:%u\n", filename, lineno);
+ log_debug("NAME=\"\" is ignored, because udev will not delete any device nodes, "
+ "please remove it from %s:%u\n", filename, lineno);
continue;
}
rule_add_key(&rule_tmp, TK_A_NAME, op, value, NULL);
int prio = atoi(&pos[strlen("link_priority=")]);
rule_add_key(&rule_tmp, TK_A_DEVLINK_PRIO, op, NULL, &prio);
- dbg(rules->udev, "link priority=%i\n", prio);
}
pos = strstr(value, "event_timeout=");
int tout = atoi(&pos[strlen("event_timeout=")]);
rule_add_key(&rule_tmp, TK_M_EVENT_TIMEOUT, op, NULL, &tout);
- dbg(rules->udev, "event timeout=%i\n", tout);
}
pos = strstr(value, "string_escape=");
const int off = 0;
rule_add_key(&rule_tmp, TK_A_INOTIFY_WATCH, op, NULL, &off);
- dbg(rules->udev, "inotify watch of device disabled\n");
} else {
pos = strstr(value, "watch");
if (pos != NULL) {
const int on = 1;
rule_add_key(&rule_tmp, TK_A_INOTIFY_WATCH, op, NULL, &on);
- dbg(rules->udev, "inotify watch of device requested\n");
}
}
continue;
}
- err(rules->udev, "unknown key '%s' in %s:%u\n", key, filename, lineno);
+ log_error("unknown key '%s' in %s:%u\n", key, filename, lineno);
goto invalid;
}
return 0;
invalid:
- err(rules->udev, "invalid rule '%s:%u'\n", filename, lineno);
+ log_error("invalid rule '%s:%u'\n", filename, lineno);
return -1;
}
int line_nr = 0;
unsigned int i;
- info(rules->udev, "reading '%s' as rules file\n", filename);
+ log_debug("reading '%s' as rules file\n", filename);
f = fopen(filename, "r");
if (f == NULL)
}
if (len+1 >= sizeof(line)) {
- err(rules->udev, "line too long '%s':%u, ignored\n", filename, line_nr);
+ log_error("line too long '%s':%u, ignored\n", filename, line_nr);
continue;
}
add_rule(rules, key, filename, filename_off, line_nr);
break;
}
if (rules->tokens[i].key.rule_goto == 0)
- err(rules->udev, "GOTO '%s' has no matching label in: '%s'\n", label, filename);
+ log_error("GOTO '%s' has no matching label in: '%s'\n", label, filename);
}
}
return 0;
struct dirent *dent;
char filename[UTIL_PATH_SIZE];
- dbg(udev, "open directory '%s'\n", dirname);
dir = opendir(dirname);
if (dir == NULL) {
- info(udev, "unable to open '%s': %m\n", dirname);
+ log_debug("unable to open '%s': %m\n", dirname);
return -1;
}
continue;
}
util_strscpyl(filename, sizeof(filename), dirname, "/", dent->d_name, NULL);
- dbg(udev, "put file '%s' into list\n", filename);
/*
* the basename is the key, the filename the value
* identical basenames from different directories override each other
/* offset 0 is always '\0' */
rules->buf[0] = '\0';
rules->buf_cur = 1;
- dbg(udev, "prealloc %zu bytes tokens (%u * %zu bytes), %zu bytes buffer\n",
- rules->token_max * sizeof(struct token), rules->token_max, sizeof(struct token), rules->buf_max);
rules->trie_nodes = malloc(PREALLOC_TRIE * sizeof(struct trie_node));
if (rules->trie_nodes == NULL) {
struct stat st;
if (stat(filename, &st) != 0) {
- err(udev, "can not find '%s': %m\n", filename);
+ log_error("can not find '%s': %m\n", filename);
continue;
}
if (S_ISREG(st.st_mode) && st.st_size <= 0) {
- info(udev, "ignore empty '%s'\n", filename);
+ log_debug("ignore empty '%s'\n", filename);
continue;
}
if (S_ISCHR(st.st_mode)) {
- info(udev, "ignore masked '%s'\n", filename);
+ log_debug("ignore masked '%s'\n", filename);
continue;
}
parse_file(rules, filename, filename_off);
rules->buf_max = rules->buf_cur;
}
}
- info(udev, "rules use %zu bytes tokens (%u * %zu bytes), %zu bytes buffer\n",
- rules->token_max * sizeof(struct token), rules->token_max, sizeof(struct token), rules->buf_max);
- info(udev, "temporary index used %zu bytes (%u * %zu bytes)\n",
- rules->trie_nodes_cur * sizeof(struct trie_node),
- rules->trie_nodes_cur, sizeof(struct trie_node));
+ log_debug("rules use %zu bytes tokens (%u * %zu bytes), %zu bytes buffer\n",
+ rules->token_max * sizeof(struct token), rules->token_max, sizeof(struct token), rules->buf_max);
+ log_debug("temporary index used %zu bytes (%u * %zu bytes)\n",
+ rules->trie_nodes_cur * sizeof(struct trie_node),
+ rules->trie_nodes_cur, sizeof(struct trie_node));
/* cleanup trie */
free(rules->trie_nodes);
pos[0] = '\0';
pos = &pos[1];
}
- dbg(rules->udev, "match %s '%s' <-> '%s'\n", token_str(token->type), key_value, val);
match = (fnmatch(key_value, val, 0) == 0);
if (match)
break;
return -1;
}
- if (match && (token->key.op == OP_MATCH)) {
- dbg(rules->udev, "%s is true (matching value)\n", token_str(token->type));
+ if (match && (token->key.op == OP_MATCH))
return 0;
- }
- if (!match && (token->key.op == OP_NOMATCH)) {
- dbg(rules->udev, "%s is true (non-matching value)\n", token_str(token->type));
+ if (!match && (token->key.op == OP_NOMATCH))
return 0;
- }
- dbg(rules->udev, "%s is not true\n", token_str(token->type));
return -1;
}
}
while (len > 0 && isspace(vbuf[--len]))
vbuf[len] = '\0';
- dbg(rules->udev, "removed trailing whitespace from '%s'\n", value);
}
}
const char *value;
value = udev_device_get_property_value(event->dev, key_name);
- if (value == NULL) {
- dbg(event->udev, "ENV{%s} is not set, treat as empty\n", key_name);
+ if (value == NULL)
value = "";
- }
if (match_key(rules, cur, value))
goto nomatch;
break;
for (;;) {
struct token *key;
- dbg(event->udev, "parent: '%s'\n", udev_device_get_syspath(event->dev_parent));
/* loop over sequence of parent match keys */
for (key = cur; key < next; key++ ) {
dump_token(rules, key);
default:
goto nomatch;
}
- dbg(event->udev, "parent key matched\n");
}
- dbg(event->udev, "all parent keys matched\n");
break;
try_parent:
attr_subst_subdir(filename, sizeof(filename));
match = (stat(filename, &statbuf) == 0);
- dbg(event->udev, "'%s' %s", filename, match ? "exists\n" : "does not exist\n");
- if (match && cur->key.mode > 0) {
+ if (match && cur->key.mode > 0)
match = ((statbuf.st_mode & cur->key.mode) > 0);
- dbg(event->udev, "'%s' has mode=%#o and %s %#o\n", filename, statbuf.st_mode,
- match ? "matches" : "does not match", cur->key.mode);
- }
if (match && cur->key.op == OP_NOMATCH)
goto nomatch;
if (!match && cur->key.op == OP_MATCH)
break;
}
case TK_M_EVENT_TIMEOUT:
- info(event->udev, "OPTIONS event_timeout=%u\n", cur->key.event_timeout);
+ log_debug("OPTIONS event_timeout=%u\n", cur->key.event_timeout);
event->timeout_usec = cur->key.event_timeout * 1000 * 1000;
break;
case TK_M_PROGRAM: {
event->program_result = NULL;
udev_event_apply_format(event, &rules->buf[cur->key.value_off], program, sizeof(program));
envp = udev_device_get_properties_envp(event->dev);
- info(event->udev, "PROGRAM '%s' %s:%u\n",
- program,
- &rules->buf[rule->rule.filename_off],
- rule->rule.filename_line);
+ log_debug("PROGRAM '%s' %s:%u\n",
+ program,
+ &rules->buf[rule->rule.filename_off],
+ rule->rule.filename_line);
if (udev_event_spawn(event, program, envp, sigmask, result, sizeof(result)) < 0) {
if (cur->key.op != OP_NOMATCH)
if (esc == ESCAPE_UNSET || esc == ESCAPE_REPLACE) {
count = util_replace_chars(result, UDEV_ALLOWED_CHARS_INPUT);
if (count > 0)
- info(event->udev, "%i character(s) replaced\n" , count);
+ log_debug("%i character(s) replaced\n" , count);
}
event->program_result = strdup(result);
- dbg(event->udev, "storing result '%s'\n", event->program_result);
if (cur->key.op == OP_NOMATCH)
goto nomatch;
}
char import[UTIL_PATH_SIZE];
udev_event_apply_format(event, &rules->buf[cur->key.value_off], import, sizeof(import));
- info(event->udev, "IMPORT '%s' %s:%u\n",
- import,
- &rules->buf[rule->rule.filename_off],
- rule->rule.filename_line);
+ log_debug("IMPORT '%s' %s:%u\n",
+ import,
+ &rules->buf[rule->rule.filename_off],
+ rule->rule.filename_line);
if (import_program_into_properties(event, import, sigmask) != 0)
if (cur->key.op != OP_NOMATCH)
if (udev_builtin_run_once(cur->key.builtin_cmd)) {
/* check if we ran already */
if (event->builtin_run & (1 << cur->key.builtin_cmd)) {
- info(event->udev, "IMPORT builtin skip '%s' %s:%u\n",
- udev_builtin_name(cur->key.builtin_cmd),
- &rules->buf[rule->rule.filename_off],
- rule->rule.filename_line);
+ log_debug("IMPORT builtin skip '%s' %s:%u\n",
+ udev_builtin_name(cur->key.builtin_cmd),
+ &rules->buf[rule->rule.filename_off],
+ rule->rule.filename_line);
/* return the result from earlier run */
if (event->builtin_ret & (1 << cur->key.builtin_cmd))
if (cur->key.op != OP_NOMATCH)
}
udev_event_apply_format(event, &rules->buf[cur->key.value_off], command, sizeof(command));
- info(event->udev, "IMPORT builtin '%s' %s:%u\n",
- udev_builtin_name(cur->key.builtin_cmd),
- &rules->buf[rule->rule.filename_off],
- rule->rule.filename_line);
+ log_debug("IMPORT builtin '%s' %s:%u\n",
+ udev_builtin_name(cur->key.builtin_cmd),
+ &rules->buf[rule->rule.filename_off],
+ rule->rule.filename_line);
if (udev_builtin_run(event->dev, cur->key.builtin_cmd, command, false) != 0) {
/* remember failure */
- info(rules->udev, "IMPORT builtin '%s' returned non-zero\n",
- udev_builtin_name(cur->key.builtin_cmd));
+ log_debug("IMPORT builtin '%s' returned non-zero\n",
+ udev_builtin_name(cur->key.builtin_cmd));
event->builtin_ret |= (1 << cur->key.builtin_cmd);
if (cur->key.op != OP_NOMATCH)
goto nomatch;
event->owner_final = true;
udev_event_apply_format(event, &rules->buf[cur->key.value_off], owner, sizeof(owner));
event->uid = util_lookup_user(event->udev, owner);
- info(event->udev, "OWNER %u %s:%u\n",
- event->uid,
- &rules->buf[rule->rule.filename_off],
- rule->rule.filename_line);
+ log_debug("OWNER %u %s:%u\n",
+ event->uid,
+ &rules->buf[rule->rule.filename_off],
+ rule->rule.filename_line);
break;
}
case TK_A_GROUP: {
event->group_final = true;
udev_event_apply_format(event, &rules->buf[cur->key.value_off], group, sizeof(group));
event->gid = util_lookup_group(event->udev, group);
- info(event->udev, "GROUP %u %s:%u\n",
- event->gid,
- &rules->buf[rule->rule.filename_off],
- rule->rule.filename_line);
+ log_debug("GROUP %u %s:%u\n",
+ event->gid,
+ &rules->buf[rule->rule.filename_off],
+ rule->rule.filename_line);
break;
}
case TK_A_MODE: {
udev_event_apply_format(event, &rules->buf[cur->key.value_off], mode_str, sizeof(mode_str));
mode = strtol(mode_str, &endptr, 8);
if (endptr[0] != '\0') {
- err(event->udev, "ignoring invalid mode '%s'\n", mode_str);
+ log_error("ignoring invalid mode '%s'\n", mode_str);
break;
}
if (cur->key.op == OP_ASSIGN_FINAL)
event->mode_final = true;
event->mode_set = true;
event->mode = mode;
- info(event->udev, "MODE %#o %s:%u\n",
- event->mode,
- &rules->buf[rule->rule.filename_off],
- rule->rule.filename_line);
+ log_debug("MODE %#o %s:%u\n",
+ event->mode,
+ &rules->buf[rule->rule.filename_off],
+ rule->rule.filename_line);
break;
}
case TK_A_OWNER_ID:
if (cur->key.op == OP_ASSIGN_FINAL)
event->owner_final = true;
event->uid = cur->key.uid;
- info(event->udev, "OWNER %u %s:%u\n",
- event->uid,
- &rules->buf[rule->rule.filename_off],
- rule->rule.filename_line);
+ log_debug("OWNER %u %s:%u\n",
+ event->uid,
+ &rules->buf[rule->rule.filename_off],
+ rule->rule.filename_line);
break;
case TK_A_GROUP_ID:
if (event->group_final)
if (cur->key.op == OP_ASSIGN_FINAL)
event->group_final = true;
event->gid = cur->key.gid;
- info(event->udev, "GROUP %u %s:%u\n",
- event->gid,
- &rules->buf[rule->rule.filename_off],
- rule->rule.filename_line);
+ log_debug("GROUP %u %s:%u\n",
+ event->gid,
+ &rules->buf[rule->rule.filename_off],
+ rule->rule.filename_line);
break;
case TK_A_MODE_ID:
if (event->mode_final)
event->mode_final = true;
event->mode_set = true;
event->mode = cur->key.mode;
- info(event->udev, "MODE %#o %s:%u\n",
- event->mode,
- &rules->buf[rule->rule.filename_off],
- rule->rule.filename_line);
+ log_debug("MODE %#o %s:%u\n",
+ event->mode,
+ &rules->buf[rule->rule.filename_off],
+ rule->rule.filename_line);
break;
case TK_A_ENV: {
const char *name = &rules->buf[cur->key.attr_off];
(*p >= '0' && *p <= '9') ||
*p == '-' || *p == '_')
continue;
- err(event->udev, "ignoring invalid tag name '%s'\n", tag);
+ log_error("ignoring invalid tag name '%s'\n", tag);
break;
}
udev_device_add_tag(event->dev, tag);
if (esc == ESCAPE_UNSET || esc == ESCAPE_REPLACE) {
count = util_replace_chars(name_str, "/");
if (count > 0)
- info(event->udev, "%i character(s) replaced\n", count);
+ log_debug("%i character(s) replaced\n", count);
}
if (major(udev_device_get_devnum(event->dev))) {
size_t devlen = strlen(udev_get_dev_path(event->udev))+1;
if (strcmp(name_str, &udev_device_get_devnode(event->dev)[devlen]) != 0) {
- err(event->udev, "NAME=\"%s\" ignored, kernel device nodes "
+ log_error("NAME=\"%s\" ignored, kernel device nodes "
"can not be renamed; please fix it in %s:%u\n", name,
&rules->buf[rule->rule.filename_off], rule->rule.filename_line);
break;
}
free(event->name);
event->name = strdup(name_str);
- info(event->udev, "NAME '%s' %s:%u\n",
- event->name,
- &rules->buf[rule->rule.filename_off],
- rule->rule.filename_line);
+ log_debug("NAME '%s' %s:%u\n",
+ event->name,
+ &rules->buf[rule->rule.filename_off],
+ rule->rule.filename_line);
break;
}
case TK_A_DEVLINK: {
else if (esc == ESCAPE_REPLACE)
count = util_replace_chars(temp, "/");
if (count > 0)
- info(event->udev, "%i character(s) replaced\n" , count);
- dbg(event->udev, "rule applied, added symlink(s) '%s'\n", temp);
+ log_debug("%i character(s) replaced\n" , count);
pos = temp;
while (isspace(pos[0]))
pos++;
next = strchr(pos, ' ');
while (next != NULL) {
next[0] = '\0';
- info(event->udev, "LINK '%s' %s:%u\n", pos,
- &rules->buf[rule->rule.filename_off], rule->rule.filename_line);
+ log_debug("LINK '%s' %s:%u\n", pos,
+ &rules->buf[rule->rule.filename_off], rule->rule.filename_line);
util_strscpyl(filename, sizeof(filename), udev_get_dev_path(event->udev), "/", pos, NULL);
udev_device_add_devlink(event->dev, filename, cur->key.devlink_unique);
while (isspace(next[1]))
next = strchr(pos, ' ');
}
if (pos[0] != '\0') {
- info(event->udev, "LINK '%s' %s:%u\n", pos,
- &rules->buf[rule->rule.filename_off], rule->rule.filename_line);
+ log_debug("LINK '%s' %s:%u\n", pos,
+ &rules->buf[rule->rule.filename_off], rule->rule.filename_line);
util_strscpyl(filename, sizeof(filename), udev_get_dev_path(event->udev), "/", pos, NULL);
udev_device_add_devlink(event->dev, filename, cur->key.devlink_unique);
}
attr_subst_subdir(attr, sizeof(attr));
udev_event_apply_format(event, &rules->buf[cur->key.value_off], value, sizeof(value));
- info(event->udev, "ATTR '%s' writing '%s' %s:%u\n", attr, value,
- &rules->buf[rule->rule.filename_off],
- rule->rule.filename_line);
+ log_debug("ATTR '%s' writing '%s' %s:%u\n", attr, value,
+ &rules->buf[rule->rule.filename_off],
+ rule->rule.filename_line);
f = fopen(attr, "w");
if (f != NULL) {
if (fprintf(f, "%s", value) <= 0)
- err(event->udev, "error writing ATTR{%s}: %m\n", attr);
+ log_error("error writing ATTR{%s}: %m\n", attr);
fclose(f);
} else {
- err(event->udev, "error opening ATTR{%s} for writing: %m\n", attr);
+ log_error("error opening ATTR{%s} for writing: %m\n", attr);
}
break;
}
case TK_A_RUN: {
if (cur->key.op == OP_ASSIGN || cur->key.op == OP_ASSIGN_FINAL)
udev_list_cleanup(&event->run_list);
- info(event->udev, "RUN '%s' %s:%u\n",
- &rules->buf[cur->key.value_off],
- &rules->buf[rule->rule.filename_off],
- rule->rule.filename_line);
+ log_debug("RUN '%s' %s:%u\n",
+ &rules->buf[cur->key.value_off],
+ &rules->buf[rule->rule.filename_off],
+ rule->rule.filename_line);
udev_list_entry_add(&event->run_list, &rules->buf[cur->key.value_off], NULL);
break;
}
case TK_M_PARENTS_MAX:
case TK_M_MAX:
case TK_UNSET:
- err(rules->udev, "wrong type %u\n", cur->type);
+ log_error("wrong type %u\n", cur->type);
goto nomatch;
}
nomatch:
/* fast-forward to next rule */
cur = rule + rule->rule.token_count;
- dbg(rules->udev, "forward to rule: %u\n",
- (unsigned int) (cur - rules->tokens));
}
}
}
if (mode != (stats.st_mode & 01777)) {
chmod(filename, mode);
- info(rules->udev, "chmod '%s' %#o\n", filename, mode);
+ log_debug("chmod '%s' %#o\n", filename, mode);
}
if ((uid != 0 && uid != stats.st_uid) || (gid != 0 && gid != stats.st_gid)) {
chown(filename, uid, gid);
- info(rules->udev, "chown '%s' %u %u\n", filename, uid, gid);
+ log_debug("chown '%s' %u %u\n", filename, uid, gid);
}
utimensat(AT_FDCWD, filename, NULL, 0);
/*
- * Copyright (C) 2004-2010 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2004-2012 Kay Sievers <kay.sievers@vrfy.org>
* Copyright (C) 2009 Canonical Ltd.
* Copyright (C) 2009 Scott James Remnant <scott@netsplit.com>
*
{
inotify_fd = inotify_init1(IN_CLOEXEC);
if (inotify_fd < 0)
- err(udev, "inotify_init failed: %m\n");
+ log_error("inotify_init failed: %m\n");
return inotify_fd;
}
dir = opendir(oldname);
if (dir == NULL) {
- err(udev, "unable to open old watches dir '%s', old watches will not be restored: %m", oldname);
+ log_error("unable to open old watches dir '%s', old watches will not be restored: %m", oldname);
return;
}
if (dev == NULL)
goto unlink;
- info(udev, "restoring old watch on '%s'\n", udev_device_get_devnode(dev));
+ log_debug("restoring old watch on '%s'\n", udev_device_get_devnode(dev));
udev_watch_begin(udev, dev);
udev_device_unref(dev);
unlink:
rmdir(oldname);
} else if (errno != ENOENT) {
- err(udev, "unable to move watches dir '%s', old watches will not be restored: %m", filename);
+ log_error("unable to move watches dir '%s', old watches will not be restored: %m", filename);
}
}
if (inotify_fd < 0)
return;
- info(udev, "adding watch on '%s'\n", udev_device_get_devnode(dev));
+ log_debug("adding watch on '%s'\n", udev_device_get_devnode(dev));
wd = inotify_add_watch(inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE);
if (wd < 0) {
- err(udev, "inotify_add_watch(%d, %s, %o) failed: %m\n",
+ log_error("inotify_add_watch(%d, %s, %o) failed: %m\n",
inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE);
return;
}
if (wd < 0)
return;
- info(udev, "removing watch on '%s'\n", udev_device_get_devnode(dev));
+ log_debug("removing watch on '%s'\n", udev_device_get_devnode(dev));
inotify_rm_watch(inotify_fd, wd);
snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd);
value = udev_device_get_sysattr_value(device, name);
if (value == NULL)
continue;
- dbg(udev, "attr '%s'='%s'\n", name, value);
/* skip any values that look like a path */
if (value[0] == '/')
len = strlen(value);
while (len > 0 && isprint(value[len-1]))
len--;
- if (len > 0) {
- dbg(udev, "attribute value of '%s' non-printable, skip\n", name);
+ if (len > 0)
continue;
- }
printf(" %s{%s}==\"%s\"\n", key, name, value);
}
if (option == -1)
break;
- dbg(udev, "option '%c'\n", option);
switch (option) {
case 'n':
if (device != NULL) {
fd_ep = epoll_create1(EPOLL_CLOEXEC);
if (fd_ep < 0) {
- err(udev, "error creating epoll fd: %m\n");
+ log_error("error creating epoll fd: %m\n");
goto out;
}
ep_udev.events = EPOLLIN;
ep_udev.data.fd = fd_udev;
if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_udev, &ep_udev) < 0) {
- err(udev, "fail to add fd to epoll: %m\n");
+ log_error("fail to add fd to epoll: %m\n");
goto out;
}
ep_kernel.events = EPOLLIN;
ep_kernel.data.fd = fd_kernel;
if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_kernel, &ep_kernel) < 0) {
- err(udev, "fail to add fd to epoll: %m\n");
+ log_error("fail to add fd to epoll: %m\n");
goto out;
}
struct udev_queue *udev_queue = NULL;
int rc = EXIT_FAILURE;
- dbg(udev, "version %s\n", VERSION);
-
for (;;) {
int option;
int seconds;
timeout = seconds;
else
fprintf(stderr, "invalid timeout value\n");
- dbg(udev, "timeout=%i\n", timeout);
break;
case 'q':
quiet = 1;
end = udev_queue_get_kernel_seqnum(udev_queue);
if (start > end) {
- err(udev, "seq-start larger than seq-end, ignoring\n");
+ log_error("seq-start larger than seq-end, ignoring\n");
start = 0;
end = 0;
}
if (start > kernel_seq || end > kernel_seq) {
- err(udev, "seq-start or seq-end larger than current kernel value, ignoring\n");
+ log_error("seq-start or seq-end larger than current kernel value, ignoring\n");
start = 0;
end = 0;
}
- info(udev, "start=%llu end=%llu current=%llu\n", start, end, kernel_seq);
+ log_debug("start=%llu end=%llu current=%llu\n", start, end, kernel_seq);
} else {
if (end > 0) {
- err(udev, "seq-end needs seq-start parameter, ignoring\n");
+ log_error("seq-end needs seq-start parameter, ignoring\n");
end = 0;
}
}
uctrl = udev_ctrl_new(udev);
if (uctrl != NULL) {
if (udev_ctrl_send_ping(uctrl, timeout) < 0) {
- info(udev, "no connection to daemon\n");
+ log_debug("no connection to daemon\n");
udev_ctrl_unref(uctrl);
rc = EXIT_SUCCESS;
goto out;
pfd[0].events = POLLIN;
pfd[0].fd = inotify_init1(IN_CLOEXEC);
if (pfd[0].fd < 0) {
- err(udev, "inotify_init failed: %m\n");
+ log_error("inotify_init failed: %m\n");
} else {
if (inotify_add_watch(pfd[0].fd, udev_get_run_path(udev), IN_MOVED_TO) < 0) {
- err(udev, "watching '%s' failed\n", udev_get_run_path(udev));
+ log_error("watching '%s' failed\n", udev_get_run_path(udev));
close(pfd[0].fd);
pfd[0].fd = -1;
}
struct udev_list_entry *list_entry;
if (!quiet && udev_queue_get_queued_list_entry(udev_queue) != NULL) {
- info(udev, "timeout waiting for udev queue\n");
+ log_debug("timeout waiting for udev queue\n");
printf("\nudevadm settle - timeout of %i seconds reached, the event queue contains:\n", timeout);
udev_list_entry_foreach(list_entry, udev_queue_get_queued_list_entry(udev_queue))
printf(" %s (%s)\n",
enum udev_builtin_cmd cmd;
int rc = EXIT_SUCCESS;
- dbg(udev, "version %s\n", VERSION);
-
for (;;) {
int option;
{}
};
- info(udev, "version %s\n", VERSION);
+ log_debug("version %s\n", VERSION);
for (;;) {
int option;
if (option == -1)
break;
- dbg(udev, "option '%c'\n", option);
switch (option) {
case 'a':
action = optarg;
resolve_names = -1;
} else {
fprintf(stderr, "resolve-names must be early, late or never\n");
- err(udev, "resolve-names must be early, late or never\n");
+ log_error("resolve-names must be early, late or never\n");
exit(EXIT_FAILURE);
}
break;
goto out;
}
- printf("This program is for debugging only, it does not run any program,\n"
+ printf("This program is for debugging only, it does not run any program\n"
"specified by a RUN key. It may show incorrect results, because\n"
"some values may be different, or not available at a simulation run.\n"
"\n");
continue;
util_strscpyl(filename, sizeof(filename), udev_list_entry_get_name(entry), "/uevent", NULL);
fd = open(filename, O_WRONLY);
- if (fd < 0) {
- dbg(udev, "error on opening %s: %m\n", filename);
+ if (fd < 0)
continue;
- }
if (write(fd, action, strlen(action)) < 0)
- info(udev, "error writing '%s' to '%s': %m\n", action, filename);
+ log_debug("error writing '%s' to '%s': %m\n", action, filename);
close(fd);
}
}
struct udev_enumerate *udev_enumerate;
int rc = 0;
- dbg(udev, "version %s\n", VERSION);
udev_enumerate = udev_enumerate_new(udev);
if (udev_enumerate == NULL) {
rc = 1;
} else if (strcmp(optarg, "subsystems") == 0) {
device_type = TYPE_SUBSYSTEMS;
} else {
- err(udev, "unknown type --type=%s\n", optarg);
+ log_error("unknown type --type=%s\n", optarg);
rc = 2;
goto exit;
}
util_remove_trailing_chars(path, '/');
dev = udev_device_new_from_syspath(udev, path);
if (dev == NULL) {
- err(udev, "unable to open the device '%s'\n", optarg);
+ log_error("unable to open the device '%s'\n", optarg);
rc = 2;
goto exit;
}
/*
- * Copyright (C) 2007-2009 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2007-2012 Kay Sievers <kay.sievers@vrfy.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "udev.h"
-static bool debug;
-
void udev_main_log(struct udev *udev, int priority,
const char *file, int line, const char *fn,
const char *format, va_list args)
{
- if (debug) {
- fprintf(stderr, "%s: ", fn);
- vfprintf(stderr, format, args);
- } else {
- va_list args2;
-
- va_copy(args2, args);
- vfprintf(stderr, format, args2);
- va_end(args2);
- vsyslog(priority, format, args);
- }
+ log_metav(priority, file, line, fn, format, args);
}
static int adm_version(struct udev *udev, int argc, char *argv[])
printf("%s\n", VERSION);
return 0;
}
+
static const struct udevadm_cmd udevadm_version = {
.name = "version",
.cmd = adm_version,
};
static int adm_help(struct udev *udev, int argc, char *argv[]);
+
static const struct udevadm_cmd udevadm_help = {
.name = "help",
.cmd = adm_help,
static int run_command(struct udev *udev, const struct udevadm_cmd *cmd, int argc, char *argv[])
{
- if (cmd->debug) {
- debug = true;
- if (udev_get_log_priority(udev) < LOG_INFO)
- udev_set_log_priority(udev, LOG_INFO);
- }
- info(udev, "calling: %s\n", cmd->name);
+ if (cmd->debug)
+ log_set_max_level(LOG_DEBUG);
+ log_debug("calling: %s\n", cmd->name);
return cmd->cmd(udev, argc, argv);
}
if (udev == NULL)
goto out;
- udev_log_init("udevadm");
+ log_open();
+ log_parse_environment();
udev_set_log_fn(udev, udev_main_log);
udev_selinux_init(udev);
switch (option) {
case 'd':
- debug = true;
- if (udev_get_log_priority(udev) < LOG_INFO)
- udev_set_log_priority(udev, LOG_INFO);
+ log_set_max_level(LOG_DEBUG);
+ udev_set_log_priority(udev, LOG_DEBUG);
break;
case 'h':
rc = adm_help(udev, argc, argv);
}
command = argv[optind];
- info(udev, "runtime dir '%s'\n", udev_get_run_path(udev));
+ log_debug("runtime dir '%s'\n", udev_get_run_path(udev));
if (command != NULL)
for (i = 0; i < ARRAY_SIZE(udevadm_cmds); i++) {
out:
udev_selinux_exit(udev);
udev_unref(udev);
- udev_log_close();
+ log_close();
return rc;
}
/*
- * Copyright (C) 2004-2011 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2004-2012 Kay Sievers <kay.sievers@vrfy.org>
* Copyright (C) 2004 Chris Friesen <chris_friesen@sympatico.ca>
* Copyright (C) 2009 Canonical Ltd.
* Copyright (C) 2009 Scott James Remnant <scott@netsplit.com>
const char *file, int line, const char *fn,
const char *format, va_list args)
{
- if (debug) {
- char buf[1024];
- struct timespec ts;
-
- vsnprintf(buf, sizeof(buf), format, args);
- clock_gettime(CLOCK_MONOTONIC, &ts);
- fprintf(stderr, "[%llu.%06u] [%u] %s: %s",
- (unsigned long long) ts.tv_sec, (unsigned int) ts.tv_nsec/1000,
- (int) getpid(), fn, buf);
- } else {
- vsyslog(priority, format, args);
- }
+ log_metav(priority, file, line, fn, format, args);
}
static struct udev_rules *rules;
if (export) {
udev_queue_export_device_finished(udev_queue_export, event->dev);
- info(event->udev, "seq %llu done with %i\n", udev_device_get_seqnum(event->dev), event->exitcode);
+ log_debug("seq %llu done with %i\n", udev_device_get_seqnum(event->dev), event->exitcode);
}
udev_device_unref(event->dev);
free(event);
worker->refcount--;
if (worker->refcount > 0)
return;
- info(worker->udev, "worker [%u] cleaned up\n", worker->pid);
+ log_debug("worker [%u] cleaned up\n", worker->pid);
worker_cleanup(worker);
}
sigfillset(&mask);
fd_signal = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);
if (fd_signal < 0) {
- err(udev, "error creating signalfd %m\n");
+ log_error("error creating signalfd %m\n");
rc = 2;
goto out;
}
fd_ep = epoll_create1(EPOLL_CLOEXEC);
if (fd_ep < 0) {
- err(udev, "error creating epoll fd: %m\n");
+ log_error("error creating epoll fd: %m\n");
rc = 3;
goto out;
}
if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_signal, &ep_signal) < 0 ||
epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_monitor, &ep_monitor) < 0) {
- err(udev, "fail to add fds to epoll: %m\n");
+ log_error("fail to add fds to epoll: %m\n");
rc = 4;
goto out;
}
struct worker_message msg;
int err;
- info(udev, "seq %llu running\n", udev_device_get_seqnum(dev));
+ log_debug("seq %llu running\n", udev_device_get_seqnum(dev));
udev_event = udev_event_new(dev);
if (udev_event == NULL) {
rc = 5;
msg.pid = getpid();
send(worker_watch[WRITE_END], &msg, sizeof(struct worker_message), 0);
- info(udev, "seq %llu processed with %i\n", udev_device_get_seqnum(dev), err);
+ log_debug("seq %llu processed with %i\n", udev_device_get_seqnum(dev), err);
udev_device_unref(dev);
dev = NULL;
if (errno == EINTR)
continue;
err = -errno;
- err(udev, "failed to poll: %m\n");
+ log_error("failed to poll: %m\n");
goto out;
}
udev_builtin_exit(udev);
udev_monitor_unref(worker_monitor);
udev_unref(udev);
- udev_log_close();
+ log_close();
exit(rc);
}
case -1:
udev_monitor_unref(worker_monitor);
event->state = EVENT_QUEUED;
free(worker);
- err(udev, "fork of child failed: %m\n");
+ log_error("fork of child failed: %m\n");
break;
default:
/* close monitor, but keep address around */
event->state = EVENT_RUNNING;
udev_list_node_append(&worker->node, &worker_list);
children++;
- info(udev, "seq %llu forked new worker [%u]\n", udev_device_get_seqnum(event->dev), pid);
+ log_debug("seq %llu forked new worker [%u]\n", udev_device_get_seqnum(event->dev), pid);
break;
}
}
count = udev_monitor_send_device(monitor, worker->monitor, event->dev);
if (count < 0) {
- err(event->udev, "worker [%u] did not accept message %zi (%m), kill it\n", worker->pid, count);
+ log_error("worker [%u] did not accept message %zi (%m), kill it\n", worker->pid, count);
kill(worker->pid, SIGKILL);
worker->state = WORKER_KILLED;
continue;
if (children >= children_max) {
if (children_max > 1)
- info(event->udev, "maximum number (%i) of children reached\n", children);
+ log_debug("maximum number (%i) of children reached\n", children);
return;
}
event->ifindex = udev_device_get_ifindex(dev);
udev_queue_export_device_queued(udev_queue_export, dev);
- info(event->udev, "seq %llu queued, '%s' '%s'\n", udev_device_get_seqnum(dev),
+ log_debug("seq %llu queued, '%s' '%s'\n", udev_device_get_seqnum(dev),
udev_device_get_action(dev), udev_device_get_subsystem(dev));
event->state = EVENT_QUEUED;
continue;
/* do not start event if parent or child event is still running */
- if (is_devpath_busy(event)) {
- dbg(udev, "delay seq %llu (%s)\n", event->seqnum, event->devpath);
+ if (is_devpath_busy(event))
continue;
- }
event_run(event);
}
i = udev_ctrl_get_set_log_level(ctrl_msg);
if (i >= 0) {
- info(udev, "udevd message (SET_LOG_PRIORITY) received, log_priority=%i\n", i);
+ log_debug("udevd message (SET_LOG_PRIORITY) received, log_priority=%i\n", i);
+ log_set_max_level(i);
udev_set_log_priority(udev, i);
worker_kill(udev, 0);
}
if (udev_ctrl_get_stop_exec_queue(ctrl_msg) > 0) {
- info(udev, "udevd message (STOP_EXEC_QUEUE) received\n");
+ log_debug("udevd message (STOP_EXEC_QUEUE) received\n");
stop_exec_queue = true;
}
if (udev_ctrl_get_start_exec_queue(ctrl_msg) > 0) {
- info(udev, "udevd message (START_EXEC_QUEUE) received\n");
+ log_debug("udevd message (START_EXEC_QUEUE) received\n");
stop_exec_queue = false;
}
if (udev_ctrl_get_reload(ctrl_msg) > 0) {
- info(udev, "udevd message (RELOAD) received\n");
+ log_debug("udevd message (RELOAD) received\n");
reload = true;
}
val[0] = '\0';
val = &val[1];
if (val[0] == '\0') {
- info(udev, "udevd message (ENV) received, unset '%s'\n", key);
+ log_debug("udevd message (ENV) received, unset '%s'\n", key);
udev_add_property(udev, key, NULL);
} else {
- info(udev, "udevd message (ENV) received, set '%s=%s'\n", key, val);
+ log_debug("udevd message (ENV) received, set '%s=%s'\n", key, val);
udev_add_property(udev, key, val);
}
} else {
- err(udev, "wrong key format '%s'\n", key);
+ log_error("wrong key format '%s'\n", key);
}
free(key);
}
i = udev_ctrl_get_set_children_max(ctrl_msg);
if (i >= 0) {
- info(udev, "udevd message (SET_MAX_CHILDREN) received, children_max=%i\n", i);
+ log_debug("udevd message (SET_MAX_CHILDREN) received, children_max=%i\n", i);
children_max = i;
}
if (udev_ctrl_get_ping(ctrl_msg) > 0)
- info(udev, "udevd message (SYNC) received\n");
+ log_debug("udevd message (SYNC) received\n");
if (udev_ctrl_get_exit(ctrl_msg) > 0) {
- info(udev, "udevd message (EXIT) received\n");
+ log_debug("udevd message (EXIT) received\n");
udev_exit = true;
/* keep reference to block the client until we exit */
udev_ctrl_connection_ref(ctrl_conn);
buf = malloc(nbytes);
if (buf == NULL) {
- err(udev, "error getting buffer for inotify\n");
+ log_error("error getting buffer for inotify\n");
return -1;
}
ev = (struct inotify_event *)(buf + pos);
dev = udev_watch_lookup(udev, ev->wd);
if (dev != NULL) {
- info(udev, "inotify event: %x for %s\n", ev->mask, udev_device_get_devnode(dev));
+ log_debug("inotify event: %x for %s\n", ev->mask, udev_device_get_devnode(dev));
if (ev->mask & IN_CLOSE_WRITE) {
char filename[UTIL_PATH_SIZE];
int fd;
- info(udev, "device %s closed, synthesising 'change'\n", udev_device_get_devnode(dev));
+ log_debug("device %s closed, synthesising 'change'\n", udev_device_get_devnode(dev));
util_strscpyl(filename, sizeof(filename), udev_device_get_syspath(dev), "/uevent", NULL);
fd = open(filename, O_WRONLY);
if (fd >= 0) {
if (write(fd, "change", 6) < 0)
- info(udev, "error writing uevent: %m\n");
+ log_debug("error writing uevent: %m\n");
close(fd);
}
}
if (worker->pid != pid)
continue;
- info(udev, "worker [%u] exit\n", pid);
+ log_debug("worker [%u] exit\n", pid);
if (WIFEXITED(status)) {
if (WEXITSTATUS(status) != 0)
- err(udev, "worker [%u] exit with return code %i\n", pid, WEXITSTATUS(status));
+ log_error("worker [%u] exit with return code %i\n", pid, WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
- err(udev, "worker [%u] terminated by signal %i (%s)\n",
+ log_error("worker [%u] terminated by signal %i (%s)\n",
pid, WTERMSIG(status), strsignal(WTERMSIG(status)));
} else if (WIFSTOPPED(status)) {
- err(udev, "worker [%u] stopped\n", pid);
+ log_error("worker [%u] stopped\n", pid);
} else if (WIFCONTINUED(status)) {
- err(udev, "worker [%u] continued\n", pid);
+ log_error("worker [%u] continued\n", pid);
} else {
- err(udev, "worker [%u] exit with status 0x%04x\n", pid, status);
+ log_error("worker [%u] exit with status 0x%04x\n", pid, status);
}
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
if (worker->event) {
- err(udev, "worker [%u] failed while handling '%s'\n",
- pid, worker->event->devpath);
+ log_error("worker [%u] failed while handling '%s'\n",
+ pid, worker->event->devpath);
worker->event->exitcode = -32;
event_queue_delete(worker->event, true);
/* drop reference taken for state 'running' */
util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/", devname, NULL);
util_create_path_selinux(udev, filename);
udev_selinux_setfscreatecon(udev, filename, mode);
- info(udev, "mknod '%s' %c%u:%u\n", filename, type, maj, min);
+ log_debug("mknod '%s' %c%u:%u\n", filename, type, maj, min);
if (mknod(filename, mode, makedev(maj, min)) < 0 && errno == EEXIST)
utimensat(AT_FDCWD, filename, NULL, 0);
udev_selinux_resetfscreatecon(udev);
if (ctrl < 0 || netlink < 0)
return -1;
- info(udev, "ctrl=%i netlink=%i\n", ctrl, netlink);
+ log_debug("ctrl=%i netlink=%i\n", ctrl, netlink);
*rctrl = ctrl;
*rnetlink = netlink;
return 0;
/* first check */
if (stamp_usec[i] != 0) {
- info(udev, "reload - timestamp of '%s' changed\n", p[i]);
+ log_debug("reload - timestamp of '%s' changed\n", p[i]);
changed = true;
}
if (udev == NULL)
goto exit;
- udev_log_init("udevd");
+ log_open();
+ log_parse_environment();
udev_set_log_fn(udev, udev_main_log);
- info(udev, "version %s\n", VERSION);
+ log_debug("version %s\n", VERSION);
udev_selinux_init(udev);
for (;;) {
resolve_names = -1;
} else {
fprintf(stderr, "resolve-names must be early, late or never\n");
- err(udev, "resolve-names must be early, late or never\n");
+ log_error("resolve-names must be early, late or never\n");
goto exit;
}
break;
if (getuid() != 0) {
fprintf(stderr, "root privileges required\n");
- err(udev, "root privileges required\n");
+ log_error("root privileges required\n");
goto exit;
}
close(fd);
} else {
fprintf(stderr, "cannot open /dev/null\n");
- err(udev, "cannot open /dev/null\n");
+ log_error("cannot open /dev/null\n");
}
}
/* get control and netlink socket from from systemd */
udev_ctrl = udev_ctrl_new_from_fd(udev, fd_ctrl);
if (udev_ctrl == NULL) {
- err(udev, "error taking over udev control socket");
+ log_error("error taking over udev control socket");
rc = 1;
goto exit;
}
monitor = udev_monitor_new_from_netlink_fd(udev, "kernel", fd_netlink);
if (monitor == NULL) {
- err(udev, "error taking over netlink socket\n");
+ log_error("error taking over netlink socket\n");
rc = 3;
goto exit;
}
udev_ctrl = udev_ctrl_new(udev);
if (udev_ctrl == NULL) {
fprintf(stderr, "error initializing udev control socket");
- err(udev, "error initializing udev control socket");
+ log_error("error initializing udev control socket");
rc = 1;
goto exit;
}
monitor = udev_monitor_new_from_netlink(udev, "kernel");
if (monitor == NULL) {
fprintf(stderr, "error initializing netlink socket\n");
- err(udev, "error initializing netlink socket\n");
+ log_error("error initializing netlink socket\n");
rc = 3;
goto exit;
}
if (udev_monitor_enable_receiving(monitor) < 0) {
fprintf(stderr, "error binding netlink socket\n");
- err(udev, "error binding netlink socket\n");
+ log_error("error binding netlink socket\n");
rc = 3;
goto exit;
}
if (udev_ctrl_enable_receiving(udev_ctrl) < 0) {
fprintf(stderr, "error binding udev control socket\n");
- err(udev, "error binding udev control socket\n");
+ log_error("error binding udev control socket\n");
rc = 1;
goto exit;
}
/* create queue file before signalling 'ready', to make sure we block 'settle' */
udev_queue_export = udev_queue_export_new(udev);
if (udev_queue_export == NULL) {
- err(udev, "error creating queue file\n");
+ log_error("error creating queue file\n");
goto exit;
}
case 0:
break;
case -1:
- err(udev, "fork of daemon failed: %m\n");
+ log_error("fork of daemon failed: %m\n");
rc = 4;
goto exit;
default:
/* Fallback to old interface */
fd = open("/proc/self/oom_adj", O_RDWR);
if (fd < 0) {
- err(udev, "error disabling OOM: %m\n");
+ log_error("error disabling OOM: %m\n");
} else {
/* OOM_DISABLE == -17 */
write(fd, "-17", 3);
fd_inotify = udev_watch_init(udev);
if (fd_inotify < 0) {
fprintf(stderr, "error initializing inotify\n");
- err(udev, "error initializing inotify\n");
+ log_error("error initializing inotify\n");
rc = 4;
goto exit;
}
fd_signal = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);
if (fd_signal < 0) {
fprintf(stderr, "error creating signalfd\n");
- err(udev, "error creating signalfd\n");
+ log_error("error creating signalfd\n");
rc = 5;
goto exit;
}
/* unnamed socket from workers to the main daemon */
if (socketpair(AF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0, worker_watch) < 0) {
fprintf(stderr, "error creating socketpair\n");
- err(udev, "error creating socketpair\n");
+ log_error("error creating socketpair\n");
rc = 6;
goto exit;
}
rules = udev_rules_new(udev, resolve_names);
if (rules == NULL) {
- err(udev, "error reading rules\n");
+ log_error("error reading rules\n");
goto exit;
}
fd_ep = epoll_create1(EPOLL_CLOEXEC);
if (fd_ep < 0) {
- err(udev, "error creating epoll fd: %m\n");
+ log_error("error creating epoll fd: %m\n");
goto exit;
}
if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_ctrl, &ep_ctrl) < 0 ||
epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_signal, &ep_signal) < 0 ||
epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_netlink, &ep_netlink) < 0 ||
epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_worker, &ep_worker) < 0) {
- err(udev, "fail to add fds to epoll: %m\n");
+ log_error("fail to add fds to epoll: %m\n");
goto exit;
}
else
children_max = 128;
}
- info(udev, "set children_max to %u\n", children_max);
+ log_debug("set children_max to %u\n", children_max);
udev_rules_apply_static_dev_perms(rules);
/* timeout */
if (udev_exit) {
- err(udev, "timeout, giving up waiting for workers to finish\n");
+ log_error("timeout, giving up waiting for workers to finish\n");
break;
}
/* kill idle workers */
if (udev_list_node_is_empty(&event_list)) {
- info(udev, "cleanup idle workers\n");
+ log_debug("cleanup idle workers\n");
worker_kill(udev, 2);
}
continue;
if ((now_usec() - worker->event_start_usec) > 30 * 1000 * 1000) {
- err(udev, "worker [%u] timeout, kill it\n", worker->pid,
+ log_error("worker [%u] timeout, kill it\n", worker->pid,
worker->event ? worker->event->devpath : "<idle>");
kill(worker->pid, SIGKILL);
worker->state = WORKER_KILLED;
/* drop reference taken for state 'running' */
worker_unref(worker);
if (worker->event) {
- err(udev, "seq %llu '%s' killed\n",
- udev_device_get_seqnum(worker->event->dev), worker->event->devpath);
+ log_error("seq %llu '%s' killed\n",
+ udev_device_get_seqnum(worker->event->dev), worker->event->devpath);
worker->event->exitcode = -64;
event_queue_delete(worker->event, true);
worker->event = NULL;
udev_ctrl_unref(udev_ctrl);
udev_selinux_exit(udev);
udev_unref(udev);
- udev_log_close();
+ log_close();
return rc;
}