X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flibudev%2Flibudev.c;h=b1649b651435cce8b10bd9022a8cc25dde25eb0b;hp=af36cc44524c9f788f26d803afd4435f20a61400;hb=ea55caa60c6860e33fa4f1a216c003ff666e9c68;hpb=4db17f291c627c885de668200ff8cce2e57c933f diff --git a/src/libudev/libudev.c b/src/libudev/libudev.c index af36cc445..b1649b651 100644 --- a/src/libudev/libudev.c +++ b/src/libudev/libudev.c @@ -1,13 +1,21 @@ -/* - * libudev - interface to udev device information - * - * Copyright (C) 2008-2010 Kay Sievers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - */ +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ #include #include @@ -57,6 +65,7 @@ void udev_log(struct udev *udev, va_end(args); } +_printf_(6,0) static void log_stderr(struct udev *udev, int priority, const char *file, int line, const char *fn, const char *format, va_list args) @@ -70,7 +79,7 @@ static void log_stderr(struct udev *udev, * @udev: udev library context * * Retrieve stored data pointer from library context. This might be useful - * to access from callbacks like a custom logging function. + * to access from callbacks like a custom log function. * * Returns: stored userdata **/ @@ -110,20 +119,20 @@ _public_ struct udev *udev_new(void) { struct udev *udev; const char *env; - FILE *f; + _cleanup_fclose_ FILE *f = NULL; - udev = calloc(1, sizeof(struct udev)); + udev = new0(struct udev, 1); if (udev == NULL) return NULL; udev->refcount = 1; udev->log_fn = log_stderr; - udev->log_priority = LOG_ERR; + udev->log_priority = LOG_INFO; udev_list_init(udev, &udev->properties_list, true); - f = fopen(SYSCONFDIR "/udev/udev.conf", "re"); + f = fopen("/etc/udev/udev.conf", "re"); if (f != NULL) { char line[UTIL_LINE_SIZE]; - int line_nr = 0; + unsigned line_nr = 0; while (fgets(line, sizeof(line), f)) { size_t len; @@ -144,7 +153,7 @@ _public_ struct udev *udev_new(void) /* split key/value */ val = strchr(key, '='); if (val == NULL) { - udev_err(udev, "missing = in " SYSCONFDIR "/udev/udev.conf[%i]; skip line\n", line_nr); + udev_err(udev, "/etc/udev/udev.conf:%u: missing assignment, skipping line.\n", line_nr); continue; } val[0] = '\0'; @@ -176,25 +185,37 @@ _public_ struct udev *udev_new(void) /* unquote */ if (val[0] == '"' || val[0] == '\'') { if (val[len-1] != val[0]) { - udev_err(udev, "inconsistent quoting in " SYSCONFDIR "/udev/udev.conf[%i]; skip line\n", line_nr); + udev_err(udev, "/etc/udev/udev.conf:%u: inconsistent quoting, skipping line.\n", line_nr); continue; } val[len-1] = '\0'; val++; } - if (strcmp(key, "udev_log") == 0) { - udev_set_log_priority(udev, util_log_priority(val)); + if (streq(key, "udev_log")) { + int prio; + + prio = util_log_priority(val); + if (prio < 0) + udev_err(udev, "/etc/udev/udev.conf:%u: invalid log level '%s', ignoring.\n", line_nr, val); + else + udev_set_log_priority(udev, prio); continue; } } - fclose(f); } /* environment overrides config */ env = secure_getenv("UDEV_LOG"); - if (env != NULL) - udev_set_log_priority(udev, util_log_priority(env)); + if (env != NULL) { + int prio; + + prio = util_log_priority(env); + if (prio < 0) + udev_err(udev, "$UDEV_LOG specifies invalid log level '%s', ignoring.\n", env); + else + udev_set_log_priority(udev, prio); + } return udev; } @@ -239,11 +260,11 @@ _public_ struct udev *udev_unref(struct udev *udev) /** * udev_set_log_fn: * @udev: udev library context - * @log_fn: function to be called for logging messages + * @log_fn: function to be called for log messages * * The built-in logging writes to stderr. It can be * overridden by a custom function, to plug log messages - * into the users' logging functionality. + * into the users' log functionality. * **/ _public_ void udev_set_log_fn(struct udev *udev, @@ -252,17 +273,16 @@ _public_ void udev_set_log_fn(struct udev *udev, const char *format, va_list args)) { udev->log_fn = log_fn; - udev_dbg(udev, "custom logging function %p registered\n", log_fn); + udev_dbg(udev, "custom log function %p registered\n", log_fn); } /** * udev_get_log_priority: * @udev: udev library context * - * The initial logging priority is read from the udev config file - * at startup. + * The initial log level is read from the udev config file at startup. * - * Returns: the current logging priority + * Returns: the current log level **/ _public_ int udev_get_log_priority(struct udev *udev) { @@ -272,10 +292,9 @@ _public_ int udev_get_log_priority(struct udev *udev) /** * udev_set_log_priority: * @udev: udev library context - * @priority: the new logging priority + * @priority: the new log priority * - * Set the current logging priority. The value controls which messages - * are logged. + * Set the log level. This value controls which messages are logged. **/ _public_ void udev_set_log_priority(struct udev *udev, int priority) {