Skip to content

Commit

Permalink
Merge pull request #291 from sshedi/refactor-locking-stable-3.2
Browse files Browse the repository at this point in the history
Move instance running check to TDNFOpenHandle()
  • Loading branch information
oliverkurth authored Feb 3, 2022
2 parents 9fb53a1 + 67d281d commit 6c785ea
Show file tree
Hide file tree
Showing 16 changed files with 459 additions and 131 deletions.
12 changes: 6 additions & 6 deletions ci/Dockerfile.fedora
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM fedora:34

RUN dnf -q -y upgrade
RUN dnf -q -y install gcc make cmake libcurl-devel rpm-devel rpm-build libsolv-devel \
popt-devel sed createrepo_c glib2-devel libxml2 findutils \
python3-pytest python3-requests python3-urllib3 python3-pyOpenSSL \
python3 python3-devel valgrind gpgme-devel libxml2-devel \
openssl-devel rpm-sign which
RUN dnf -y upgrade
RUN dnf -y install gcc make cmake libcurl-devel rpm-devel rpm-build \
libsolv-devel popt-devel sed createrepo_c glib2-devel libxml2 \
findutils python3-pytest python3-requests python3-urllib3 \
python3-pyOpenSSL python3 python3-devel valgrind gpgme-devel \
libxml2-devel openssl-devel rpm-sign which python3-pip

CMD ["/bin/bash"]
21 changes: 10 additions & 11 deletions ci/Dockerfile.photon
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
FROM photon:latest

MAINTAINER [email protected]

RUN tdnf update -q -y
RUN tdnf remove -q -y toybox
RUN tdnf install -q -y --enablerepo=photon-debuginfo \
build-essential cmake curl-devel rpm-build libsolv-devel \
popt-devel sed createrepo_c glib libxml2 findutils \
python3 python3-pip python3-setuptools python3-devel \
valgrind gpgme-devel glibc-debuginfo libxml2-devel \
openssl-devel zlib-devel which
RUN tdnf update -y
RUN tdnf remove -y toybox
RUN tdnf install -y --enablerepo=photon-debuginfo \
build-essential cmake curl-devel rpm-build \
libsolv-devel popt-devel sed createrepo_c glib libxml2 \
findutils python3 python3-pip python3-setuptools \
python3-devel valgrind gpgme-devel glibc-debuginfo \
libxml2-devel openssl-devel zlib-devel which \
python3-requests python3-urllib3 python3-pyOpenSSL

# python build/test dependencies
RUN pip3 install -q requests urllib3 pyOpenSSL pytest
RUN pip3 install -q pytest

CMD ["/bin/bash"]
23 changes: 11 additions & 12 deletions ci/Dockerfile.photon-3.0
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
FROM photon:3.0

MAINTAINER [email protected]
RUN tdnf update -y
RUN tdnf remove -y toybox
RUN tdnf install -y --enablerepo=photon-debuginfo \
build-essential cmake curl-devel rpm-build \
libsolv-devel popt-devel sed createrepo_c glib libxml2 \
findutils python3 python3-setuptools python3-devel \
valgrind gpgme-devel glibc-debuginfo libxml2-devel \
openssl-devel zlib-devel which python3-requests \
python3-urllib3 python3-pyOpenSSL python3-pip

RUN tdnf update -q -y
RUN tdnf remove -q -y toybox
RUN tdnf install -q -y --enablerepo=photon-debuginfo \
build-essential cmake curl-devel rpm-build libsolv-devel \
popt-devel sed createrepo_c glib libxml2 findutils \
python3 python3-pip python3-setuptools python3-devel \
valgrind gpgme-devel glibc-debuginfo libxml2-devel \
openssl-devel zlib-devel which

# python build/test dependencies
RUN pip3 install -q requests urllib3 pyOpenSSL pytest
# TODO: we need to fix pytest in Ph3, after that this can be removed
RUN pip3 install -q pytest

CMD ["/bin/bash"]
38 changes: 29 additions & 9 deletions client/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,36 @@
* Authors : Priyesh Padmavilasom ([email protected])
*/

#include <ftw.h>
#include "includes.h"
#include "config.h"

static TDNF_ENV gEnv = {0};

uint32_t
TDNFInit(
void
)
static tdnflock instance_lock;

static void TdnfExitHandler(void);
static void IsTdnfAlreadyRunning(void);

static void TdnfExitHandler(void)
{
tdnflockFree(instance_lock);
}

static void IsTdnfAlreadyRunning(void)
{
instance_lock = tdnflockNewAcquire(TDNF_INSTANCE_LOCK_FILE,
"tdnf_instance");
if (!instance_lock)
{
pr_err("Failed to acquire tdnf_instance lock\n");
}
}

uint32_t TDNFInit(void)
{
uint32_t dwError = 0;
int nLocked = 0;
uint32_t dwError = 0;

pthread_mutex_lock (&gEnv.mutexInitialize);
pthread_mutex_lock(&gEnv.mutexInitialize);
nLocked = 1;
if(!gEnv.nInitialized)
{
Expand Down Expand Up @@ -640,6 +655,10 @@ TDNFOpenHandle(
BAIL_ON_TDNF_ERROR(dwError);
}

IsTdnfAlreadyRunning();

GlobalSetQuiet(pArgs->nQuiet);

dwError = TDNFAllocateMemory(1, sizeof(TDNF), (void**)&pTdnf);
BAIL_ON_TDNF_ERROR(dwError);

Expand Down Expand Up @@ -1469,7 +1488,7 @@ TDNFRepoQuery(
BAIL_ON_TDNF_ERROR(dwError);
}

/* get results in list */
/* get results in list */
dwError = SolvGetQueryResult(pQuery, &pPkgList);
BAIL_ON_TDNF_ERROR(dwError);

Expand Down Expand Up @@ -1930,6 +1949,7 @@ TDNFCloseHandle(
TDNFFreePlugins(pTdnf->pPlugins);
TDNFFreeMemory(pTdnf);
}
TdnfExitHandler();
}

const char*
Expand Down
9 changes: 9 additions & 0 deletions client/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@

#include "config.h"

/*
* creating this under /var/run because /var/run/lock doesn't exist
* in fedora docker images and as a result ci fails
*/
#define TDNF_INSTANCE_LOCK_FILE "/var/run/.tdnf-instance-lockfile"

/* wait for lock retries, interval is 1s */
#define TDNF_LOCK_MAX_RETRIES 300

typedef enum
{
/* this should be a bitmask */
Expand Down
5 changes: 4 additions & 1 deletion client/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
#include <stdbool.h>
#include <unistd.h>
#include <fcntl.h>
#include <ftw.h>
#include <time.h>
#include <utime.h>
#include <fnmatch.h>
#include <libgen.h>
#include <ctype.h>
//
#include <sys/file.h>
#include <sys/utsname.h>

#include <dirent.h>
Expand Down Expand Up @@ -67,6 +68,8 @@
#include "../common/prototypes.h"
#include "prototypes.h"

#include "config.h"

// Enum in order of preference
enum {
TDNF_HASH_MD5 = 0,
Expand Down
1 change: 1 addition & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ add_library(${LIB_TDNF_COMMON}
strings.c
utils.c
log.c
lock.c
)
3 changes: 3 additions & 0 deletions common/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <string.h>
#include <errno.h>
#include <stdbool.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>

#include <tdnftypes.h>
#include <tdnferror.h>
Expand Down
Loading

0 comments on commit 6c785ea

Please sign in to comment.