Skip to content

Commit

Permalink
tidy up error reporting, complain on -k doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
falconindy committed Mar 19, 2012
1 parent 05956c1 commit 00b38b2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/modtree.c
Expand Up @@ -7,6 +7,7 @@
#include <stdbool.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <unistd.h>

#include <libkmod.h>

Expand Down Expand Up @@ -184,8 +185,8 @@ static struct tt_line *add_line(struct tt *tt, struct kmod_module *mod,
return line;
}

static int modtree_do(struct kmod_ctx *kmod, struct tt *tt, struct kmod_module *mod,
struct tt_line *parent_line)
static int modtree_do(struct kmod_ctx *kmod, struct tt *tt,
struct kmod_module *mod, struct tt_line *parent_line)
{
int rc;
struct tt_line *line;
Expand Down Expand Up @@ -213,7 +214,8 @@ static int modtree_do(struct kmod_ctx *kmod, struct tt *tt, struct kmod_module *

/* loop over list,of,depends */
depstring = strdup(v);
for (dep = strtok_r(depstring, ",", &saveptr); dep; dep = strtok_r(NULL, ",", &saveptr)) {
for (dep = strtok_r(depstring, ",", &saveptr); dep;
dep = strtok_r(NULL, ",", &saveptr)) {
struct kmod_list *d, *deplist = NULL;
int r = kmod_module_new_from_lookup(kmod, dep, &deplist);

Expand Down Expand Up @@ -378,7 +380,7 @@ int main(int argc, char *argv[])
}

if (optind >= argc)
errx(EXIT_FAILURE, "missing module name");
errx(EXIT_FAILURE, "no modules specified (use -h for help)");

argc -= optind;
argv += optind;
Expand All @@ -392,6 +394,9 @@ int main(int argc, char *argv[])
}
snprintf(kdir_buf, sizeof(kdir_buf), ROOTPREFIX "/lib/modules/%s", kver);

if (access(kdir_buf, F_OK) != 0)
err(EXIT_FAILURE, "%s does not appear to be a valid directory", kdir_buf);

kmod = kmod_new(kdir_buf, NULL);
if (kmod == NULL) {
fputs("error: kmod_new() failed!\n", stderr);
Expand Down

0 comments on commit 00b38b2

Please sign in to comment.