summaryrefslogtreecommitdiff
path: root/src/audit.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2013-06-18 13:01:51 +0300
committerTimo Teräs <timo.teras@iki.fi>2013-06-18 13:02:27 +0300
commitfe41ae07b90bbd4609ee6871def851a41027aae8 (patch)
tree7f5a872c5ee030450e3cfdb84a73c9338f69d7f4 /src/audit.c
parentc51d82f8f616c2c8939b74c1d78f723ef778f0c8 (diff)
downloadapk-tools-fe41ae07b90bbd4609ee6871def851a41027aae8.tar.gz
apk-tools-fe41ae07b90bbd4609ee6871def851a41027aae8.tar.bz2
apk-tools-fe41ae07b90bbd4609ee6871def851a41027aae8.tar.xz
apk-tools-fe41ae07b90bbd4609ee6871def851a41027aae8.zip
apk: use string array in applet mains, separate apk_name_foreach_matching
Diffstat (limited to 'src/audit.c')
-rw-r--r--src/audit.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/src/audit.c b/src/audit.c
index 3e08930..27d3391 100644
--- a/src/audit.c
+++ b/src/audit.c
@@ -236,39 +236,40 @@ done:
return reason < 0 ? reason : 0;
}
-static int audit_main(void *ctx, struct apk_database *db, int argc, char **argv)
+static int audit_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
{
struct audit_tree_ctx atctx;
- int i, r = 0;
+ char **parg, *arg;
+ int r = 0;
atctx.db = db;
atctx.actx = (struct audit_ctx *) ctx;
atctx.pathlen = 0;
atctx.path[0] = 0;
- if (argc == 0) {
+ if (args->num == 0) {
atctx.dir = apk_db_dir_get(db, APK_BLOB_PTR_LEN(atctx.path, atctx.pathlen));
r = apk_dir_foreach_file(dup(db->root_fd), audit_directory_tree_item, &atctx);
apk_db_dir_unref(db, atctx.dir, FALSE);
- } else {
- for (i = 0; i < argc; i++) {
- if (argv[i][0] != '/') {
- apk_warning("%s: relative path skipped.\n",
- argv[i]);
- continue;
- }
- argv[i]++;
- atctx.pathlen = strlen(argv[i]);
- memcpy(atctx.path, argv[i], atctx.pathlen);
- if (atctx.path[atctx.pathlen-1] != '/')
- atctx.path[atctx.pathlen++] = '/';
-
- atctx.dir = apk_db_dir_get(db, APK_BLOB_PTR_LEN(atctx.path, atctx.pathlen));
- r |= apk_dir_foreach_file(
- openat(db->root_fd, argv[i], O_RDONLY|O_CLOEXEC),
- audit_directory_tree_item, &atctx);
- apk_db_dir_unref(db, atctx.dir, FALSE);
+ return r;
+ }
+
+ foreach_array_item(parg, args) {
+ arg = *parg;
+ if (arg[0] != '/') {
+ apk_warning("%s: relative path skipped.\n", arg);
+ continue;
}
+ arg++;
+ atctx.pathlen = strlen(arg);
+ memcpy(atctx.path, arg, atctx.pathlen);
+ if (atctx.path[atctx.pathlen-1] != '/')
+ atctx.path[atctx.pathlen++] = '/';
+
+ atctx.dir = apk_db_dir_get(db, APK_BLOB_PTR_LEN(atctx.path, atctx.pathlen));
+ r |= apk_dir_foreach_file(openat(db->root_fd, arg, O_RDONLY|O_CLOEXEC),
+ audit_directory_tree_item, &atctx);
+ apk_db_dir_unref(db, atctx.dir, FALSE);
}
return r;
}