UI: Size the abstract-socket address properly

Unlike filesystem addresses, which are paths,
abstract addresses are blobs.

This means that the address wasn't "\0/com/obsproject 2413747 version",
but rather "\0/com/obsproject 2402613 version\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
this is reflected in both /proc/net/unix:
  000000001bf56057: 00000002 00000000 00000000 0002 01 56719817
                    @/com/obsproject 2402613 version@@@@@@@@@@@
                    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
                    @@@@@@@@@@@@@@@@@@@@@@
  000000003e897b41: 00000002 00000000 00000000 0002 01 56730132
                    @/com/obsproject 2413747 version
and ss -l, extending the whole address column to the point of
unusability.

This size calculation follows trivially from the manual,
and naturally behaves correctly, as above.
This commit is contained in:
наб 2024-03-14 17:23:07 +01:00 committed by Georges Basile Stavracas Neto
parent 41f07913e5
commit 87902cb106

View file

@ -67,12 +67,13 @@ void CheckIfAlreadyRunning(bool &already_running)
struct sockaddr_un bindInfo;
memset(&bindInfo, 0, sizeof(sockaddr_un));
bindInfo.sun_family = AF_LOCAL;
snprintf(bindInfo.sun_path + 1, sizeof(bindInfo.sun_path) - 1,
"%s %d %s", "/com/obsproject", getpid(),
App()->GetVersionString().c_str());
auto bindInfoStrlen = snprintf(bindInfo.sun_path + 1,
sizeof(bindInfo.sun_path) - 1,
"%s %d %s", "/com/obsproject", getpid(),
App()->GetVersionString().c_str());
int bindErr = bind(uniq, (struct sockaddr *)&bindInfo,
sizeof(struct sockaddr_un));
sizeof(sa_family_t) + 1 + bindInfoStrlen);
already_running = bindErr == 0 ? 0 : 1;
if (already_running) {