ext2fs_mark_super_dirty(fs);
fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
inode.i_links_count = 0;
- inode.i_dtime = time(0);
+ inode.i_dtime = time(NULL);
if ((retval = ext2fs_write_inode(fs, ino, &inode)) != 0)
goto err_out;
*/
if (!LINUX_S_ISDIR(inode->i_mode)) {
if (fix_problem(ctx, PR_1_ROOT_NO_DIR, &pctx)) {
- inode->i_dtime = time(0);
+ inode->i_dtime = time(NULL);
inode->i_links_count = 0;
ext2fs_icount_store(ctx->inode_link_info,
ino, 0);
inode->i_dtime < ctx->fs->super->s_inodes_count) {
if (fix_problem(ctx, PR_1_LOW_DTIME, &pctx)) {
inode->i_dtime = inode->i_links_count ?
- 0 : time(0);
+ 0 : time(NULL);
e2fsck_write_inode(ctx, ino, inode,
"pass1");
}
if (!inode->i_dtime && inode->i_mode) {
if (fix_problem(ctx,
PR_1_ZERO_DTIME, &pctx)) {
- inode->i_dtime = time(0);
+ inode->i_dtime = time(NULL);
e2fsck_write_inode(ctx, ino, inode,
"pass1");
}
}
e2fsck_read_inode(ctx, EXT2_RESIZE_INO, inode,
"recreate inode");
- inode->i_mtime = time(0);
+ inode->i_mtime = time(NULL);
e2fsck_write_inode(ctx, EXT2_RESIZE_INO, inode,
"recreate inode");
fs->block_map = save_bmap;
if (pb.clear) {
inode->i_links_count = 0;
ext2fs_icount_store(ctx->inode_link_info, ino, 0);
- inode->i_dtime = time(0);
+ inode->i_dtime = time(NULL);
dirty_inode++;
ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino);
ext2fs_unmark_inode_bitmap(ctx->inode_reg_map, ino);
if (fix_problem(ctx, PR_1_ZERO_LENGTH_DIR, pctx)) {
inode->i_links_count = 0;
ext2fs_icount_store(ctx->inode_link_info, ino, 0);
- inode->i_dtime = time(0);
+ inode->i_dtime = time(NULL);
dirty_inode++;
ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino);
ext2fs_unmark_inode_bitmap(ctx->inode_reg_map, ino);
/* Inode may have changed by block_iterate, so reread it */
e2fsck_read_inode(ctx, ino, &inode, "delete_file");
inode.i_links_count = 0;
- inode.i_dtime = time(0);
+ inode.i_dtime = time(NULL);
if (inode.i_file_acl &&
(fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR)) {
count = 1;
ext2fs_icount_store(ctx->inode_link_info, ino, 0);
e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode");
inode.i_links_count = 0;
- inode.i_dtime = time(0);
+ inode.i_dtime = time(NULL);
e2fsck_write_inode(ctx, ino, &inode, "deallocate_inode");
clear_problem_context(&pctx);
pctx.ino = ino;
memset(&inode, 0, sizeof(inode));
inode.i_mode = 040755;
inode.i_size = fs->blocksize;
- inode.i_atime = inode.i_ctime = inode.i_mtime = time(0);
+ inode.i_atime = inode.i_ctime = inode.i_mtime = time(NULL);
inode.i_links_count = 2;
inode.i_blocks = fs->blocksize / 512;
inode.i_block[0] = blk;
memset(&inode, 0, sizeof(inode));
inode.i_mode = 040700;
inode.i_size = fs->blocksize;
- inode.i_atime = inode.i_ctime = inode.i_mtime = time(0);
+ inode.i_atime = inode.i_ctime = inode.i_mtime = time(NULL);
inode.i_links_count = 2;
inode.i_blocks = fs->blocksize / 512;
inode.i_block[0] = blk;
if (fix_problem(ctx, PR_4_ZERO_LEN_INODE, &pctx)) {
ext2fs_icount_store(ctx->inode_link_info, i, 0);
inode.i_links_count = 0;
- inode.i_dtime = time(0);
+ inode.i_dtime = time(NULL);
e2fsck_write_inode(ctx, i, &inode,
"disconnect_inode");
/*
if (!inode.i_links_count) {
ext2fs_inode_alloc_stats2(fs, ino, -1,
LINUX_S_ISDIR(inode.i_mode));
- inode.i_dtime = time(0);
+ inode.i_dtime = time(NULL);
} else {
inode.i_dtime = 0;
}
unsigned int reason_arg = 0;
long next_check;
int batt = is_on_batt();
- time_t now = time(0);
+ time_t now = time(NULL);
if ((ctx->options & E2F_OPT_FORCE) || cflag || swapfs)
return;
return 1;
}
+
static int read_mac(const char *line, void *arg)
{
return NULL == ether_aton_r(line, (struct ether_addr *)arg);
if (leases[i].yiaddr == 0)
continue;
- /* screw with the time in the struct, for easier writing */
+ /* Screw with the time in the struct, for easier writing */
tmp_time = leases[i].expires;
leases[i].expires -= curr;
* we lose some leases on restart. Oh well. */
full_write(fd, &leases[i], sizeof(leases[i]));
- /* then restore it when done */
+ /* Then restore it when done */
leases[i].expires = tmp_time;
}
close(fd);
void FAST_FUNC read_leases(const char *file)
{
- int fd;
- unsigned i;
struct dhcpOfferedAddr lease;
- int64_t written_at, curr;
+ int64_t written_at, time_passed;
+ int fd;
+ USE_UDHCP_DEBUG(unsigned i;)
fd = open_or_warn(file, O_RDONLY);
if (fd < 0)
if (full_read(fd, &written_at, sizeof(written_at)) != sizeof(written_at))
goto ret;
written_at = ntoh64(written_at);
- curr = time(NULL);
- if (curr < written_at)
- written_at = curr; /* lease file from future! :) */
-
- i = 0;
- while (i < server_config.max_leases
- && full_read(fd, &lease, sizeof(lease)) == sizeof(lease)
- ) {
+
+ time_passed = time(NULL) - written_at;
+ /* Strange written_at, or lease file from old version of udhcpd
+ * which had no "written_at" field? */
+ if ((uint64_t)time_passed > 12 * 60 * 60)
+ goto ret;
+
+ USE_UDHCP_DEBUG(i = 0;)
+ while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
/* ADDME: what if it matches some static lease? */
uint32_t y = ntohl(lease.yiaddr);
if (y >= server_config.start_ip && y <= server_config.end_ip) {
- int64_t expires = ntohl(lease.expires) + written_at - curr;
+ signed_leasetime_t expires = ntohl(lease.expires) - (signed_leasetime_t)time_passed;
if (expires <= 0)
continue;
/* NB: add_lease takes "relative time", IOW,
bb_error_msg("too many leases while loading %s", file);
break;
}
- i++;
+ USE_UDHCP_DEBUG(i++;)
}
}
DEBUG("Read %d leases", i);