Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=fw32.git;a=commitdiff;h=cdea3162b8bd526be74f5b10b899159aaa7881b9

commit cdea3162b8bd526be74f5b10b899159aaa7881b9
Author: James Buren <r...@frugalware.org>
Date:   Wed Nov 9 10:21:03 2011 -0600

fw32.c: use /proc/mounts for umount-all

diff --git a/fw32.c b/fw32.c
index 3f9abe8..1270888 100644
--- a/fw32.c
+++ b/fw32.c
@@ -288,21 +288,66 @@ mount_all(void)
static void
umount_all(void)
{
-  FW32_DIR *p, d;
-  char path[PATH_MAX];
+  char line[LINE_MAX];
+  char *p, *s, *e;
+  size_t n;
+  FILE *in, *out;
+  FW32_DIR d;

-  p = FW32_DIRS;
+  in = fopen("/proc/mounts","rb");

-  while(p->dir)
+  if(!in)
+    error("Cannot open /proc/mounts for reading.\n");
+
+  out = open_memstream(&p,&n);
+
+  if(!out)
+    error("Failed to open a memory stream.\n");
+
+  while(fgets(line,sizeof line,in))
{
-    snprintf(path,sizeof path,"%s%s",FW32_ROOT,(p++)->dir);
+    s = strchr(line,' ');
+
+    if(!s)
+      continue;

-    d.dir = path;
+    e = strchr(++s,' ');
+
+    if(!e)
+      continue;
+
+    *e = 0;
+
+    if(!strncmp(s,FW32_ROOT,strlen(FW32_ROOT)))
+      if(fwrite(s,1,e-s,out) != e-s || fwrite("\n",1,1,out) != 1 || 
fflush(out))
+        error("Failed to write to memory stream.\n");
+  }
+
+  fclose(in);
+
+  fclose(out);
+
+  s = p;
+
+  while(true)
+  {
+    e = strchr(s,'\n');
+
+    if(!e)
+      break;
+
+    *e++ = 0;
+
+    d.dir = s;

d.ro = false;

umount_directory(&d);
+
+    s = e;
}
+
+  free(p);
}

static void
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to