mirror of
https://github.com/systemd/systemd.git
synced 2024-12-17 14:13:32 +08:00
udev: never bypass our own logging framework and call vsyslog() directly from udev tools
This commit is contained in:
parent
c1dc6153c9
commit
5168f84a29
@ -20,7 +20,6 @@
|
||||
#ifndef _LIBUDEV_PRIVATE_H_
|
||||
#define _LIBUDEV_PRIVATE_H_
|
||||
|
||||
#include <syslog.h>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <syslog.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/epoll.h>
|
||||
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <grp.h>
|
||||
#include <sched.h>
|
||||
#include <sys/mount.h>
|
||||
|
@ -69,19 +69,12 @@
|
||||
#define LONG(x) ((x)/BITS_PER_LONG)
|
||||
#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
|
||||
|
||||
static int debug = 0;
|
||||
|
||||
_printf_(6,0)
|
||||
static void log_fn(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 {
|
||||
vsyslog(priority, format, args);
|
||||
}
|
||||
log_metav(priority, file, line, fn, format, args);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
@ -233,11 +226,13 @@ int main (int argc, char** argv)
|
||||
struct udev_enumerate *enumerate;
|
||||
struct udev_list_entry *list_entry;
|
||||
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
udev = udev_new();
|
||||
if (udev == NULL)
|
||||
return 1;
|
||||
|
||||
log_open();
|
||||
udev_set_log_fn(udev, log_fn);
|
||||
|
||||
/* CLI argument parsing */
|
||||
@ -250,9 +245,10 @@ int main (int argc, char** argv)
|
||||
|
||||
switch (option) {
|
||||
case 'd':
|
||||
debug = 1;
|
||||
log_set_target(LOG_TARGET_CONSOLE);
|
||||
log_set_max_level(LOG_DEBUG);
|
||||
udev_set_log_priority(udev, LOG_DEBUG);
|
||||
log_open();
|
||||
break;
|
||||
case 'h':
|
||||
help();
|
||||
|
@ -410,7 +410,7 @@ static void log_fn(struct udev *udev, int priority,
|
||||
const char *file, int line, const char *fn,
|
||||
const char *format, va_list args)
|
||||
{
|
||||
vsyslog(priority, format, args);
|
||||
log_metav(priority, file, line, fn, format, args);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -435,11 +435,13 @@ int main(int argc, char *argv[])
|
||||
{}
|
||||
};
|
||||
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
udev = udev_new();
|
||||
if (udev == NULL)
|
||||
goto exit;
|
||||
|
||||
log_open();
|
||||
udev_set_log_fn(udev, log_fn);
|
||||
|
||||
while (1) {
|
||||
|
@ -37,19 +37,12 @@
|
||||
#include "libudev.h"
|
||||
#include "libudev-private.h"
|
||||
|
||||
static bool debug;
|
||||
|
||||
_printf_(6,0)
|
||||
static void log_fn(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 {
|
||||
vsyslog(priority, format, args);
|
||||
}
|
||||
log_metav(priority, file, line, fn, format, args);
|
||||
}
|
||||
|
||||
/* device info */
|
||||
@ -875,11 +868,13 @@ int main(int argc, char *argv[])
|
||||
int cnt;
|
||||
int rc = 0;
|
||||
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
udev = udev_new();
|
||||
if (udev == NULL)
|
||||
goto exit;
|
||||
|
||||
log_open();
|
||||
udev_set_log_fn(udev, log_fn);
|
||||
|
||||
while (1) {
|
||||
@ -900,9 +895,10 @@ int main(int argc, char *argv[])
|
||||
eject = true;
|
||||
break;
|
||||
case 'd':
|
||||
debug = true;
|
||||
log_set_target(LOG_TARGET_CONSOLE);
|
||||
log_set_max_level(LOG_DEBUG);
|
||||
udev_set_log_priority(udev, LOG_DEBUG);
|
||||
log_open();
|
||||
break;
|
||||
case 'h':
|
||||
printf("Usage: cdrom_id [options] <device>\n"
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <ctype.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/stat.h>
|
||||
@ -55,7 +54,6 @@ static bool dev_specified = false;
|
||||
static char config_file[MAX_PATH_LEN] = "/etc/scsi_id.config";
|
||||
static enum page_code default_page_code = PAGE_UNSPECIFIED;
|
||||
static int sg_version = 4;
|
||||
static int debug = 0;
|
||||
static bool reformat_serial = false;
|
||||
static bool export = false;
|
||||
static char vendor_str[64];
|
||||
@ -70,7 +68,7 @@ static void log_fn(struct udev *udev, int priority,
|
||||
const char *file, int line, const char *fn,
|
||||
const char *format, va_list args)
|
||||
{
|
||||
vsyslog(priority, format, args);
|
||||
log_metav(priority, file, line, fn, format, args);
|
||||
}
|
||||
|
||||
static void set_type(const char *from, char *to, size_t len)
|
||||
@ -390,7 +388,10 @@ static int set_options(struct udev *udev,
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
debug++;
|
||||
log_set_target(LOG_TARGET_CONSOLE);
|
||||
log_set_max_level(LOG_DEBUG);
|
||||
udev_set_log_priority(udev, LOG_DEBUG);
|
||||
log_open();
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
@ -583,11 +584,13 @@ int main(int argc, char **argv)
|
||||
int newargc;
|
||||
char **newargv = NULL;
|
||||
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
udev = udev_new();
|
||||
if (udev == NULL)
|
||||
goto exit;
|
||||
|
||||
log_open();
|
||||
udev_set_log_fn(udev, log_fn);
|
||||
|
||||
/*
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <time.h>
|
||||
#include <inttypes.h>
|
||||
#include <scsi/scsi.h>
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <syslog.h>
|
||||
#include <getopt.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <syslog.h>
|
||||
#include <getopt.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <syslog.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/signalfd.h>
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <syslog.h>
|
||||
#include <fnmatch.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
Loading…
Reference in New Issue
Block a user