mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-24 21:05:40 +02:00
module/i3: fix gcc warning
Gcc (correctly) figured out that we may end up truncating the socket path. In practice, it's something that should never happen. Never the less, silence the warning by writing the socket path directly into the sockaddr_un object.
This commit is contained in:
parent
efe3dd06ab
commit
552739fa20
1 changed files with 5 additions and 8 deletions
13
modules/i3.c
13
modules/i3.c
|
@ -353,7 +353,7 @@ run(struct module_run_context *ctx)
|
|||
{
|
||||
struct private *m = ctx->module->private;
|
||||
|
||||
char sock_path[1024];
|
||||
struct sockaddr_un addr = {.sun_family = AF_UNIX};
|
||||
{
|
||||
FILE *out = popen("i3 --get-socketpath", "r");
|
||||
if (out == NULL) {
|
||||
|
@ -362,13 +362,13 @@ run(struct module_run_context *ctx)
|
|||
return 1;
|
||||
}
|
||||
|
||||
fgets(sock_path, sizeof(sock_path), out);
|
||||
fgets(addr.sun_path, sizeof(addr.sun_path), out);
|
||||
pclose(out);
|
||||
|
||||
/* Strip newline */
|
||||
ssize_t len = strlen(sock_path);
|
||||
if (sock_path[len - 1] == '\n')
|
||||
sock_path[len - 1] = '\0';
|
||||
ssize_t len = strlen(addr.sun_path);
|
||||
if (addr.sun_path[len - 1] == '\n')
|
||||
addr.sun_path[len - 1] = '\0';
|
||||
}
|
||||
|
||||
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
|
@ -378,9 +378,6 @@ run(struct module_run_context *ctx)
|
|||
return 1;
|
||||
}
|
||||
|
||||
struct sockaddr_un addr = {.sun_family = AF_UNIX};
|
||||
strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1);
|
||||
|
||||
int r = connect(sock, (const struct sockaddr *)&addr, sizeof(addr));
|
||||
if (r == -1) {
|
||||
LOG_ERRNO("failed to connect to i3 socket");
|
||||
|
|
Loading…
Add table
Reference in a new issue