Example #1
0
static int list_vconsole_keymaps(DBusConnection *bus, char **args, unsigned n) {
        char _cleanup_strv_free_ **l = NULL;
        char **i;

        keymaps = set_new(string_hash_func, string_compare_func);
        if (!keymaps)
                return log_oom();

        nftw("/usr/share/kbd/keymaps/", nftw_cb, 20, FTW_MOUNT|FTW_PHYS);
        nftw("/usr/lib/kbd/keymaps/", nftw_cb, 20, FTW_MOUNT|FTW_PHYS);
        nftw("/lib/kbd/keymaps/", nftw_cb, 20, FTW_MOUNT|FTW_PHYS);

        l = set_get_strv(keymaps);
        if (!l) {
                set_free_free(keymaps);
                return log_oom();
        }

        set_free(keymaps);

        if (strv_isempty(l)) {
                log_error("Couldn't find any console keymaps.");
                return -ENOENT;
        }

        strv_sort(l);

        pager_open_if_enabled();

        STRV_FOREACH(i, l)
                puts(*i);


        return 0;
}
static int loop_devs(const char *devtree)
{
	int error;
	int i;
	char prefix[256];

	nic_count = 0;
	error = nftw(devtree, find_nics, 20, 0);
	if (error)
		return error;

	/*
	 * Sort the nics into "natural" order.	The proc fs
	 * device-tree has them in somewhat random, or reversed order.
	 */
	qsort(niclist, nic_count, sizeof(char *), nic_cmp);

	snprintf(prefix, sizeof(prefix), "%s/%s", devtree, "aliases");
	dev_count = 0;
	error = nftw(prefix, find_initiator, 20, 0);
	if (error)
		return error;

	for (i = 0; i < dev_count; i++) {
		snprintf(prefix, sizeof(prefix), "%s%s", devtree,
			 ofwdevs[i]->prop_path);
		if (find_file(prefix) > 0) {
			error = parse_params(bootpath_val, ofwdevs[i]);
			if (!error)
				error = locate_mac(devtree, ofwdevs[i]);

		}
	}
	return error;
}
Example #3
0
void
test18A(void)
{
	int         ret;

	unlink("./tmp/byebye");

	visit=0;

#ifdef DEBUG
	fprintf(temp, "TEST: nftw with FTW_PHYS does not pass FTW_SLN\n");
#endif

	if((ret = nftw("./tmp/data/dirg", test_func18, MAX_FD, 
			FTW_PHYS)) == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}
	if (ret == 999) {
		fprintf(temp, "ERROR: nftw() passed FTW_SLN\n");
		cleanup_function();
		fail_exit();
	}

	visit=0;

#ifdef DEBUG
	fprintf(temp, "TEST: nftw without FTW_PHYS passes FTW_SLN\n");
#endif

	if((ret=nftw("./tmp/data/dirg", test_func18, MAX_FD, 0)) == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}
	
	if (visit == 1) {
		if (ret == 999) {
			/* Test is passed */
			return;
		} else { 
			fprintf(temp, "ERROR: nftw passed FTW_SLN but did"); 
			fprintf(temp, "not return value returned by fn()\n");
			cleanup_function();
			fail_exit();
		}
	} else {
		fprintf(temp, "ERROR: nftw() did not pass FTW_SLN\n");
		cleanup_function();
		fail_exit();
	}
}
int task_execute(oph_operator_struct * handle)
{
	if (!handle || !handle->operator_handle) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Null Handle\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_UNPUBLISH_NULL_OPERATOR_HANDLE);
		return OPH_ANALYTICS_OPERATOR_NULL_OPERATOR_HANDLE;
	}
	//Only master process has to continue
	if (handle->proc_rank != 0)
		return OPH_ANALYTICS_OPERATOR_SUCCESS;

	int res;
	char *datacube_path = ((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->datacube_path;
	struct stat st;

	//Check if datacube folder exists and delete it
	if (stat(datacube_path, &st)) {
		pmesg(LOG_WARNING, __FILE__, __LINE__, "Cuboid hasn't been published %s\n", datacube_path);
		logging(LOG_WARNING, __FILE__, __LINE__, ((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_UNPUBLISH_DATACUBE_NOT_PUBLISHED, datacube_path);
	} else {
		if ((res = nftw(datacube_path, oph_dir_unlink_path, 2, (FTW_DEPTH | FTW_PHYS)))) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Error while deleting files. ERRNO: %d\n", (res == -1 ? errno : res));
			logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_UNPUBLISH_operator_handle *) handle->operator_handle)->id_input_container, OPH_LOG_OPH_UNPUBLISH_DELETING_FILES_ERROR,
				(res == -1 ? errno : res));
			return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
		}
	}

	return OPH_ANALYTICS_OPERATOR_SUCCESS;
}
Example #5
0
static int builtin_posix_module_dataset_unlink (struct hio_module_t *module, const char *name, int64_t set_id) {
  struct stat statinfo;
  char *path = NULL;
  int rc;

  if (module->context->c_rank) {
    return HIO_ERR_NOT_AVAILABLE;
  }

  rc = builtin_posix_dataset_path (module, &path, name, set_id);
  if (HIO_SUCCESS != rc) {
    return rc;
  }

  if (stat (path, &statinfo)) {
    free (path);
    return hioi_err_errno (errno);
  }

  hioi_log (module->context, HIO_VERBOSE_DEBUG_LOW, "posix: unlinking existing dataset %s::%llu",
            name, set_id);

  /* use tree walk depth-first to remove all of the files for this dataset */
  rc = nftw (path, builtin_posix_unlink_cb, 32, FTW_DEPTH | FTW_PHYS);
  free (path);
  if (0 > rc) {
    hioi_err_push (hioi_err_errno (errno), &module->context->c_object, "posix: could not unlink dataset. errno: %d",
                  errno);
    return hioi_err_errno (errno);
  }

  return HIO_SUCCESS;
}
Example #6
0
int check_dir(char *path,int *number){
     
  int ret = 0;   
  struct stat pathbuf;   
  if(stat(path,&pathbuf)){
    printf("-nfwt_t:invalid dirpath:%s/n",path);
    return -1;   
  }else{   
    if(0 == S_ISDIR(pathbuf.st_mode)){   
      printf("-nfwt_t:/""%s/" "is not dirpath/n",path);
      return -1;   
    }   
  }   
  gb_filecount=0;   
  ret = nftw(path,getMetadata,FILEOPEN,FTW_PHYS);
    if(ret<0){   
    printf("-nftw:[wrong:%d]ntfw search %d files/n",ret,gb_filecount);   
    return -1;   
  }else if(ret == 0){
    printf("-nftw:[done:%d]trasvers in %s search %d files/n",ret,path,gb_filecount);
    *number = gb_filecount;
    return 0;   
  }
  else if(ret == 99){
	  return 1;
  }
}   
Example #7
0
static
void count_path(const char *path, int flags, int bs)
{
	int olderrcnt = errcnt;

	used_blocks = used_inodes = 0;

	if (inotable)
		tdestroy(inotable, inofree);

	inotable = NULL;

	nftw(path, handle_file, 50, flags);

	printf("%s", path);

	if (errcnt > olderrcnt)
		printf(" ERR");

	else if (do_hr) {
		if (do_space)
			printf(" %s", pretty_mem(used_blocks * 512 / bs));
		if (do_inode)
			printf(" %s", pretty_ino(used_inodes));
	}

	else {
		if (do_space)
			printf(" %" PRIu64, used_blocks * 512 / bs);
		if (do_inode)
			printf(" %" PRIu64, used_inodes);
	}

	printf("\n");
}
Example #8
0
int
main(int argc, char *argv[])
{
    int flags, opt;

    flags = 0;
    while ((opt = getopt(argc, argv, "dmp")) != -1) {
        switch (opt) {
        case 'd':
            flags |= FTW_DEPTH;
            break;
        case 'm':
            flags |= FTW_MOUNT;
            break;
        case 'p':
            flags |= FTW_PHYS;
            break;
        default:
            usage(argv[0], NULL);
        }
    }

    if (argc > optind + 1) {
        usage(argv[0], NULL);
    }

    if (nftw((argc > optind) ? argv[optind] : ".",
                dir_tree, 10, flags) == -1)
    {
        perror("ntfw");
        exit(EXIT_FAILURE);
    }

    exit(EXIT_SUCCESS);
}
Example #9
0
static int unlink_file(const char *filename, const struct stat *sb, int tflag, struct FTW *ftwbuf)
{
    /* we need to check here if we have a regular file. */
    if (tflag != FTW_F)
    	return 0;
#else
static int unlink_file(const char *filename, const struct stat *sb, int tflag, void *ftwbuf)
{
#endif

    /* remove the file from the file system */
    if (unlink(filename) == -1) {
        error(errno, "Could not unlink file `%s'.", filename);
    }

    return 0;
}


/*
 * The function traverses a directory structure and calls a callback
 * function for each regular file within that directory structure.
 */
#ifdef HAVE_NFTW
static int for_each_file(const Octstr *dir_s, int ignore_err,
		                 int(*cb)(const char *, const struct stat *, int, struct FTW *))
{
	 int ret;

	 ret = nftw(octstr_get_cstr(dir_s), cb, 20, FTW_PHYS);

	 return ret;
}
Example #10
0
static int get_boot_info(struct boot_context *context, char *rootdir,
			 char *subsys)
{
	char initiator_dir[FILENAMESZ];
	int rc = ENODEV;
	int nic_idx = -1, tgt_idx = -1;

	memset(&initiator_dir, 0 , FILENAMESZ);
	snprintf(initiator_dir, FILENAMESZ, "%sinitiator", rootdir);

	nic_cnt = 0;
	tgt_cnt = 0;
	if (file_exist(initiator_dir)) {
		/* Find the targets and the ethernets */
		rc = nftw(rootdir, find_sysfs_dirs, 20, 1);

		/* Find wihch target and which ethernet have
		the boot flag set. */
		rc = find_boot_flag(subsys, nic_list, nic_cnt, &nic_idx);
		if (rc)
			goto free;

		rc = find_boot_flag(subsys, target_list, tgt_cnt, &tgt_idx);
		if (rc)
			goto free;

		/* Fill in the context values */
		rc = fill_nic_context(subsys, nic_list[nic_idx], context);
		rc |= fill_tgt_context(subsys, target_list[tgt_idx], context);
		fill_initiator_context(subsys, context);
	}
free:
	deallocate_lists();
	return rc;
}
Example #11
0
void
test2A(void)
{
	int         i, ret;

	temp = stderr;
#ifdef DEBUG
	fprintf(temp, "TEST: nftw with FTW_PHYS does not follow symbolic links\n");
#endif

	visit = 0;
	if((ret = nftw("./tmp/data/dirl", test_func1, MAX_FD, FTW_PHYS)) 
			== -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}

	if(ret == 999) {
		cleanup_function();
		fail_exit();
	}

	if (visit != NO_LINK_CNT)
	{
		fprintf(temp, "ERROR: Expected %d files to be visited.  nftw() visited %d\n", NO_LINK_CNT, visit);
		cleanup_function();
		fail_exit();
	}

	for (i = 0; i < visit; i++) {
		if (dirlist[i] != (char *)NULL)
			free(dirlist[i]);
	}
}
Example #12
0
void
test11A(void)
{
	int         i, ret;

	for (i = 0; i < nbads; i++)
		if (badlist[i].i == FTW_D)
			badlist[i].i = FTW_DP;

#ifdef DEBUG
	fprintf(temp, "TEST: nftw passes FTW_DP when file is directory and subdirs already visited\n");
#endif

	if((ret = nftw("./tmp/data/dirg", test_func11, MAX_FD, FTW_DEPTH |
			FTW_PHYS)) == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}

	if (ret == 999) {
		cleanup_function();
		fail_exit();
	}
}
Example #13
0
void
test13A(void)
{
	int         i, ret;

	if(unlink("./tmp/byebye") == -1){
		perror("unlink");
		cleanup_function();
		fail_exit();	
	}

	for (i = 0; i < nbads; i++)
		if (badlist[i].i == FTW_SL)
			badlist[i].i = FTW_SLN;

#ifdef DEBUG
	fprintf(temp, "TEST: nftw with FTW_PHYS passes FTW_SLN when file");
	fprintf(temp, " is symlink pointing \n to non-existent file\n");
#endif

	if((ret = nftw("./tmp/data/dirg", test_func13, MAX_FD,
			FTW_PHYS)) == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}

	if (ret == 999) {
		cleanup_function();
		fail_exit();
	}
}
Example #14
0
void
test6A(void)
{
	char 	path[PATH_MAX + NAME_MAX];
	int 	ret_val;

	if(getcwd(path, sizeof(path)) == NULL) {
		perror("getcwd");
		cleanup_function();
		fail_exit();
	}
	(void)strcat(path, "/tmp/data/dirh");

#ifdef DEBUG
	fprintf(temp, "TEST: nftw with FTW_CHDIR changes to each dir before reporting files in it\n");
#endif

	ret_val = nftw(path, test_func5, MAX_FD, FTW_CHDIR);
	if (ret_val == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}
	if ((ret_val == 998) || (ret_val == 999)) {
		cleanup_function();
		fail_exit();
	}
}
Example #15
0
void
test5A(void)
{
	char 	path[] = "./tmp/data/d777";
	int	ret_val;

#ifdef DEBUG
	fprintf(temp, "TEST: Verify traversal without FTW_DEPTH set\n");
#endif

	visit = 0;
	if((ret_val = nftw(path, test_func4, MAX_FD, 0)) == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}
	if(ret_val != 999) {
		fprintf(temp, "ERROR: %s never visited\n", path);
		cleanup_function();
		fail_exit();
	}

	if (visit != 1)
	{
		fprintf(temp, "ERROR: Visited contents before directory\n");
		cleanup_function();
		fail_exit();
	}
}
Example #16
0
void
test3A(void)
{
	int         ret;

#ifdef DEBUG
	fprintf(temp, "TEST: nftw without FTW_PHYS follows symbolic links\n");
#endif

	visit = 0;

	if((ret = nftw("./tmp/data/dirl", test_func3, MAX_FD, 0)) == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}
	if(ret == 999) {
		cleanup_function();
		fail_exit();
	}

	if (visit != LINK_CNT-1)
	{
		fprintf(temp, "ERROR: Expected %d files to be visited.  nftw() visited %d\n", LINK_CNT-1, visit);
		cleanup_function(); 
		fail_exit();
	}
}
Example #17
0
void shapefiles_list(struct mg_connection *conn, const struct mg_request_info *ri, void *data)
{
  char * formatc = mg_get_var(conn, "format");
  int json = 0;
  if (formatc != NULL && strcmp(formatc, "json") == 0)
    json = 1;
  free(formatc);
  
  if (json)
  {
    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/javascript\r\nConnection: close\r\n\r\n");
    mg_printf(conn, "[");
  }
  else
  {
    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n");
    mg_printf(conn, "<table>");
  }
  
  general_count = 0;
  dconn = conn; // dconn used in display_info callback
  int flags = FTW_DEPTH | FTW_PHYS;
  if (nftw(data_path, display_info, 20, flags) == -1) mg_printf(conn, "nftw FAILED\n");
  dconn = NULL;
  
  if (json)
    mg_printf(conn, "\n]\n");
  else
    mg_printf(conn, "</table>");
}
Example #18
0
static int list_vconsole_keymaps(sd_bus *bus, char **args, unsigned n) {
        _cleanup_strv_free_ char **l = NULL;
        const char *dir;

        keymaps = set_new(string_hash_func, string_compare_func);
        if (!keymaps)
                return log_oom();

        NULSTR_FOREACH(dir, KBD_KEYMAP_DIRS)
                nftw(dir, nftw_cb, 20, FTW_MOUNT|FTW_PHYS);

        l = set_get_strv(keymaps);
        if (!l) {
                set_free_free(keymaps);
                return log_oom();
        }

        set_free(keymaps);

        if (strv_isempty(l)) {
                log_error("Couldn't find any console keymaps.");
                return -ENOENT;
        }

        strv_sort(l);

        pager_open_if_enabled();

        strv_print(l);

        return 0;
}
Example #19
0
void
test19A(void)
{
	int	ret_val;

#ifdef DEBUG
	fprintf(temp, "TEST: Can not traverse directory with no read permission\n");
#endif

	visit = 0;

	ret_val = nftw("./tmp/data/d333", test_func19, MAX_FD, 0);
	if (ret_val == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}

	if (ret_val == 999) {
		cleanup_function();
		fail_exit();
	}

#ifdef DEBUG
	fprintf(temp, "TEST: fn only be called once\n");
#endif

	if (visit != 1)
	{
		fprintf(temp, "ERROR: %s","Directory without read permission allows traversing\n");
		fprintf(temp, "       Visited %d files\n", visit);
		cleanup_function();
		fail_exit();
	}
}
Example #20
0
/**
 * @function parcFile_Delete
 * @abstract Deletes the file or directory
 * @discussion
 *
 * @param <#param1#>
 * @return true if everything deleted, false otherwise
 */
bool
parcFile_Delete(const PARCFile *file)
{
    char *string = parcPathName_ToString(file->pathName);

    // only allow under tmp
    assertTrue(strncmp(string, "/tmp/", 5) == 0,
               "Path must begin with /tmp/: %s", string);
    // dont allow ".."
    assertNull(strstr(string, ".."), "Path cannot have .. in it: %s", string);

    bool result = false;
    if (parcFile_IsDirectory(file)) {
        // depth first, dont't follow symlinks, do not cross mount points.
        int flags = FTW_DEPTH | FTW_PHYS | FTW_MOUNT;

        // maximum 20 fds open at a time
        int maximumFileDescriptors = 20;

        int failure = nftw(string, _deleteNode, maximumFileDescriptors, flags);
        assertFalse(failure, "Error on recursive delete: (%d) %s", errno, strerror(errno));

        result = failure == false;
    } else {
        result = (unlink(string) == 0);
    }

    parcMemory_Deallocate((void **) &string);

    return result;
}
Example #21
0
int
main (int argc, char *argv[])
{
	int flags, opt;

	flags = 0;
	while ((opt = getopt (argc, argv, "dmp")) != -1) {
		switch (opt) {
			case 'd': flags |= FTW_DEPTH; break;
			case 'm': flags |= FTW_MOUNT; break;
			case 'p': flags |= FTW_PHYS;  break;
			default:
				usage (argv[0]);
		}
	}

	if (argc > optind + 1) {
		printf ("required cmdline arg missing\n");
		usage (argv[0]);
		return 3;
	}

	if (nftw ((argc > optind)? argv[optind] : ".", dir_tree, 10, flags) == -1) {
		perror ("nftw()");
		return 1;
	}

	return 0;
}
Example #22
0
void
test23A(void)
{
	int 	ret;

	visit=0;

#ifdef DEBUG
	fprintf(temp, "TEST: The function nftw should return with value set by fn\n");
#endif

	if((ret=nftw("./tmp/data/dirh", test_func23, MAX_FD, FTW_PHYS)) == -1) {
		perror("nftw");
		cleanup_function();
		fail_exit();
	}

	if (ret != 999) {
		fprintf(temp, "ERROR: nftw did not return value returned by fn()\n");
		cleanup_function();
		fail_exit();
	}
	if(visit != 4){
		fprintf(temp, "ERROR: nftw() did not return immediately on non-zero fn() return\n");
		cleanup_function();
		fail_exit();
	}
}
bool FileUtils::removeDirectory(const std::string& path)
{
    if (path.size() > 0 && path[path.size() - 1] != '/')
    {
        CCLOGERROR("Fail to remove directory, path must termniate with '/': %s", path.c_str());
        return false;
    }
    
    // Remove downloaded files
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
	std::string command = "cmd /c rd /s /q ";
	// Path may include space.
	command += "\"" + path + "\"";

	if (WinExec(command.c_str(), SW_HIDE) > 31)
		return true;
	else
		return false;
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    if (nftw(path.c_str(),unlink_cb, 64, FTW_DEPTH | FTW_PHYS))
        return false;
    else
        return true;
#else
    std::string command = "rm -r ";
    // Path may include space.
    command += "\"" + path + "\"";
    if (system(command.c_str()) >= 0)
        return true;
    else
        return false;
#endif
}
Example #24
0
int
main(int argc, char *argv[])
{
        int  ret = 0;
        int  i = 0;

        ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
        if (ret != 0) {
                fprintf (stderr, "parsing arguments failed\n");
                return -2;
        }

         /* Use FTW_ACTIONRETVAL to take decision on what to do depending upon */
         /* the return value of the callback function */
         /* (process_entry in this case) */
        ret = nftw (arequal_config.test_directory, process_entry, 30,
                    FTW_ACTIONRETVAL|FTW_PHYS|FTW_MOUNT);
        if (ret != 0) {
                fprintf (stderr, "ftw (%s) returned %d (%s), terminating\n",
                         argv[1], ret, strerror (errno));
                return 1;
        }

        display_stats (stdout);

        if (arequal_config.ignored_directory) {
                for (i = 0; i < arequal_config.directories_ignored; i++) {
                        if (arequal_config.ignored_directory[i])
                            free (arequal_config.ignored_directory[i]);
                }
                free (arequal_config.ignored_directory);
        }

        return 0;
}
Example #25
0
int
main(int argc, char *argv[])
{
    int numFiles;       /* Total number of files */

    if (argc != 2 || strcmp(argv[1], "--help") == 0)
        usageErr("%s dir-path\n", argv[0]);

    /* Traverse directory tree counting files; don't follow symbolic links */

    if (nftw(argv[1], &countFile, 20, FTW_PHYS) == -1) {
        perror("nftw");
        exit(EXIT_FAILURE);
    }

    numFiles = numReg + numDir + numSymLk + numSocket +
                numFifo + numChar + numBlock;

    if (numFiles == 0) {
        printf("No files found\n");
    } else {
        printf("Total files:      %6d\n", numFiles);
        printStats("Regular:", numReg, numFiles);
        printStats("Directory:", numDir, numFiles);
        printStats("Char device:", numChar, numFiles);
        printStats("Block device:", numBlock, numFiles);
        printStats("Symbolic link:", numSymLk, numFiles);
        printStats("FIFO:", numFifo, numFiles);
        printStats("Socket:", numSocket, numFiles);
    }
    exit(EXIT_SUCCESS);
}
Example #26
0
int
main(int argc, char **args) {
    param_t     param;
    param.path = NULL;
    param.touch = false;

    if (!parse_params(argc, args, &param)) {
        exit(1);
    }

    if (!isdir(param.path)) {
        inspect(param.path, param.touch);
    } else if (nftw(param.path, traverse, 10, 0) == -1) {
        fprintf(stderr, "error on walking through %s\n", param.path);
        exit(1);
    }
    fprintf(stderr,
            "total:\n"
            "\t page count: %lu, cached: %lu\n"
            "\t file size: %lu(%luK), cached: %lu(%luK)\n",
            pages_total, pages_incore_total,
            fsize_total, fsize_total/1024, bytes_incore_total, bytes_incore_total/1024);

    return 0;
}
Example #27
0
int main(int argc, char *argv[])
{
	int result = 0;
    int loop_cnt = 20;
    int ii=0;

    if(get_option(argc, argv) == 0)
	{
		Usage();
	}
	log_prt(gs_logname,"File Watcher Start");
    log_prt(gs_logname,"Watch Path: %s, File: %s, Delay(sec): %d",
			          gs_watch_dname, 
					  gs_watch_fname,
					  DELAY_SEC);
    while(ii<loop_cnt)
	{
		gi_detect_cnt = 0;
		result = nftw(gs_watch_dname,search_directory, USE_FDS, FTW_PHYS);
	
		if(result !=0)
		{
			log_prt(gs_logname,"error!!! %d", result);
		    return result;
		}
		log_prt(gs_logname,"phase%d : %d file/directory detected.",ii,gi_detect_cnt);
		sleep(DELAY_SEC);
		ii++;
	}
	log_prt(gs_logname,"File Watcher Stop");
	return 0;
}
Example #28
0
int apply_cipso(const char *path)
{
	struct stat sbuf;
	int fd;
	int ret;

	if (stat(path, &sbuf)) {
		fprintf(stderr, "stat() failed for '%s' : %s\n", path, strerror(errno));
		return -1;
	}

	if (S_ISDIR(sbuf.st_mode))
		return nftw(path, apply_cipso_cb, 1, FTW_PHYS|FTW_ACTIONRETVAL);

	fd = open(path, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "open() failed for '%s' : %s\n", path, strerror(errno));
		return -1;
	}

	ret = apply_cipso_file(fd);
	if (ret)
		fprintf(stderr, "Applying rules failed for '%s'.\n",  path);
	close(fd);
	return ret;
}
Example #29
0
File: fs.c Project: sothis/cstd
int fs_delete_deep(const char* directory)
{
	const char* p = directory;
	int flags = 0;
	int max_open_descriptors = 0;

/*
 * FTW_DEPTH	pass content of a directory to the callback before the directory
 * 		itself, useful for recursively deleting a directory, since
 * 		directories must be emtpy before we can remove them
 * FTW_MOUNT	stay within the same filesystem
 * FTW_CHDIR	chdir(dirname(fpath)) before calling the callback
 * FTW_PHYS	don't follow symbolic links */
	flags |= FTW_DEPTH;
	flags |= FTW_PHYS;
	flags |= FTW_MOUNT;

/* glibc nftw(): if max_open_descriptors is less than 1, it is set
 * internally to 1 without further notice. Lower values may slow down code,
 * higher ones may hit max open filedescriptor limit, resulting in nftw()
 * to fail. */
	max_open_descriptors = 1;

/* NOTE: glibc nftw() recurses internally and is therefore bound to
 * available stack memory. Returns -1 on error, 0 on success or any
 * non-zero value returned by the callback in case of the callback
 * failing. */
	return nftw(p, &_nftw_remove, max_open_descriptors, flags);
}
Example #30
0
int
main (int argc, char *argv[])
{
  struct args *args = parse_args (argc, argv);

  validate_args (args);

  JBDATA *data =
    classify_components (args->num_input_files, args->input_files,
			 args->thresh, args->weight);

  /* Render output of leptonica's classifier, if requested */
  if (args->debug_render_pages)
    {
      int i;
      PIXA *pa = jbDataRender (data, 0);
      for (i = 0; i < pa->n; i++)
	{
	  PIX *pix = pa->pix[i];
	  char filename[512];
	  sprintf (filename, "rendered_%05d.png", i);
	  pixWrite (filename, pix, IFF_PNG);
	}
    }

  struct mapping *maps = NULL;
  int num_fonts = register_mappings (data, &maps);

  char *tmpdirname = NULL;

  if (!args->debug_skip_font_gen)
    {
      tmpdirname = generate_fonts (data, maps, num_fonts, args->debug_tmpdir);
    }

  generate_pdf (args->outname, tmpdirname, num_fonts, args->num_input_files,
		data, maps, args->debug_draw_borders);

  /* clean up tmpdir */

  if (!args->debug_no_clean_tmpdir)
    {
      /* This may not be Windows compatible */
      if (nftw (tmpdirname, delete_file, 64, FTW_DEPTH | FTW_PHYS) == -1)
	{
	  error_quit ("Failed to clean up tmpdir.");
	}
    }

  if (args->debug_tmpdir == NULL)
    {
      free (tmpdirname);
    }

  free (maps);
  jbDataDestroy (&data);
  free (args->input_files);
  free (args);
  return 0;
}