mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bryan Wilkerson <bryanwilkerson@yahoo.com>
To: rlove@rlove.org, linux-kernel@vger.kernel.org
Subject: inotify 0.23 errno 28 (ENOSPC)
Date: Tue, 24 May 2005 09:33:09 -0700 (PDT)	[thread overview]
Message-ID: <20050524163309.74541.qmail@web53401.mail.yahoo.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 530 bytes --]

Hi,  

I read an earlier thread where you said that it was
possible to manually walk a tree and add all
directories to an inotify watch descriptor.  I wrote
some code to do this and the ioctl call fails on my
machine after adding 9,977 directories with ENOSPC.  

I've attached a small repro case.  Just point it at
the base of a large dir tree (e.g. inotify-r ~) to
use. 

My kernel is 2.6.12-rc3 with the inotify 0.23 patch. 
Let me know if you need more information.  

Please cc my e-mail addr in all replies.

Thanks,

-bryan

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 1249210018-inotify-r.c --]
[-- Type: text/x-csrc; name="inotify-r.c", Size: 2139 bytes --]


/*  this just demonstrates adding a large number of directories
    to inotify
*/

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <dirent.h>


#include "inotify.h"

int dirsWatched = 0;
int fd;

static void fatal_error(char *fmt, ...) __attribute__((noreturn));
static void fatal_error(char *fmt, ...) 
{
	fprintf(stderr, "\n\nFATAL ERROR:%d:%s: ", errno, strerror(errno));
	va_list ap;
	va_start(ap, fmt);
	vfprintf(stderr, fmt, ap);
	va_end(ap);
	fprintf(stderr, "\n\nDirs successfully added to watch: %d\n", dirsWatched);
	exit(errno);
}


int add_dir(const char *path)
{
	struct inotify_watch_request iwr;
	iwr.mask = 0xffffffff;
	iwr.fd = open(path, O_RDONLY);
	if( iwr.fd <= 0 )
		fatal_error("Unable to open directory %s for reading", path);
	
	int wd = ioctl(fd, INOTIFY_WATCH, &iwr);
	close(iwr.fd);
	
	if (wd < 0) 
		fatal_error("Unable to create inotify watch on object: %s", path);
	else
		dirsWatched++;

	struct dirent **namelist;
	int i, n;
	struct stat statstruct;
	
	n = scandir(path, &namelist, 0, alphasort);
	if( n < 0 )
		fatal_error("scandir failed");

	for( i = 0; i < n; i++ )
	{
		char fileName[4096];
		int len = sprintf(fileName, "%s/%s", path, namelist[i]->d_name);
		
		if( !(strcmp(&fileName[len-2], "/.")==0 || strcmp(&fileName[len-3], "/..")==0) )
		{
			// most likely cause of not being able to stat is 
			// permissions which we quietly ignore and assume 
			// to be benign
			if( stat(fileName, &statstruct) == 0 )
			{
				if( S_ISDIR(statstruct.st_mode) )
				{
					// recursive add
					add_dir(fileName);
				}
			}
		}
		free(namelist[i]);
	}
	free(namelist);
}

int main(int argc, char **argv)
{
	if( argc < 2 || strcmp(argv[1], "--help") == 0 )
	{
		printf( "inotify-r - tests adding a directory recusively to an inotify descriptor\n"
			"\n"
			"Usage: inotify-r <path>\n");
		exit(1);
	}
	fd = open("/dev/inotify", O_RDONLY);
	if (fd < 0) 
		fatal_error("Unable to open inotify device.");

	add_dir(argv[1]);
	return 0;
}


             reply	other threads:[~2005-05-24 16:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-24 16:33 Bryan Wilkerson [this message]
2005-05-24 16:35 ` Robert Love
2005-05-24 16:52   ` Arjan van de Ven
2005-05-24 16:55     ` Robert Love

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050524163309.74541.qmail@web53401.mail.yahoo.com \
    --to=bryanwilkerson@yahoo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rlove@rlove.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®