Bump to version 2018.02.26

This commit is contained in:
NADAL Jean-Baptiste
2019-04-16 17:05:19 +02:00
parent daa0aad546
commit c7be80baf3
10 changed files with 228 additions and 135 deletions

View File

@@ -30,11 +30,12 @@
#include "include/ucix.h" #include "include/ucix.h"
#include "include/autofs.h" #include "include/autofs.h"
int fdin = 0; /* data coming out of the kernel */ static int fdin = 0; /* data coming out of the kernel */
int fdout = 0;/* data going into the kernel */ static int fdout = 0;/* data going into the kernel */
dev_t dev; static bool term = false;
static dev_t dev;
time_t uci_timeout; static time_t uci_timeout;
char uci_path[32]; char uci_path[32];
static void umount_autofs(void) static void umount_autofs(void)
@@ -147,7 +148,7 @@ static int autofs_in(union autofs_v5_packet_union *pkt)
fds[0].fd = fdout; fds[0].fd = fdout;
fds[0].events = POLLIN; fds[0].events = POLLIN;
while(1) while(!term)
{ {
res = poll(fds, 1, -1); res = poll(fds, 1, -1);
@@ -163,6 +164,7 @@ static int autofs_in(union autofs_v5_packet_union *pkt)
return fullread(pkt, sizeof(*pkt)); return fullread(pkt, sizeof(*pkt));
} }
} }
return 1;
} }
pid_t autofs_safe_fork(void) pid_t autofs_safe_fork(void)
@@ -171,24 +173,29 @@ pid_t autofs_safe_fork(void)
if(!pid) if(!pid)
{ {
close(fdin); close(fdin);
close(fdout); close(fdout);
} }
return pid; return pid;
} }
static void autofs_cleanup_handler(void) static void autofs_cleanup(void)
{ {
close(fdin); close(fdin);
close(fdout); close(fdout);
umount_autofs(); umount_autofs();
} }
static void autofs_end_handler(int sig)
{
term = true;
}
static void autofs_init(void) static void autofs_init(void)
{ {
int kproto_version; int kproto_version;
char *p; char *p;
struct uci_context *ctx; struct uci_context *ctx;
signal_init(autofs_cleanup_handler); signal_init(autofs_end_handler);
ctx = ucix_init("mountd"); ctx = ucix_init("mountd");
uci_timeout = ucix_get_option_int(ctx, "mountd", "mountd", "timeout", 60); uci_timeout = ucix_get_option_int(ctx, "mountd", "mountd", "timeout", 60);
p = ucix_get_option(ctx, "mountd", "mountd", "path"); p = ucix_get_option(ctx, "mountd", "mountd", "path");
@@ -226,7 +233,7 @@ int autofs_loop(void)
{ {
chdir("/"); chdir("/");
autofs_init(); autofs_init();
while(1) while(!term)
{ {
union autofs_v5_packet_union pkt; union autofs_v5_packet_union pkt;
if(autofs_in(&pkt)) if(autofs_in(&pkt))
@@ -240,7 +247,7 @@ int autofs_loop(void)
log_printf("unknown packet type %d\n", pkt.hdr.type); log_printf("unknown packet type %d\n", pkt.hdr.type);
poll(0, 0, 200); poll(0, 0, 200);
} }
umount_autofs(); autofs_cleanup();
log_printf("... quitting\n"); log_printf("... quitting\n");
closelog(); closelog();
return 0; return 0;

View File

@@ -153,8 +153,8 @@ static int detect_hfsplus(int fd)
{ {
if(!journal) if(!journal)
ret = HFSPLUS; ret = HFSPLUS;
// else else
// ret = HFSPLUSJOURNAL; ret = HFSPLUSJOURNAL;
} }
out: out:
free(buffer); free(buffer);
@@ -191,7 +191,7 @@ out:
return ret; return ret;
} }
dfunc funcs[] = { static dfunc funcs[] = {
detect_ext23, detect_ext23,
detect_exfat, detect_exfat,
detect_fat, detect_fat,

View File

@@ -1,13 +1,16 @@
#define NONE -1 #define NONE -1
#define MBR 2 #define MBR 2
#define EXT2 3 #define EXT2 3
#define EXT3 4 #define EXT3 4
#define FAT 5 #define FAT 5
#define HFSPLUS 6 #define HFSPLUS 6
#define EFI 7 #define EFI 7
#define NTFS 8 #define NTFS 8
#define EXTENDED 9 #define EXTENDED 9
#define EXFAT 10 #define EXFAT 10
#define EXT4 11 #define EXT4 11
#define HFSPLUSJOURNAL 12
#define LASTFS HFSPLUSJOURNAL
int detect_fs(char *device); int detect_fs(char *device);

View File

@@ -1,7 +1,7 @@
#ifndef _SIGNAL_H__ #ifndef _SIGNAL_H__
#define _SIGNAL_H__ #define _SIGNAL_H__
void signal_init(void (*_crtlc_cb)(void)); void signal_init(void (*_crtlc_cb)(int));
int signal_usr1(void); int signal_usr1(void);
int signal_usr2(void); int signal_usr2(void);

View File

@@ -14,7 +14,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* *
* Provided by fon.com * Provided by fon.com
* Copyright (C) 2009 John Crispin <blogic@openwrt.org> * Copyright (C) 2009 John Crispin <blogic@openwrt.org>
*/ */
@@ -27,7 +27,7 @@
#include "include/timer.h" #include "include/timer.h"
#include "include/led.h" #include "include/led.h"
char usbled[16]; static char usbled[16];
void led_ping(void) void led_ping(void)
{ {

View File

@@ -1,3 +1,4 @@
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@@ -11,12 +12,10 @@
#include <dirent.h> #include <dirent.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/inotify.h> #include <sys/inotify.h>
#include <sys/stat.h> #include <sys/mount.h>
#include <sys/types.h>
#include <glob.h> #include <glob.h>
#include <libgen.h> #include <libgen.h>
#include <poll.h> #include <poll.h>
#include <dirent.h>
#include <syslog.h> #include <syslog.h>
#include "include/log.h" #include "include/log.h"
@@ -31,7 +30,22 @@
int mount_new(char *path, char *dev); int mount_new(char *path, char *dev);
struct list_head mounts; static struct list_head mounts;
/**
* enum status - status of mount entry
*
* @STATUS_UNMOUNTED: currently not mounted
* @STATUS_MOUNTED: mounted & ready for usage
* @STATUS_EXPIRED: mount expired & *temporary* unmounted
* @STATUS_IGNORE: entry should be ignored and never mounted
*/
enum status {
STATUS_UNMOUNTED = 0,
STATUS_MOUNTED,
STATUS_EXPIRED,
STATUS_IGNORE,
};
struct mount { struct mount {
struct list_head list; struct list_head list;
@@ -41,32 +55,33 @@ struct mount {
char vendor[64]; char vendor[64];
char model[64]; char model[64];
char rev[64]; char rev[64];
int mounted; enum status status;
int ignore;
char size[64]; char size[64];
char sector_size[64]; char sector_size[64];
int fs; int fs;
}; };
char *fs_names[] = { static char *fs_names[] = {
"", "",
"", "",
"MBR", "mbr",
"EXT2", "ext2",
"EXT3", "ext3",
"FAT", "fat",
"HFSPLUS", "hfsplus",
"", "",
"NTFS", "ntfs",
"", "",
"EXT4" "exfat",
"ext4",
"hfsplusjournal"
}; };
#define MAX_MOUNTED 32 #define MAX_MOUNTED 32
#define MAX_MOUNT_NAME 32 #define MAX_MOUNT_NAME 32
char mounted[MAX_MOUNTED][3][MAX_MOUNT_NAME]; static char mounted[MAX_MOUNTED][3][MAX_MOUNT_NAME];
int mounted_count = 0; static int mounted_count = 0;
extern char uci_path[32]; extern char uci_path[32];
static void mount_dump_uci_state(void) static void mount_dump_uci_state(void)
@@ -93,20 +108,20 @@ static void mount_dump_uci_state(void)
ucix_add_option(ctx, mountd, q->serial, "disc", t); ucix_add_option(ctx, mountd, q->serial, "disc", t);
ucix_add_option(ctx, mountd, q->serial, "sector_size", q->sector_size); ucix_add_option(ctx, mountd, q->serial, "sector_size", q->sector_size);
snprintf(t, 64, "part%dmounted", atoi(&q->dev[3])); snprintf(t, 64, "part%dmounted", atoi(&q->dev[3]));
ucix_add_option(ctx, mountd, q->serial, t, (q->mounted)?("1"):("0")); ucix_add_option(ctx, mountd, q->serial, t, q->status == STATUS_MOUNTED ? "1" : "0");
ucix_add_option(ctx, mountd, q->serial, "vendor", q->vendor); ucix_add_option(ctx, mountd, q->serial, "vendor", q->vendor);
ucix_add_option(ctx, mountd, q->serial, "model", q->model); ucix_add_option(ctx, mountd, q->serial, "model", q->model);
ucix_add_option(ctx, mountd, q->serial, "rev", q->rev); ucix_add_option(ctx, mountd, q->serial, "rev", q->rev);
snprintf(t, 64, "size%d", atoi(&q->dev[3])); snprintf(t, 64, "size%d", atoi(&q->dev[3]));
ucix_add_option(ctx, mountd, q->serial, t, q->size); ucix_add_option(ctx, mountd, q->serial, t, q->size);
if(q->fs > MBR && q->fs <= EXT4) if(q->fs > MBR && q->fs <= LASTFS)
{ {
snprintf(t, 64, "fs%d", atoi(&q->dev[3])); snprintf(t, 64, "fs%d", atoi(&q->dev[3]));
ucix_add_option(ctx, mountd, q->serial, t, fs_names[q->fs]); ucix_add_option(ctx, mountd, q->serial, t, fs_names[q->fs]);
} }
if(q->mounted) if (q->status == STATUS_MOUNTED)
mounted++; mounted++;
if((!q->ignore) && q->size && q->sector_size) if ((q->status != STATUS_IGNORE) && q->size && q->sector_size)
size = size + (((unsigned long long int)atoi(q->size)) * ((unsigned long long int)atoi(q->sector_size))); size = size + (((unsigned long long int)atoi(q->size)) * ((unsigned long long int)atoi(q->sector_size)));
} }
ucix_add_option_int(ctx, mountd, mountd, "mounted", mounted); ucix_add_option_int(ctx, mountd, mountd, "mounted", mounted);
@@ -136,9 +151,8 @@ static void mount_add_list(char *name, char *dev, char *serial,
char *vendor, char *model, char *rev, int ignore, char *size, char *sector_size, int fs) char *vendor, char *model, char *rev, int ignore, char *size, char *sector_size, int fs)
{ {
struct mount *mount; struct mount *mount;
char tmp[64], tmp2[64]; char dev_path[64], dev_link[64], tmp[64];
if(fs <= MBR || fs > EXT4)
return;
mount = malloc(sizeof(struct mount)); mount = malloc(sizeof(struct mount));
INIT_LIST_HEAD(&mount->list); INIT_LIST_HEAD(&mount->list);
strncpy(mount->vendor, vendor, 64); strncpy(mount->vendor, vendor, 64);
@@ -149,18 +163,29 @@ static void mount_add_list(char *name, char *dev, char *serial,
strncpy(mount->serial, serial, 64); strncpy(mount->serial, serial, 64);
strncpy(mount->size, size, 64); strncpy(mount->size, size, 64);
strncpy(mount->sector_size, sector_size, 64); strncpy(mount->sector_size, sector_size, 64);
mount->ignore = ignore; mount->status = STATUS_UNMOUNTED;
mount->mounted = 0;
mount->fs = fs; mount->fs = fs;
list_add(&mount->list, &mounts); list_add(&mount->list, &mounts);
if((!mount->ignore) && (mount->fs > MBR) && (mount->fs <= EXT4))
{ if (ignore) {
mount->status = STATUS_IGNORE;
} else {
struct stat st;
log_printf("new mount : %s -> %s (%s)\n", name, dev, fs_names[mount->fs]); log_printf("new mount : %s -> %s (%s)\n", name, dev, fs_names[mount->fs]);
snprintf(tmp, 64, "%s%s", uci_path, name);
snprintf(tmp2, 64, "/tmp/run/mountd/%s", dev); snprintf(dev_link, sizeof(dev_link), "%s%s", uci_path, name);
symlink(tmp2, tmp); snprintf(dev_path, sizeof(dev_path), "%s%s", "/tmp/run/mountd/", dev);
mount_new("/tmp/run/mountd/", dev); /* If link aleady exists - replace it */
system_printf("/etc/mountd/event add %s %s", dev, name); if (lstat(dev_link, &st) == 0 && S_ISLNK(st.st_mode)) {
snprintf(tmp, sizeof(tmp), "%s%s", uci_path, "tmp");
symlink(dev_path, tmp);
rename(tmp, dev_link);
} else {
symlink(dev_path, dev_link);
}
if (!mount_new("/tmp/run/mountd/", dev))
system_printf("ACTION=add DEVICE=%s NAME=%s /sbin/hotplug-call mount", dev, name);
} }
} }
@@ -172,10 +197,9 @@ static int mount_check_disc(char *disc)
if(!fp) if(!fp)
{ {
log_printf("error reading /proc/mounts"); log_printf("error reading /proc/mounts");
fclose(fp);
return avail; return avail;
} }
while((fgets(tmp, 256, fp) > 0) && (avail == -1)) while((fgets(tmp, 256, fp) != NULL) && (avail == -1))
{ {
char *t; char *t;
char tmp2[32]; char tmp2[32];
@@ -219,7 +243,7 @@ int mount_new(char *path, char *dev)
log_printf("request for invalid path %s%s\n", path, dev); log_printf("request for invalid path %s%s\n", path, dev);
return -1; return -1;
} }
if(mount->ignore || mount->mounted || mount->fs == EXTENDED) if (mount->status == STATUS_IGNORE || mount->status == STATUS_MOUNTED || mount->fs == EXTENDED)
return -1; return -1;
snprintf(tmp, 256, "%s%s", path, mount->dev); snprintf(tmp, 256, "%s%s", path, mount->dev);
log_printf("mounting %s\n", tmp); log_printf("mounting %s\n", tmp);
@@ -228,51 +252,77 @@ int mount_new(char *path, char *dev)
pid = autofs_safe_fork(); pid = autofs_safe_fork();
if(!pid) if(!pid)
{ {
char *options, *fstype;
if(mount->fs == EXFAT) if(mount->fs == EXFAT)
{ {
log_printf("mount -t exfat -o rw,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp); options = "rw,uid=1000,gid=1000";
ret = system_printf("mount -t exfat -o rw,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp); fstype = "exfat";
} }
if(mount->fs == FAT) if(mount->fs == FAT)
{ {
log_printf("mount -t vfat -o rw,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp); options = "rw,uid=1000,gid=1000";
ret = system_printf("mount -t vfat -o rw,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp); fstype = "vfat";
} }
if(mount->fs == EXT4) if(mount->fs == EXT4)
{ {
log_printf("mount -t ext4 -o rw,defaults /dev/%s %s", mount->dev, tmp); options = "rw,defaults";
ret = system_printf("mount -t ext4 -o rw,defaults /dev/%s %s", mount->dev, tmp); fstype = "ext4";
} }
if(mount->fs == EXT3) if(mount->fs == EXT3)
{ {
log_printf("mount -t ext3 -o rw,defaults /dev/%s %s", mount->dev, tmp); options = "rw,defaults";
ret = system_printf("mount -t ext3 -o rw,defaults /dev/%s %s", mount->dev, tmp); fstype = "ext3";
} }
if(mount->fs == EXT2) if(mount->fs == EXT2)
{ {
log_printf("mount -t ext2 -o rw,defaults /dev/%s %s", mount->dev, tmp); options = "rw,defaults";
ret = system_printf("mount -t ext2 -o rw,defaults /dev/%s %s", mount->dev, tmp); fstype = "ext2";
} }
if(mount->fs == HFSPLUS) if(mount->fs == HFSPLUS)
{ {
log_printf("mount -t hfsplus -o rw,defaults,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp); options = "rw,defaults,uid=1000,gid=1000";
ret = system_printf("mount -t hfsplus -o rw,defaults,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp); fstype = "hfsplus";
}
if(mount->fs == HFSPLUSJOURNAL)
{
options = "ro,defaults,uid=1000,gid=1000";
fstype = "hfsplus";
} }
if(mount->fs == NTFS) if(mount->fs == NTFS)
{ {
log_printf("ntfs-3g /dev/%s %s -o force", mount->dev, tmp); options = "force";
ret = system_printf("ntfs-3g /dev/%s %s -o force", mount->dev, tmp); fstype = "ntfs-3g";
}
if(mount->fs > MBR && mount->fs <= LASTFS)
{
struct uci_context *ctx;
char *uci_options, *uci_fstype;
ctx = ucix_init("mountd");
if(fs_names[mount->fs])
{
uci_options = ucix_get_option(ctx, "mountd", fs_names[mount->fs], "options");
uci_fstype = ucix_get_option(ctx, "mountd", fs_names[mount->fs], "fstype");
if(uci_options)
options = uci_options;
if(uci_fstype)
fstype = uci_fstype;
log_printf("mount -t %s -o %s /dev/%s %s", fstype, options, mount->dev, tmp);
ret = system_printf("mount -t %s -o %s /dev/%s %s", fstype, options, mount->dev, tmp);
}
ucix_cleanup(ctx);
} }
exit(WEXITSTATUS(ret)); exit(WEXITSTATUS(ret));
} }
pid = waitpid(pid, &ret, 0); pid = waitpid(pid, &ret, 0);
ret = WEXITSTATUS(ret); ret = WEXITSTATUS(ret);
log_printf("----------> mount ret = %d\n", ret); log_printf("----------> mount ret = %d\n", ret);
if(ret && (ret != 0xff)) if (ret && ret != 0xff) {
rmdir(tmp);
return -1; return -1;
}
if(mount_wait_for_disc(mount->dev) == 0) if(mount_wait_for_disc(mount->dev) == 0)
{ {
mount->mounted = 1; mount->status = STATUS_MOUNTED;
mount_dump_uci_state(); mount_dump_uci_state();
} else return -1; } else return -1;
return 0; return 0;
@@ -284,14 +334,14 @@ int mount_remove(char *path, char *dev)
char tmp[256]; char tmp[256];
int ret; int ret;
snprintf(tmp, 256, "%s%s", path, dev); snprintf(tmp, 256, "%s%s", path, dev);
log_printf("%s has expired... unmounting\n", tmp); log_printf("device %s has expired... unmounting %s\n", dev, tmp);
ret = system_printf("/bin/umount %s", tmp); ret = system_printf("/bin/umount %s", tmp);
if(ret != 0) if(ret != 0)
return 0; return 0;
rmdir(tmp); rmdir(tmp);
mount = mount_find(0, dev); mount = mount_find(0, dev);
if(mount) if(mount)
mount->mounted = 0; mount->status = STATUS_EXPIRED;
log_printf("finished unmounting\n"); log_printf("finished unmounting\n");
mount_dump_uci_state(); mount_dump_uci_state();
return 0; return 0;
@@ -363,7 +413,7 @@ static char* mount_get_serial(char *dev)
fp = fopen(tmp2, "r"); fp = fopen(tmp2, "r");
if(fp) if(fp)
{ {
while(fgets(tmp2, 64, fp) > 0) while(fgets(tmp2, 64, fp) != NULL)
{ {
serial = strstr(tmp2, "Serial Number:"); serial = strstr(tmp2, "Serial Number:");
if(serial) if(serial)
@@ -426,6 +476,7 @@ static void mount_dev_add(char *dev)
char sector_size[64]; char sector_size[64];
FILE *fp; FILE *fp;
int offset = 3; int offset = 3;
int fs;
strcpy(name, dev); strcpy(name, dev);
if (!strncmp(name, "mmcblk", 6)) if (!strncmp(name, "mmcblk", 6))
@@ -531,29 +582,32 @@ static void mount_dev_add(char *dev)
fclose(fp); fclose(fp);
} }
snprintf(tmp, 64, "/dev/%s", dev); snprintf(tmp, 64, "/dev/%s", dev);
mount_add_list(node, dev, s, vendor, model, rev, ignore, size, sector_size, detect_fs(tmp)); fs = detect_fs(tmp);
if (fs <= MBR || fs > LASTFS) {
ignore = 1;
}
mount_add_list(node, dev, s, vendor, model, rev, ignore, size, sector_size, fs);
mount_dump_uci_state(); mount_dump_uci_state();
} }
} }
static void mount_dev_del(char *dev) static int mount_dev_del(struct mount *mount)
{ {
struct mount *mount = mount_find(0, dev);
char tmp[256]; char tmp[256];
if(mount) int err = 0;
{
if(mount->mounted) if (mount->status == STATUS_MOUNTED) {
{ snprintf(tmp, 256, "%s%s", "/tmp/run/mountd/", mount->dev);
snprintf(tmp, 256, "%s%s", "/tmp/run/mountd/", mount->name); log_printf("device %s has disappeared ... unmounting %s\n", mount->dev, tmp);
log_printf("%s has dissappeared ... unmounting\n", tmp); if (umount(tmp)) {
snprintf(tmp, 256, "%s%s", "/tmp/run/mountd/", mount->dev); err = -errno;
system_printf("/bin/umount %s", tmp); umount2(tmp, MNT_DETACH);
rmdir(tmp);
snprintf(tmp, 64, "%s%s", uci_path, mount->name);
unlink(tmp);
mount_dump_uci_state();
} }
rmdir(tmp);
mount_dump_uci_state();
} }
return err;
} }
void mount_dump_list(void) void mount_dump_list(void)
@@ -562,7 +616,7 @@ void mount_dump_list(void)
list_for_each(p, &mounts) list_for_each(p, &mounts)
{ {
struct mount *q = container_of(p, struct mount, list); struct mount *q = container_of(p, struct mount, list);
log_printf("* %s %s %d\n", q->name, q->dev, q->mounted); log_printf("* %s %s %d\n", q->name, q->dev, q->status == STATUS_MOUNTED);
} }
} }
@@ -581,7 +635,7 @@ char* is_mounted(char *block, char *path)
return 0; return 0;
} }
static void mount_check_mount_list(void) static void mount_update_mount_list(void)
{ {
FILE *fp = fopen("/proc/mounts", "r"); FILE *fp = fopen("/proc/mounts", "r");
char tmp[256]; char tmp[256];
@@ -589,13 +643,18 @@ static void mount_check_mount_list(void)
if(!fp) if(!fp)
{ {
log_printf("error reading /proc/mounts"); log_printf("error reading /proc/mounts");
fclose(fp);
return; return;
} }
mounted_count = 0; mounted_count = 0;
while(fgets(tmp, 256, fp) > 0) while(fgets(tmp, 256, fp) != NULL)
{ {
char *t, *t2; char *t, *t2;
if (mounted_count + 1 > MAX_MOUNTED) {
log_printf("found more than %d mounts \n", MAX_MOUNTED);
break;
}
t = strstr(tmp, " "); t = strstr(tmp, " ");
if(t) if(t)
{ {
@@ -621,10 +680,8 @@ static void mount_check_mount_list(void)
mounted[mounted_count][0], mounted[mounted_count][0],
mounted[mounted_count][1], mounted[mounted_count][1],
mounted[mounted_count][2]);*/ mounted[mounted_count][2]);*/
if(mounted_count < MAX_MOUNTED - 1)
mounted_count++; mounted_count++;
else
log_printf("found more than %d mounts \n", MAX_MOUNTED);
} }
fclose(fp); fclose(fp);
} }
@@ -637,8 +694,8 @@ static int dir_filter2(const struct dirent *a)
return 0; return 0;
} }
#define MAX_BLOCK 64 #define MAX_BLOCK 64
char block[MAX_BLOCK][MAX_BLOCK]; static char block[MAX_BLOCK][MAX_BLOCK];
int blk_cnt = 0; static int blk_cnt = 0;
static int check_block(char *b) static int check_block(char *b)
{ {
@@ -667,13 +724,19 @@ static void mount_enum_drives(void)
char tmp[64]; char tmp[64];
snprintf(tmp, 64, "/sys/block/%s/", namelist[n]->d_name); snprintf(tmp, 64, "/sys/block/%s/", namelist[n]->d_name);
m = scandir(tmp, &namelist2, dir_filter2, dir_sort); m = scandir(tmp, &namelist2, dir_filter2, dir_sort);
while(m--) if(m > 0)
{ {
strncpy(&block[blk_cnt][0], namelist2[m]->d_name, MAX_BLOCK); while(m--)
{
strncpy(&block[blk_cnt][0], namelist2[m]->d_name, MAX_BLOCK);
blk_cnt++;
free(namelist2[m]);
}
free(namelist2);
} else {
strncpy(&block[blk_cnt][0], namelist[n]->d_name, MAX_BLOCK);
blk_cnt++; blk_cnt++;
free(namelist2[m]);
} }
free(namelist2);
} }
free(namelist[n]); free(namelist[n]);
} }
@@ -691,11 +754,11 @@ static void mount_enum_drives(void)
ctx = ucix_init("mountd"); ctx = ucix_init("mountd");
t = ucix_get_option(ctx, "mountd", q->serial, tmp); t = ucix_get_option(ctx, "mountd", q->serial, tmp);
ucix_cleanup(ctx); ucix_cleanup(ctx);
if(t && !q->mounted) if (t && q->status != STATUS_MOUNTED)
{ {
if(!strcmp(t, "0")) if(!strcmp(t, "0"))
{ {
if(!q->ignore) if (q->status != STATUS_IGNORE)
del = 1; del = 1;
} else if(!strcmp(t, "1")) } else if(!strcmp(t, "1"))
{ {
@@ -708,15 +771,33 @@ static void mount_enum_drives(void)
} }
if(!check_block(q->dev)||del) if(!check_block(q->dev)||del)
{ {
mount_dev_del(q->dev); if (q->status == STATUS_MOUNTED || q->status == STATUS_EXPIRED) {
char dev_link[64];
int err;
system_printf("ACTION=remove DEVICE=%s NAME=%s /sbin/hotplug-call mount", q->dev, q->name);
err = mount_dev_del(q);
snprintf(dev_link, sizeof(dev_link), "%s%s", uci_path, q->name);
if (err == -EBUSY) {
/* Create "tmp" symlink to non-existing path */
snprintf(tmp, sizeof(tmp), "%s%s", uci_path, "tmp");
symlink("## DEVICE MISSING ##", tmp);
/* Replace old symlink with the not working one */
rename(tmp, dev_link);
} else {
log_printf("unlinking %s\n", dev_link);
unlink(dev_link);
}
}
p->prev->next = p->next; p->prev->next = p->next;
p->next->prev = p->prev; p->next->prev = p->prev;
p = p->next; p = p->next;
log_printf("removing %s\n", q->dev);
snprintf(tmp, 64, "%s%s", uci_path, q->name);
unlink(tmp);
system_printf("/etc/mountd/event remove %s %s", q->dev, q->name);
free(q); free(q);
mount_dump_uci_state(); mount_dump_uci_state();
system_printf("/etc/fonstated/ReloadSamba"); system_printf("/etc/fonstated/ReloadSamba");
} else p = p->next; } else p = p->next;
@@ -735,7 +816,7 @@ static void mount_check_enum(void)
void mount_init(void) void mount_init(void)
{ {
INIT_LIST_HEAD(&mounts); INIT_LIST_HEAD(&mounts);
timer_add(mount_check_mount_list, 2); timer_add(mount_update_mount_list, 2);
timer_add(mount_check_enum, 1); timer_add(mount_check_enum, 1);
mount_check_mount_list(); mount_update_mount_list();
} }

View File

@@ -7,21 +7,10 @@
#include "include/led.h" #include "include/led.h"
#include "include/signal.h" #include "include/signal.h"
void (*crtlc_cb)(void) = 0; void signal_init(void (*_crtlc_cb)(int))
static void handlerINT(int s)
{
log_printf("caught sig int ... cleaning up\n");
if(crtlc_cb)
crtlc_cb();
exit(0);
}
void signal_init(void (*_crtlc_cb)(void))
{ {
struct sigaction s; struct sigaction s;
crtlc_cb = _crtlc_cb; s.sa_handler = _crtlc_cb;
s.sa_handler = handlerINT;
s.sa_flags = 0; s.sa_flags = 0;
sigaction(SIGINT, &s, NULL); sigaction(SIGTERM, &s, NULL);
} }

View File

@@ -9,7 +9,7 @@
/* when using this file, alarm() is used */ /* when using this file, alarm() is used */
struct list_head timers; static struct list_head timers;
struct timer { struct timer {
struct list_head list; struct list_head list;

View File

@@ -54,6 +54,9 @@ char* uci_get_option(struct uci_context *ctx, char *section, char *option)
char *value = NULL; char *value = NULL;
struct uci_ptr ptr; struct uci_ptr ptr;
if (!p)
return NULL;
memset(&ptr, 0, sizeof(ptr)); memset(&ptr, 0, sizeof(ptr));
ptr.package = p->e.name; ptr.package = p->e.name;
ptr.section = section; ptr.section = section;
@@ -101,6 +104,9 @@ void uci_for_each_section_type(char *type, void (*cb)(char*, void*), void *priv)
{ {
struct uci_element *e; struct uci_element *e;
if (!p)
return;
uci_foreach_element(&p->sections, e) uci_foreach_element(&p->sections, e)
if (!strcmp(type, uci_to_section(e)->type)) if (!strcmp(type, uci_to_section(e)->type))
cb(e->name, priv); cb(e->name, priv);

View File

@@ -18,6 +18,8 @@ static inline int ucix_get_ptr(struct uci_context *ctx, const char *p, const cha
struct uci_context* ucix_init(const char *config_file) struct uci_context* ucix_init(const char *config_file)
{ {
struct uci_context *ctx = uci_alloc_context(); struct uci_context *ctx = uci_alloc_context();
if(!ctx)
return NULL;
uci_add_delta_path(ctx, "/var/state"); uci_add_delta_path(ctx, "/var/state");
if(uci_load(ctx, config_file, NULL) != UCI_OK) if(uci_load(ctx, config_file, NULL) != UCI_OK)
{ {
@@ -30,6 +32,8 @@ struct uci_context* ucix_init(const char *config_file)
struct uci_context* ucix_init_path(const char *path, const char *config_file) struct uci_context* ucix_init_path(const char *path, const char *config_file)
{ {
struct uci_context *ctx = uci_alloc_context(); struct uci_context *ctx = uci_alloc_context();
if(!ctx)
return NULL;
if(path) if(path)
{ {
uci_set_savedir(ctx, path); uci_set_savedir(ctx, path);
@@ -44,7 +48,10 @@ struct uci_context* ucix_init_path(const char *path, const char *config_file)
void ucix_cleanup(struct uci_context *ctx) void ucix_cleanup(struct uci_context *ctx)
{ {
uci_free_context(ctx); if(ctx)
{
uci_free_context(ctx);
}
} }
int ucix_save(struct uci_context *ctx, const char *p) int ucix_save(struct uci_context *ctx, const char *p)