24 Commits

Author SHA1 Message Date
4fb2bb2d62 Merge pull request #26 from javalsai/env-fixes
feat: add behavior.{source,user_source} for custom env
2024-12-25 22:26:52 +01:00
2c283a14fe docs: threaten ppl to star 2024-12-25 20:32:18 +01:00
f34a71195e chore: use size_t for indexing and iterating 2024-12-25 20:22:28 +01:00
e13a8ff79c fix: #includes 👀 2024-12-25 20:16:25 +01:00
4c7d221a17 dev: use #includes according to error's concerns 2024-12-25 20:00:09 +01:00
6d9b02e6de grammer: codespell 🤓 2024-12-25 19:34:40 +01:00
f03656f509 chore: add basic source paths to default themes 2024-12-25 19:30:23 +01:00
9495bd5afe chore: write man pages 2024-12-25 19:28:31 +01:00
0ba5519937 feat: add behavior.{source,user_source} for custom env 2024-12-25 19:25:09 +01:00
1e0ffcdf2f Merge pull request #24 from javalsai/code-quality
Code quality & Fixes
2024-11-01 13:33:20 +01:00
b8caf5b7d7 chore: readable vec_pop 2024-11-01 13:28:32 +01:00
06fa419a6c fix: logic 👍 (tf was i thinking here?) 2024-11-01 13:25:38 +01:00
49e3ad528f add: safety bound checks for vec_get 2024-11-01 13:11:01 +01:00
d7bfa79284 finally fix? 2024-10-19 18:49:26 +02:00
6489df2e41 fix: idk lol, versions again? 2024-10-19 18:31:52 +02:00
ab6703416f fix: still fails (version?) 2024-10-19 18:16:40 +02:00
43447ca415 grammar 👍 (again) 2024-10-19 18:15:55 +02:00
2c606cda2c fix: ci builds (hopefully 🤞)
https://github.com/uraimo/run-on-arch-action/issues/152#issuecomment-2401981347
2024-10-19 18:12:49 +02:00
d30d5a8884 grammar 👍 2024-10-19 17:52:33 +02:00
a0b68491ba chore: implement vectors
also seems to address several of these:
https://github.com/javalsai/lidm/issues/3#issuecomment-2423933131

not sure about the issue itself, might be permission stuff
2024-10-19 17:50:50 +02:00
01ddd62852 chore: make specific vector (heap stack) impl 2024-10-18 21:54:39 +02:00
c586a48320 chore: remove make as it's part of base-devel 2024-10-13 13:54:56 +02:00
c4a996c1e8 ci: add AUR pkg updates PRs on release 2024-09-15 21:12:16 +02:00
9f32ce274b update: bump pkgbuild versions up
also added scripts to automate this better
2024-09-15 21:11:57 +02:00
36 changed files with 372 additions and 180 deletions

View File

@@ -1,2 +1,2 @@
[codespell]
skip = ./assets/pkg/aur/*/src
skip = ./assets/pkg/aur/*/src,./assets/pkg/aur/*/*/objects

View File

@@ -136,8 +136,9 @@ jobs:
- uses: uraimo/run-on-arch-action@v2
with:
arch: aarch64
distro: ubuntu22.04
arch: none
distro: none
base_image: '--platform=linux/aarch64 ubuntu:22.04'
githubToken: ${{ github.token }}
install: |
apt-get update && \
@@ -180,8 +181,9 @@ jobs:
- uses: uraimo/run-on-arch-action@v2
with:
arch: armv7
distro: ubuntu22.04
arch: none
distro: none
base_image: '--platform=linux/arm/v7 ubuntu:22.04'
githubToken: ${{ github.token }}
install: |
apt-get update && \
@@ -224,8 +226,9 @@ jobs:
- uses: uraimo/run-on-arch-action@v2
with:
arch: riscv64
distro: ubuntu22.04
arch: none
distro: none
base_image: '--platform=linux/riscv64 riscv64/ubuntu:22.04'
githubToken: ${{ github.token }}
install: |
apt-get update && \

View File

@@ -33,7 +33,37 @@ jobs:
tag: v${{ inputs.version }}
commit: ${{ github.sha }}
artifacts: builds/lidm-*
artifactsErrorsFailBuild: true
artifactErrorsFailBuild: true
body: Release notes not generated yet.
# TODO: get checksums and commit new AUR pkgbuilds
aur-update:
name: Update AUR pkgs
runs-on: ubuntu-24.04
container: archlinux:latest
permissions: write-all
needs: release
steps:
- run: pacman -Sy --noconfirm git github-cli base-devel pacman-contrib
- uses: actions/checkout@v4
- run: |
cd "assets/pkg/aur"
chown nobody:nobody . -R
su - -s /bin/bash nobody -c "$PWD/update-pkgs.sh ${{ inputs.version }}"
su - -s /bin/bash nobody -c "$PWD/test-makepkg.sh" # This will also update -git pkgver
chown $UID:$(id -g) . -R
- run: |
BRANCH=actions/update-aur-${{ inputs.version }}
git config --global --add safe.directory $GITHUB_WORKSPACE
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git checkout -b $BRANCH
git commit -am "Update AUR pkgs to v${{ inputs.version }}"
git push -u origin $BRANCH
gh pr create --head $BRANCH \
--title "[AUR update]: Bump to ${{ inputs.version }}" \
--body "*This PR was created automatically*"
env:
GH_TOKEN: ${{ github.token }}

View File

@@ -123,3 +123,9 @@ The name is just ly but changing "y" with "i", that had a reason but forgot it,
* cerealexperiments\_, found a missing newline (had the guts to read the source code, crazy ik)
* ChatGPT, in times of slow laptops where pages take ages to load, a single tab connected to a bunch of burning cloud GPUs feeding corporate hype is all you need to get quick answers for your questions, as long as you know how to filter AI crap ofc.
* [My lack of gf](https://www.instagram.com/reel/C8sa3Gltmtq), can't imagine this project being possible if somebody actually cared about me daily.
---
🌟 Finally, consider starring this repo or... 🔪
![star-history](https://api.star-history.com/svg?repos=javalsai/lidm&type=Date)

View File

@@ -73,6 +73,12 @@ Text to display as the header for such sessions.
.TP
\fBbehavior.include_defshell\fP
"true"/"false" (invalid input defaults to false), if true, includes the user default shell as a session to launch
.TP
\fBbehavior.source\fP
Specify paths to source on login, simple KEY=VALUE format with comments (#) or empty'ish lines, quoting or escape sequences not supported yet. It is NOT an array, but you rather assign to it multiple times.
.TP
\fBbehavior.user_source\fP
Same as \fIbehavior.source\fP but relative to user home (if present).
.SH "SEE ALSO"

View File

@@ -1,6 +1,6 @@
pkgbase = lidm-bin
pkgdesc = A fully colorful customizable TUI display manager made in C. (release binary)
pkgver = 0.0.2
pkgver = 0.1.0
pkgrel = 1
url = https://github.com/javalsai/lidm
arch = x86_64
@@ -9,13 +9,13 @@ pkgbase = lidm-bin
depends = pam
provides = lidm
conflicts = lidm
source = lidm::https://github.com/javalsai/lidm/releases/download/0.0.2/lidm-x86_64
source = default-theme.ini::https://raw.githubusercontent.com/javalsai/lidm/0.0.2/themes/default.ini
source = lidm.1::https://raw.githubusercontent.com/javalsai/lidm/0.0.2/assets/man/lidm.1
source = lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/0.0.2/assets/man/lidm-config.5
source = lidm::https://github.com/javalsai/lidm/releases/download/v0.1.0/lidm-amd64
source = default-theme.ini::https://raw.githubusercontent.com/javalsai/lidm/v0.1.0/themes/default.ini
source = lidm.1::https://raw.githubusercontent.com/javalsai/lidm/v0.1.0/assets/man/lidm.1
source = lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/v0.1.0/assets/man/lidm-config.5
sha256sums = b5d1dbdaa6b78da57be69ce5e2cc3366717a045de3cb316e66c1c3f36b796ee0
sha256sums = 27db9b0cd2da80c0c60dcb13dfad0f9d65e7dddbb7b344b859803b9ac3943cd7
sha256sums = SKIP
sha256sums = SKIP
sha256sums = a6807a55ff72ec5a5678583156b3efd0d367f0bcb79854094132771f0cb86bce
sha256sums = c44f78940212b946e157eac02e159b215376d291d11adfe4925b594405ad85da
pkgname = lidm-bin

View File

@@ -1,6 +1,7 @@
# shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164
# Maintainer: javalsai <javalsai@proton.me>
pkgname=lidm-bin
pkgver=0.0.2
pkgver=0.1.0
pkgrel=1
depends=('pam')
makedepends=('gzip')
@@ -11,22 +12,20 @@ license=('GPL')
provides=('lidm')
conflicts=('lidm')
source=(
"lidm::$url/releases/download/$pkgver/lidm-$arch"
"default-theme.ini::https://raw.githubusercontent.com/javalsai/lidm/$pkgver/themes/default.ini"
"lidm.1::https://raw.githubusercontent.com/javalsai/lidm/$pkgver/assets/man/lidm.1"
"lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/$pkgver/assets/man/lidm-config.5"
)
sha256sums=(
'b5d1dbdaa6b78da57be69ce5e2cc3366717a045de3cb316e66c1c3f36b796ee0'
'27db9b0cd2da80c0c60dcb13dfad0f9d65e7dddbb7b344b859803b9ac3943cd7'
'SKIP'
'SKIP'
"lidm::$url/releases/download/v$pkgver/lidm-amd64"
"default-theme.ini::https://raw.githubusercontent.com/javalsai/lidm/v$pkgver/themes/default.ini"
"lidm.1::https://raw.githubusercontent.com/javalsai/lidm/v$pkgver/assets/man/lidm.1"
"lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/v$pkgver/assets/man/lidm-config.5"
)
sha256sums=('b5d1dbdaa6b78da57be69ce5e2cc3366717a045de3cb316e66c1c3f36b796ee0'
'27db9b0cd2da80c0c60dcb13dfad0f9d65e7dddbb7b344b859803b9ac3943cd7'
'a6807a55ff72ec5a5678583156b3efd0d367f0bcb79854094132771f0cb86bce'
'c44f78940212b946e157eac02e159b215376d291d11adfe4925b594405ad85da')
package() {
install -Dm755 lidm "${pkgdir}/usr/bin/lidm"
install -Dm644 default-theme.ini "${pkgdir}/etc/lidm.ini"
install -Dm644 lidm.1 "${pkgdir}/usr/share/man/man1/"
install -Dm644 lidm-config.5 "${pkgdir}/usr/share/man/man5/"
gzip -f "${pkgdir}"/share/man/man{1/lidm.1,5/lidm-config.5}
install -Dm644 lidm.1 "${pkgdir}/usr/share/man/man1/lidm.1"
install -Dm644 lidm-config.5 "${pkgdir}/usr/share/man/man5/lidm-config.5"
gzip -f "${pkgdir}"/usr/share/man/man{1/lidm.1,5/lidm-config.5}
}

View File

@@ -1,6 +1,6 @@
pkgbase = lidm-git
pkgdesc = A fully colorful customizable TUI display manager made in C. (last git commit)
pkgver = 0.0.2.r37.gf1f9d6b
pkgver = 0.1.0.r0.g8071694
pkgrel = 1
url = https://github.com/javalsai/lidm
arch = any

View File

@@ -1,6 +1,7 @@
# shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164
# Maintainer: javalsai <javalsai@proton.me>
pkgname=lidm-git
pkgver=0.0.2.r37.gf1f9d6b
pkgver=0.1.0.r0.g8071694
pkgrel=1
depends=('pam')
makedepends=('git' 'make' 'gcc')

View File

@@ -1,16 +1,15 @@
pkgbase = lidm
pkgdesc = A fully colorful customizable TUI display manager made in C. (build latest tag)
pkgver = 0.0.2
pkgrel = 1
pkgver = 0.1.0
pkgrel = 2
url = https://github.com/javalsai/lidm
arch = any
license = GPL
makedepends = git
makedepends = make
makedepends = gcc
makedepends = gzip
depends = pam
source = tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/0.0.2.tar.gz
sha256sums = adf2d196969f6a2df8ceeb3564e1d51cc377f0deaeca31fee0bace58a3d2df2d
source = tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/v0.1.0.tar.gz
sha256sums = de1981603f3fa54caacfcd68cc07d650c186990175baf210ba5275d6450e5030
pkgname = lidm

View File

@@ -1,15 +1,16 @@
# shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164
# Maintainer: javalsai <javalsai@proton.me>
pkgname=lidm
pkgver=0.0.2
pkgrel=1
pkgver=0.1.0
pkgrel=2
depends=('pam')
makedepends=('git' 'make' 'gcc' 'gzip')
makedepends=('git' 'gcc' 'gzip')
pkgdesc="A fully colorful customizable TUI display manager made in C. (build latest tag)"
arch=('any')
url="https://github.com/javalsai/lidm"
license=('GPL')
source=("tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/$pkgver.tar.gz")
sha256sums=('adf2d196969f6a2df8ceeb3564e1d51cc377f0deaeca31fee0bace58a3d2df2d')
source=("tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/v$pkgver.tar.gz")
sha256sums=('de1981603f3fa54caacfcd68cc07d650c186990175baf210ba5275d6450e5030')
build() {
tar -xzf "tarball.tar.gz"

22
assets/pkg/aur/update-pkgs.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -e
MYSELF=$(realpath "$0")
MYDIR=$(dirname "$MYSELF")
if [ -z "$1" ]; then
printf "\x1b[1;31mERR: No version to update provided\x1b[0m\n" >&2
exit 1;
fi
version="$1"
printf "\x1b[34mINF: Using '%s' version\x1b[0m\n" "$version"
for pkg in "$MYDIR"/lidm{,-bin}/; do
cd "$pkg"
printf "\x1b[1mEntering '%s'\x1b[0m\n" "$pkg"
sed -i "s/pkgver=.*/pkgver=$1/" PKGBUILD
sed -i "s/pkgrel=.*/pkgrel=1/" PKGBUILD
updpkgsums
makepkg --printsrcinfo | tee .SRCINFO
echo
done

View File

@@ -3,8 +3,9 @@
#include <stdbool.h>
#include <sessions.h>
#include "config.h"
#include "sessions.h"
bool launch(char *user, char *passwd, struct session session, void (*cb)(void));
bool launch(char *user, char *passwd, struct session session, void (*cb)(void), struct behavior* behavior);
#endif

View File

@@ -4,9 +4,8 @@
#include <stdbool.h>
#include <stdio.h>
#include <keys.h>
#include <sessions.h>
#include <users.h>
#include "keys.h"
#include "util.h"
// should be ansi escape codes under \x1b[...m
// if not prepared accordingly, it might break
@@ -63,6 +62,8 @@ struct strings {
struct behavior {
bool include_defshell;
struct Vector source;
struct Vector user_source;
};
struct config {

View File

@@ -3,6 +3,8 @@
#include <sys/types.h>
#include "util.h"
enum session_type {
XORG,
WAYLAND,
@@ -16,11 +18,6 @@ struct session {
enum session_type type;
};
struct sessions_list {
u_int16_t length;
struct session *sessions;
};
struct sessions_list *get_avaliable_sessions();
struct Vector get_avaliable_sessions();
#endif

View File

@@ -1,10 +1,11 @@
#ifndef _UIH_
#define _UIH_
#include <config.h>
#include "config.h"
#include "util.h"
void setup(struct config);
int load(struct users_list *, struct sessions_list *);
int load(struct Vector * users, struct Vector * sessions);
void print_err(const char *);
void print_errno(const char *);

View File

@@ -3,17 +3,14 @@
#include <sys/types.h>
#include "util.h"
struct user {
char *shell;
char *username;
char *display_name;
};
struct users_list {
u_int16_t length;
struct user *users;
};
struct users_list *get_human_users();
struct Vector get_human_users();
#endif

View File

@@ -1,13 +1,31 @@
#ifndef _UTILH_
#define _UTILH_
#include <keys.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#include "keys.h"
enum keys find_keyname(char *);
enum keys find_ansi(char *);
void read_press(u_char *, char *);
void strcln(char **dest, const char *source);
struct Vector {
uint32_t length;
uint32_t alloc_len;
uint16_t alloc_size;
void** pages;
};
struct Vector vec_new();
int vec_push(struct Vector*, void* item);
void vec_free(struct Vector*);
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

View File

@@ -1,22 +1,25 @@
#include <grp.h>
#include <pwd.h>
#include <security/pam_misc.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <auth.h>
#include <sessions.h>
#include <ui.h>
#include <unistd.h>
#include <util.h>
#include "auth.h"
#include "config.h"
#include "sessions.h"
#include "ui.h"
#include "unistd.h"
#include "util.h"
int pam_conversation(int num_msg, const struct pam_message **msg,
struct pam_response **resp, void *appdata_ptr) {
struct pam_response *reply =
(struct pam_response *)malloc(sizeof(struct pam_response) * num_msg);
for (int i = 0; i < num_msg; i++) {
for (size_t i = 0; i < num_msg; i++) {
reply[i].resp = NULL;
reply[i].resp_retcode = 0;
if (msg[i]->msg_style == PAM_PROMPT_ECHO_OFF ||
@@ -59,7 +62,40 @@ void *shmalloc(size_t size) {
-1, 0);
}
void moarEnv(char *user, struct session session, struct passwd *pw) {
void sourceFileTry(char *file) {
FILE *file2source = fopen(file, "r");
if (file2source == NULL)
return;
char *line = NULL;
size_t len = 0;
ssize_t read;
while ((read = getline(&line, &len, file2source)) != -1) {
if (read == 0 || (read > 0 && *line == '#'))
continue;
if (line[read - 1] == '\n')
line[read - 1] = '\0';
/* printf("Retrieved line of length %zu:\n", read); */
/* printf("%s\n", line); */
for (size_t i = 1; i < read; i++) {
if (line[i] == '=') {
/* printf("FOUND '='!\n"); */
line[i] = '\0';
setenv(line, &line[i + 1], 1);
break;
}
}
}
if (line)
free(line);
fclose(file2source);
}
void moarEnv(char *user, struct session session, struct passwd *pw,
struct behavior *behavior) {
if (chdir(pw->pw_dir) == -1)
print_errno("can't chdir to user home");
@@ -81,6 +117,31 @@ void moarEnv(char *user, struct session session, struct passwd *pw) {
xdg_session_type = "wayland";
setenv("XDG_SESSION_TYPE", xdg_session_type, true);
printf("\n\n\n\n\x1b[1m");
for (size_t i = 0; i < behavior->source.length; i++) {
/* printf("DEBUG(source)!!!! %d %s\n", i, (char*)vec_get(&behavior->source,
* i)); */
sourceFileTry((char *)vec_get(&behavior->source, i));
}
/* printf("\n"); */
if (pw->pw_dir) {
uint home_len = strlen(pw->pw_dir);
for (size_t i = 0; i < behavior->user_source.length; i++) {
char *file2sourcepath = (char *)vec_get(&behavior->user_source, i);
char *newbuf =
malloc(home_len + strlen(file2sourcepath) + 2); // nullbyte and slash
if (newbuf == NULL)
continue; // can't bother
strcpy(newbuf, pw->pw_dir);
newbuf[home_len] = '/'; // assume pw_dir doesn't start with '/' :P
strcpy(&newbuf[home_len + 1], file2sourcepath);
/* printf("DEBUG(user_source)!!!! %d %s\n", i, newbuf); */
sourceFileTry(newbuf);
free(newbuf);
}
}
/*char *buf;*/
/*size_t bsize = snprintf(NULL, 0, "/run/user/%d", pw->pw_uid) + 1;*/
/*buf = malloc(bsize);*/
@@ -92,8 +153,8 @@ void moarEnv(char *user, struct session session, struct passwd *pw) {
/*setenv("XDG_SEAT", "seat0", true);*/
}
bool launch(char *user, char *passwd, struct session session,
void (*cb)(void)) {
bool launch(char *user, char *passwd, struct session session, void (*cb)(void),
struct behavior *behavior) {
struct passwd *pw = getpwnam(user);
if (pw == NULL) {
print_err("could not get user info");
@@ -129,7 +190,7 @@ bool launch(char *user, char *passwd, struct session session,
print_errno("pam_getenvlist");
_exit(EXIT_FAILURE);
}
for (uint i = 0; envlist[i] != NULL; i++) {
for (size_t i = 0; envlist[i] != NULL; i++) {
putenv(envlist[i]);
}
// FIXME: path hotfix
@@ -140,7 +201,7 @@ bool launch(char *user, char *passwd, struct session session,
}
free(envlist);
moarEnv(user, session, pw);
moarEnv(user, session, pw, behavior);
// TODO: chown stdin to user
// does it inherit stdin from parent and
@@ -168,11 +229,14 @@ bool launch(char *user, char *passwd, struct session session,
// TODO: these will be different due to TryExec
// and, Exec/TryExec might contain spaces as args
printf("\x1b[0m");
if (session.type == SHELL) {
clear_screen();
fflush(stdout);
execlp(session.exec, session.exec, NULL);
} else if (session.type == XORG || session.type == WAYLAND) {
clear_screen();
fflush(stdout);
execlp(session.exec, session.exec, NULL);
}
perror("execl error");

View File

@@ -3,7 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <chvt.h>
#include "chvt.h"
static char *vterms[] = {"/dev/tty", "/dev/tty0", "/dev/vc/0", "/dev/systty",
"/dev/console"};
@@ -26,7 +26,7 @@ int chvt_str(char *str) {
int chvt(int n) {
fprintf(stderr, "activating vt %d\n", n);
char c = 0;
for (int i = 0; i < sizeof(vterms) / sizeof(vterms[0]); i++) {
for (size_t i = 0; i < sizeof(vterms) / sizeof(vterms[0]); i++) {
int fd = open(vterms[i], O_RDWR);
if (fd >= 0 && isatty(fd) && ioctl(fd, KDGKBTYPE, &c) == 0 && c < 3) {
if (ioctl(fd, VT_ACTIVATE, n) < 0 || ioctl(fd, VT_WAITACTIVE, n) < 0) {

View File

@@ -1,8 +1,8 @@
#include "util.h"
#include <string.h>
#include <sys/stat.h>
#include <config.h>
#include "config.h"
#include "util.h"
bool line_parser(FILE *fd, ssize_t *blksize,
u_char (*cb)(char *key, char *value)) {
@@ -109,6 +109,10 @@ u_char config_line_handler(char *k, char *v) {
__config->strings.s_shell = v;
else if (strcmp(k, "behavior.include_defshell") == 0)
__config->behavior.include_defshell = strcmp(v, "true") == 0;
else if (strcmp(k, "behavior.source") == 0)
vec_push(&__config->behavior.source, v);
else if (strcmp(k, "behavior.user_source") == 0)
vec_push(&__config->behavior.user_source, v);
else
return 0b1111;
@@ -124,6 +128,9 @@ struct config *parse_config(char *path) {
}
__config = malloc(sizeof(struct config));
__config->behavior.source = vec_new();
__config->behavior.user_source = vec_new();
if (__config == NULL)
return NULL;
bool ret = line_parser(fd, (ssize_t *)&sb.st_blksize, config_line_handler);

View File

@@ -1,7 +1,7 @@
#include <string.h>
#include <efield.h>
#include <ui.h>
#include "efield.h"
#include "ui.h"
struct editable_field field_new(char *content) {
struct editable_field __efield;

View File

@@ -4,11 +4,12 @@
#include <sys/types.h>
#include <unistd.h>
#include <chvt.h>
#include <config.h>
#include <sessions.h>
#include <ui.h>
#include <users.h>
#include "chvt.h"
#include "config.h"
#include "sessions.h"
#include "ui.h"
#include "users.h"
#include "util.h"
int main(int argc, char *argv[]) {
if (argc == 2)
@@ -23,10 +24,10 @@ int main(int argc, char *argv[]) {
}
setup(*config);
struct users_list *users = get_human_users();
struct sessions_list *sessions = get_avaliable_sessions();
struct Vector users = get_human_users();
struct Vector sessions = get_avaliable_sessions();
int ret = load(users, sessions);
int ret = load(&users, &sessions);
if (ret == 0)
execl(argv[0], argv[0], NULL);
}

View File

@@ -7,8 +7,8 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sessions.h>
#include <util.h>
#include "sessions.h"
#include "util.h"
struct source_dir {
enum session_type type;
@@ -18,7 +18,6 @@ static const struct source_dir sources[] = {
{XORG, "/usr/share/xsessions"},
{WAYLAND, "/usr/share/wayland-sessions"},
};
static const size_t sources_size = sizeof(sources) / sizeof(sources[0]);
static struct session __new_session(enum session_type type, char *name,
const char *exec, const char *tryexec) {
@@ -31,24 +30,12 @@ static struct session __new_session(enum session_type type, char *name,
return __session;
}
static const u_int8_t bs = 16;
static const u_int8_t unit_size = sizeof(struct session);
static u_int16_t alloc_size = bs;
static u_int16_t used_size = 0;
static struct session *sessions = NULL;
static struct sessions_list *__sessions_list = NULL;
static struct Vector *cb_sessions = NULL;
// NOTE: commented printf's here would be nice to have debug logs if I ever
// implement it
static enum session_type session_type;
static int fn(const char *fpath, const struct stat *sb, int typeflag) {
// practically impossible to reach this
// but will prevent break
if (used_size == 0xffff)
return 0;
if (sb == NULL || !S_ISREG(sb->st_mode))
return 0;
@@ -56,7 +43,7 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
FILE *fd = fopen(fpath, "r");
if (fd == NULL) {
perror("fopen");
fprintf(stderr, "error opening file (r) %s\n", fpath);
fprintf(stderr, "error opening file (r) '%s'\n", fpath);
return 0;
}
@@ -66,8 +53,8 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
char *name_buf = NULL;
char *exec_buf = NULL;
char *tryexec_buf = NULL;
// This should be made a specific function
while (true) {
/*printf(".");*/
char *buf = malloc(sb->st_blksize);
ssize_t read_size = getline(&buf, &alloc_size, fd);
if (read_size == -1) {
@@ -102,17 +89,10 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
// just add this to the list
if (name_buf != NULL && exec_buf != NULL) {
/*printf("gonna add to session list\n");*/
if (used_size >= alloc_size) {
alloc_size += bs;
sessions = realloc(sessions, alloc_size * unit_size);
}
/*printf("n %s\ne %s\nte %s\n", name_buf, exec_buf, tryexec_buf);*/
sessions[used_size] = __new_session(session_type, name_buf, exec_buf,
tryexec_buf == NULL ? "" : tryexec_buf);
used_size++;
struct session *session_i = malloc(sizeof (struct session));
*session_i = __new_session(session_type, name_buf, exec_buf,
tryexec_buf == NULL ? "" : tryexec_buf);
vec_push(cb_sessions, session_i);
}
if (name_buf != NULL)
@@ -125,23 +105,17 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
return 0;
}
static struct sessions_list __list;
// This code is designed to be run purely single threaded
struct sessions_list *get_avaliable_sessions() {
if (sessions != NULL)
return __sessions_list;
else
sessions = malloc(alloc_size * unit_size);
struct Vector get_avaliable_sessions() {
struct Vector sessions = vec_new();
for (uint i = 0; i < sources_size; i++) {
session_type = sources[i].type;
cb_sessions = &sessions;
for (size_t i = 0; i < (sizeof(sources) / sizeof(sources[0])); i++) {
/*printf("recurring into %s\n", sources[i].dir);*/
session_type = sources[i].type;
ftw(sources[i].dir, &fn, 1);
}
cb_sessions = NULL;
sessions = realloc(sessions, used_size * unit_size);
__list.length = used_size;
__list.sessions = sessions;
return __sessions_list = &__list;
return sessions;
}

View File

@@ -10,17 +10,19 @@
#include <string.h>
#include <sys/ioctl.h>
#include <sys/reboot.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <auth.h>
#include <efield.h>
#include <keys.h>
#include <sessions.h>
#include <ui.h>
#include <util.h>
#include "auth.h"
#include "efield.h"
#include "keys.h"
#include "sessions.h"
#include "ui.h"
#include "users.h"
#include "util.h"
static void print_box();
static void print_footer();
@@ -179,8 +181,8 @@ struct opt_field of_session;
struct opt_field of_user;
struct opt_field of_passwd;
struct users_list *gusers;
struct sessions_list *gsessions;
struct Vector *gusers;
struct Vector *gsessions;
// not *that* OF tho
struct opt_field *get_of(enum input from) {
@@ -217,7 +219,7 @@ void ffield_cursor_focus() {
struct user get_current_user() {
if (of_user.current_opt != 0)
return gusers->users[of_user.current_opt - 1];
return *(struct user*)vec_get(gusers, of_user.current_opt - 1);
else {
struct user custom_user;
custom_user.shell = "/usr/bin/bash";
@@ -237,7 +239,7 @@ struct session get_current_session() {
shell_session.exec = shell_session.name = get_current_user().shell;
return shell_session;
} else
return gsessions->sessions[of_session.current_opt - 1];
return *(struct session*)vec_get(gsessions, of_session.current_opt - 1);
} else {
struct session custom_session;
custom_session.type = SHELL;
@@ -320,7 +322,7 @@ void ffield_type(char *text) {
print_ffield();
}
int load(struct users_list *users, struct sessions_list *sessions) {
int load(struct Vector *users, struct Vector *sessions) {
/// SETUP
gusers = users;
gsessions = sessions;
@@ -394,7 +396,7 @@ int load(struct users_list *users, struct sessions_list *sessions) {
} else {
if (len == 1 && *seq == '\n') {
if (!launch(get_current_user().username, of_passwd.efield.content,
get_current_session(), &restore_all)) {
get_current_session(), &restore_all, &behavior)) {
print_passwd(box_start(), of_passwd.efield.length, true);
ffield_cursor_focus();
}
@@ -498,15 +500,15 @@ static void print_passwd(struct uint_point origin, uint length, bool err) {
}
static void print_empty_row(uint w, uint n, char *edge1, char *edge2) {
for (uint i = 0; i < n; i++) {
for (size_t i = 0; i < n; i++) {
printf("%s\x1b[%dC%s\x1b[%dD\x1b[1B", edge1, w, edge2, w + 2);
}
}
static void print_row(uint w, uint n, char *edge1, char *edge2, char *filler) {
for (uint i = 0; i < n; i++) {
for (size_t i = 0; i < n; i++) {
printf("%s", edge1);
for (uint i = 0; i < w; i++) {
for (size_t i = 0; i < w; i++) {
printf("%s", filler);
}
printf("%s\x1b[%dD\x1b[1B", edge2, w + 2);

View File

@@ -5,8 +5,8 @@
#include <string.h>
#include <sys/types.h>
#include <users.h>
#include <util.h>
#include "users.h"
#include "util.h"
static struct user __new_user(struct passwd *p) {
struct user __user;
@@ -20,43 +20,19 @@ static struct user __new_user(struct passwd *p) {
return __user;
}
static const u_int8_t bs = 16;
static const u_int8_t unit_size = sizeof(struct user);
static u_int16_t alloc_size = bs;
static u_int16_t used_size = 0;
static struct user *users = NULL;
static struct users_list *__users_list = NULL;
struct users_list __list;
// This code is designed to be run purely single threaded
struct users_list *get_human_users() {
if (users != NULL)
return __users_list;
else
users = malloc(alloc_size * unit_size);
struct Vector get_human_users() {
struct Vector users = vec_new();
struct passwd *pwd;
while ((pwd = getpwent()) != NULL) {
// practically impossible to reach this (== 0xffff)
// but will prevent break
if (used_size == 0xffff ||
!(pwd->pw_dir && strncmp(pwd->pw_dir, "/home/", 6) == 0))
if (!(pwd->pw_dir && strncmp(pwd->pw_dir, "/home/", 6) == 0))
continue;
if (used_size >= alloc_size) {
alloc_size += bs;
users = realloc(users, alloc_size * unit_size);
}
users[used_size] = __new_user(pwd);
used_size++;
struct user *user_i = malloc(sizeof(struct user));
*user_i = __new_user(pwd);
vec_push(&users, user_i);
}
users = realloc(users, used_size * unit_size);
__list.length = used_size;
__list.users = users;
return __users_list = &__list;
return users;
}

View File

@@ -1,12 +1,13 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <keys.h>
#include <ui.h>
#include <util.h>
#include "keys.h"
#include "ui.h"
#include "util.h"
static int selret_magic();
@@ -66,3 +67,61 @@ static int selret_magic() {
timeout.tv_usec = 0;
return select(1, &set, NULL, NULL, &timeout);
}
// Vector shii
struct Vector vec_new() {
struct Vector vec;
vec_clear(&vec);
return vec;
}
int vec_push(struct Vector* vec, void* item) {
if (vec->length >= vec->alloc_len) {
uint32_t new_size = vec->alloc_len + vec->alloc_size;
void **new_location = realloc(vec->pages, vec->alloc_size);
if (new_location != NULL) {
vec->alloc_size = new_size;
vec->pages = new_location;
} else {
return -1;
}
}
vec->pages[vec->length] = item;
vec->length++;
return 0;
}
void vec_free(struct Vector* vec) {
while(vec->length > 0)
free(vec->pages[--vec->length]);
vec_clear(vec);
}
void vec_clear(struct Vector* vec) {
free(vec->pages);
vec_reset(vec);
}
void vec_reset(struct Vector* vec) {
vec->length = 0;
vec->alloc_len = 0;
vec->alloc_size = 4096; // 4KiB page size?
vec->pages = NULL;
}
void* vec_pop(struct Vector* vec) {
if (vec->length == 0)
return NULL;
return vec->pages[--vec->length];
}
void* vec_get(struct Vector* vec, size_t index) {
if (index >= vec->length)
return NULL;
return vec->pages[index];
}

View File

@@ -30,3 +30,6 @@ strings.s_wayland = wayland
strings.s_xorg = xorg
strings.s_shell = shell
behavior.include_defshell = true
behavior.source = /etc/lidm.env
behavior.source = /etc/locale.conf
behavior.user_source = .lidm.env

View File

@@ -30,3 +30,6 @@ strings.s_wayland = wayland
strings.s_xorg = xorg
strings.s_shell = shell
behavior.include_defshell = true
behavior.source = /etc/lidm.env
behavior.source = /etc/locale.conf
behavior.user_source = .lidm.env

View File

@@ -30,3 +30,6 @@ strings.s_wayland = wayland
strings.s_xorg = xorg
strings.s_shell = shell
behavior.include_defshell = true
behavior.source = /etc/lidm.env
behavior.source = /etc/locale.conf
behavior.user_source = .lidm.env

View File

@@ -30,3 +30,6 @@ strings.s_wayland = wayland
strings.s_xorg = xorg
strings.s_shell = shell
behavior.include_defshell = true
behavior.source = /etc/lidm.env
behavior.source = /etc/locale.conf
behavior.user_source = .lidm.env

View File

@@ -30,3 +30,6 @@ strings.s_wayland = wayland
strings.s_xorg = xorg
strings.s_shell = shell
behavior.include_defshell = true
behavior.source = /etc/lidm.env
behavior.source = /etc/locale.conf
behavior.user_source = .lidm.env

View File

@@ -30,3 +30,6 @@ strings.s_wayland = wayland
strings.s_xorg = xorg
strings.s_shell = shell
behavior.include_defshell = true
behavior.source = /etc/lidm.env
behavior.source = /etc/locale.conf
behavior.user_source = .lidm.env

View File

@@ -30,3 +30,6 @@ strings.s_wayland = wayland
strings.s_xorg = xorg
strings.s_shell = shell
behavior.include_defshell = true
behavior.source = /etc/lidm.env
behavior.source = /etc/locale.conf
behavior.user_source = .lidm.env

View File

@@ -30,3 +30,6 @@ strings.s_wayland = waywand
strings.s_xorg = xworg
strings.s_shell = swell
behavior.include_defshell = true
behavior.source = /etc/lidm.env
behavior.source = /etc/locale.conf
behavior.user_source = .lidm.env

View File

@@ -30,3 +30,6 @@ strings.s_wayland = wayland
strings.s_xorg = xorg
strings.s_shell = shell
behavior.include_defshell = true
behavior.source = /etc/lidm.env
behavior.source = /etc/locale.conf
behavior.user_source = .lidm.env