2009-03-11 21:39:53 +01:00
|
|
|
--- libinit.h
|
|
|
|
+++ libinit.h 2009-03-10 13:06:32.512001779 +0100
|
|
|
|
@@ -46,7 +46,7 @@
|
|
|
|
# define restrict __restrict__
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
-#define alignof(type) (sizeof(type)+(sizeof(type)%sizeof(void*)))
|
|
|
|
+#define alignof(type) ((sizeof(type)+(sizeof(void*)-1)) & ~(sizeof(void*)-1))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LSB specs:
|
|
|
|
--- mkill.c
|
2009-03-17 23:25:53 +01:00
|
|
|
+++ mkill.c 2009-03-13 18:01:55.276001810 +0100
|
|
|
|
@@ -60,10 +60,19 @@ extern inline DIR * opendirat(int dirfd,
|
|
|
|
" %s [-SIG] [-u] /mnt1 [/mnt2...]\n"\
|
|
|
|
" %s -l\n", we_are, we_are
|
2009-03-11 21:39:53 +01:00
|
|
|
|
2009-03-17 23:25:53 +01:00
|
|
|
+typedef struct _s_shadow
|
|
|
|
+{
|
|
|
|
+ struct _s_shadow *next;
|
|
|
|
+ struct _s_shadow *prev;
|
|
|
|
+ size_t nlen;
|
|
|
|
+ char * name;
|
|
|
|
+} shadow_t;
|
|
|
|
+
|
|
|
|
typedef struct _s_mnt
|
|
|
|
{
|
|
|
|
struct _s_mnt *next; /* Pointer to next struct. */
|
|
|
|
struct _s_mnt *prev; /* Pointer to previous st. */
|
|
|
|
+ shadow_t *shadow; /* Pointer to shadows */
|
|
|
|
size_t nlen;
|
|
|
|
char * name;
|
|
|
|
int order; /* Order of the mount point*/
|
|
|
|
@@ -327,12 +336,8 @@ int main(int argc, char* argv[])
|
|
|
|
sort_proc();
|
|
|
|
|
|
|
|
num = 0;
|
|
|
|
- this = procs;
|
|
|
|
- last = (proc_t*)0;
|
|
|
|
found = false;
|
|
|
|
- for (ptr = procs; this; ptr = this) {
|
|
|
|
- last = ptr->prev;
|
|
|
|
- this = ptr->next;
|
|
|
|
+ for (ptr = procs; ptr; ptr = ptr->next) {
|
|
|
|
if (nsig) {
|
|
|
|
if (stop)
|
|
|
|
kill(ptr->pid, SIGSTOP);
|
|
|
|
@@ -391,11 +396,7 @@ int main(int argc, char* argv[])
|
|
|
|
if (!found)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
- this = procs;
|
|
|
|
- last = (proc_t*)0;
|
|
|
|
- for (ptr = procs; this; ptr = this) {
|
|
|
|
- last = ptr->prev;
|
|
|
|
- this = ptr->next;
|
|
|
|
+ for (ptr = procs; ptr; ptr = ptr->next) {
|
|
|
|
kill(ptr->pid, SIGSTOP);
|
|
|
|
kill(ptr->pid, SIGKILL);
|
|
|
|
}
|
|
|
|
@@ -440,9 +441,10 @@ static void init_mnt(int argc, char* arg
|
|
|
|
error(100, "malloc(): %s\n", strerror(errno));
|
|
|
|
ptr->order = order++;
|
|
|
|
ptr->name = ((char*)ptr)+alignof(mntent_t);
|
|
|
|
+ ptr->shadow = (shadow_t*)0;
|
|
|
|
|
|
|
|
strcpy(ptr->name, ent->mnt_dir);
|
|
|
|
- ptr->nlen = strlen(ptr->name);
|
|
|
|
+ ptr->nlen = nlen;
|
|
|
|
if (mntent)
|
|
|
|
mntent->prev = ptr;
|
|
|
|
ptr->next = mntent;
|
|
|
|
@@ -451,6 +453,57 @@ static void init_mnt(int argc, char* arg
|
|
|
|
}
|
|
|
|
endmntent(mnt);
|
|
|
|
maxorder = order;
|
|
|
|
+
|
|
|
|
+ if ((mnt = setmntent("/proc/mounts", "r")) == (FILE*)0)
|
|
|
|
+ error(100, "cannot open /proc/mounts: %s\n", strerror(errno));
|
|
|
|
+
|
|
|
|
+ while ((ent = getmntent(mnt))) {
|
|
|
|
+ mntent_t *p;
|
|
|
|
+
|
|
|
|
+ for (p = mntent; p; p = p->next) {
|
|
|
|
+ shadow_t *restrict s;
|
|
|
|
+ size_t nlen;
|
|
|
|
+
|
|
|
|
+ if (strcmp(ent->mnt_dir, p->name) == 0)
|
|
|
|
+ continue;
|
|
|
|
+ if (strncmp(ent->mnt_dir, p->name, p->nlen) != 0)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ nlen = strlen(ent->mnt_dir);
|
|
|
|
+ if (posix_memalign((void*)&s, sizeof(void*), alignof(shadow_t)+(nlen+1)) != 0)
|
|
|
|
+ error(100, "malloc(): %s\n", strerror(errno));
|
|
|
|
+ s->name = ((char*)s)+alignof(shadow_t);
|
|
|
|
+
|
|
|
|
+ strcpy(s->name, ent->mnt_dir);
|
|
|
|
+ s->nlen = nlen;
|
|
|
|
+ if (p->shadow)
|
|
|
|
+ p->shadow->prev = s;
|
|
|
|
+ s->next = p->shadow;
|
|
|
|
+ s->prev = (shadow_t*)0;
|
|
|
|
+ p->shadow = s;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ endmntent(mnt);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void clear_shadow(shadow_t *restrict shadow)
|
|
|
|
+{
|
|
|
|
+ shadow_t *s, *n, *l;
|
|
|
|
+
|
|
|
|
+ n = shadow;
|
|
|
|
+ l = (shadow_t*)0;
|
|
|
|
+ for (s = shadow; n; s = n) {
|
|
|
|
+ l = s->prev;
|
|
|
|
+ n = s->next;
|
|
|
|
+ if (s == shadow) {
|
|
|
|
+ if (n) n->prev = (shadow_t*)0;
|
|
|
|
+ shadow = n;
|
|
|
|
+ } else if (l) {
|
|
|
|
+ if (n) n->prev = l;
|
|
|
|
+ l->next = n;
|
|
|
|
+ }
|
|
|
|
+ free(s);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clear_mnt(const boolean lazy)
|
|
|
|
@@ -471,6 +524,8 @@ static void clear_mnt(const boolean lazy
|
|
|
|
if (n) n->prev = l;
|
|
|
|
l->next = n;
|
|
|
|
}
|
|
|
|
+ if (p->shadow)
|
|
|
|
+ clear_shadow(p->shadow);
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -523,17 +578,39 @@ static void sort_proc(void)
|
|
|
|
procs = sort;
|
|
|
|
}
|
|
|
|
|
|
|
|
+static boolean shadow(shadow_t *restrict this, const char *restrict name, const size_t nlen)
|
|
|
|
+{
|
|
|
|
+ shadow_t *s;
|
|
|
|
+
|
|
|
|
+ if (!this)
|
|
|
|
+ goto out;
|
|
|
|
+ for (s = this; s; s = s->next) {
|
|
|
|
+ if (nlen < s->nlen)
|
|
|
|
+ continue;
|
|
|
|
+ if (name[s->nlen] != '\0' && name[s->nlen] != '/')
|
|
|
|
+ continue;
|
|
|
|
+ if (strncmp(name, s->name, s->nlen) == 0)
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+out:
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
2009-03-11 21:39:53 +01:00
|
|
|
static int check(const char *restrict name)
|
|
|
|
{
|
2009-03-17 23:25:53 +01:00
|
|
|
- mntent_t *p, *n, *l;
|
2009-03-11 21:39:53 +01:00
|
|
|
+ const size_t nlen = strlen(name);
|
2009-03-17 23:25:53 +01:00
|
|
|
+ mntent_t *p;
|
2009-03-11 21:39:53 +01:00
|
|
|
|
2009-03-17 23:25:53 +01:00
|
|
|
- n = mntent;
|
|
|
|
- l = (mntent_t*)0;
|
|
|
|
- for (p = mntent; n; p = n) {
|
|
|
|
- l = p->prev;
|
|
|
|
- n = p->next;
|
|
|
|
- if (strncmp(name, p->name, p->nlen) == 0)
|
|
|
|
+ for (p = mntent; p; p = p->next) {
|
2009-03-11 21:39:53 +01:00
|
|
|
+ if (nlen < p->nlen)
|
|
|
|
+ continue;
|
|
|
|
+ if (name[p->nlen] != '\0' && name[p->nlen] != '/')
|
|
|
|
+ continue;
|
2009-03-17 23:25:53 +01:00
|
|
|
+ if (strncmp(name, p->name, p->nlen) == 0) {
|
|
|
|
+ if (shadow(p->shadow, name, nlen))
|
|
|
|
+ continue;
|
2009-03-11 21:39:53 +01:00
|
|
|
return p->order;
|
2009-03-17 23:25:53 +01:00
|
|
|
+ }
|
2009-03-11 21:39:53 +01:00
|
|
|
}
|
2009-03-17 23:25:53 +01:00
|
|
|
return 0;
|
|
|
|
}
|