Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENT-10347: Fixed changing perms noise in no-noise sequential test #5386

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions cf-execd/cf-execd.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,19 +631,7 @@ static int SetupRunagentSocket(const ExecdConfig *execd_config)
if (GetRunagentSocketInfo(&sock_info))
{
sock_info.sun_family = AF_LOCAL;

bool created;
MakeParentDirectory(sock_info.sun_path, true, &created);

/* Make sure the permissions are correct if the directory was created
* (note: this code doesn't run on Windows). */
if (created)
{
char *last_slash = strrchr(sock_info.sun_path, '/');
*last_slash = '\0';
chmod(sock_info.sun_path, (mode_t) 0750);
*last_slash = '/';
}
MakeParentDirectoryPerms(sock_info.sun_path, true, NULL, (mode_t) 0700);

/* Remove potential left-overs from old processes. */
unlink(sock_info.sun_path);
Expand All @@ -667,6 +655,7 @@ static int SetupRunagentSocket(const ExecdConfig *execd_config)
}
else
{
safe_chmod(sock_info.sun_path, (mode_t) 0600);
Copy link
Contributor

@vpodzime vpodzime Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think fchmod(runagent_socket,...) would be better.

Copy link
Contributor Author

@larsewi larsewi Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fchmod() did not seem to work. Tried locally with both fchmod() and chmod() using this little program:

#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>

int main(void) {
    const char *path = "bogus.sock";
    int sock = socket(AF_LOCAL, SOCK_STREAM, 0);
    assert(sock >= 0);
    struct sockaddr_un sock_info;
    memset(&sock_info, 0, sizeof(struct sockaddr_un));
    strncpy(sock_info.sun_path, path, sizeof(sock_info.sun_path));
    sock_info.sun_family = AF_LOCAL;
    unlink(path);
    int ret = bind(sock, (const struct sockaddr *)&sock_info, sizeof(sock_info));
    assert(ret == 0);
    chmod(path, (mode_t) 0600);
    close(sock);
    return 0;
}

Only the latter one actually changed the permissions. Thus I'm changing it back to use safe_chmod().

ret = listen(runagent_socket, CF_EXECD_RUNAGENT_SOCKET_LISTEN_QUEUE);
assert(ret == 0);
if (ret == -1)
Expand Down