Skip to content

Commit

Permalink
#78 Fall Back To Writable Location For cfg.yaml (#124)
Browse files Browse the repository at this point in the history
* 78 do not print 'Wrote configuration file' following failure

* add mkdir_p

* 70 unit test cfg_file_write

* 78 add cfg_file_paths, not yet functional

* 78 harden XDG_CONFIG_HOME using tests

* 78 allow unused results for getcwd in older nix/gcc environment

* 78 harden XDG_CONFIG_HOME using tests

* 78 use cfg_file_paths, resolve_paths->resolve_cfg_file, extract fs.ch

* 78 extract file_write

* #78 on write failure use alternatives

* #78 ignore ~/.config when XDG_CONFIG_HOME present

* #78 remember which cfg_file_paths was used to resolve the file

* #78 write new file when none used

* #78 write new file when none used

* #78 create directory before writing new file

* #78 tidy

* #78 tidy following merge

* #78 add directory watcher destroy, tidy unit test directories

* #78 kill cfg dir watcher on failure to write

* #78 kill cfg dir watcher on failure to write

* #78 kill cfg dir watcher on failure to write

* #78 create new cfg dir watcher on new file write

* #78 newly written file is immediately watched

* #78 don't snprintf in tests

* #78 do snprintf in tests, valgrind on CI is strict

* #78 do snprintf in tests, valgrind on CI is strict

* #78 tidy IPC doc
  • Loading branch information
alex-courtis authored Aug 21, 2023
1 parent 558a339 commit a291b46
Show file tree
Hide file tree
Showing 24 changed files with 922 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .cppcheck.supp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
unusedFunction:tst/wrap-log.c
unusedFunction:tst/tst.c
unusedFunction:tst/util.c
2 changes: 1 addition & 1 deletion config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ INCS = -Iinc -Ipro -Ilib/alex-c-collections/inc
CPPFLAGS += $(INCS) -D_GNU_SOURCE -DVERSION=\"$(VERSION)\" -DROOT_ETC=\"$(ROOT_ETC)\"

OFLAGS = -O3
WFLAGS = -pedantic -Wall -Wextra -Werror -Wno-unused-parameter
WFLAGS = -pedantic -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-result
DFLAGS = -g
COMPFLAGS = $(WFLAGS) $(OFLAGS) $(DFLAGS)

Expand Down
44 changes: 21 additions & 23 deletions doc/IPC.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
# way-displays IPC

// TODO rewrite removing examples

`$WAYLAND_DISPLAY` must be set.
`$WAYLAND_DISPLAY` must be set and `$XDG_VTNR` set to match the server's.

way-displays server creates a socket `${XDG_RUNTIME_DIR}/way-displays.${XDG_VTNR}.sock`.

If `$XDG_RUNTIME_DIR` is unset the socket will be `/tmp/way-displays.${XDG_VTNR}.sock`.

Clients send an [!!ipc_request](YAML_SCHEMAS.md#ipc_request) and will receive a sequence of [!!ipc_response](YAML_SCHEMAS.md#ipc_response) until the operation is complete and the socket closed.

## Example

```sh
make examples
```

### client-get-raw

Sends a `GET` and prints the raw response.

### client-set-scaling

Sends a `CFG_SET` to reset `SCALING`. Unpacks all responses and prints some config and head states as the operation progresses.

### poke-server

Validates and prints client and server readiness for IPC.

## Response

[STATE](YAML_SCHEMAS.md#state) contains the device states.
Expand Down Expand Up @@ -66,7 +46,7 @@ OP: CFG_WRITE

Mutate multiple configuration values.

Compose a [CFG](YAML_SCHEMAS.md#cfg) containing only the desired elements to change e.g.:
[CFG](YAML_SCHEMAS.md#cfg) containing only the desired elements to change e.g.:

```yaml
OP: CFG_SET
Expand All @@ -87,7 +67,7 @@ Only these [CFG](YAML_SCHEMAS.md#cfg) elements that may be deleted:
- `DISABLED`
- `VRR_OFF`

Compose a [CFG](YAML_SCHEMAS.md#cfg) containing only the desired elements to delete e.g.:
[CFG](YAML_SCHEMAS.md#cfg) containing only the desired elements to delete e.g.:

```yaml
OP: CFG_DEL
Expand All @@ -103,3 +83,21 @@ CFG:
- eDP-1
```

## Examples

```sh
make examples
```

### client-get-raw

Sends a `GET` and prints the raw response.

### client-set-scaling

Sends a `CFG_SET` to reset `SCALING`. Unpacks all responses and prints some config and head states as the operation progresses.

### poke-server

Validates and prints client and server readiness for IPC.

9 changes: 8 additions & 1 deletion inc/cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ struct Cfg {
char *dir_path;
char *file_path;
char *file_name;
char *resolved_from;

bool written;
bool updated;

char *laptop_display_prefix;
struct SList *order_name_desc;
Expand Down Expand Up @@ -78,6 +79,8 @@ enum CfgElement {
ARRANGE_ALIGN,
};

void cfg_file_paths_init(const char *user_path);

void cfg_init(const char *cfg_path);

bool cfg_equal(struct Cfg *a, struct Cfg *b);
Expand Down Expand Up @@ -112,5 +115,9 @@ void cfg_destroy(void);

void cfg_free(struct Cfg *cfg);

void cfg_free_paths(struct Cfg *cfg);

void cfg_file_paths_destroy(void);

#endif // CFG_H

11 changes: 8 additions & 3 deletions inc/fds.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
extern int fd_signal;
extern int fd_socket_server;
extern int fd_cfg_dir;
extern int wd_cfg_dir;

extern nfds_t npfds;
extern struct pollfd pfds[5];
Expand All @@ -17,11 +18,15 @@ extern struct pollfd *pfd_wayland;
extern struct pollfd *pfd_lid;
extern struct pollfd *pfd_cfg_dir;

void init_pfds(void);
void pfds_init(void);

void destroy_pfds(void);
void pfds_destroy(void);

bool cfg_file_modified(char *file_name);
void fd_wd_cfg_dir_create(void);

void fd_wd_cfg_dir_destroy(void);

bool fd_cfg_dir_modified(char *file_name);

#endif // FDS_H

12 changes: 12 additions & 0 deletions inc/fs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef FS_H
#define FS_H

#include <stdbool.h>
#include <sys/stat.h>

bool mkdir_p(char *path, mode_t mode);

bool file_write(const char *path, const char *contents);

#endif // FS_H

2 changes: 2 additions & 0 deletions inc/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ extern struct Displ *displ;
extern struct Cfg *cfg;
extern struct Lid *lid;

extern struct SList *cfg_file_paths;

extern struct Head *head_changing_mode;
extern struct Head *head_changing_adaptive_sync;

Expand Down
Loading

0 comments on commit a291b46

Please sign in to comment.