|
C-Menu 0.2.9
A User Interface Toolkit
|
list files based on matching criteria More...
#include "lf.h"#include <argp.h>#include <dirent.h>#include <errno.h>#include <fcntl.h>#include <grp.h>#include <inttypes.h>#include <linux/limits.h>#include <locale.h>#include <pthread.h>#include <pwd.h>#include <regex.h>#include <stdarg.h>#include <stdatomic.h>#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/mman.h>#include <sys/resource.h>#include <sys/stat.h>#include <sys/syscall.h>#include <sys/sysinfo.h>#include <sys/types.h>#include <time.h>#include <unistd.h>#include <valgrind/helgrind.h>Go to the source code of this file.
Macros | |
| #define | _GNU_SOURCE |
| #define | WRITE_STR(p, str) |
Functions | |
| unsigned long | a_to_ul (const char *str) |
| Converts a string to an unsigned long long integer, with support for suffixes K, M, and G for kilobytes, megabytes, and gigabytes respectively. | |
| int | a_toi (char *s, bool *a_toi_error) |
| a safer alternative to atoi() for converting ASCII strings to integers. | |
| bool | append_output_buffer (GlobalContext *__G, OutputBuffer *output_buffer, const char *path, size_t path_len, bool append_slash) |
| Append a path to the output_buffer, flushing if necessary. | |
| void | build_path (ThreadLocal *__tl, char *file_name) |
| Build the full path for a file or directory entry. | |
| void | coders_timestamp (LogCtx *log_ctx) |
| Generate a timestamp string for logging, including both current time and interval since last log entry. | |
| void | debug_out (GlobalContext *__G, int argc, char **argv) |
| Display everything and the kitchen sink on stderr. | |
| bool | expand_tilde (char *str, uint path_maxlen) |
| Replaces "~/" in string with the user's home directory. | |
| void * | finder (GlobalContext *__G, ThreadLocal *__tl) |
| Traverse a directory and process its entries. | |
| void | flush_output_buffer (GlobalContext *__G, OutputBuffer *output_buffer) |
| Flush the output_buffer to stdout in a thread-safe manner. | |
| char * | format_local_timestamp (time_t t, char *buf, size_t n) |
| Formats a time_t as an ISO 8601 string in local time. | |
| bool | global_arena_create (GlobalContext *__G) |
| Create a queue arena for managing directory traversal tasks. | |
| void | global_arena_destroy (GlobalContext *__G) |
| Destroy the queue arena and free associated resources. | |
| bool | init_lf (GlobalContext *__G, int argc, char **argv) |
| Initialize the file search process. | |
| void | initialize_thread_timer (GlobalContext *__G, LogCtx *log_ctx) |
| Initialize the timer for a thread, capturing the start time and setting up interval tracking. | |
| void | initialize_timer (GlobalContext *__G, LogCtx *log_ctx) |
| Initialize the timer for logging, capturing the start time and setting up interval tracking. | |
| bool | is_directory (const char *path) |
| Checks if the given path is a directory. | |
| bool | is_dirsys (const char *) |
| bool | is_hidden (const char *) |
| bool | is_symlink_to_dir (const char *path) |
| Checks if the given path is a symbolic link to a directory. | |
| bool | is_valid_regex (const char *pattern) |
| Checks if the given regular expression pattern is valid. | |
| void | iso8601_timestamp (GlobalContext *__G, LogCtx *log_ctx) |
| Generate an ISO 8601 timestamp string. | |
| void | log_open (GlobalContext *__G, LogCtx *log_ctx, size_t thread_id) |
| Open the log file for writing. | |
| void | log_write (const ll_e level, GlobalContext *__G, LogCtx *log_ctx, const char *file, const char *func, const int line, const char *fmt,...) |
| Write a log message to the log file and/or display. | |
| int | main (int argc, char **argv) |
| bool | mpmc_bulk_enqueue (GlobalContext *__G, ThreadLocal *__tl) |
| Bulk enqueue multiple nodes into the MPMC queue. | |
| bool | mpmc_dequeue (GlobalContext *__G, uint_fast32_t *dequeue_pos) |
| Dequeue a node from the MPMC queue. | |
| bool | mpmc_enqueue (GlobalContext *__G, QueueNode *node, const char *path, size_t len) |
| bool | parse_local_timestamp (const char *s, time_t *out) |
| Parses an ISO 8601 timestamp string in local time and converts it to time_t. | |
| int | print_file (GlobalContext *__G, ThreadLocal *__tl) |
| Print the path of a file or directory entry based on filtering criteria. | |
| void | push_root_node (GlobalContext *__G, dev_t dev, ino_t ino) |
| Push the root directory node into the queue arena. | |
| char * | rep_substring (const char *org_s, const char *tgt_s, const char *rep_s) |
| Replace all occurrences of "tgt_s" in "org_s" with "rep_s". | |
| int | sort_lf_output (GlobalContext *__G, int argc, char **argv) |
| Sort the output of the lf command using the system's sort utility. | |
| size_t | ssnprintf (char *buf, size_t buf_size, const char *format,...) |
| A safer snprintf that ensures null-termination and handles edge cases. | |
| size_t | strnz__cat (char *d, const char *s, size_t max_len) |
| safer alternative to strncat | |
| size_t | strnz__cpy (char *d, const char *s, size_t max_len) |
| safer alternative to strncpy | |
| size_t | vssnprintf (char *buf, size_t buf_size, const char *format, va_list args) |
| A safer vsnprintf that ensures null-termination and handles edge cases. | |
| void * | worker (void *arg) |
| Worker thread function for processing directory nodes. | |
Variables | |
| const char * | argp_program_bug_address = "billxwaller@gmail.com" |
| const char * | argp_program_version = LF_VERSION |
| char * | debug_p |
| const char | doc [] |
| char | em0 [MAXLEN] |
| char | em1 [MAXLEN] |
| char | em2 [MAXLEN] |
| char | em3 [MAXLEN] |
| char | em4 [MAXLEN] |
| char * | exec |
| char * | file_types_p |
| unsigned char const | lf_type_mask [15] |
| int | lfargc |
| char * | lfargs [3] |
| log_level | ll_t [] |
| char * | log_p |
| const char * | log_s [] = {LOG_LEVEL_LIST(AS_STRINGS)} |
| MemMetrics | mm |
| char * | perms_p |
| int | pipe_in |
| int | pipe_out |
| const char * | sgr_c [] |
| const char * | sgr_s [] = {ANSI_COLOR_LIST(AS_STRINGS)} |
| int | stderr_fd |
| int | stdin_fd |
| int | stdout_fd |
| TerminationStatus | termination_status |
| struct tm | tm_info |
| const char * | tss_s [] = {TIMESTAMP_STYLE(AS_STRINGS)} |
| int | tty_fd |
| #define WRITE_STR | ( | p, | |
| str ) |
| bool append_output_buffer | ( | GlobalContext * | __G, |
| OutputBuffer * | output_buffer, | ||
| const char * | path, | ||
| size_t | path_len, | ||
| bool | append_slash ) |
Append a path to the output_buffer, flushing if necessary.
| lf | A pointer to the GlobalContext struct containing the output mutex. |
| output_buffer | A pointer to the OutputBuffer struct where the path will be appended. |
| path | The path string to append to the output_buffer. |
| path_len | The length of the path string. |
| append_slash | A boolean indicating whether to append a slash after the path. |
This function appends a given path to the output_buffer. If the combined length of the current buffer and the new path exceeds the buffer's capacity, it flushes the buffer to stdout before appending. It also handles appending a slash if specified. The function ensures thread-safe access to stdout using a mutex during flushing.
Definition at line 971 of file lf.c.
References OutputBuffer::data, flush_output_buffer(), OutputBuffer::len, and GlobalContext::output_mutex.
Referenced by print_file().
| void build_path | ( | ThreadLocal * | __tl, |
| char * | file_name ) |
Build the full path for a file or directory entry.
| tl | A pointer to the ThreadLocal struct containing the current directory context. |
| file_name | The name of the file or directory entry to append to the path. |
This function constructs the full path for a given file or directory entry by appending its name to the parent path stored in the ThreadLocal context. It updates the path length and ensures that the resulting path is null-terminated. This function is used during directory traversal to prepare paths for processing and output.
Definition at line 1583 of file lf.c.
References ThreadLocal::d_name, ThreadLocal::d_name_len, ThreadLocal::parent_path_len, ThreadLocal::path, and ThreadLocal::path_len.
Referenced by finder().
| void coders_timestamp | ( | LogCtx * | log_ctx | ) |
Generate a timestamp string for logging, including both current time and interval since last log entry.
coders_timestamp
| log_ctx | A pointer to the LogCtx struct containing timing information. |
This function calculates the current time since the start of the program and the interval since the last log entry. It formats these values into a timestamp string stored in log_ctx->time_buf. The timestamp includes seconds, milliseconds, microseconds, and nanoseconds, with color-coded formatting for better visibility in logs. If you are wondering about the seemingly complex output section, it is designed to mitigate the classical and unavoidable observation error.
Definition at line 1847 of file lf.c.
References LogCtx::p_int_nsec, LogCtx::p_int_sec, sgr_c, LogCtx::start_nsec, LogCtx::start_sec, and LogCtx::time_buf.
Referenced by log_write().
| void debug_out | ( | GlobalContext * | __G, |
| int | argc, | ||
| char ** | argv ) |
Display everything and the kitchen sink on stderr.
| lf | A pointer to the GlobalContext struct containing the debug settings. |
| argc | The number of command-line arguments. |
| argv | An array of command-line argument strings. |
This function outputs debug information to stderr if debugging is enabled in the GlobalContext. It includes a timestamp, user information, IP addresses, command-line arguments, and various configuration settings. The output is formatted for readability and includes details about file types, permissions, regex patterns, and other relevant settings.
Definition at line 582 of file lf.c.
References GlobalContext::after, GlobalContext::base_path, GlobalContext::before, log_level::bits, GlobalContext::disp_level_mask, GlobalContext::ere, GlobalContext::file_size_min, GlobalContext::flags, GlobalContext::follow_links, format_local_timestamp(), GlobalContext::ignore_case, GlobalContext::include_hidden, GlobalContext::include_perms, GlobalContext::include_types, LF_BLK, LF_CHR, LF_DIR, LF_EXC_REGEX, LF_FIFO, LF_IRUSR, LF_ISGID, LF_ISUID, LF_IWUSR, LF_IXUSR, LF_LNK, LF_REG, LF_REGEX, LF_SOCK, LF_UNKNOWN, LF_USER, ll_t, GlobalContext::max_depth, GlobalContext::nthreads, GlobalContext::re, GlobalContext::sort, GlobalContext::sort_reverse, ssnprintf(), GlobalContext::suppress_types, GlobalContext::user_id, and GlobalContext::user_name.
Referenced by init_lf().
| void * finder | ( | GlobalContext * | __G, |
| ThreadLocal * | __tl ) |
Traverse a directory and process its entries.
| lf | A pointer to the GlobalContext struct containing the search settings. |
| tl | A pointer to the ThreadLocal struct containing the current directory context. |
This function opens a directory specified in the ThreadLocal context, reads its entries, and processes each entry based on the provided settings in the GlobalContext. It handles filtering of directory entries, retrieves advanced metadata if necessary, and manages the traversal of subdirectories. The function also logs errors and flushes output buffers as needed. It is designed to be called by worker threads for concurrent processing of directories.
Definition at line 1335 of file lf.c.
References GlobalContext::active_tasks, log_level::bits, build_path(), QueueNode::child_dirs_remaining, ThreadLocal::child_dirs_remaining, ThreadLocal::cum_path_offset, linux_dirent64::d_name, ThreadLocal::d_name, ThreadLocal::d_name_len, linux_dirent64::d_reclen, linux_dirent64::d_type, QueueNode::depth, ThreadLocal::depth, QueueNode::dev, ThreadLocal::dir_buf, GlobalContext::disp_level_mask, ThreadLocal::effective_type, GlobalContext::error_count, GlobalContext::f_logging, GlobalContext::file_level_mask, flush_output_buffer(), GlobalContext::follow_links, GlobalContext::hidden_only, GlobalContext::include_hidden, QueueNode::ino, ll_t, ThreadLocal::log_ctx, log_write(), GlobalContext::max_depth, mpmc_bulk_enqueue(), GlobalContext::only_errors, ThreadLocal::output_buffer, QueueNode::parent_idx, ThreadLocal::path, ThreadLocal::path_data, QueueNode::path_len, QueueNode::path_offset, print_file(), GlobalContext::queue, ThreadLocal::queue_idx, ThreadLocal::stage_idx, ThreadLocal::stage_node, and GlobalContext::xdev.
Referenced by worker().
| void flush_output_buffer | ( | GlobalContext * | __G, |
| OutputBuffer * | output_buffer ) |
Flush the output_buffer to stdout in a thread-safe manner.
| lf | A pointer to the GlobalContext struct containing the output mutex. |
| output_buffer | A pointer to the OutputBuffer struct containing the data to be flushed. |
This function writes the contents of the output_buffer to stdout using fwrite_unlocked for efficiency. It uses a mutex to ensure that only one thread can write to stdout at a time, preventing interleaved output from multiple threads. After flushing, it resets the length of the output_buffer to zero.
Definition at line 947 of file lf.c.
References OutputBuffer::data, OutputBuffer::len, and GlobalContext::output_mutex.
Referenced by append_output_buffer(), and finder().
| bool global_arena_create | ( | GlobalContext * | __G | ) |
Create a queue arena for managing directory traversal tasks.
| lf | A pointer to the GlobalContext struct where the queue arena will be created. |
| max_nodes | The maximum number of nodes that the queue arena can hold. |
This function allocates memory for a QueueArena structure and initializes its properties. It uses mmap to allocate a contiguous block of memory for the queue nodes, allowing for efficient management of directory traversal tasks in a multi-threaded environment. The cursor is initialized to zero, indicating that no nodes have been added yet.
Definition at line 878 of file lf.c.
References GlobalContext::arena, GlobalContext::arena_bytes, GlobalContext::path_bytes, GlobalContext::path_data, GlobalContext::queue, GlobalContext::queue_bytes, and GlobalContext::sequence.
Referenced by init_lf().
| void global_arena_destroy | ( | GlobalContext * | __G | ) |
Destroy the queue arena and free associated resources.
| lf | A pointer to the GlobalContext struct containing the queue arena. |
This function unmaps the memory allocated for the queue arena using munmap. It checks if the arena pointer is valid before attempting to unmap it, ensuring that resources are properly released when they are no longer needed.
Definition at line 929 of file lf.c.
References GlobalContext::arena, and GlobalContext::arena_bytes.
Referenced by init_lf().
| bool init_lf | ( | GlobalContext * | __G, |
| int | argc, | ||
| char ** | argv ) |
Initialize the file search process.
| lf | A pointer to the GlobalContext struct containing the search settings. |
| argc | The number of command-line arguments. |
| argv | An array of command-line argument strings. |
This function initializes the file search process based on the provided settings in the GlobalContext struct. It sets up file type inclusion and suppression, compiles regular expressions if specified, and creates a multi-producer, multi-consumer queue for managing directory traversal tasks. It also initializes threads for concurrent processing of directory entries.
Definition at line 731 of file lf.c.
References GlobalContext::base_path, GlobalContext::compiled_ere, GlobalContext::compiled_re, debug_out(), GlobalContext::dequeue_pos, GlobalContext::disp_level_mask, GlobalContext::enqueue_pos, GlobalContext::ere, GlobalContext::f_logging, GlobalContext::file_level_mask, GlobalContext::flags, global_arena_create(), global_arena_destroy(), GlobalContext::ignore_case, GlobalContext::include_hidden, GlobalContext::include_types, LF_EXC_REGEX, LF_HIDE, LF_REGEX, GlobalContext::log_record, GlobalContext::nthreads, GlobalContext::output_mutex, LogCtx::p_int_nsec, LogCtx::p_int_sec, push_root_node(), GlobalContext::re, LogCtx::record, GlobalContext::reg_flags, GlobalContext::shut_down, ssnprintf(), LogCtx::start_nsec, LogCtx::start_sec, GlobalContext::suppress_types, termination_status, GlobalContext::thread_id, GlobalContext::threads, TS_ERROR, TS_SUCCESS, and worker().
Referenced by main(), and sort_lf_output().
| void initialize_thread_timer | ( | GlobalContext * | __G, |
| LogCtx * | log_ctx ) |
Initialize the timer for a thread, capturing the start time and setting up interval tracking.
| lf | A pointer to the GlobalContext struct containing the search settings. |
| log_ctx | A pointer to the LogCtx struct where timing information will be stored. |
This function retrieves the current time using clock_gettime and initializes both the start time and the previous interval time in the provided LogCtx structure. It also sets the corresponding values in the GlobalContext structure for global timing reference. This setup is essential for accurate timestamping of log entries and interval calculations during program execution.
Definition at line 1799 of file lf.c.
References LogCtx::p_int_nsec, LogCtx::p_int_sec, GlobalContext::start_nsec, LogCtx::start_nsec, GlobalContext::start_sec, and LogCtx::start_sec.
Referenced by worker().
| void initialize_timer | ( | GlobalContext * | __G, |
| LogCtx * | log_ctx ) |
Initialize the timer for logging, capturing the start time and setting up interval tracking.
| lf | A pointer to the GlobalContext struct containing the search settings. |
| log_ctx | A pointer to the LogCtx struct where timing information will be stored. |
This function retrieves the current time using clock_gettime and initializes both the start time and the previous interval time in the provided LogCtx structure. It also sets the corresponding values in the GlobalContext structure for global timing reference. This setup is essential for accurate timestamping of log entries and interval calculations during program execution.
Definition at line 1821 of file lf.c.
References GlobalContext::p_int_nsec, LogCtx::p_int_nsec, GlobalContext::p_int_sec, LogCtx::p_int_sec, GlobalContext::start_nsec, LogCtx::start_nsec, GlobalContext::start_sec, and LogCtx::start_sec.
Referenced by worker().
| bool is_dirsys | ( | const char * | ) |
| bool is_hidden | ( | const char * | ) |
| void iso8601_timestamp | ( | GlobalContext * | __G, |
| LogCtx * | log_ctx ) |
Generate an ISO 8601 timestamp string.
iso8601_timestamp
| buf | Buffer to store the timestamp string |
| n | Size of the buffer |
| local | If true, use local time; if false, use UTC |
Definition at line 1695 of file lf.c.
References ssnprintf(), LogCtx::time_buf, and GlobalContext::timestamp_style.
Referenced by log_write().
| void log_open | ( | GlobalContext * | __G, |
| LogCtx * | log_ctx, | ||
| size_t | thread_id ) |
Open the log file for writing.
log_open
Definition at line 1918 of file lf.c.
References GlobalContext::disp_level_mask, em0, em1, em2, em3, GlobalContext::f_logging, GlobalContext::file_level_mask, GlobalContext::log_fd, GlobalContext::log_file_spec, log_write(), GlobalContext::p_int_nsec, LogCtx::p_int_nsec, GlobalContext::p_int_sec, LogCtx::p_int_sec, ssnprintf(), GlobalContext::start_nsec, LogCtx::start_nsec, GlobalContext::start_sec, LogCtx::start_sec, and strnz__cpy().
Referenced by log_write().
| void log_write | ( | const ll_e | level, |
| GlobalContext * | __G, | ||
| LogCtx * | log_ctx, | ||
| const char * | file, | ||
| const char * | func, | ||
| const int | line, | ||
| const char * | fmt, | ||
| ... ) |
Write a log message to the log file and/or display.
| level | The log level (e.g., INFO, ERROR) |
| lf | Pointer to the GlobalContext struct containing logging settings |
| log_ctx | Pointer to the LogCtx struct for the current thread |
| file | The source file name where the log is generated |
| func | The function name where the log is generated |
| line | The line number in the source file where the log is generated |
| fmt | The format string for the log message |
| ... | Additional arguments for the format string |
This function checks if the specified log level is enabled for file or display output. If enabled, it formats the log message with a timestamp, source information, and user-provided message. It handles opening the log file if necessary and manages log rotation based on size limits. The formatted message is written to the appropriate output destinations.
Definition at line 1984 of file lf.c.
References log_level::bits, coders_timestamp(), GlobalContext::disp_level_mask, GlobalContext::err_fd, GlobalContext::file_level_mask, iso8601_timestamp(), ll_t, GlobalContext::log_fd, GlobalContext::log_file_spec, log_open(), log_level::name, log_level::SGR, ssnprintf(), strnz__cat(), strnz__cpy(), LogCtx::thread_id, LogCtx::time_buf, GlobalContext::timestamp_style, and vssnprintf().
Referenced by finder(), and log_open().
| int main | ( | int | argc, |
| char ** | argv ) |
Definition at line 420 of file lf.c.
References GlobalContext::base_path, GlobalContext::count, GlobalContext::count_silently, GlobalContext::depth_first, GlobalContext::disp_level_mask, GlobalContext::ere, GlobalContext::error_count, expand_tilde(), GlobalContext::f_logging, GlobalContext::file_count, GlobalContext::file_level_mask, GlobalContext::flags, GlobalContext::follow_links, GlobalContext::hidden_only, GlobalContext::ignore_case, GlobalContext::include_hidden, init_lf(), is_directory(), is_symlink_to_dir(), is_valid_regex(), LF_HIDE, LF_REGEX, lfargc, lfargs, GlobalContext::log_error_count, GlobalContext::log_fd, mm, GlobalContext::nthreads, GlobalContext::re, GlobalContext::sbuffer, GlobalContext::sort, sort_lf_output(), GlobalContext::sort_reverse, MemMetrics::stack_base, strnz__cpy(), termination_status, GlobalContext::threads, GlobalContext::timestamp_style, TS_ERROR, TS_SUCCESS, GlobalContext::unlink, GlobalContext::user_name, and GlobalContext::xdev.
| bool mpmc_bulk_enqueue | ( | GlobalContext * | __G, |
| ThreadLocal * | __tl ) |
Bulk enqueue multiple nodes into the MPMC queue.
| lf | A pointer to the GlobalContext struct containing the queue. |
| tl | A pointer to the ThreadLocal struct containing the nodes to enqueue. |
This function attempts to enqueue multiple nodes from a thread-local buffer into a multi-producer, multi-consumer (MPMC) queue. It checks for available slots in the queue and uses atomic operations to reserve space for the nodes. If successful, it copies the nodes and their associated path data into the global queue and updates the sequence numbers accordingly. If the queue is full, it returns false, indicating that the caller should fall back to local stack or single enqueue.
Definition at line 1048 of file lf.c.
References ThreadLocal::cum_path_offset, GlobalContext::enqueue_pos, GlobalContext::path_data, ThreadLocal::path_data, QueueNode::path_len, GlobalContext::path_offset, QueueNode::path_offset, GlobalContext::queue, GlobalContext::sequence, ThreadLocal::stage_idx, and ThreadLocal::stage_node.
Referenced by finder().
| bool mpmc_dequeue | ( | GlobalContext * | __G, |
| uint_fast32_t * | dequeue_pos ) |
Dequeue a node from the MPMC queue.
| lf | A pointer to the GlobalContext struct containing the queue. |
| dequeue_pos | A pointer to a uint_fast32_t variable where the dequeued position will be stored. |
This function attempts to dequeue a node from a multi-producer, multi-consumer (MPMC) queue. It checks for available nodes in the queue and uses atomic operations to claim a node for processing. If successful, it updates the sequence number for the dequeued position and returns true. If the queue is empty or has been shut down, it returns false, indicating that there are no more nodes to process.
Definition at line 1144 of file lf.c.
References GlobalContext::active_tasks, GlobalContext::dequeue_pos, GlobalContext::enqueue_pos, GlobalContext::sequence, and GlobalContext::shut_down.
Referenced by worker().
| bool mpmc_enqueue | ( | GlobalContext * | __G, |
| QueueNode * | node, | ||
| const char * | path, | ||
| size_t | len ) |
Definition at line 997 of file lf.c.
References GlobalContext::enqueue_pos, GlobalContext::path_data, GlobalContext::path_offset, GlobalContext::queue, and GlobalContext::sequence.
Referenced by push_root_node().
| int print_file | ( | GlobalContext * | __G, |
| ThreadLocal * | __tl ) |
Print the path of a file or directory entry based on filtering criteria.
| lf | A pointer to the GlobalContext struct containing the search settings. |
| tl | A pointer to the ThreadLocal struct containing the current directory context. |
This function checks various filtering criteria specified in the GlobalContext, such as type suppression, regex matching, user ownership, permissions, modification time, and file size. If the entry passes all filters, it increments the file count and appends the path to the output buffer for printing. The function returns true if the entry was printed and false if it was excluded based on any of the filtering criteria.
Definition at line 1602 of file lf.c.
References GlobalContext::after, append_output_buffer(), GlobalContext::before, ThreadLocal::cached_sb, GlobalContext::compiled_ere, GlobalContext::compiled_re, GlobalContext::count_silently, ThreadLocal::effective_type, GlobalContext::file_count, GlobalContext::file_size_min, GlobalContext::flags, GlobalContext::include_perms, LF_EXC_REGEX, LF_IRUSR, LF_ISGID, LF_ISUID, LF_IWUSR, LF_IXUSR, LF_REGEX, lf_type_mask, LF_USER, GlobalContext::only_errors, ThreadLocal::output_buffer, ThreadLocal::path, ThreadLocal::path_len, ThreadLocal::stat_cached, GlobalContext::suppress_types, termination_status, TS_MATCH, and GlobalContext::user_id.
Referenced by finder().
| void push_root_node | ( | GlobalContext * | __G, |
| dev_t | dev, | ||
| ino_t | ino ) |
Push the root directory node into the queue arena.
| lf | A pointer to the GlobalContext struct containing the queue arena. |
| path_offset | The offset of the root path in the path arena. |
| path_len | The length of the root path string. |
| dev | The device ID of the root directory. |
| ino | The inode number of the root directory. |
This function initializes and pushes the root directory node into the queue arena. It allocates a new directory context and cycle context for the root node, sets up its properties, and returns its index in the queue arena. This is typically called at the start of a file search operation to establish the starting point for traversal.
Definition at line 908 of file lf.c.
References GlobalContext::active_tasks, GlobalContext::base_path, QueueNode::child_dirs_remaining, QueueNode::depth, QueueNode::dev, QueueNode::ino, mpmc_enqueue(), QueueNode::parent_idx, QueueNode::path_len, QueueNode::path_offset, and GlobalContext::queue_idx.
Referenced by init_lf().
| int sort_lf_output | ( | GlobalContext * | __G, |
| int | argc, | ||
| char ** | argv ) |
Sort the output of the lf command using the system's sort utility.
| lf | A pointer to the GlobalContext struct containing the search settings. |
| argc | The number of command-line arguments. |
| argv | An array of command-line argument strings. |
This function sets up a pipeline to sort the output of the lf command. It creates a pipe, forks a child process to execute the sort command, and redirects the standard input and output streams accordingly. The sort command is executed with optional flags for parallel processing and buffer size, as well as a reverse sort option if specified in the GlobalContext. The function waits for the child process to complete before returning.
Definition at line 529 of file lf.c.
References init_lf(), GlobalContext::sort_reverse, and TS_ERROR.
Referenced by main().
| void * worker | ( | void * | arg | ) |
Worker thread function for processing directory nodes.
| arg | A pointer to the GlobalContext struct containing the search settings. |
This function is executed by each worker thread. It dequeues directory nodes from the global queue, reconstructs their paths, and invokes the finder function to process them. Each thread maintains its own local context, including a stage arena for temporary storage of nodes and path data. The function continues processing until there are no more nodes to dequeue or the search is shut down.
Definition at line 1227 of file lf.c.
References GlobalContext::active_tasks, QueueNode::child_dirs_remaining, ThreadLocal::child_dirs_remaining, ThreadLocal::cum_path_offset, ThreadLocal::dir_buf, GlobalContext::f_logging, finder(), initialize_thread_timer(), initialize_timer(), OutputBuffer::len, ThreadLocal::log_ctx, GlobalContext::log_fd, mpmc_dequeue(), ThreadLocal::output_buffer, QueueNode::parent_idx, ThreadLocal::parent_path_len, ThreadLocal::path, GlobalContext::path_data, ThreadLocal::path_data, QueueNode::path_len, QueueNode::path_offset, GlobalContext::queue, ThreadLocal::queue_idx, ThreadLocal::stage_arena, ThreadLocal::stage_arena_size, ThreadLocal::stage_idx, ThreadLocal::stage_node, ThreadLocal::stage_path_size, ThreadLocal::stage_queue_size, GlobalContext::thread_id, LogCtx::thread_id, and ThreadLocal::thread_id.
Referenced by init_lf().
| const char* argp_program_version = LF_VERSION |
| char doc |
| char em0 |
error message string for error messages
Definition at line 42 of file lf.c.
Referenced by enter_file_spec(), form_desc_error(), form_parse_desc(), form_process(), form_read_data(), form_write(), handle_signal(), log_open(), mk_dir(), ncurses_input(), new_init(), new_pick(), new_view(), parse_menu_description(), ui_action_disposition(), ui_add_pair(), ui_color_from_rgb(), ui_get_event(), ui_open_log(), verify_dir(), verify_file(), view_cmd_processor(), view_init_input(), write_config(), and write_view_buffer().
| char em1 |
error message string for error messages
Definition at line 43 of file lf.c.
Referenced by enter_file_spec(), form_desc_error(), form_parse_desc(), form_process(), form_read_data(), form_write(), handle_signal(), log_open(), mk_dir(), ncurses_input(), new_init(), new_pick(), new_view(), parse_menu_description(), ui_add_pair(), ui_color_from_rgb(), ui_get_event(), ui_open_log(), verify_dir(), verify_file(), view_cmd_processor(), view_init_input(), and write_view_buffer().
| char em2 |
error message string for error messages
Definition at line 44 of file lf.c.
Referenced by enter_file_spec(), form_desc_error(), form_parse_desc(), form_process(), form_read_data(), form_write(), handle_signal(), log_open(), mk_dir(), ncurses_input(), new_init(), new_view(), parse_menu_description(), ui_add_pair(), ui_get_event(), ui_open_log(), verify_dir(), verify_file(), view_cmd_processor(), view_init_input(), and write_view_buffer().
| char em3 |
error message string for error messages
Definition at line 45 of file lf.c.
Referenced by log_open(), ui_open_log(), ui_timeout_prompt(), ui_update_timeout_prompt(), verify_dir(), and verify_file().
| unsigned char const lf_type_mask |
Definition at line 110 of file lf.c.
Referenced by print_file().
| log_level ll_t |
Definition at line 63 of file lf.c.
Referenced by debug_out(), finder(), and log_write().
| const char * log_s = {LOG_LEVEL_LIST(AS_STRINGS)} |
| MemMetrics mm |
| const char * sgr_c |
Definition at line 81 of file lf.c.
Referenced by coders_timestamp().
| const char * sgr_s = {ANSI_COLOR_LIST(AS_STRINGS)} |
| int stderr_fd |
| int stdin_fd |
| int stdout_fd |
| TerminationStatus termination_status |
Definition at line 60 of file lf.c.
Referenced by init_lf(), main(), and print_file().
| const char * tss_s = {TIMESTAMP_STYLE(AS_STRINGS)} |