Skip to content

Commit

Permalink
Fix silly errors
Browse files Browse the repository at this point in the history
  • Loading branch information
CluelessCatBurger committed Nov 13, 2024
1 parent fd187d1 commit 42fdf45
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 26 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "src/third_party/json.h"]
path = src/third_party/json.h
url = https://github.com/sheredom/json.h
[submodule "json.h"]
path = json.h
url = https://github.com/sheredom/json.h
1 change: 0 additions & 1 deletion json.h
Submodule json.h deleted from 3e1c62
33 changes: 12 additions & 21 deletions src/shimeji-overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
static mascot_prototype_store* prototype_store = NULL;
static struct mascot_affordance_manager affordance_manager = {0};

char socket_path[PATH_MAX] = {0};
char config_path[PATH_MAX] = {0};

struct {
environment_t** entries;
uint8_t* entry_states;
Expand Down Expand Up @@ -122,7 +125,7 @@ struct {
} mascot_store = {0};


size_t get_config_path(char* pathbuf, size_t pathbuf_len)
size_t get_default_config_path(char* pathbuf, size_t pathbuf_len)
{
// Get home directory
const char *home = secure_getenv("HOME");
Expand All @@ -133,8 +136,6 @@ size_t get_config_path(char* pathbuf, size_t pathbuf_len)

size_t get_mascots_path(char* pathbuf, size_t pathbuf_len)
{
char config_path[PATH_MAX];
get_config_path(config_path, sizeof(config_path));
return snprintf(pathbuf, pathbuf_len, "%s/shimejis", config_path);
}

Expand Down Expand Up @@ -751,13 +752,11 @@ void* mascot_manager_thread(void* arg)

int main(int argc, const char** argv)
{
char socket_path[128];
char mascots_path[256];
int inhereted_fd = -1;
int fds_count = 0;
bool spawn_everything = false;

get_mascots_path(mascots_path, 256);
get_default_config_path(config_path, 256);
get_default_socket_path(socket_path, 128);

// Arguments:
Expand All @@ -781,7 +780,7 @@ int main(int argc, const char** argv)
fprintf(stderr, "Error: missing argument for --config-dir\n");
return 1;
}
strncpy(mascots_path, argv[i + 1], 255);
strncpy(config_path, argv[i + 1], 255);
i++;
} else if (strcmp(argv[i], "-cfd") == 0 || strcmp(argv[i], "--caller-fd") == 0) {
if (i + 1 >= argc) {
Expand Down Expand Up @@ -812,17 +811,9 @@ int main(int argc, const char** argv)
}
}

struct stat st = {0};
if (stat(mascots_path, &st) == -1) {
mkdir(mascots_path, 0700);
}
if (stat(mascots_path, &st) == -1) {
ERROR("Failed to create mascots directory");
return 1;
}

char mascots_path_packages[256] = {0};
int slen = snprintf(mascots_path_packages, 255, "%s/shimejis", mascots_path);
int slen = get_mascots_path(mascots_path_packages, 255);
struct stat st = {0};
if (slen < 0 || slen >= 255) {
ERROR("Provided config directory path is too long!");
return 1;
Expand Down Expand Up @@ -892,13 +883,13 @@ int main(int argc, const char** argv)
}

// Load mascot protos
DIR* dir = opendir(mascots_path);
DIR* dir = opendir(mascots_path_packages);
if (dir) {
struct dirent* ent;
while ((ent = readdir(dir)) != NULL) {
if (ent->d_type == DT_DIR) {
char proto_path[256];
int slen = snprintf(proto_path, 255, "%s/%s", mascots_path, ent->d_name);
int slen = snprintf(proto_path, 255, "%s/%s", mascots_path_packages, ent->d_name);
if (slen < 0 || slen >= 255) {
WARN("Mascot prototype path is too long! Skipping...");
continue;
Expand All @@ -909,11 +900,11 @@ int main(int argc, const char** argv)
closedir(dir);
} else {
char buf[1025+sizeof(size_t)];
size_t strlen = snprintf(buf+1+sizeof(size_t), 1024, "Failed to open mascots directory: %s", mascots_path);
size_t strlen = snprintf(buf+1+sizeof(size_t), 1024, "Failed to open mascots directory: %s", mascots_path_packages);
memcpy(buf+1, &strlen, sizeof(size_t));
buf[0] = 0xFF;
send(inhereted_fd, buf, 1025+sizeof(size_t), 0);
ERROR("Failed to open mascots directory: %s", mascots_path);
ERROR("Failed to open mascots directory: %s", mascots_path_packages);
}

// Spawn mascots if requested
Expand Down
2 changes: 1 addition & 1 deletion utils/shimejictl
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ class ShimejiCtl:
sock.connect(f'{os.environ.get("XDG_RUNTIME_DIR", "/tmp")}/shimeji-overlayd.sock')
if exclusive:
return None
except ConnectionRefusedError:
except (ConnectionRefusedError, FileNotFoundError):
# Overlay not running, start it
if do_not_start:
return None
Expand Down

0 comments on commit 42fdf45

Please sign in to comment.