|
C-Menu 0.2.9
A User Interface Toolkit
|
Headder for lf. More...
#include <argp.h>#include <pthread.h>#include <regex.h>#include <stdatomic.h>#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <stdlib.h>#include <sys/types.h>#include <time.h>#include <unistd.h>#include <wait.h>Go to the source code of this file.
Data Structures | |
| struct | GlobalContext |
| struct | linux_dirent64 |
| struct | log_level |
| struct | LogCtx |
| struct | MemMetrics |
| struct | OutputBuffer |
| struct | QueueNode |
| struct | ThreadLocal |
Macros | |
| #define | _(String) |
| #define | __atexit |
| This macro registers the end_pgm function to be called when the program exits. | |
| #define | ABS(x) |
| #define | ANSI_COLOR_LIST(X) |
| #define | ANSI_RESET "\033[0m" |
| #define | AS_ENUM(NAME) |
| #define | AS_STRINGS(NAME) |
| #define | ATTR_FORMAT(archetype, fmt_idx, first_arg) |
| #define | bindtextdomain(Package, Directory) |
| #define | CACHE_LINE_SIZE 64 |
| #define | DEFAULTSHELL "/bin/bash" |
| #define | DIR_BUF_SIZE 65536 |
| #define | F_NO_STDERR 1 |
| #define | lf_log(level, fmt, ...) |
| #define | LF_VERSION "v0.3.3" |
| #define | LF_VERSION_MAJOR 0 |
| #define | LF_VERSION_MINOR 3 |
| #define | LF_VERSION_PATCH 3 |
| #define | LOG_LEVEL_LIST(X) |
| #define | MAX(a, b) |
| #define | max(a, b) |
| #define | MAX_ARGS 64 |
| #define | MAX_DEPTH 64 |
| #define | MAX_LOG_REC_LEN 1024 |
| #define | MAX_LOG_RECORD_LEN MAX_PATH_LEN |
| #define | MAX_LOG_SIZE (1024 * 1024) |
| #define | MAX_PATH_LEN PATH_MAX |
| #define | MAX_THREADS 64 |
| #define | MAX_TIMESTAMP_LEN 64 |
| #define | MAXLEN 256 |
| #define | MIN(x, y) |
| #define | min(x, y) |
| #define | N_(String) |
| #define | NO_PARENT UINT32_MAX |
| #define | nullptr NULL |
| #define | OUTPUT_BUFFER_BYTES (16 * MAX_PATH_LEN) |
| #define | PATH_BYTES (32 * 1024 * 1024) |
| #define | print_file_type(mask, lf_type, dt_type, name) |
| #define | QUEUE_MASK (QUEUE_NODES - 1) |
| #define | QUEUE_NODES (1024 * 1024) |
| #define | S_QUIET 0x2000 |
| #define | S_TOLOWER(c) |
| #define | S_TOUPPER(c) |
| #define | S_WCOK 0x1000 |
| #define | STAGE_NODES 8 |
| #define | STAGE_PATH_BYTES (STAGE_NODES * 1024) |
| #define | textdomain(Domain) |
| #define | TIMESTAMP_STYLE(X) |
| #define | to_lowercase(c) |
| #define | to_uppercase(c) |
| #define | to_uppercase(c) |
Typedefs | |
| typedef uint16_t | LogLevel |
Enumerations | |
| enum | __attribute { TIMESTAMP_STYLE =(AS_ENUM) TIMESTAMP_STYLE_COUNT , ANSI_COLOR_LIST =(AS_ENUM) ANSI_COLOR_COUNT } |
| enum | __attribute { TIMESTAMP_STYLE =(AS_ENUM) TIMESTAMP_STYLE_COUNT , ANSI_COLOR_LIST =(AS_ENUM) ANSI_COLOR_COUNT } |
| enum | F_Type { F_F0 , F_FIFO , F_CHR , F_F1 , F_DIR , F_F2 , F_BLK , F_F3 , F_REG , F_F4 , F_LNK , F_F5 , F_SOCK , F_F6 , F_UNKNOWN } |
| enum | LFFlags { LF_HIDE = 0b00000001 , LF_ICASE = 0b00000010 , LF_EXC_REGEX = 0b00000100 , LF_REGEX = 0b00001000 , LF_EXEC = 0b00010000 , LF_USER = 0b00100000 , LF_IXUSR = 0b00000001 , LF_IWUSR = 0b00000010 , LF_IRUSR = 0b00000100 , LF_ISGID = 0b00010000 , LF_ISUID = 0b00100000 } |
| enum | LFTypes { LF_FIFO = 0b00000001 , LF_CHR = 0b00000010 , LF_DIR = 0b00000100 , LF_BLK = 0b00001000 , LF_REG = 0b00010000 , LF_LNK = 0b00100000 , LF_SOCK = 0b01000000 , LF_UNKNOWN = 0b10000000 } |
| enum | ll_e : uint16_t { LOG_LEVEL_LIST =(AS_ENUM) LOG_LEVEL_COUNT } |
| enum | TerminationStatus { TS_SUCCESS = 0 , TS_ERROR = 1 , TS_MATCH = 2 , TS_MATCH_PLUS_ERROR = 3 } |
Functions | |
| unsigned long | a_to_ul (const char *) |
| 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 *, bool *) |
| a safer alternative to atoi() for converting ASCII strings to integers. | |
| bool | append_output_buffer (GlobalContext *__G, OutputBuffer *output, 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, char **) |
| Display everything and the kitchen sink on stderr. | |
| bool | expand_tilde (char *, uint) |
| Replaces "~/" in string with the user's home directory. | |
| void | finalize_dir_node (GlobalContext *__G, size_t node_offset) |
| void * | finder (GlobalContext *__G, ThreadLocal *tl) |
| Traverse a directory and process its entries. | |
| size_t | flush_ch (GlobalContext *__G, ThreadLocal *tl) |
| void | flush_output_buffer (GlobalContext *, OutputBuffer *) |
| 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. | |
| char * | get_ip_addresses (char *, uint) |
| Retrieves the IP addresses of the local machine and formats them into a string. | |
| char * | get_local_timestamp () |
| Returns the current local time as an ISO 8601 formatted string. | |
| void | get_proc_memory () |
| char * | get_user_str (char *, size_t) |
| Retrieves the current user's name and UID, and formats it into a string. | |
| 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, char **) |
| 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 *) |
| Checks if the given path is a directory. | |
| bool | is_newer (char *, char *) |
| Checks if the file specified by "fut" is newer than the file specified by "control". | |
| bool | is_symlink_to_dir (const char *) |
| Checks if the given path is a symbolic link to a directory. | |
| bool | is_valid_regex (const char *) |
| 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. | |
| 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 | mpmc_enqueue_staged (GlobalContext *, ThreadLocal *__tl) |
| 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. | |
| void | path_data_destroy (GlobalContext *__G) |
| char * | path_data_init (GlobalContext *__G, LogCtx *log_ctx) |
| 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, char **) |
| Sort the output of the lf command using the system's sort utility. | |
| size_t | ssnprintf (char *, size_t, const char *,...) |
| Custom safe string formatting utility (Variadic version). | |
| int | str_to_args (char **, char *, uint) |
| Converts a string into an array of argument strings. | |
| char * | strerror__r (int errnum, char *buf, size_t buflen) |
| A thread-safe alternative to strerror() that writes the error message corresponding to errnum into the provided buffer. | |
| size_t | strnz__cat (char *, const char *, size_t) |
| safer alternative to strncat | |
| size_t | strnz__cpy (char *, const char *, size_t) |
| safer alternative to strncpy | |
| size_t | strnz__pcat (char *d, size_t pos, const char *s, size_t max_len) |
| size_t | vssnprintf (char *buf, size_t buf_size, const char *format, va_list args) |
| Custom safe string formatting utility (va_list version). | |
| void * | worker (void *arg) |
| Worker thread function for processing directory nodes. | |
| #define __atexit |
This macro registers the end_pgm function to be called when the program exits.
It checks the return value of atexit() to ensure that the registration was successful, and if not, it prints an error message and exits with a failure status. Programs using libcm should call __atexit in their main function to ensure that the end_pgm function is registered to be called on program exit. This will help ensure that the terminal is properly restored to its original state, even if the program encounters an error or is terminated unexpectedly.
Definition at line 292 of file lf.h.
| #define ABS | ( | x | ) |
| #define ANSI_COLOR_LIST | ( | X | ) |
Definition at line 118 of file lf.h.
| #define ATTR_FORMAT | ( | archetype, | |
| fmt_idx, | |||
| first_arg ) |
| #define lf_log | ( | level, | |
| fmt, | |||
| ... ) |
| #define LOG_LEVEL_LIST | ( | X | ) |
Definition at line 89 of file lf.h.
| #define MAX | ( | a, | |
| b ) |
| #define max | ( | a, | |
| b ) |
| #define MAX_ARGS 64 |
| #define MAX_LOG_RECORD_LEN MAX_PATH_LEN |
| #define MAXLEN 256 |
| #define MIN | ( | x, | |
| y ) |
| #define min | ( | x, | |
| y ) |
| #define OUTPUT_BUFFER_BYTES (16 * MAX_PATH_LEN) |
| #define print_file_type | ( | mask, | |
| lf_type, | |||
| dt_type, | |||
| name ) |
Definition at line 447 of file lf.h.
| #define QUEUE_MASK (QUEUE_NODES - 1) |
| #define S_TOLOWER | ( | c | ) |
| #define S_TOUPPER | ( | c | ) |
| #define STAGE_PATH_BYTES (STAGE_NODES * 1024) |
| #define TIMESTAMP_STYLE | ( | X | ) |
| #define to_lowercase | ( | c | ) |
| #define to_uppercase | ( | c | ) |
| #define to_uppercase | ( | c | ) |
| enum __attribute |
| Enumerator | |
|---|---|
| TIMESTAMP_STYLE | |
| ANSI_COLOR_LIST | |
Definition at line 138 of file lf.h.
| enum __attribute |
| Enumerator | |
|---|---|
| TIMESTAMP_STYLE | |
| ANSI_COLOR_LIST | |
Definition at line 115 of file lf.h.
| enum F_Type |
| enum LFFlags |
Definition at line 209 of file lf.h.
| enum LFTypes |
byte 2 - bits 16-23 File types
| Enumerator | |
|---|---|
| LF_FIFO | 1 named pipe |
| LF_CHR | 2 character device |
| LF_DIR | 4 directory |
| LF_BLK | 8 block |
| LF_REG | 16 regular file |
| LF_LNK | 32 link |
| LF_SOCK | 64 socket |
| LF_UNKNOWN | 128 unknown |
| enum TerminationStatus |
| Enumerator | |
|---|---|
| TS_SUCCESS | |
| TS_ERROR | |
| TS_MATCH | |
| TS_MATCH_PLUS_ERROR | |
Definition at line 370 of file lf.h.
| 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 finalize_dir_node | ( | GlobalContext * | __G, |
| size_t | node_offset ) |
| 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().
| size_t flush_ch | ( | GlobalContext * | __G, |
| ThreadLocal * | tl ) |
| 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().
| void get_proc_memory | ( | ) |
| 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().
| 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().
| 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().
| bool mpmc_enqueue_staged | ( | GlobalContext * | , |
| ThreadLocal * | __tl ) |
| void path_data_destroy | ( | GlobalContext * | __G | ) |
| char * path_data_init | ( | GlobalContext * | __G, |
| LogCtx * | log_ctx ) |
| 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().
| size_t strnz__pcat | ( | char * | d, |
| size_t | pos, | ||
| const char * | s, | ||
| size_t | max_len ) |
Definition at line 577 of file futil.c.
| 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().