Skip to content

Commit de484e9

Browse files
committed
lib: change xbps_dbg_printf to not require xbps_handle
This allows to simplify a lot of code by not having to pass around the xbps handle everywhere just to print some debug information.
1 parent 1a3d1ea commit de484e9

39 files changed

Lines changed: 288 additions & 300 deletions

bin/xbps-install/state_cb.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED)
196196
if (xscd->desc)
197197
printf("%s\n", xscd->desc);
198198
else
199-
xbps_dbg_printf(xscd->xhp,
200-
"%s: unknown state %d\n", xscd->arg, xscd->state);
199+
xbps_dbg_printf("%s: unknown state %d\n", xscd->arg, xscd->state);
201200

202201
break;
203202
}

bin/xbps-install/transaction.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,15 @@ exec_transaction(struct xbps_handle *xhp, unsigned int maxcols, bool yes, bool d
384384
goto proceed;
385385
}
386386
} else {
387-
xbps_dbg_printf(xhp, "Empty transaction dictionary: %s\n",
387+
xbps_dbg_printf("Empty transaction dictionary: %s\n",
388388
strerror(errno));
389389
}
390390
goto out;
391391
}
392392
proceed:
393393
#ifdef FULL_DEBUG
394-
xbps_dbg_printf(xhp, "Dictionary before transaction happens:\n");
395-
xbps_dbg_printf_append(xhp, "%s",
394+
xbps_dbg_printf("Dictionary before transaction happens:\n");
395+
xbps_dbg_printf_append("%s",
396396
xbps_dictionary_externalize(xhp->transd));
397397
#endif
398398

bin/xbps-query/ownedby.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ repo_match_cb(struct xbps_handle *xhp,
146146
assert(bfile);
147147
filesd = xbps_archive_fetch_plist(bfile, "/files.plist");
148148
if (filesd == NULL) {
149-
xbps_dbg_printf(xhp, "%s: couldn't fetch files.plist from %s: %s\n",
149+
xbps_dbg_printf("%s: couldn't fetch files.plist from %s: %s\n",
150150
pkgver, bfile, strerror(errno));
151151
return EINVAL;
152152
}

bin/xbps-query/show-info-files.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ cat_file(struct xbps_handle *xhp, const char *pkg, const char *file)
296296
if (url == NULL)
297297
return EINVAL;
298298

299-
xbps_dbg_printf(xhp, "matched pkg at %s\n", url);
299+
xbps_dbg_printf("matched pkg at %s\n", url);
300300
rv = xbps_archive_fetch_file_into_fd(url, file, STDOUT_FILENO);
301301
free(url);
302302
return rv;
@@ -317,7 +317,7 @@ repo_cat_file(struct xbps_handle *xhp, const char *pkg, const char *file)
317317
if (url == NULL)
318318
return EINVAL;
319319

320-
xbps_dbg_printf(xhp, "matched pkg at %s\n", url);
320+
xbps_dbg_printf("matched pkg at %s\n", url);
321321
rv = xbps_archive_fetch_file_into_fd(url, file, STDOUT_FILENO);
322322
free(url);
323323
return rv;

bin/xbps-remove/clean-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj,
8888
}
8989
if (strcmp(binpkgarch, xhp->target_arch ? xhp->target_arch : xhp->native_arch) != 0 &&
9090
strcmp(binpkgarch, "noarch") != 0) {
91-
xbps_dbg_printf(xhp, "%s: ignoring binpkg with unmatched arch\n", binpkg);
91+
xbps_dbg_printf("%s: ignoring binpkg with unmatched arch\n", binpkg);
9292
return 0;
9393
}
9494

@@ -150,7 +150,7 @@ clean_cachedir(struct xbps_handle *xhp, bool drun)
150150
if ((ext = strrchr(dp->d_name, '.')) == NULL)
151151
continue;
152152
if (strcmp(ext, ".xbps")) {
153-
xbps_dbg_printf(xhp, "ignoring unknown file: %s\n", dp->d_name);
153+
xbps_dbg_printf("ignoring unknown file: %s\n", dp->d_name);
154154
continue;
155155
}
156156
xbps_array_add_cstring(array, dp->d_name);

bin/xbps-rindex/index-clean.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct CleanerCbInfo {
4646
};
4747

4848
static int
49-
idx_cleaner_cb(struct xbps_handle *xhp,
49+
idx_cleaner_cb(struct xbps_handle *xhp UNUSED,
5050
xbps_object_t obj,
5151
const char *key UNUSED,
5252
void *arg,
@@ -59,7 +59,7 @@ idx_cleaner_cb(struct xbps_handle *xhp,
5959
xbps_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
6060
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
6161

62-
xbps_dbg_printf(xhp, "%s: checking %s [%s] ...\n", info->repourl, pkgver, arch);
62+
xbps_dbg_printf("%s: checking %s [%s] ...\n", info->repourl, pkgver, arch);
6363

6464
filen = xbps_xasprintf("%s/%s.%s.xbps", info->repourl, pkgver, arch);
6565
if (access(filen, R_OK) == -1) {

include/xbps.h.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,10 @@ struct xbps_handle {
681681
int flags;
682682
};
683683

684-
void xbps_dbg_printf(struct xbps_handle *, const char *, ...) __attribute__ ((format (printf, 2, 3)));
685-
void xbps_dbg_printf_append(struct xbps_handle *, const char *, ...)__attribute__ ((format (printf, 2, 3)));
684+
extern int xbps_debug_level;
685+
686+
void xbps_dbg_printf(const char *, ...) __attribute__ ((format (printf, 1, 2)));
687+
void xbps_dbg_printf_append(const char *, ...)__attribute__ ((format (printf, 1, 2)));
686688
void xbps_error_printf(const char *, ...)__attribute__ ((format (printf, 1, 2)));
687689
void xbps_warn_printf(const char *, ...)__attribute__ ((format (printf, 1, 2)));
688690

lib/conf.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ store_virtualpkg(struct xbps_handle *xhp, const char *path, size_t line, char *v
6161
*/
6262
p = strchr(val, ':');
6363
if (p == NULL || p[1] == '\0') {
64-
xbps_dbg_printf(xhp, "%s: ignoring invalid "
64+
xbps_dbg_printf("%s: ignoring invalid "
6565
"virtualpkg option at line %zu\n", path, line);
6666
return 0;
6767
}
@@ -71,7 +71,7 @@ store_virtualpkg(struct xbps_handle *xhp, const char *path, size_t line, char *v
7171
return -errno;
7272
if (!xbps_dictionary_set_cstring(xhp->vpkgd_conf, val, p))
7373
return -errno;
74-
xbps_dbg_printf(xhp, "%s: added virtualpkg %s for %s\n", path, val, p);
74+
xbps_dbg_printf("%s: added virtualpkg %s for %s\n", path, val, p);
7575
return 1;
7676
}
7777

@@ -95,7 +95,7 @@ store_preserved_file(struct xbps_handle *xhp, const char *file)
9595
if (xbps_match_string_in_array(xhp->preserved_files, file))
9696
goto out;
9797
xbps_array_add_cstring(xhp->preserved_files, file);
98-
xbps_dbg_printf(xhp, "Added preserved file: %s\n", file);
98+
xbps_dbg_printf("Added preserved file: %s\n", file);
9999
goto out;
100100
} else if (rv != 0) {
101101
goto out;
@@ -109,7 +109,7 @@ store_preserved_file(struct xbps_handle *xhp, const char *file)
109109
assert(p);
110110
xbps_strlcpy(p, globbuf.gl_pathv[i] + strlen(xhp->rootdir), len);
111111
xbps_array_add_cstring(xhp->preserved_files, p);
112-
xbps_dbg_printf(xhp, "Added preserved file: %s (expanded from %s)\n", p, file);
112+
xbps_dbg_printf("Added preserved file: %s (expanded from %s)\n", p, file);
113113
free(p);
114114
}
115115
out:
@@ -134,7 +134,7 @@ store_ignored_pkg(struct xbps_handle *xhp, const char *pkgname)
134134
assert(xhp->ignored_pkgs);
135135
}
136136
xbps_array_add_cstring(xhp->ignored_pkgs, pkgname);
137-
xbps_dbg_printf(xhp, "Added ignored package: %s\n", pkgname);
137+
xbps_dbg_printf("Added ignored package: %s\n", pkgname);
138138
}
139139

140140
static void
@@ -147,7 +147,7 @@ store_noextract(struct xbps_handle *xhp, const char *value)
147147
assert(xhp->noextract);
148148
}
149149
xbps_array_add_cstring(xhp->noextract, value);
150-
xbps_dbg_printf(xhp, "Added noextract pattern: %s\n", value);
150+
xbps_dbg_printf("Added noextract pattern: %s\n", value);
151151
}
152152

153153
enum {
@@ -288,7 +288,7 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested)
288288
return rv;
289289
}
290290

291-
xbps_dbg_printf(xhp, "Parsing configuration file: %s\n", path);
291+
xbps_dbg_printf("Parsing configuration file: %s\n", path);
292292

293293
while ((rd = getline(&line, &len, fp)) != -1) {
294294
char *val = NULL;
@@ -310,7 +310,7 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested)
310310

311311
switch (parse_option(line, rd, &val, &vallen)) {
312312
case KEY_ERROR:
313-
xbps_dbg_printf(xhp, "%s: ignoring invalid option at "
313+
xbps_dbg_printf("%s: ignoring invalid option at "
314314
"line %zu\n", path, nlines);
315315
continue;
316316
case KEY_ROOTDIR:
@@ -320,7 +320,7 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested)
320320
rv = ENOMEM;
321321
break;
322322
}
323-
xbps_dbg_printf(xhp, "%s: rootdir set to %s\n", path, val);
323+
xbps_dbg_printf("%s: rootdir set to %s\n", path, val);
324324
break;
325325
case KEY_CACHEDIR:
326326
size = sizeof xhp->cachedir;
@@ -329,7 +329,7 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested)
329329
rv = ENOMEM;
330330
break;
331331
}
332-
xbps_dbg_printf(xhp, "%s: cachedir set to %s\n", path, val);
332+
xbps_dbg_printf("%s: cachedir set to %s\n", path, val);
333333
break;
334334
case KEY_ARCHITECTURE:
335335
size = sizeof xhp->native_arch;
@@ -338,21 +338,21 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested)
338338
rv = ENOMEM;
339339
break;
340340
}
341-
xbps_dbg_printf(xhp, "%s: native architecture set to %s\n", path,
341+
xbps_dbg_printf("%s: native architecture set to %s\n", path,
342342
val);
343343
break;
344344
case KEY_SYSLOG:
345345
if (strcasecmp(val, "true") == 0) {
346346
xhp->flags &= ~XBPS_FLAG_DISABLE_SYSLOG;
347-
xbps_dbg_printf(xhp, "%s: syslog enabled\n", path);
347+
xbps_dbg_printf("%s: syslog enabled\n", path);
348348
} else {
349349
xhp->flags |= XBPS_FLAG_DISABLE_SYSLOG;
350-
xbps_dbg_printf(xhp, "%s: syslog disabled\n", path);
350+
xbps_dbg_printf("%s: syslog disabled\n", path);
351351
}
352352
break;
353353
case KEY_REPOSITORY:
354354
if (store_repo(xhp, val))
355-
xbps_dbg_printf(xhp, "%s: added repository %s\n", path, val);
355+
xbps_dbg_printf("%s: added repository %s\n", path, val);
356356
break;
357357
case KEY_VIRTUALPKG:
358358
rv = store_virtualpkg(xhp, path, nlines, val);
@@ -368,19 +368,19 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested)
368368
case KEY_KEEPCONF:
369369
if (strcasecmp(val, "true") == 0) {
370370
xhp->flags |= XBPS_FLAG_KEEP_CONFIG;
371-
xbps_dbg_printf(xhp, "%s: config preservation enabled\n", path);
371+
xbps_dbg_printf("%s: config preservation enabled\n", path);
372372
} else {
373373
xhp->flags &= ~XBPS_FLAG_KEEP_CONFIG;
374-
xbps_dbg_printf(xhp, "%s: config preservation disabled\n", path);
374+
xbps_dbg_printf("%s: config preservation disabled\n", path);
375375
}
376376
break;
377377
case KEY_BESTMATCHING:
378378
if (strcasecmp(val, "true") == 0) {
379379
xhp->flags |= XBPS_FLAG_BESTMATCH;
380-
xbps_dbg_printf(xhp, "%s: pkg best matching enabled\n", path);
380+
xbps_dbg_printf("%s: pkg best matching enabled\n", path);
381381
} else {
382382
xhp->flags &= ~XBPS_FLAG_BESTMATCH;
383-
xbps_dbg_printf(xhp, "%s: pkg best matching disabled\n", path);
383+
xbps_dbg_printf("%s: pkg best matching disabled\n", path);
384384
}
385385
break;
386386
case KEY_IGNOREPKG:
@@ -392,7 +392,7 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested)
392392
case KEY_INCLUDE:
393393
/* Avoid double-nested parsing, only allow it once */
394394
if (nested) {
395-
xbps_dbg_printf(xhp, "%s: ignoring nested include\n", path);
395+
xbps_dbg_printf("%s: ignoring nested include\n", path);
396396
continue;
397397
}
398398
dir = strdup(path);
@@ -418,12 +418,12 @@ xbps_conf_init(struct xbps_handle *xhp)
418418
assert(seen);
419419

420420
if (*xhp->confdir) {
421-
xbps_dbg_printf(xhp, "Processing configuration directory: %s\n", xhp->confdir);
421+
xbps_dbg_printf("Processing configuration directory: %s\n", xhp->confdir);
422422
if ((rv = parse_files_glob(xhp, seen, xhp->confdir, "*.conf", false)))
423423
goto out;
424424
}
425425
if (*xhp->sysconfdir) {
426-
xbps_dbg_printf(xhp, "Processing system configuration directory: %s\n", xhp->sysconfdir);
426+
xbps_dbg_printf("Processing system configuration directory: %s\n", xhp->sysconfdir);
427427
if ((rv = parse_files_glob(xhp, seen, xhp->sysconfdir, "*.conf", false)))
428428
goto out;
429429
}

lib/download.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ xbps_fetch_file_dest_sha256(struct xbps_handle *xhp, const char *uri, const char
172172
fio = fetchXGet(url, &url_st, fetch_flags);
173173

174174
/* debug stuff */
175-
xbps_dbg_printf(xhp, "st.st_size: %zd\n", (ssize_t)stp->st_size);
176-
xbps_dbg_printf(xhp, "st.st_atime: %s\n", print_time(&stp->st_atime));
177-
xbps_dbg_printf(xhp, "st.st_mtime: %s\n", print_time(&stp->st_mtime));
178-
xbps_dbg_printf(xhp, "url_stat.size: %zd\n", (ssize_t)url_st.size);
179-
xbps_dbg_printf(xhp, "url_stat.atime: %s\n", print_time(&url_st.atime));
180-
xbps_dbg_printf(xhp, "url_stat.mtime: %s\n", print_time(&url_st.mtime));
175+
xbps_dbg_printf("st.st_size: %zd\n", (ssize_t)stp->st_size);
176+
xbps_dbg_printf("st.st_atime: %s\n", print_time(&stp->st_atime));
177+
xbps_dbg_printf("st.st_mtime: %s\n", print_time(&stp->st_mtime));
178+
xbps_dbg_printf("url_stat.size: %zd\n", (ssize_t)url_st.size);
179+
xbps_dbg_printf("url_stat.atime: %s\n", print_time(&url_st.atime));
180+
xbps_dbg_printf("url_stat.mtime: %s\n", print_time(&url_st.mtime));
181181

182182
if (fio == NULL) {
183183
if (fetchLastErrCode == FETCH_UNCHANGED) {
@@ -191,26 +191,26 @@ xbps_fetch_file_dest_sha256(struct xbps_handle *xhp, const char *uri, const char
191191
goto fetch_file_out;
192192
}
193193
if (url_st.size == -1) {
194-
xbps_dbg_printf(xhp, "Remote file size is unknown, resume "
194+
xbps_dbg_printf("Remote file size is unknown, resume "
195195
"not possible...\n");
196196
restart = false;
197197
} else if (stp->st_size > url_st.size) {
198198
/*
199199
* Remove local file if bigger than remote, and refetch the
200200
* whole shit again.
201201
*/
202-
xbps_dbg_printf(xhp, "Local file %s is greater than remote, "
202+
xbps_dbg_printf("Local file %s is greater than remote, "
203203
"removing local file and refetching...\n", filename);
204204
(void)remove(tempfile);
205205
restart = false;
206206
}
207-
xbps_dbg_printf(xhp, "url->scheme: %s\n", url->scheme);
208-
xbps_dbg_printf(xhp, "url->host: %s\n", url->host);
209-
xbps_dbg_printf(xhp, "url->port: %d\n", url->port);
210-
xbps_dbg_printf(xhp, "url->doc: %s\n", url->doc);
211-
xbps_dbg_printf(xhp, "url->offset: %zd\n", (ssize_t)url->offset);
212-
xbps_dbg_printf(xhp, "url->length: %zu\n", url->length);
213-
xbps_dbg_printf(xhp, "url->last_modified: %s\n",
207+
xbps_dbg_printf("url->scheme: %s\n", url->scheme);
208+
xbps_dbg_printf("url->host: %s\n", url->host);
209+
xbps_dbg_printf("url->port: %d\n", url->port);
210+
xbps_dbg_printf("url->doc: %s\n", url->doc);
211+
xbps_dbg_printf("url->offset: %zd\n", (ssize_t)url->offset);
212+
xbps_dbg_printf("url->length: %zu\n", url->length);
213+
xbps_dbg_printf("url->last_modified: %s\n",
214214
print_time(&url->last_modified));
215215
/*
216216
* If restarting, open the file for appending otherwise create it.
@@ -235,7 +235,7 @@ xbps_fetch_file_dest_sha256(struct xbps_handle *xhp, const char *uri, const char
235235
SHA256_Update(&sha256, buf, bytes_read);
236236
}
237237
if (bytes_read == -1) {
238-
xbps_dbg_printf(xhp, "IO error while reading %s: %s\n",
238+
xbps_dbg_printf("IO error while reading %s: %s\n",
239239
tempfile, strerror(errno));
240240
errno = EIO;
241241
rv = -1;
@@ -260,8 +260,7 @@ xbps_fetch_file_dest_sha256(struct xbps_handle *xhp, const char *uri, const char
260260
SHA256_Update(&sha256, buf, bytes_read);
261261
bytes_written = write(fd, buf, (size_t)bytes_read);
262262
if (bytes_written != bytes_read) {
263-
xbps_dbg_printf(xhp,
264-
"Couldn't write to %s!\n", tempfile);
263+
xbps_dbg_printf("Couldn't write to %s!\n", tempfile);
265264
rv = -1;
266265
goto fetch_file_out;
267266
}
@@ -275,13 +274,13 @@ xbps_fetch_file_dest_sha256(struct xbps_handle *xhp, const char *uri, const char
275274
filename, false, true, false);
276275
}
277276
if (bytes_read == -1) {
278-
xbps_dbg_printf(xhp, "IO error while fetching %s: %s\n",
277+
xbps_dbg_printf("IO error while fetching %s: %s\n",
279278
filename, fetchLastErrString);
280279
errno = EIO;
281280
rv = -1;
282281
goto fetch_file_out;
283282
} else if (url_st.size > 0 && ((bytes_dload + url->offset) != url_st.size)) {
284-
xbps_dbg_printf(xhp, "file %s is truncated\n", filename);
283+
xbps_dbg_printf("file %s is truncated\n", filename);
285284
errno = EIO;
286285
rv = -1;
287286
goto fetch_file_out;
@@ -311,7 +310,7 @@ xbps_fetch_file_dest_sha256(struct xbps_handle *xhp, const char *uri, const char
311310
rename_file:
312311
/* File downloaded successfully, rename to destfile */
313312
if (rename(tempfile, filename) == -1) {
314-
xbps_dbg_printf(xhp, "failed to rename %s to %s: %s",
313+
xbps_dbg_printf("failed to rename %s to %s: %s",
315314
tempfile, filename, strerror(errno));
316315
rv = -1;
317316
goto fetch_file_out;

lib/external/fexec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ pfcexec(struct xbps_handle *xhp, const char *file, const char **argv)
5858
if (strcmp(xhp->rootdir, "/")) {
5959
if ((geteuid() == 0) && (access("bin/sh", X_OK) == 0)) {
6060
if (chroot(xhp->rootdir) == -1) {
61-
xbps_dbg_printf(xhp, "%s: chroot() "
61+
xbps_dbg_printf("%s: chroot() "
6262
"failed: %s\n", *argv, strerror(errno));
6363
_exit(errno);
6464
}
6565
if (chdir("/") == -1) {
66-
xbps_dbg_printf(xhp, "%s: chdir() "
66+
xbps_dbg_printf("%s: chdir() "
6767
"failed: %s\n", *argv, strerror(errno));
6868
_exit(errno);
6969
}

0 commit comments

Comments
 (0)