File: redir2mount.c

package info (click to toggle)
avfs 1.0.1-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,584 kB
  • ctags: 5,078
  • sloc: ansic: 41,578; sh: 11,267; perl: 1,916; makefile: 529; lisp: 14; csh: 12
file content (38 lines) | stat: -rw-r--r-- 803 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mount.h>

int main(int argc, char *argv[])
{
    int res;
    FILE *fp;
  
    if(argc != 3) {
        fprintf(stderr, "usage: %s from to\n", argv[0]);
        exit(1);
    }

    fp = fopen("/proc/fs/redir2/mount_pid", "w");
    if(fp == NULL) {
            perror("opening /proc/fs/redir2/mount_pid");
            exit(1);
    }
    fprintf(fp, "%u", getpid());
    fclose(fp);
    
    if (argv[1][0] == '-') {
        res = umount2(argv[2], 0);
        if (res == -1) {
            perror("umount failed");
            exit(1);
        }
    } else {
        res = mount(argv[1], argv[2], "none", MS_BIND, NULL);
        if(res == -1) {
            perror("mount failed");
            exit(1);
        }
    }
    return 0;
}