Skip to content

Commit

Permalink
[C++] Remove PATH_MAX madness
Browse files Browse the repository at this point in the history
There is no such path limitation as PATH_MAX.
See: https://stackoverflow.com/questions/9449241/where-is-path-max-defined-in-linux
One shall not use this historical constant for anything.
  • Loading branch information
Nekotekina committed Dec 15, 2024
1 parent 9298899 commit 78f83a5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
27 changes: 15 additions & 12 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "string.h"
#include "unicode.h"
#include <limits>
#include <string>

#define MAX_FILE_SZ 65536
#define MAX_LINE_LEN 256
Expand Down Expand Up @@ -85,26 +86,28 @@ static struct {

static const char *resolve_include_path(const char *path, const char *include_path)
{
static char resolved_path[PATH_MAX];
char tmp[PATH_MAX];
const char *dir;
static std::string resolved_path;
std::string tmp;

if (strstr(include_path, ".")) {
warn("%s: included files may not have a file extension", include_path);
return NULL;
}

strcpy(tmp, path);
dir = dirname(tmp);
snprintf(resolved_path, sizeof resolved_path, "%s/%s", dir, include_path);
tmp = path;
resolved_path = dirname(tmp.data());
resolved_path += '/';
resolved_path += include_path;

if (!access(resolved_path, F_OK))
return resolved_path;
if (!access(resolved_path.c_str(), F_OK))
return resolved_path.c_str();

snprintf(resolved_path, sizeof resolved_path, DATA_DIR"/%s", include_path);
resolved_path = DATA_DIR;
resolved_path += '/';
resolved_path += include_path;

if (!access(resolved_path, F_OK))
return resolved_path;
if (!access(resolved_path.c_str(), F_OK))
return resolved_path.c_str();

return NULL;
}
Expand Down Expand Up @@ -937,7 +940,7 @@ int config_parse(struct config *config, const char *path)
return -1;

config_init(config);
snprintf(config->path, sizeof(config->path), "%s", path);
config->pathstr = path;
return config_parse_string(config, content);
}

Expand Down
7 changes: 1 addition & 6 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
#define MAX_LAYERS 32
#define MAX_EXP_LEN 512


#ifndef PATH_MAX
#define PATH_MAX 1024
#endif

#define ID_EXCLUDED 1
#define ID_MOUSE 2
#define ID_KEYBOARD 4
Expand Down Expand Up @@ -110,7 +105,7 @@ struct layer {
};

struct config {
char path[PATH_MAX];
std::string pathstr;
struct layer layers[MAX_LAYERS];

/* Auxiliary descriptors used by layer bindings. */
Expand Down
2 changes: 1 addition & 1 deletion src/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ static void manage_device(struct device *dev)
}

keyd_log("DEVICE: g{match} %s %s\t(%s)\n",
dev->id, ent->config.path, dev->name);
dev->id, ent->config.pathstr.c_str(), dev->name);

dev->data = ent->kbd.get();
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ int ipc_connect()

int ipc_create_server()
{
char lockpath[PATH_MAX];
int sd = socket(AF_UNIX, SOCK_STREAM, 0);
int lfd;
struct sockaddr_un addr = {};
Expand All @@ -59,8 +58,7 @@ int ipc_create_server()
}
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, SOCKET_PATH, sizeof(addr.sun_path)-1);
snprintf(lockpath, sizeof lockpath, "%s.lock", SOCKET_PATH);
lfd = open(lockpath, O_CREAT | O_RDONLY, 0600);
lfd = open(SOCKET_PATH ".lock", O_CREAT | O_RDONLY, 0600);

if (lfd < 0) {
perror("open");
Expand Down

0 comments on commit 78f83a5

Please sign in to comment.