/*
- * Copyright (C) 2011 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2011 Kay Sievers <kay@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 <errno.h>
#include <dirent.h>
#include <fcntl.h>
-#include <syslog.h>
#include <getopt.h>
#include <signal.h>
#include <time.h>
#include "udev.h"
-static void help(struct udev *udev)
-{
+static void help(struct udev *udev) {
fprintf(stderr, "\n");
- fprintf(stderr, "Usage: udevadm builtin [--help] <command> <syspath>\n");
+ fprintf(stderr, "Usage: udevadm builtin [--help] COMMAND SYSPATH\n");
udev_builtin_list(udev);
fprintf(stderr, "\n");
}
-static int adm_builtin(struct udev *udev, int argc, char *argv[])
-{
+static int adm_builtin(struct udev *udev, int argc, char *argv[]) {
static const struct option options[] = {
{ "help", no_argument, NULL, 'h' },
{}
char filename[UTIL_PATH_SIZE];
struct udev_device *dev = NULL;
enum udev_builtin_cmd cmd;
- int rc = EXIT_SUCCESS;
+ int rc = EXIT_SUCCESS, c;
- dbg(udev, "version %s\n", VERSION);
-
- for (;;) {
- int option;
-
- option = getopt_long(argc, argv, "h", options, NULL);
- if (option == -1)
- break;
-
- switch (option) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
+ switch (c) {
case 'h':
help(udev);
goto out;
}
- }
command = argv[optind++];
if (command == NULL) {
syspath = argv[optind++];
if (syspath == NULL) {
- fprintf(stderr, "syspath missing\n\n");
+ fprintf(stderr, "syspath missing\n");
rc = 3;
goto out;
}
}
/* add /sys if needed */
- if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0)
- util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), syspath, NULL);
+ if (!startswith(syspath, "/sys"))
+ strscpyl(filename, sizeof(filename), "/sys", syspath, NULL);
else
- util_strscpy(filename, sizeof(filename), syspath);
+ strscpy(filename, sizeof(filename), syspath);
util_remove_trailing_chars(filename, '/');
dev = udev_device_new_from_syspath(udev, filename);
goto out;
}
- if (udev_builtin_run(dev, cmd, command, true) < 0) {
- fprintf(stderr, "error executing '%s'\n\n", command);
+ rc = udev_builtin_run(dev, cmd, command, true);
+ if (rc < 0) {
+ fprintf(stderr, "error executing '%s', exit code %i\n\n", command, rc);
rc = 6;
}
out: