11 Commits

Author SHA1 Message Date
b22ae6b2cc fix: memory leaks 2025-06-06 19:40:38 +02:00
04a102a7bb perf: better and efficient vec impl 2025-06-06 19:39:44 +02:00
dc6424979e fix: address mem issues 2025-06-06 18:12:45 +02:00
82e92df95c fix(aur): v0.2.1 checksums on the srcfile (again x2) 2025-06-06 17:05:14 +02:00
f2dbeb0236 Merge pull request #34 from AliensInc/master
Fixes the first two lines in the sha256sum

> *Why dont the checks runnnnnnnnnnnn*
2025-06-06 16:58:48 +02:00
Basher52
d72643c030 Fixes the first two lines in the sha256sum 2025-05-27 21:35:05 +02:00
f7139b16b5 Merge pull request #32 from rmntgx/memory-fixes
fix: memory leaks and memory access errors
2025-05-20 17:02:24 +02:00
rmntgx
ee6565d5b4 fix: memory leaks and memory access errors 2025-05-20 19:42:24 +05:00
620d861d8c fix(aur): lidm-bin@0.2.1 checksums 2025-03-22 18:27:15 +01:00
e879561cbd Merge pull request #28 from javalsai/actions/update-aur-0.2.1
[AUR update]: Bump to 0.2.1
2025-03-22 18:01:24 +01:00
GitHub Actions
eecfd7ac4c Update AUR pkgs to v0.2.1 2025-03-22 16:54:29 +00:00
11 changed files with 138 additions and 72 deletions

View File

@@ -1,17 +1,17 @@
pkgbase = lidm-bin pkgbase = lidm-bin
pkgdesc = A fully colorful customizable TUI display manager made in C. (release binary) pkgdesc = A fully colorful customizable TUI display manager made in C. (release binary)
pkgver = 0.2.0 pkgver = 0.2.1
pkgrel = 1 pkgrel = 2
url = https://github.com/javalsai/lidm url = https://github.com/javalsai/lidm
arch = x86_64 arch = x86_64
license = GPL license = GPL
depends = pam depends = pam
provides = lidm provides = lidm
conflicts = lidm conflicts = lidm
source = lidm::https://github.com/javalsai/lidm/releases/download/v0.2.0/lidm-amd64 source = lidm::https://github.com/javalsai/lidm/releases/download/v0.2.1/lidm-amd64
source = default-theme.ini::https://raw.githubusercontent.com/javalsai/lidm/v0.2.0/themes/default.ini source = default-theme.ini::https://raw.githubusercontent.com/javalsai/lidm/v0.2.1/themes/default.ini
source = lidm.1::https://raw.githubusercontent.com/javalsai/lidm/v0.2.0/assets/man/lidm.1 source = lidm.1::https://raw.githubusercontent.com/javalsai/lidm/v0.2.1/assets/man/lidm.1
source = lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/v0.2.0/assets/man/lidm-config.5 source = lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/v0.2.1/assets/man/lidm-config.5
sha256sums = 65b42f4f7acd970b167fe84d1fa75450b54e01a6f0edddb9d8dd487058a20850 sha256sums = 65b42f4f7acd970b167fe84d1fa75450b54e01a6f0edddb9d8dd487058a20850
sha256sums = 68662430a6d262b35cc54d9f0e164ed935b7f7f4497a87cc94946c558bbe8a91 sha256sums = 68662430a6d262b35cc54d9f0e164ed935b7f7f4497a87cc94946c558bbe8a91
sha256sums = a6807a55ff72ec5a5678583156b3efd0d367f0bcb79854094132771f0cb86bce sha256sums = a6807a55ff72ec5a5678583156b3efd0d367f0bcb79854094132771f0cb86bce

View File

@@ -1,8 +1,8 @@
# shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164 # shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164
# Maintainer: javalsai <javalsai@proton.me> # Maintainer: javalsai <javalsai@proton.me>
pkgname=lidm-bin pkgname=lidm-bin
pkgver=0.2.0 pkgver=0.2.1
pkgrel=1 pkgrel=2
depends=('pam') depends=('pam')
pkgdesc="A fully colorful customizable TUI display manager made in C. (release binary)" pkgdesc="A fully colorful customizable TUI display manager made in C. (release binary)"
arch=('x86_64') arch=('x86_64')

View File

@@ -1,7 +1,7 @@
# shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164 # shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164
# Maintainer: javalsai <javalsai@proton.me> # Maintainer: javalsai <javalsai@proton.me>
pkgname=lidm-git pkgname=lidm-git
pkgver=0.2.0.r2.g255256b pkgver=0.2.1.r0.ge2014f4
pkgrel=1 pkgrel=1
depends=('pam') depends=('pam')
makedepends=('git' 'make' 'gcc') makedepends=('git' 'make' 'gcc')

View File

@@ -1,6 +1,6 @@
pkgbase = lidm pkgbase = lidm
pkgdesc = A fully colorful customizable TUI display manager made in C. (build latest tag) pkgdesc = A fully colorful customizable TUI display manager made in C. (build latest tag)
pkgver = 0.2.0 pkgver = 0.2.1
pkgrel = 1 pkgrel = 1
url = https://github.com/javalsai/lidm url = https://github.com/javalsai/lidm
arch = any arch = any
@@ -8,7 +8,7 @@ pkgbase = lidm
makedepends = git makedepends = git
makedepends = gcc makedepends = gcc
depends = pam depends = pam
source = tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/v0.2.0.tar.gz source = tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/v0.2.1.tar.gz
sha256sums = 6d397cf75cafdcb95e5a2623d70f2e07bbb085a07b7c3b743caac06454ed7b16 sha256sums = 56aaf8025fac16f5deef3058274635198fc3bf3f7eadc1de5c6539614f03d84b
pkgname = lidm pkgname = lidm

View File

@@ -1,7 +1,7 @@
# shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164 # shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164
# Maintainer: javalsai <javalsai@proton.me> # Maintainer: javalsai <javalsai@proton.me>
pkgname=lidm pkgname=lidm
pkgver=0.2.0 pkgver=0.2.1
pkgrel=1 pkgrel=1
depends=('pam') depends=('pam')
makedepends=('git' 'gcc') makedepends=('git' 'gcc')
@@ -10,7 +10,7 @@ arch=('any')
url="https://github.com/javalsai/lidm" url="https://github.com/javalsai/lidm"
license=('GPL') license=('GPL')
source=("tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/v$pkgver.tar.gz") source=("tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/v$pkgver.tar.gz")
sha256sums=('6d397cf75cafdcb95e5a2623d70f2e07bbb085a07b7c3b743caac06454ed7b16') sha256sums=('56aaf8025fac16f5deef3058274635198fc3bf3f7eadc1de5c6539614f03d84b')
build() { build() {
tar -xzf "tarball.tar.gz" tar -xzf "tarball.tar.gz"

View File

@@ -14,18 +14,20 @@ void read_press(u_char *, char *);
void strcln(char **dest, const char *source); void strcln(char **dest, const char *source);
struct Vector { struct Vector {
uint32_t length; uint32_t length;
uint32_t alloc_len; uint32_t capacity;
uint16_t alloc_size; void **pages;
void** pages;
}; };
struct Vector vec_new(); struct Vector vec_new();
int vec_push(struct Vector*, void* item); int vec_resize(struct Vector *, size_t size);
void vec_free(struct Vector*); int vec_reserve(struct Vector *, size_t size);
void vec_clear(struct Vector*); int vec_reserve_exact(struct Vector *, size_t size);
void vec_reset(struct Vector*); int vec_push(struct Vector *, void *item);
void* vec_pop(struct Vector*); // won't free it, nor shrink vec list space void vec_free(struct Vector *);
void* vec_get(struct Vector*, size_t index); void vec_clear(struct Vector *);
void vec_reset(struct Vector *);
void *vec_pop(struct Vector *); // won't free it, nor shrink vec list space
void *vec_get(struct Vector *, size_t index);
#endif #endif

View File

@@ -4,6 +4,14 @@
#include "config.h" #include "config.h"
#include "util.h" #include "util.h"
// Alr so ima explain the bitfield returned by `cb` a bit
// 4 bits:
// 0b0001: break out of parsing (returning true)
// 0b0010: free the value
// 0b0100: free the key
// 0b1000: break out of parsing (returning false)
//
// This would return true if everything goes fine, false otherwise (malloc error, broke parsing, etc)
bool line_parser(FILE *fd, ssize_t *blksize, bool line_parser(FILE *fd, ssize_t *blksize,
u_char (*cb)(char *key, char *value)) { u_char (*cb)(char *key, char *value)) {
size_t opt_size = 4096; size_t opt_size = 4096;
@@ -27,23 +35,34 @@ bool line_parser(FILE *fd, ssize_t *blksize,
free(buf); free(buf);
return false; return false;
} }
if ((read = sscanf(buf, "%[^ ] = %[^\n]\n", key, buf)) != 0) { char *value = malloc(read_size);
u_char ret = cb(key, buf); if (value == NULL) {
free(buf);
return false;
}
if ((read = sscanf(buf, "%[^ ] = %[^\n]\n", key, value)) != 0) {
u_char ret = cb(key, value);
if (ret & 0b0100) if (ret & 0b0100)
free(key); free(key);
if (ret & 0b0010) if (ret & 0b0010)
free(value);
if (ret & 0b1000) {
free(buf); free(buf);
if (ret & 0b1000)
return false; return false;
if (ret & 0b0001) }
if (ret & 0b0001) {
free(buf);
break; break;
}
} }
free(buf);
} }
return true; return true;
} }
struct config *__config; struct config *__config;
// Yanderedev code (wanna fix this with a table or smth)
u_char config_line_handler(char *k, char *v) { u_char config_line_handler(char *k, char *v) {
if (strcmp(k, "colors.bg") == 0) if (strcmp(k, "colors.bg") == 0)
__config->theme.colors.bg = v; __config->theme.colors.bg = v;
@@ -85,13 +104,16 @@ u_char config_line_handler(char *k, char *v) {
__config->theme.chars.cbl = v; __config->theme.chars.cbl = v;
else if (strcmp(k, "chars.cbr") == 0) else if (strcmp(k, "chars.cbr") == 0)
__config->theme.chars.cbr = v; __config->theme.chars.cbr = v;
else if (strcmp(k, "functions.poweroff") == 0) else if (strcmp(k, "functions.poweroff") == 0) {
__config->functions.poweroff = find_keyname(v); __config->functions.poweroff = find_keyname(v);
else if (strcmp(k, "functions.reboot") == 0) return 0b0110;
} else if (strcmp(k, "functions.reboot") == 0) {
__config->functions.reboot = find_keyname(v); __config->functions.reboot = find_keyname(v);
else if (strcmp(k, "functions.refresh") == 0) return 0b0110;
} else if (strcmp(k, "functions.refresh") == 0) {
__config->functions.refresh = find_keyname(v); __config->functions.refresh = find_keyname(v);
else if (strcmp(k, "strings.f_poweroff") == 0) return 0b0110;
} else if (strcmp(k, "strings.f_poweroff") == 0)
__config->strings.f_poweroff = v; __config->strings.f_poweroff = v;
else if (strcmp(k, "strings.f_reboot") == 0) else if (strcmp(k, "strings.f_reboot") == 0)
__config->strings.f_reboot = v; __config->strings.f_reboot = v;
@@ -107,16 +129,17 @@ u_char config_line_handler(char *k, char *v) {
__config->strings.s_xorg = v; __config->strings.s_xorg = v;
else if (strcmp(k, "strings.s_shell") == 0) else if (strcmp(k, "strings.s_shell") == 0)
__config->strings.s_shell = v; __config->strings.s_shell = v;
else if (strcmp(k, "behavior.include_defshell") == 0) else if (strcmp(k, "behavior.include_defshell") == 0) {
__config->behavior.include_defshell = strcmp(v, "true") == 0; __config->behavior.include_defshell = strcmp(v, "true") == 0;
else if (strcmp(k, "behavior.source") == 0) return 0b0110;
} else if (strcmp(k, "behavior.source") == 0)
vec_push(&__config->behavior.source, v); vec_push(&__config->behavior.source, v);
else if (strcmp(k, "behavior.user_source") == 0) else if (strcmp(k, "behavior.user_source") == 0)
vec_push(&__config->behavior.user_source, v); vec_push(&__config->behavior.user_source, v);
else else
return 0b1111; return 0b1111;
return 0b100; return 0b0100;
} }
struct config *parse_config(char *path) { struct config *parse_config(char *path) {

View File

@@ -54,6 +54,7 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
char *exec_buf = NULL; char *exec_buf = NULL;
char *tryexec_buf = NULL; char *tryexec_buf = NULL;
// This should be made a specific function // This should be made a specific function
// Emm, if anything goes wrong just free the inner loop and `break;` fd and the rest is handled after
while (true) { while (true) {
char *buf = malloc(sb->st_blksize); char *buf = malloc(sb->st_blksize);
ssize_t read_size = getline(&buf, &alloc_size, fd); ssize_t read_size = getline(&buf, &alloc_size, fd);
@@ -63,28 +64,44 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
} }
uint read; uint read;
char *key = malloc(read_size); char *key = malloc(read_size + sizeof(char));
if ((read = sscanf(buf, "%[^=]=%[^\n]\n", key, buf)) != 0) { if(key == NULL) {
free(buf);
// TODO: more sophisticated error handling??
break;
}
char *value = malloc(read_size + sizeof(char));
if(value == NULL) {
free(buf);
free(key);
// TODO: more sophisticated error handling??
break;
}
value[0] = '\0'; // I'm not sure if sscanf would null this string out
if ((read = sscanf(buf, "%[^=]=%[^\n]\n", key, value)) != 0) {
if (strcmp(key, "Name") == 0) { if (strcmp(key, "Name") == 0) {
found &= 0b001; found &= 0b001;
name_buf = realloc(buf, read); name_buf = realloc(value, strlen(value) + sizeof(char));
} else if (strcmp(key, "Exec") == 0) { } else if (strcmp(key, "Exec") == 0) {
found &= 0b010; found &= 0b010;
exec_buf = realloc(buf, read); exec_buf = realloc(value, strlen(value) + sizeof(char));
} else if (strcmp(key, "TryExec") == 0) { } else if (strcmp(key, "TryExec") == 0) {
found &= 0b100; found &= 0b100;
tryexec_buf = realloc(buf, read); tryexec_buf = realloc(value, strlen(value) + sizeof(char));
} else } else {
free(buf); free(value);
} else }
free(buf); } else {
free(value);
}
free(key); free(key);
free(buf);
if (found == 0b111) if (found == 0b111) break;
break;
} }
/*printf("\nend parsing...\n");*/ /*printf("\nend parsing...\n");*/
// Generic handling of exit
fclose(fd); fclose(fd);
// just add this to the list // just add this to the list
@@ -108,6 +125,7 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
// This code is designed to be run purely single threaded // This code is designed to be run purely single threaded
struct Vector get_avaliable_sessions() { struct Vector get_avaliable_sessions() {
struct Vector sessions = vec_new(); struct Vector sessions = vec_new();
vec_reserve(&sessions, 8);
cb_sessions = &sessions; cb_sessions = &sessions;
for (size_t i = 0; i < (sizeof(sources) / sizeof(sources[0])); i++) { for (size_t i = 0; i < (sizeof(sources) / sizeof(sources[0])); i++) {

View File

@@ -322,6 +322,7 @@ void ffield_type(char *text) {
print_ffield(); print_ffield();
} }
static char* unknown_str = "unknown";
int load(struct Vector *users, struct Vector *sessions) { int load(struct Vector *users, struct Vector *sessions) {
/// SETUP /// SETUP
gusers = users; gusers = users;
@@ -331,9 +332,9 @@ int load(struct Vector *users, struct Vector *sessions) {
char *hostname = malloc(16); char *hostname = malloc(16);
if (gethostname(hostname, 16) != 0) { if (gethostname(hostname, 16) != 0) {
free(hostname); free(hostname);
hostname = "unknown"; hostname = unknown_str;
} else { } else {
hostname = realloc(hostname, strlen(hostname) + 1); hostname[15] = '\0';
} }
of_session = ofield_new(sessions->length + behavior.include_defshell); of_session = ofield_new(sessions->length + behavior.include_defshell);
@@ -350,12 +351,14 @@ int load(struct Vector *users, struct Vector *sessions) {
printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", boxstart.y + 2, printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", boxstart.y + 2,
boxstart.x + 12 - (uint)strlen(hostname), theme.colors.e_hostname, boxstart.x + 12 - (uint)strlen(hostname), theme.colors.e_hostname,
hostname, theme.colors.fg); hostname, theme.colors.fg);
if(hostname != unknown_str) free(hostname);
// put date // put date
char *fmtd_time = fmt_time(); char *fmtd_time = fmt_time();
printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", boxstart.y + 2, printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", boxstart.y + 2,
boxstart.x + boxw - 3 - (uint)strlen(fmtd_time), theme.colors.e_date, boxstart.x + boxw - 3 - (uint)strlen(fmtd_time), theme.colors.e_date,
fmtd_time, theme.colors.fg); fmtd_time, theme.colors.fg);
free(fmtd_time);
print_field(SESSION); print_field(SESSION);
print_field(USER); print_field(USER);

View File

@@ -23,6 +23,7 @@ static struct user __new_user(struct passwd *p) {
// This code is designed to be run purely single threaded // This code is designed to be run purely single threaded
struct Vector get_human_users() { struct Vector get_human_users() {
struct Vector users = vec_new(); struct Vector users = vec_new();
vec_reserve(&users, 4);
struct passwd *pwd; struct passwd *pwd;
while ((pwd = getpwent()) != NULL) { while ((pwd = getpwent()) != NULL) {

View File

@@ -68,58 +68,77 @@ static int selret_magic() {
return select(1, &set, NULL, NULL, &timeout); return select(1, &set, NULL, NULL, &timeout);
} }
// Vector shii // Vector shii
struct Vector vec_new() { struct Vector vec_new() {
struct Vector vec; struct Vector vec;
vec_clear(&vec); vec_reset(&vec);
return vec; return vec;
} }
int vec_push(struct Vector* vec, void* item) { int vec_resize(struct Vector *vec, size_t size) {
if (vec->length >= vec->alloc_len) { void **new_location = realloc(vec->pages, size * sizeof(void*));
uint32_t new_size = vec->alloc_len + vec->alloc_size; if (new_location != NULL) {
void **new_location = realloc(vec->pages, vec->alloc_size); if (vec->length > size)
if (new_location != NULL) { vec->length = size;
vec->alloc_size = new_size; vec->capacity = size;
vec->pages = new_location; vec->pages = new_location;
} else { } else {
return -1; return -1;
}
} }
vec->pages[vec->length] = item;
vec->length++;
return 0; return 0;
} }
void vec_free(struct Vector* vec) { int vec_reserve(struct Vector *vec, size_t size) {
while(vec->length > 0) uint32_t new_capacity = vec->capacity;
while (vec->length + size > new_capacity) {
new_capacity = new_capacity + (new_capacity >> 1) + 1; // cap * 1.5 + 1; 0 1 2 4 7 11...
}
return vec_resize(vec, new_capacity);
}
int vec_reserve_exact(struct Vector *vec, size_t size) {
uint32_t needed_capacity = vec->length + size;
if (vec->capacity < needed_capacity) {
return vec_resize(vec, needed_capacity);
} else {
return 0;
}
}
int vec_push(struct Vector *vec, void *item) {
int res_ret = vec_reserve(vec, 1);
if(res_ret != 0) return res_ret;
vec->pages[vec->length++] = item;
return 0;
}
void vec_free(struct Vector *vec) {
while (vec->length > 0)
free(vec->pages[--vec->length]); free(vec->pages[--vec->length]);
vec_clear(vec); vec_clear(vec);
} }
void vec_clear(struct Vector* vec) { void vec_clear(struct Vector *vec) {
free(vec->pages); free(vec->pages);
vec_reset(vec); vec_reset(vec);
} }
void vec_reset(struct Vector* vec) { void vec_reset(struct Vector *vec) {
vec->length = 0; vec->length = 0;
vec->alloc_len = 0; vec->capacity = 0;
vec->alloc_size = 4096; // 4KiB page size?
vec->pages = NULL; vec->pages = NULL;
} }
void* vec_pop(struct Vector* vec) { void *vec_pop(struct Vector *vec) {
if (vec->length == 0) if (vec->length == 0)
return NULL; return NULL;
return vec->pages[--vec->length]; return vec->pages[--vec->length];
} }
void* vec_get(struct Vector* vec, size_t index) { void *vec_get(struct Vector *vec, size_t index) {
if (index >= vec->length) if (index >= vec->length)
return NULL; return NULL;