<commit_before>/**
   @file diskmonitor.c
   Periodically monitors the disks and sends a message if the disk space usage
   exceeds the use limits.

   <p>
   Copyright (C) 2011 Nokia Corporation.

   @author <NAME> <<EMAIL>>

   This file is part of Dsme.

   Dsme is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License
   version 2.1 as published by the Free Software Foundation.

   Dsme is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with Dsme.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __cplusplus
#define _GNU_SOURCE
#endif

#include <iphbd/iphb_internal.h>

#include "diskmonitor.h"
#include "validatorlistener.h"
#include "dsme/modules.h"
#include "dsme/logging.h"
#include "heartbeat.h"

#include <string.h>
#include <mntent.h>
#include <sys/statfs.h>
#include <stdbool.h>

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

static bool init_done_ind = false;

typedef struct {
    const char*     mntpoint;
    int             max_usage_percent;
} disk_use_limit_t;

static disk_use_limit_t disk_space_use_limits[] = {
   /* [mount path, max usage percent] */
   {  "/",                        95 },
   {  "/tmp",                     95 },
   {  "/home/user/MyDocs",        95 }
};

static void schedule_next_wakeup(void)
{
    /* Don't cause too frequent wakeups for checking the disks;
     * the check is now twice in an hour.
     */

    DSM_MSGTYPE_WAIT msg = DSME_MSG_INIT(DSM_MSGTYPE_WAIT);
    msg.req.mintime = 1800; /* 30 minutes */
    msg.req.maxtime = msg.req.mintime + 120;
    msg.req.pid     = 0;
    msg.data        = 0;

    broadcast_internally(&msg);
}

static disk_use_limit_t* find_use_limit_for_mount(const char* mntpoint)
{
    disk_use_limit_t* use_limit = 0;
    size_t i;<commit_msg>Lower the disk space use limit for /<commit_after>/**
   @file diskmonitor.c
   Periodically monitors the disks and sends a message if the disk space usage
   exceeds the use limits.

   <p>
   Copyright (C) 2011 Nokia Corporation.

   @author <NAME> <<EMAIL>>

   This file is part of Dsme.

   Dsme is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License
   version 2.1 as published by the Free Software Foundation.

   Dsme is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with Dsme.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __cplusplus
#define _GNU_SOURCE
#endif

#include <iphbd/iphb_internal.h>

#include "diskmonitor.h"
#include "validatorlistener.h"
#include "dsme/modules.h"
#include "dsme/logging.h"
#include "heartbeat.h"

#include <string.h>
#include <mntent.h>
#include <sys/statfs.h>
#include <stdbool.h>

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

static bool init_done_ind = false;

typedef struct {
    const char*     mntpoint;
    int             max_usage_percent;
} disk_use_limit_t;

static disk_use_limit_t disk_space_use_limits[] = {
   /* [mount path, max usage percent] */
   {  "/",                        90 },
   {  "/tmp",                     95 },
   {  "/home/user/MyDocs",        95 }
};

static void schedule_next_wakeup(void)
{
    /* Don't cause too frequent wakeups for checking the disks;
     * the check is now twice in an hour.
     */

    DSM_MSGTYPE_WAIT msg = DSME_MSG_INIT(DSM_MSGTYPE_WAIT);
    msg.req.mintime = 1800; /* 30 minutes */
    msg.req.maxtime = msg.req.mintime + 120;
    msg.req.pid     = 0;
    msg.data        = 0;

    broadcast_internally(&msg);
}

static disk_use_limit_t* find_use_limit_for_mount(const char* mntpoint)
{
    disk_use_limit_t* use_limit = 0;
    size_t i;
{'fraction_non_alphanumeric': 0.09440307470574105, 'fraction_numerical': 0.011530146528945472, 'mean_word_length': 2.9694947569113443, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6500298', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1346, 'n_words': 448}