Home | History | Annotate | Download | only in other
      1 /* lsmod.c - Show the status of modules in the kernel
      2  *
      3  * Copyright 2012 Elie De Brauwer <eliedebrauwer (at) gmail.com>
      4 
      5 USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_SBIN))
      6 
      7 config LSMOD
      8   bool "lsmod"
      9   default y
     10   help
     11     usage: lsmod
     12 
     13     Display the currently loaded modules, their sizes and their dependencies.
     14 */
     15 
     16 #include "toys.h"
     17 
     18 void lsmod_main(void)
     19 {
     20   char *modfile = "/proc/modules";
     21   FILE * file = xfopen(modfile, "r");
     22 
     23   xprintf("%-23s Size  Used by\n", "Module");
     24 
     25   while (fgets(toybuf, sizeof(toybuf), file)) {
     26     char *name = strtok(toybuf, " "), *size = strtok(NULL, " "),
     27          *refcnt = strtok(NULL, " "), *users = strtok(NULL, " ");
     28 
     29     if(users) {
     30       int len = strlen(users)-1;
     31       if (users[len] == ',' || users[len] == '-') users[len] = 0;
     32       xprintf("%-19s %8s  %s %s\n", name, size, refcnt, users);
     33     } else perror_exit("bad %s", modfile);
     34   }
     35   fclose(file);
     36 }
     37