chiark / gitweb /
remove unused includes
[elogind.git] / src / udev / udevadm-monitor.c
index b2f7f6ba4c08baf30d67f248fe651b307a02e6b6..7ef2e68233deaf0f75731017e7d9685af3235b65 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <unistd.h>
 #include <stdio.h>
-#include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
-#include <fcntl.h>
 #include <errno.h>
 #include <signal.h>
 #include <getopt.h>
 #include <time.h>
 #include <sys/time.h>
-#include <sys/socket.h>
-#include <sys/un.h>
 #include <sys/epoll.h>
-#include <linux/types.h>
-#include <linux/netlink.h>
 
 #include "udev.h"
 #include "udev-util.h"
 
 static bool udev_exit;
 
-static void sig_handler(int signum)
-{
+static void sig_handler(int signum) {
         if (signum == SIGINT || signum == SIGTERM)
                 udev_exit = true;
 }
 
-static void print_device(struct udev_device *device, const char *source, int prop)
-{
+static void print_device(struct udev_device *device, const char *source, int prop) {
         struct timespec ts;
 
         clock_gettime(CLOCK_MONOTONIC, &ts);
-        printf("%-6s[%llu.%06u] %-8s %s (%s)\n",
+        printf("%-6s[%"PRI_TIME".%06ld] %-8s %s (%s)\n",
                source,
-               (unsigned long long) ts.tv_sec, (unsigned int) ts.tv_nsec/1000,
+               ts.tv_sec, ts.tv_nsec/1000,
                udev_device_get_action(device),
                udev_device_get_devpath(device),
                udev_device_get_subsystem(device));
@@ -66,17 +57,19 @@ static void print_device(struct udev_device *device, const char *source, int pro
 }
 
 static void help(void) {
-        printf("Usage: udevadm monitor [--property] [--kernel] [--udev] [--help]\n"
-               "  -p,--property                            print the event properties\n"
-               "  -k,--kernel                              print kernel uevents\n"
-               "  -u,--udev                                print udev events\n"
-               "  -s,--subsystem-match=SUBSYSTEM[/DEVTYPE] filter events by subsystem\n"
-               "  -t,--tag-match=TAG                       filter events by tag\n"
-               "  -h,--help\n\n");
+        printf("%s monitor [--property] [--kernel] [--udev] [--help]\n\n"
+               "Listen to kernel and udev events.\n\n"
+               "  -h --help                                Show this help\n"
+               "     --version                             Show package version\n"
+               "  -p --property                            Print the event properties\n"
+               "  -k --kernel                              Print kernel uevents\n"
+               "  -u --udev                                Print udev events\n"
+               "  -s --subsystem-match=SUBSYSTEM[/DEVTYPE] Filter events by subsystem\n"
+               "  -t --tag-match=TAG                       Filter events by tag\n"
+               , program_invocation_short_name);
 }
 
-static int adm_monitor(struct udev *udev, int argc, char *argv[])
-{
+static int adm_monitor(struct udev *udev, int argc, char *argv[]) {
         struct sigaction act = {};
         sigset_t mask;
         bool prop = false;
@@ -158,7 +151,7 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[])
 
         fd_ep = epoll_create1(EPOLL_CLOEXEC);
         if (fd_ep < 0) {
-                log_error("error creating epoll fd: %m");
+                log_error_errno(errno, "error creating epoll fd: %m");
                 return 1;
         }
 
@@ -198,7 +191,7 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[])
                 ep_udev.events = EPOLLIN;
                 ep_udev.data.fd = fd_udev;
                 if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_udev, &ep_udev) < 0) {
-                        log_error("fail to add fd to epoll: %m");
+                        log_error_errno(errno, "fail to add fd to epoll: %m");
                         return 2;
                 }
 
@@ -232,7 +225,7 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[])
                 ep_kernel.events = EPOLLIN;
                 ep_kernel.data.fd = fd_kernel;
                 if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_kernel, &ep_kernel) < 0) {
-                        log_error("fail to add fd to epoll: %m");
+                        log_error_errno(errno, "fail to add fd to epoll: %m");
                         return 5;
                 }
 
@@ -279,5 +272,5 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[])
 const struct udevadm_cmd udevadm_monitor = {
         .name = "monitor",
         .cmd = adm_monitor,
-        .help = "listen to kernel and udev events",
+        .help = "Listen to kernel and udev events",
 };