X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fmountd.git;a=blobdiff_plain;f=autofs.c;h=a898f499bef8cabc098fc01861af90d8b3ca402e;hp=cbcada38cf05a0ffea509c5f09fbe840fa1482ba;hb=HEAD;hpb=be3b285c88648c24f7e4b36bebac56a95fa80f7e diff --git a/autofs.c b/autofs.c index cbcada3..a898f49 100644 --- a/autofs.c +++ b/autofs.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include "include/log.h" @@ -28,15 +28,17 @@ #include "include/mount.h" #include "include/signal.h" #include "include/ucix.h" +#include "include/autofs.h" -int fdin = 0; /* data coming out of the kernel */ -int fdout = 0;/* data going into the kernel */ -dev_t dev; +static int fdin = 0; /* data coming out of the kernel */ +static int fdout = 0;/* data going into the kernel */ +static bool term = false; +static dev_t dev; -time_t uci_timeout; +static time_t uci_timeout; char uci_path[32]; -void umount_autofs(void) +static void umount_autofs(void) { system_printf("umount %s 2> /dev/null", "/tmp/run/mountd/"); } @@ -113,7 +115,7 @@ static int autofs_process_request(const struct autofs_v5_packet *pkt) return 0; } -void expire_proc(void) +static void expire_proc(void) { struct autofs_packet_expire pkt; while(ioctl(fdin, AUTOFS_IOC_EXPIRE, &pkt) == 0) @@ -140,23 +142,29 @@ static int fullread(void *ptr, size_t len) static int autofs_in(union autofs_v5_packet_union *pkt) { + int res; struct pollfd fds[1]; fds[0].fd = fdout; fds[0].events = POLLIN; - while(1) + while(!term) { - if(poll(fds, 2, 1000) == -1) + res = poll(fds, 1, -1); + + if (res == -1) { if (errno == EINTR) continue; log_printf("failed while trying to read packet from kernel\n"); return -1; } - if(fds[0].revents & POLLIN) + else if ((res > 0) && (fds[0].revents & POLLIN)) + { return fullread(pkt, sizeof(*pkt)); + } } + return 1; } pid_t autofs_safe_fork(void) @@ -165,30 +173,35 @@ pid_t autofs_safe_fork(void) if(!pid) { close(fdin); - close(fdout); + close(fdout); } return pid; } -void autofs_cleanup_handler(void) +static void autofs_cleanup(void) { close(fdin); close(fdout); umount_autofs(); } -void autofs_init(void) +static void autofs_end_handler(int sig) +{ + term = true; +} + +static void autofs_init(void) { int kproto_version; char *p; struct uci_context *ctx; - signal_init(autofs_cleanup_handler); + signal_init(autofs_end_handler); ctx = ucix_init("mountd"); uci_timeout = ucix_get_option_int(ctx, "mountd", "mountd", "timeout", 60); p = ucix_get_option(ctx, "mountd", "mountd", "path"); ucix_cleanup(ctx); if(p) - snprintf(uci_path, 31, p); + snprintf(uci_path, 31, "%s", p); else snprintf(uci_path, 31, "/tmp/mounts/"); uci_path[31] = '\0'; @@ -220,7 +233,7 @@ int autofs_loop(void) { chdir("/"); autofs_init(); - while(1) + while(!term) { union autofs_v5_packet_union pkt; if(autofs_in(&pkt)) @@ -234,7 +247,7 @@ int autofs_loop(void) log_printf("unknown packet type %d\n", pkt.hdr.type); poll(0, 0, 200); } - umount_autofs(); + autofs_cleanup(); log_printf("... quitting\n"); closelog(); return 0;