Skip to content

Commit

Permalink
Merge pull request #37 from plundstr/master
Browse files Browse the repository at this point in the history
Finetuned diskmonitor and tempreaper disabled by default
  • Loading branch information
Pekka Lundstrom committed Oct 30, 2013
2 parents 31c1bad + 793bc5f commit 0cc783f
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 21 deletions.
2 changes: 1 addition & 1 deletion configure.ac
@@ -1,5 +1,5 @@
# Package name and version
AC_INIT(dsme, 0.63.3)
AC_INIT(dsme, 0.63.4)

AM_INIT_AUTOMAKE

Expand Down
8 changes: 4 additions & 4 deletions modules/diskmonitor.c
Expand Up @@ -23,8 +23,8 @@
License along with Dsme. If not, see <http://www.gnu.org/licenses/>.
*/

// to send the base_boot_done signal:
// dbus-send --system --type=signal /com/nokia/startup/signal com.nokia.startup.signal.base_boot_done
// to send the init_done signal:
// dbus-send --system --type=signal /com/nokia/startup/signal com.nokia.startup.signal.init_done

// to request a disk space check:
// dbus-send --system --print-reply --dest=com.nokia.diskmonitor /com/nokia/diskmonitor/request com.nokia.diskmonitor.request.req_check
Expand Down Expand Up @@ -156,7 +156,7 @@ static const dsme_dbus_binding_t methods[] =

static void init_done_ind(const DsmeDbusMessage* ind)
{
dsme_log(LOG_DEBUG, LOGPFIX"base_boot_done received");
dsme_log(LOG_DEBUG, LOGPFIX"init_done received");

init_done_received = true;
}
Expand Down Expand Up @@ -193,7 +193,7 @@ static void mce_inactivity_sig(const DsmeDbusMessage* sig)

static const dsme_dbus_signal_binding_t signals[] =
{
{ init_done_ind, "com.nokia.startup.signal", "base_boot_done" },
{ init_done_ind, "com.nokia.startup.signal", "init_done" },
{ mce_inactivity_sig, "com.nokia.mce.signal", "system_inactivity_ind" },
{ 0, 0 }
};
Expand Down
28 changes: 19 additions & 9 deletions modules/diskmonitor_backend.c
Expand Up @@ -34,6 +34,7 @@
#include <string.h>
#include <mntent.h>
#include <sys/statfs.h>
#include <stdbool.h>

#define ArraySize(a) (sizeof(a)/sizeof*(a))

Expand All @@ -45,15 +46,16 @@ typedef struct {
static disk_use_limit_t disk_space_use_limits[] = {
/* [mount path, max usage percent] */
{ "/", 90 },
{ "/tmp", 90 },
{ "/home", 90 },
{ "/home/user/MyDocs", 90 }
{ "/tmp", 70 },
{ "/run", 70 },
{ "/home", 90 }
};

static disk_use_limit_t* find_use_limit_for_mount(const char* mntpoint)
{
disk_use_limit_t* use_limit = 0;
size_t i;

for (i=0; i < ArraySize(disk_space_use_limits); i++) {
if (0 == strcmp(disk_space_use_limits[i].mntpoint, mntpoint)) {
use_limit = &disk_space_use_limits[i];
Expand All @@ -64,29 +66,32 @@ static disk_use_limit_t* find_use_limit_for_mount(const char* mntpoint)
return use_limit;
}

static void check_mount_use_limit(const char* mntpoint, disk_use_limit_t* use_limit)
static bool check_mount_use_limit(const char* mntpoint, disk_use_limit_t* use_limit)
{
struct statfs s;
int blocks_percent_used;
bool over_limit = false;

memset(&s, 0, sizeof(s));

if (statfs(mntpoint, &s) != 0 || s.f_blocks <= 0) {
dsme_log(LOG_WARNING, "failed to statfs the mount point (%s).", mntpoint);
return;
dsme_log(LOG_WARNING, "diskmonitor: failed to statfs the mount point (%s).", mntpoint);
return false;
}

blocks_percent_used = (int)((s.f_blocks - s.f_bfree) * 100.f / s.f_blocks + 0.5f);

if (blocks_percent_used >= use_limit->max_usage_percent) {
dsme_log(LOG_WARNING, "disk space usage (%i percent used) for (%s) exceeded the limit (%i)",
dsme_log(LOG_WARNING, "diskmonitor: disk space usage (%i percent used) for (%s) exceeded the limit (%i)",
blocks_percent_used, mntpoint, use_limit->max_usage_percent);

DSM_MSGTYPE_DISK_SPACE msg = DSME_MSG_INIT(DSM_MSGTYPE_DISK_SPACE);
msg.blocks_percent_used = blocks_percent_used;

broadcast_internally_with_extra(&msg, strlen(mntpoint) + 1, mntpoint);
}
over_limit = true;
}
return over_limit;
}

void check_disk_space_usage(void)
Expand All @@ -103,7 +108,12 @@ void check_disk_space_usage(void)
continue;
}

check_mount_use_limit(m.mnt_dir, use_limit);
if (check_mount_use_limit(m.mnt_dir, use_limit)) {
/* When we find first disk_usage over the limit, no need to continue
* Warning has been given and tempreaper has been started
*/
break;
}
}
endmntent(f);
}
2 changes: 2 additions & 0 deletions modules/startup.c
Expand Up @@ -105,7 +105,9 @@ const char *modules[] = {
"validatorlistener.so",
#endif
"diskmonitor.so",
#ifdef DSME_TEMPREAPER
"tempreaper.so",
#endif
"dbusautoconnector.so",
#ifdef DSME_PWRKEY_MONITOR
"pwrkeymonitor.so",
Expand Down
11 changes: 10 additions & 1 deletion modules/tempreaper.c
Expand Up @@ -34,6 +34,7 @@
#include <glib.h>
#include <pwd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
Expand Down Expand Up @@ -92,11 +93,19 @@ static pid_t reaper_process_new(void)
/* The tempdirs we will cleanup are given as an argument.
*/
char* const argv[] = {(char*)"rpdir",
(char*)"/var/tmp",
(char*)"/tmp",
(char*)"/run/log",
(char*)"/var/log",
(char*)"/var/cache/core-dumps",
(char*)0};

fflush(0);
pid_t pid = fork();

if (pid == 0) {
int fd;
closelog();
for( fd = 3; fd < 1024; ++fd ) close(fd);
/* Child; set a reasonably low priority, DSME runs with the priority -1
so we don't want to use the inherited priority */
if (setpriority(PRIO_PROCESS, 0, MIN_PRIORITY) != 0) {
Expand Down
2 changes: 1 addition & 1 deletion rpm/dsme.spec
Expand Up @@ -13,7 +13,7 @@ Name: dsme
# << macros

Summary: Device State Management Entity
Version: 0.63.3
Version: 0.63.4
Release: 0
Group: System/System Control
License: LGPLv2+
Expand Down
2 changes: 1 addition & 1 deletion rpm/dsme.yaml
@@ -1,6 +1,6 @@
Name: dsme
Summary: Device State Management Entity
Version: 0.63.3
Version: 0.63.4
Release: 0
Group: System/System Control
License: LGPLv2+
Expand Down
14 changes: 10 additions & 4 deletions util/rpdir.c
Expand Up @@ -86,7 +86,7 @@ static char* make_command_new(char* dirs[])
if (argz_create(dirs, &cmdline, &len) == 0) {
argz_stringify(cmdline, len, ' ');

if (asprintf(&buf, "%s %s", "/usr/bin/lsof -Fn", cmdline) < 0) {
if (asprintf(&buf, "%s %s", "/usr/sbin/lsof -Fn" , cmdline) < 0) {
goto out;
}
}
Expand Down Expand Up @@ -185,8 +185,10 @@ static bool is_open(const char* file)
return bsearch(&file, open_files, num_files, sizeof *open_files, string_cmp);
}

static int reaper(const char *file, const struct stat64 *sb, int flag)
static int reaper(const char *file, const struct stat64 *sb, int flag, struct FTW *ftwbuf)
{
(void)ftwbuf;

if (flag != FTW_F) {
#ifdef DEBUG
fprintf(stderr, "file '%s' is not a normal file, skipping\n", file);
Expand Down Expand Up @@ -220,6 +222,10 @@ static int reaper(const char *file, const struct stat64 *sb, int flag)
fprintf(stderr, ME "failed to unlink file '%s': %m\n", file);
goto out;
}
#ifdef DEBUG
else fprintf(stderr, ME "deleted file '%s'\n", file);
#endif

} else {
#ifdef DEBUG
fprintf(stderr, "file '%s' modified too recently mod_age=%lus acc_age=%lus, skipping\n",
Expand All @@ -239,8 +245,8 @@ static int reap(char* dirs[])
checkpoint = curt - TIMEOUT;

for (i = 0; dirs[i]; i++) {
if (ftw64(dirs[i], reaper, MAX_FTW_FDS) != 0) {
fprintf(stderr, ME "ERROR traversing '%s': ftw64() failed: %m\n",
if (nftw64(dirs[i], reaper, MAX_FTW_FDS, FTW_PHYS) != 0) {
fprintf(stderr, ME "ERROR traversing '%s': nftw64() failed: %m\n",
dirs[i]);
}
}
Expand Down

0 comments on commit 0cc783f

Please sign in to comment.