Skip to content

Commit

Permalink
loooots of bugfixes and changes: check changelog. Most noticeably: li…
Browse files Browse the repository at this point in the history
…budev is now mandatory.
  • Loading branch information
FedeDP committed Feb 4, 2016
1 parent 8199f9e commit 00b43eb
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 242 deletions.
13 changes: 13 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
02 / 05 / 2016
* fixed iso files mounting. Now works fine and reliably.
* removed is_mounted and relying on mntent function (get_mount_points)
* fixed check_cwd function and moved those checks to mount_fs (only when unmounting), to make them useful even when unmounting an iso.
* fixed is_iso_mounted check: it will now perform check to see if a loop device with the same backingfile is unmounted (but already present...created by user or another program), and mount the iso on this loop dev, instead of creating another loop dev.
* moved SetAutoclear on loopdevices to its own function: it has to be called after add_device mounts the loop_dev.
* fixed a bug if compiled with clang ( uint8_t bytes = '\0' was const, with gcc worked fine, but not with clang)
* fixed add_device: relying on some udev dev property values instead of is_mounted function.
* fixed print_info: if info_win is not present, it won't do anything.
* helper_string (helper_win) content will now change together with compile time options, hiding the useless ones.
* libudev is now mandatory
* fixes in add_device: checking if a "size" property is really available for current dev.

02 / 02 / 2016
* using basename() and dirname() functions instead of manually strrchr path strings. Way cleaner and probably more reliable.
* using change_dir when creating new_tab to check for chdir errors and reuse more code.
Expand Down
7 changes: 4 additions & 3 deletions PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ optdepends=('xdg-utils: xdg-open support'
'udisks2: mountable drives and ISO mount support'
'packagekit: package installation support'
'upower: AC (dis)connection events support')
# libcups, libconfig, libx11, openssl, and systemd are optional build dep.
# libcups, libconfig, libx11, and openssl are optional build dep.
# If compiled without them, the program will run just fine;
# but that would disable xdg-open, config file read, printing, shasum, powermanagement inhibition,
# drives/iso mount, local packages installation and upower AC (dis)connection signals support.
# but that would disable xdg-open, config file read, printing, and shasum support.
# systemd too is an optdep. But in arch libudev is packaged together with it,
# and libudev is a mandatory dep.
makedepends=('git')
source=("git://github.com/FedeDP/${_gitname}.git")
backup=('etc/default/ncursesFM.conf')
Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ It can be built with a very small set of dependencies, as i tried to make as man
* Every feature you would expect by a basic FM.
* Terminal window resize support.
* 2 tabs support. Their content is kept in sync. Jump between tabs with arrow keys (left/right).
* Simple sysinfo monitor that will refresh every 30s: clock, battery and some system info; battery monitor needs libudev.
* Simple sysinfo monitor that will refresh every 30s: clock, battery and some system info.
If you've got Upower installed, AC (dis)connection will refresh battery status instantly, instead of waiting up to 30s until next refresh.
* Fast browse mode: enable it with ','. It lets you jump between files by just typing their names.
* '.' to change files/dirs sorting mode: alphabetically (default), by size, by last modified or by type.
Expand All @@ -37,7 +37,7 @@ You can add whatever type of file you wish as bookmark from within ncursesFM. Yo
* Powermanagement inhibition while processing a job (eg: while pasting a file) to avoid data loss.
* Internal udisks2 monitor, to poll for new devices. It can automount new connected devices too.
Device monitor will list only mountable devices, eg: dvd reader will not be listed until a cd/dvd is inserted.
* Drives/usb sticks/ISO files (un)mount through udisks2. For drives/usb sticks mount, you also need libudev.
* Drives/usb sticks/ISO files (un)mount through udisks2.
* Distro package files installation.
* It can reveice AC (dis)connection events from upower, to instantly update battery monitor.

Expand Down Expand Up @@ -72,27 +72,26 @@ Log file is located at "$HOME/.ncursesfm.log". It is overwritten each time ncurs
* 3 : log disabled.

## Build requirements
* linux>=3.4 -> pipe2() O_DIRECT flag. See: http://man7.org/linux/man-pages/man2/pipe.2.html
* linux >= 3.4 -> pipe2() O_DIRECT flag. See: http://man7.org/linux/man-pages/man2/pipe.2.html
* ncurses -> UI
* libarchive -> archiving/extracting support
* pkg-config -> to manage libraries link in makefile
* glibc -> to set locale, for inotify, and for mntent functions (useful only if compiled with libudev too)
* glibc -> to set locale, for inotify, and for mntent functions.
* libudev -> needed for devices/iso mount, and batteries polling.
* git -> to clone repo

## Optional compile time dependencies
* libcups -> print support.
* libconfig -> config file parsing.
* libx11 -> check whether ncursesFM is started in a X environment or not, and xdg-open support.
* sd-bus -> needed for powermanagement inhibition functions, devices/iso mount and packages installation.
* libudev -> needed for devices/iso mount, and batteries polling.
* openssl -> for shasum function support.

**Build options (to be passed to make)**
* CC={gcc/clang} to choose the compiler. By default, env CC will be used.
* DISABLE_LIBX11=1 to disable libx11 support.
* DISABLE_LIBCONFIG=1 to disable libconfig support.
* DISABLE_LIBSYSTEMD=1 to disable libsystemd (sd-bus) support.
* DISABLE_LIBUDEV=1 to disable libudev support.
* DISABLE_LIBOPENSSL=1 ti disable openssl support.
* DISABLE_LIBCUPS=1 to disable libcups support.

Expand All @@ -114,11 +113,11 @@ Log file is located at "$HOME/.ncursesfm.log". It is overwritten each time ncurs

On Ubuntu install required packages:

# apt-get install libncursesw5-dev libarchive-dev pkg-config git build-essential
# apt-get install libncursesw5-dev libarchive-dev pkg-config git build-essential libudev-dev

Optional:

# apt-get install libcups2-dev libconfig-dev libx11-dev libsystemd-dev libudev-dev libssl-dev
# apt-get install libcups2-dev libconfig-dev libx11-dev libsystemd-dev libssl-dev

Clone the repo and move inside new dir, then:

Expand Down
2 changes: 0 additions & 2 deletions inc/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ struct conf {
int second_tab_starting_dir;
#ifdef SYSTEMD_PRESENT
int inhibit;
#ifdef LIBUDEV_PRESENT
int automount;
#endif
#endif
int starting_helper;
int loglevel;
Expand Down
11 changes: 4 additions & 7 deletions inc/mount.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
#ifdef SYSTEMD_PRESENT

#include "fm_functions.h"
#include <systemd/sd-bus.h>

void isomount(const char *str);

#ifdef LIBUDEV_PRESENT
#ifdef SYSTEMD_PRESENT

#include <systemd/sd-bus.h>
#include <libudev.h>
#include <mntent.h>

void isomount(const char *str);
int start_monitor(void);
void devices_bus_process(void);
void show_devices_tab(void);
void manage_mount_device(void);
void manage_enter_device(void);
void leave_device_mode(void);
void free_device_monitor(void);
#endif

#endif
8 changes: 5 additions & 3 deletions inc/string_constants.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#ifdef SYSTEMD_PRESENT
#define HELPER_HEIGHT 14
#else
#define HELPER_HEIGHT 12
#endif

#define LONG_FILE_OPERATIONS 5
#define SHORT_FILE_OPERATIONS 3

Expand Down Expand Up @@ -67,9 +72,6 @@ const char *helper_string[HELPER_HEIGHT - 2];
const char *pkg_quest;
const char *install_th_wait;
const char *package_warn;
#endif

#ifdef LIBUDEV_PRESENT
const char *device_mode_str;
#endif
const char *bookmarks_mode_str;
Expand Down
12 changes: 2 additions & 10 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LIBS =-lpthread $(shell pkg-config --silence-errors --libs libarchive ncurses)
LIBS =-lpthread $(shell pkg-config --silence-errors --libs libarchive ncurses libudev)
CFLAGS =-D_GNU_SOURCE
RM = rm
INSTALL = install -p
Expand All @@ -24,14 +24,11 @@ endif
ifneq ("$(DISABLE_LIBSYSTEMD)","1")
LIBSYSTEMD=$(shell pkg-config --silence-errors --libs libsystemd)
endif
ifneq ("$(DISABLE_LIBUDEV)","1")
LIBUDEV=$(shell pkg-config --silence-errors --libs libudev)
endif
ifneq ("$(DISABLE_OPENSSL)","1")
LIBOPENSSL=$(shell pkg-config --silence-errors --libs openssl)
endif

LIBS+=$(LIBX11) $(LIBCONFIG) $(LIBSYSTEMD) $(LIBUDEV) $(LIBOPENSSL)
LIBS+=$(LIBX11) $(LIBCONFIG) $(LIBSYSTEMD) $(LIBOPENSSL)

ifneq ("$(LIBX11)","")
CFLAGS+=-DLIBX11_PRESENT
Expand Down Expand Up @@ -61,11 +58,6 @@ CFLAGS+=-DSYSTEMD_PRESENT
$(info libsystemd support enabled.)
endif

ifneq ("$(LIBUDEV)","")
CFLAGS+=-DLIBUDEV_PRESENT
$(info libudev support enabled.)
endif

endif

all: ncursesFM clean
Expand Down
4 changes: 0 additions & 4 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@ static void log_current_options(void) {
fprintf(log_file, "* Second tab starting dir: %d\n", config.second_tab_starting_dir);
#ifdef SYSTEMD_PRESENT
fprintf(log_file, "* Inhibition: %d\n", config.inhibit);
#ifdef LIBUDEV_PRESENT
fprintf(log_file, "* Automount: %d\n", config.automount);
#endif
#endif
fprintf(log_file, "* Starting with helper window: %d\n", config.starting_helper);
fprintf(log_file, "* Log level: %d\n", config.loglevel);
fprintf(log_file, "* Log persistency: %d\n", config.persistent_log);
#ifdef LIBUDEV_PRESENT
fprintf(log_file, "* Low battery threshold: %d\n\n", config.bat_low_level);
#endif
}

void log_message(const char *filename, int lineno, const char *funcname, const char *log_msg, char type, int log_level) {
Expand Down
24 changes: 7 additions & 17 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static void read_config_file(void);
#endif
static void config_checks(void);
static void main_loop(void);
#if defined SYSTEMD_PRESENT && LIBUDEV_PRESENT
#ifdef SYSTEMD_PRESENT
static void check_device_mode(void);
#endif
static void manage_enter(struct stat current_file_stat);
Expand Down Expand Up @@ -91,7 +91,7 @@ static void set_signals(void) {
}

static void set_pollfd(void) {
#if defined SYSTEMD_PRESENT && LIBUDEV_PRESENT
#ifdef SYSTEMD_PRESENT
nfds = 6;
#else
nfds = 5;
Expand Down Expand Up @@ -122,7 +122,7 @@ static void set_pollfd(void) {
.fd = info_fd[0],
.events = POLLIN,
};
#if defined SYSTEMD_PRESENT && LIBUDEV_PRESENT
#ifdef SYSTEMD_PRESENT
main_p[DEVMON_IX] = (struct pollfd) {
.fd = start_monitor(),
.events = POLLIN,
Expand Down Expand Up @@ -157,11 +157,9 @@ static void sigsegv_handler(int signum) {
static void helper_function(int argc, const char *argv[]) {
/* default value for starting_helper, bat_low_level and device_mode */
config.starting_helper = 1;
#ifdef LIBUDEV_PRESENT
config.bat_low_level = 15;
#ifdef SYSTEMD_PRESENT
device_mode = DEVMON_STARTING;
#endif
#endif

if ((argc > 1) && (!strcmp(argv[1], "--help"))) {
Expand Down Expand Up @@ -190,11 +188,7 @@ static void helper_function(int argc, const char *argv[]) {
static void parse_cmd(int argc, const char *argv[]) {
int j = 1;
#ifdef SYSTEMD_PRESENT
#ifdef LIBUDEV_PRESENT
const char *cmd_switch[] = {"--editor", "--starting_dir", "--helper_win", "--loglevel", "--persistent_log", "--low_level", "--inhibit", "--automount"};
#else
const char *cmd_switch[] = {"--editor", "--starting_dir", "--helper_win", "--loglevel", "--persistent_log", "--low_level", "--inhibit"};
#endif
#else
const char *cmd_switch[] = {"--editor", "--starting_dir", "--helper_win", "--loglevel", "--persistent_log", "--low_level"};
#endif
Expand All @@ -217,11 +211,9 @@ static void parse_cmd(int argc, const char *argv[]) {
else if ((!strcmp(cmd_switch[6], argv[j])) && (argv[j + 1])) {
config.inhibit = atoi(argv[j + 1]);
}
#ifdef LIBUDEV_PRESENT
else if ((!strcmp(cmd_switch[7], argv[j])) && (argv[j + 1])) {
config.automount = atoi(argv[j + 1]);
}
#endif
#endif
else {
break;
Expand Down Expand Up @@ -253,9 +245,7 @@ static void read_config_file(void) {
config_lookup_int(&cfg, "starting_helper", &config.starting_helper);
#ifdef SYSTEMD_PRESENT
config_lookup_int(&cfg, "inhibit", &config.inhibit);
#ifdef LIBUDEV_PRESENT
config_lookup_int(&cfg, "automount", &config.automount);
#endif
#endif
config_lookup_int(&cfg, "loglevel", &config.loglevel);
config_lookup_int(&cfg, "persistent_log", &config.persistent_log);
Expand Down Expand Up @@ -398,7 +388,7 @@ static void main_loop(void) {
}
break;
#endif
#if defined SYSTEMD_PRESENT && LIBUDEV_PRESENT
#ifdef SYSTEMD_PRESENT
case 'm': // m to mount/unmount fs
check_device_mode();
break;
Expand Down Expand Up @@ -447,7 +437,7 @@ static void main_loop(void) {
}
}

#if defined SYSTEMD_PRESENT && LIBUDEV_PRESENT
#ifdef SYSTEMD_PRESENT
static void check_device_mode(void) {
if (sv.searching == 3 + active || bookmarks_mode[active]) {
return;
Expand All @@ -472,7 +462,7 @@ static void manage_enter(struct stat current_file_stat) {
sv.found_searched[ps[active].curr_pos][index] = '\0';
leave_search_mode(sv.found_searched[ps[active].curr_pos]);
}
#if defined SYSTEMD_PRESENT && LIBUDEV_PRESENT
#ifdef SYSTEMD_PRESENT
else if (device_mode == 1 + active) {
manage_enter_device();
}
Expand All @@ -492,7 +482,7 @@ static void manage_quit(void) {
if (sv.searching == 3 + active) {
leave_search_mode(ps[active].my_cwd);
}
#if defined SYSTEMD_PRESENT && LIBUDEV_PRESENT
#ifdef SYSTEMD_PRESENT
else if (device_mode == 1 + active) {
leave_device_mode();
}
Expand Down
Loading

0 comments on commit 00b43eb

Please sign in to comment.