Changeset 2156


Ignore:
Timestamp:
Aug 23, 2012, 3:31:20 PM (7 years ago)
Author:
matthijs
Message:

mountd: Remove a chunk of (largely) unused code.

There was code to keep a list of mounted filesystems according to
/proc/mounts and update this list every 2 seconds or so. However, this
list was only used once at mountd startup, so this is really just wasted
effort.

This commit removes all of this code and replaces the single use at
startup with a small grep call.

Location:
trunk/fon/mountd/src/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/fon/mountd/src/lib/autofs.c

    r1027 r2156  
    5454        struct stat st;
    5555        log_printf("trying to mount %s as the autofs root\n", "/tmp/run/mountd/");
    56         if(is_mounted(0, "/tmp/run/mountd/"))
     56        if (WEXITSTATUS(system("cat /proc/mounts | grep '^[^ ]* /tmp/run/mountd '")) == 0)
    5757        {
    5858                log_printf("%s is already mounted\n", "/tmp/run/mountd/");
  • trunk/fon/mountd/src/lib/mount.c

    r2155 r2156  
    930930}
    931931
    932 char* is_mounted(char *block, char *path)
    933 {
    934         int i;
    935         for(i = 0; i < mounted_count; i++)
    936         {
    937                 if(block)
    938                         if(!strncmp(&mounted[i][0][0], block, strlen(&mounted[i][0][0])))
    939                                 return &mounted[i][0][0];
    940                 if(path)
    941                         if(!strncmp(&mounted[i][1][1], &path[1], strlen(&mounted[i][1][0])))
    942                                 return &mounted[i][0][0];
    943         }
    944         return 0;
    945 }
    946 
    947 void mount_check_mount_list(void)
    948 {
    949         FILE *fp = fopen("/proc/mounts", "r");
    950         char tmp[256];
    951 
    952         if(!fp)
    953         {
    954                 log_printf("error reading /proc/mounts");
    955                 fclose(fp);
    956                 return;
    957         }
    958         mounted_count = 0;
    959         while(fgets(tmp, 256, fp) > 0)
    960         {
    961                 char *t, *t2;
    962                 t = strstr(tmp, " ");
    963                 if(t)
    964                 {
    965                         *t = '\0';
    966                         t++;
    967                 } else t = tmp;
    968                 strncpy(&mounted[mounted_count][0][0], tmp, MAX_MOUNT_NAME);
    969                 t2 = strstr(t, " ");
    970                 if(t2)
    971                 {
    972                         *t2 = '\0';
    973                         t2++;
    974                 } else t2 = t;
    975                 strncpy(&mounted[mounted_count][1][0], t, MAX_MOUNT_NAME);
    976                 t = strstr(t2, " ");
    977                 if(t)
    978                 {
    979                         *t = '\0';
    980                         t++;
    981                 } else t = tmp;
    982                 strncpy(&mounted[mounted_count][2][0], t2, MAX_MOUNT_NAME);
    983         /*      printf("%s %s %s\n",
    984                         mounted[mounted_count][0],
    985                         mounted[mounted_count][1],
    986                         mounted[mounted_count][2]);*/
    987                 if(mounted_count < MAX_MOUNTED - 1)
    988                         mounted_count++;
    989                 else
    990                         log_printf("found more than %d mounts \n", MAX_MOUNTED);
    991         }
    992         fclose(fp);
    993 }
    994 
    995932/* FIXME: we need ore intelligence here */
    996933int dir_filter2(const struct dirent *a)
     
    11571094{
    11581095        INIT_LIST_HEAD(&mounts);
    1159         timer_add(mount_check_mount_list, 2);
    11601096        timer_add(mount_check_enum, 1);
    1161         mount_check_mount_list();
    11621097        ntfy = inotify_init();
    11631098}
Note: See TracChangeset for help on using the changeset viewer.