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

Set file mode creation mask for feed lock handling (20.08) #1265

Merged
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add dummy functions to allow restoring old dumps [#1251](https://github.com/greenbone/gvmd/pull/1251)
- Fix delta sorting for unusual filter sort terms [#1249](https://github.com/greenbone/gvmd/pull/1249)
- Fix SCP alert authentication and logging [#1264](https://github.com/greenbone/gvmd/pull/1264)
- Set file mode creation mask for feed lock handling [#1265](https://github.com/greenbone/gvmd/pull/1265)

### Removed

Expand Down
10 changes: 8 additions & 2 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12360,22 +12360,28 @@ feed_type_name (int feed_type)
static int
get_feed_lock_status (const char *lockfile_name, gchar **timestamp)
{
mode_t old_umask;
int lockfile;
int ret;

if (timestamp)
*timestamp = NULL;
ret = 0;

old_umask = umask(0);
lockfile = open (lockfile_name,
O_RDWR | O_CREAT,
/* "-rw-rw-r--" */
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
if (lockfile == -1)
g_warning ("%s: failed to open lock file '%s': %s", __func__,
lockfile_name, strerror (errno));
{
g_warning ("%s: failed to open lock file '%s': %s", __func__,
lockfile_name, strerror (errno));
umask (old_umask);
}
else
{
umask (old_umask);
if (flock (lockfile, LOCK_EX | LOCK_NB)) /* Exclusive, Non blocking. */
{
if (errno == EWOULDBLOCK)
Expand Down
4 changes: 4 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ static int
lock_internal (lockfile_t *lockfile, const gchar *lockfile_name,
int operation, gboolean name_is_full_path)
{
mode_t old_umask;
int fd;
gchar *full_name;

Expand All @@ -551,17 +552,20 @@ lock_internal (lockfile_t *lockfile, const gchar *lockfile_name,
else
full_name = g_build_filename (GVM_RUN_DIR, lockfile_name, NULL);

old_umask = umask (0);
fd = open (full_name, O_RDWR | O_CREAT,
/* "-rw-rw-r--" */
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
if (fd == -1)
{
g_warning ("Failed to open lock file '%s': %s", full_name,
strerror (errno));
umask (old_umask);
lockfile->name = NULL;
g_free (full_name);
return -1;
}
umask (old_umask);

/* Lock the lockfile. */

Expand Down