chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[PATCH] udevinfo symlink reverse query
[elogind.git]
/
udevinfo.c
diff --git
a/udevinfo.c
b/udevinfo.c
index a2f5601b7c9b8518af3c88be5361f54bbe27a8ef..01c2a2a8ae646a6cd0d19e67a8052f2816cf5393 100644
(file)
--- a/
udevinfo.c
+++ b/
udevinfo.c
@@
-27,18
+27,30
@@
#include <unistd.h>
#include <errno.h>
#include <unistd.h>
#include <errno.h>
+#include "libsysfs/sysfs/libsysfs.h"
+#include "libsysfs/dlist.h"
#include "udev.h"
#include "udev_version.h"
#include "logging.h"
#include "udevdb.h"
#include "udev.h"
#include "udev_version.h"
#include "logging.h"
#include "udevdb.h"
-#include "libsysfs/libsysfs.h"
# define SYSFS_VALUE_MAX 200
char **main_argv;
int main_argc;
# define SYSFS_VALUE_MAX 200
char **main_argv;
int main_argc;
-char **main_envp;
+
+#ifdef LOG
+unsigned char logname[42];
+void log_message (int level, const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ vsyslog(level, format, args);
+ va_end(args);
+}
+#endif
static int print_all_attributes(const char *path)
{
static int print_all_attributes(const char *path)
{
@@
-61,7
+73,7
@@
static int print_all_attributes(const char *path)
dlist_for_each_data(attributes, attr, struct sysfs_attribute) {
if (attr->value != NULL) {
dlist_for_each_data(attributes, attr, struct sysfs_attribute) {
if (attr->value != NULL) {
- str
ncpy(value, attr->value, SYSFS_VALUE_MAX
);
+ str
fieldcpy(value, attr->value
);
len = strlen(value);
if (len == 0)
continue;
len = strlen(value);
if (len == 0)
continue;
@@
-79,7
+91,7
@@
static int print_all_attributes(const char *path)
len--;
}
if (len == 0)
len--;
}
if (len == 0)
- printf(" SYSFS
_%s
=\"%s\"\n", attr->name, value);
+ printf(" SYSFS
{%s}
=\"%s\"\n", attr->name, value);
}
}
printf("\n");
}
}
printf("\n");
@@
-110,7
+122,8
@@
enum query_type {
SYMLINK,
MODE,
OWNER,
SYMLINK,
MODE,
OWNER,
- GROUP
+ GROUP,
+ ALL
};
static int print_device_chain(const char *path)
};
static int print_device_chain(const char *path)
@@
-246,6
+259,11
@@
static int process_options(void)
break;
}
break;
}
+ if (strcmp(optarg, "all") == 0) {
+ query = ALL;
+ break;
+ }
+
printf("unknown query type\n");
exit(1);
printf("unknown query type\n");
exit(1);
@@
-294,8
+312,8
@@
static int process_options(void)
} else {
if (path[0] != '/') {
/* prepend '/' if missing */
} else {
if (path[0] != '/') {
/* prepend '/' if missing */
- strcat(temp, "/");
- str
ncat(temp, path, sizeof(path)
);
+ str
field
cat(temp, "/");
+ str
fieldcat(temp, path
);
pos = temp;
} else {
pos = path;
pos = temp;
} else {
pos = path;
@@
-331,7
+349,7
@@
print:
case NAME:
if (root)
strfieldcpy(result, udev_root);
case NAME:
if (root)
strfieldcpy(result, udev_root);
- str
ncat(result, dev.name, sizeof(result)
);
+ str
fieldcat(result, dev.name
);
break;
case SYMLINK:
break;
case SYMLINK:
@@
-354,6
+372,10
@@
print:
strfieldcpy(result, path);
break;
strfieldcpy(result, path);
break;
+ case ALL:
+ print_record(path, &dev);
+ goto exit;
+
default:
goto exit;
}
default:
goto exit;
}
@@
-373,7
+395,7
@@
exit:
/* prepend sysfs mountpoint if not given */
strfieldcpy(temp, path);
strfieldcpy(path, sysfs_path);
/* prepend sysfs mountpoint if not given */
strfieldcpy(temp, path);
strfieldcpy(path, sysfs_path);
- str
ncat(path, temp, sizeof(path)
);
+ str
fieldcat(path, temp
);
}
print_device_chain(path);
return 0;
}
print_device_chain(path);
return 0;
@@
-394,11
+416,13
@@
help:
" 'owner' of node\n"
" 'group' of node\n"
" 'path' sysfs device path\n"
" 'owner' of node\n"
" 'group' of node\n"
" 'path' sysfs device path\n"
+ " 'all' all values\n"
+ "\n"
" -p PATH sysfs device path used for query or chain\n"
" -p PATH sysfs device path used for query or chain\n"
- " -n NAME node name used for query\n"
+ " -n NAME node
/symlink
name used for query\n"
"\n"
" -r print udev root\n"
"\n"
" -r print udev root\n"
- " -a print all
attributes along the chain of the device
\n"
+ " -a print all
SYSFS_attributes along the device chain
\n"
" -d dump whole database\n"
" -V print udev version\n"
" -h print this help text\n"
" -d dump whole database\n"
" -V print udev version\n"
" -h print this help text\n"
@@
-412,7
+436,8
@@
int main(int argc, char *argv[], char *envp[])
main_argv = argv;
main_argc = argc;
main_argv = argv;
main_argc = argc;
- main_envp = envp;
+
+ init_logging("udevinfo");
/* initialize our configuration */
udev_init_config();
/* initialize our configuration */
udev_init_config();