mirror of
https://github.com/javalsai/lidm.git
synced 2026-02-27 03:50:44 +01:00
fixes: improve login environment handling (#114)
* chore(organization): allow nested header and c files * feat: add shell login "middleware" & etc: * lidm now calls `bash` (or other shells, depends on PACKAGE cfg) in login mode as a session wrapper to source most env (can be disabled) * this fixes a lot of env problems with all `/etc/profile` and more Extra: * implemented a musl compatible version of `execvpe` and now lidm should search for PATH everywhere it needs to * `search_path` now also checks if the found binary is properly executable * lidm now uses `confstr` for a decent PATH default if none is found * logs are unbuffered for cases where debug logs appear empty (exit without handlers moment) * chore: one-time evaluate certain makefile vars --------- Co-authored-by: grialion <48643945+grialion@users.noreply.github.com>
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "keys.h"
|
||||
#include "macros.h"
|
||||
#include "util.h"
|
||||
#include "util/vec.h"
|
||||
|
||||
enum IntrospectionType {
|
||||
STRING,
|
||||
@@ -122,7 +122,8 @@ BUILD(strings, STRINGS, TABLE_STRINGS);
|
||||
F(struct Vector, source, STRING_ARRAY, NULL_VEC, name) \
|
||||
F(struct Vector, user_source, STRING_ARRAY, NULL_VEC, name) \
|
||||
F(char* NNULLABLE, timefmt, STRING, "%X %x", name) \
|
||||
F(long long, refresh_rate, NUMBER, 100, name)
|
||||
F(long long, refresh_rate, NUMBER, 100, name) \
|
||||
F(bool, bypass_shell_login, BOOL, false, name)
|
||||
|
||||
BUILD(behavior, BEHAVIOR, TABLE_BEHAVIOR);
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
|
||||
#include "macros.h"
|
||||
|
||||
char* NULLABLE search_path(const char* NNULLABLE for_binary);
|
||||
int execvpe_desktop(char** args, char* NNULLABLE* NNULLABLE envlist);
|
||||
char* NULLABLE desktop_as_cmdline(char** args);
|
||||
int parse_exec_string(const char* exec_s, int* arg_count, char*** args);
|
||||
void free_parsed_args(int arg_count, char** args);
|
||||
|
||||
|
||||
@@ -2,16 +2,17 @@
|
||||
#define EFIELDH_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
// holds also the max string buffer in itself, not dynamic
|
||||
struct editable_field {
|
||||
u_char pos;
|
||||
uint8_t pos;
|
||||
char content[255];
|
||||
};
|
||||
|
||||
struct editable_field efield_new(char* content);
|
||||
void efield_trim(struct editable_field* self, u_char pos);
|
||||
void efield_trim(struct editable_field* self, uint8_t pos);
|
||||
void efield_update(struct editable_field* self, char* update);
|
||||
bool efield_seek(struct editable_field* self, char seek);
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#ifndef KEYSH_
|
||||
#define KEYSH_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
enum Keys {
|
||||
ESC,
|
||||
@@ -103,4 +106,15 @@ static const struct key_mapping KEY_MAPPINGS[] = {
|
||||
{PAGE_DOWN, {"\x1b[6~", NULL}},
|
||||
};
|
||||
|
||||
struct option_keys {
|
||||
bool is_some;
|
||||
enum Keys key;
|
||||
};
|
||||
|
||||
int find_keyname(enum Keys* at, const char* name);
|
||||
struct option_keys find_ansi(const char* seq);
|
||||
void read_press(uint8_t* length, char* out);
|
||||
// non blocking, waits up to tv or interrupt, returns true if actually read
|
||||
bool read_press_nb(uint8_t* length, char* out, struct timeval* tv);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -18,6 +18,6 @@ void ofield_kbd_type(struct opts_field* self, char* typed, char* empty_default);
|
||||
bool ofield_opts_seek(struct opts_field* self, char seek);
|
||||
bool ofield_seek(struct opts_field* self, char seek);
|
||||
|
||||
u_char ofield_display_cursor_col(struct opts_field* self, u_char maxlen);
|
||||
uint8_t ofield_display_cursor_col(struct opts_field* self, uint8_t maxlen);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,9 +4,8 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "desktop_exec.h"
|
||||
#include "macros.h"
|
||||
#include "util.h"
|
||||
#include "util/vec.h"
|
||||
|
||||
enum SessionType {
|
||||
XORG,
|
||||
@@ -51,18 +50,6 @@ static inline struct session_exec session_exec_desktop(
|
||||
};
|
||||
}
|
||||
|
||||
static inline int session_exec_exec(struct session_exec* NNULLABLE exec,
|
||||
char* NULLABLE* NNULLABLE envlist) {
|
||||
switch (exec->typ) {
|
||||
case EXEC_SHELL:
|
||||
return execle(exec->shell, exec->shell, NULL, envlist);
|
||||
case EXEC_DESKTOP:
|
||||
return execvpe_desktop(exec->desktop.args, envlist);
|
||||
default:
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
struct session {
|
||||
char* NNULLABLE name;
|
||||
struct session_exec exec;
|
||||
@@ -70,5 +57,9 @@ struct session {
|
||||
};
|
||||
|
||||
struct Vector get_avaliable_sessions();
|
||||
int session_exec_exec(struct session_exec* NNULLABLE exec,
|
||||
char* NULLABLE* NNULLABLE envp);
|
||||
int session_exec_login_through_shell(struct session_exec* NNULLABLE exec,
|
||||
char* NULLABLE* NNULLABLE envp);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "ofield.h"
|
||||
#include "util.h"
|
||||
#include "util/vec.h"
|
||||
|
||||
// [box_start]
|
||||
// ↓
|
||||
@@ -40,7 +40,7 @@
|
||||
#define VALUE_MAXLEN (BOX_WIDTH - VALUES_COL + 1 - BOX_HMARGIN - 2)
|
||||
|
||||
enum Input { SESSION, USER, PASSWD };
|
||||
extern const u_char INPUTS_N;
|
||||
extern const uint8_t INPUTS_N;
|
||||
|
||||
void setup(struct config* config);
|
||||
int load(struct Vector* users, struct Vector* sessions);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "util/vec.h"
|
||||
|
||||
struct user {
|
||||
char* shell;
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#ifndef UTILH_
|
||||
#define UTILH_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "keys.h"
|
||||
|
||||
int find_keyname(enum Keys* at, const char* name);
|
||||
struct option_keys {
|
||||
bool is_some;
|
||||
enum Keys key;
|
||||
};
|
||||
struct option_keys find_ansi(const char* seq);
|
||||
void read_press(u_char* length, char* out);
|
||||
// non blocking, waits up to tv or interrupt, returns true if actually read
|
||||
bool read_press_nb(u_char* length, char* out, struct timeval* tv);
|
||||
|
||||
// UTF8
|
||||
//
|
||||
bool utf8_iscont(char byte);
|
||||
size_t utf8len(const char* str);
|
||||
size_t utf8len_until(const char* str, const char* until);
|
||||
size_t utf8trunc(char* str, size_t n);
|
||||
const char* utf8back(const char* str);
|
||||
const char* utf8seek(const char* str);
|
||||
const char* utf8seekn(const char* str, size_t n);
|
||||
|
||||
// Vector
|
||||
//
|
||||
struct Vector {
|
||||
uint32_t length;
|
||||
uint32_t capacity;
|
||||
void** pages;
|
||||
};
|
||||
|
||||
struct Vector vec_from_raw(void** raw);
|
||||
void** vec_as_raw(struct Vector self);
|
||||
extern const struct Vector VEC_NEW;
|
||||
int vec_resize(struct Vector* self, size_t size);
|
||||
int vec_reserve(struct Vector* self, size_t size);
|
||||
int vec_reserve_exact(struct Vector* self, size_t size);
|
||||
int vec_push(struct Vector* self, void* item);
|
||||
void vec_free(struct Vector* self);
|
||||
void vec_clear(struct Vector* self);
|
||||
void vec_reset(struct Vector* self);
|
||||
void* vec_pop(struct Vector* self); // won't free it, nor shrink vec list space
|
||||
void* vec_get(struct Vector* self, size_t index);
|
||||
|
||||
#endif
|
||||
10
include/util/path.h
Normal file
10
include/util/path.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef UTIL_PATH_H
|
||||
#define UTIL_PATH_H
|
||||
|
||||
#include "macros.h"
|
||||
|
||||
char* NULLABLE search_path(const char* NNULLABLE for_binary);
|
||||
int execvpe(const char* NNULLABLE file, char* NULLABLE const argv[NNULLABLE],
|
||||
char* NULLABLE const envp[NNULLABLE]);
|
||||
|
||||
#endif /* UTIL_PATH_H */
|
||||
15
include/util/utf8.h
Normal file
15
include/util/utf8.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef UTIL_UTF8_H
|
||||
#define UTIL_UTF8_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
bool utf8_iscont(char byte);
|
||||
size_t utf8len(const char* str);
|
||||
size_t utf8len_until(const char* str, const char* until);
|
||||
size_t utf8trunc(char* str, size_t n);
|
||||
const char* utf8back(const char* str);
|
||||
const char* utf8seek(const char* str);
|
||||
const char* utf8seekn(const char* str, size_t n);
|
||||
|
||||
#endif /* UTIL_UTF8_H */
|
||||
26
include/util/vec.h
Normal file
26
include/util/vec.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef UTIL_VEC_H
|
||||
#define UTIL_VEC_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct Vector {
|
||||
uint32_t length;
|
||||
uint32_t capacity;
|
||||
void** pages;
|
||||
};
|
||||
|
||||
struct Vector vec_from_raw(void** raw);
|
||||
void** vec_as_raw(struct Vector self);
|
||||
extern const struct Vector VEC_NEW;
|
||||
int vec_resize(struct Vector* self, size_t size);
|
||||
int vec_reserve(struct Vector* self, size_t size);
|
||||
int vec_reserve_exact(struct Vector* self, size_t size);
|
||||
int vec_push(struct Vector* self, void* item);
|
||||
void vec_free(struct Vector* self);
|
||||
void vec_clear(struct Vector* self);
|
||||
void vec_reset(struct Vector* self);
|
||||
void* vec_pop(struct Vector* self); // won't free it, nor shrink vec list space
|
||||
void* vec_get(struct Vector* self, size_t index);
|
||||
|
||||
#endif /* UTIL_VEC_H */
|
||||
Reference in New Issue
Block a user