Commit 36d1bfb4 authored by Natanael Copa's avatar Natanael Copa

db: make apk_wait a part of dbopts

parent 7aed4494
......@@ -235,7 +235,7 @@ int main(int argc, char **argv)
struct apk_applet *applet;
char short_options[256], *sopt;
struct option *opt, *all_options;
int r, optindex, num_options, apk_wait = 0;
int r, optindex, num_options;
void *ctx = NULL;
struct apk_repository_list *repo = NULL;
struct apk_database db;
......@@ -328,7 +328,7 @@ int main(int argc, char **argv)
apk_flags |= APK_PURGE;
break;
case 0x105:
apk_wait = atoi(optarg);
dbopts.lock_wait = atoi(optarg);
break;
case 0x109:
apk_flags |= APK_NO_NETWORK;
......@@ -356,7 +356,7 @@ int main(int argc, char **argv)
argv++;
}
r = apk_db_open(&db, &dbopts, apk_wait);
r = apk_db_open(&db, &dbopts);
if (r != 0) {
apk_error("Failed to open apk database: %s",
apk_error_str(r));
......
......@@ -90,6 +90,7 @@ struct apk_repository_list {
};
struct apk_db_options {
int lock_wait;
unsigned long open_flags;
char *root;
char *keys_dir;
......@@ -155,7 +156,7 @@ struct apk_db_file *apk_db_file_query(struct apk_database *db,
APK_OPENF_NO_SCRIPTS | \
APK_OPENF_NO_WORLD)
int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts, int apk_wait);
int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts);
void apk_db_close(struct apk_database *db);
int apk_db_write_config(struct apk_database *db);
int apk_db_run_triggers(struct apk_database *db);
......
......@@ -1025,8 +1025,7 @@ static void handle_alarm(int sig)
{
}
int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts,
int apk_wait)
int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
{
const char *msg = NULL;
struct apk_repository_list *repo = NULL;
......@@ -1086,7 +1085,7 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts,
if (db->lock_fd < 0 ||
flock(db->lock_fd, LOCK_EX | LOCK_NB) < 0) {
msg = "Unable to lock database";
if (apk_wait) {
if (dbopts->lock_wait) {
struct sigaction sa, old_sa;
apk_message("Waiting for repository lock");
......@@ -1095,7 +1094,7 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts,
sa.sa_flags = SA_ONESHOT;
sigaction(SIGALRM, &sa, &old_sa);
alarm(apk_wait);
alarm(dbopts->lock_wait);
if (flock(db->lock_fd, LOCK_EX) < 0)
goto ret_errno;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment