Skip to content

Commit 1271a3d

Browse files
classabbyampDuncaen
authored andcommitted
bin/: use xbps logging functions more
1 parent 7391a7b commit 1271a3d

19 files changed

Lines changed: 94 additions & 95 deletions

File tree

bin/xbps-alternatives/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ main(int argc, char **argv)
243243
if (set_mode) {
244244
/* in set mode pkgdb must be locked and flushed on success */
245245
if ((rv = xbps_pkgdb_lock(&xh)) != 0) {
246-
fprintf(stderr, "failed to lock pkgdb: %s\n", strerror(rv));
246+
xbps_error_printf("failed to lock pkgdb: %s\n", strerror(rv));
247247
exit(EXIT_FAILURE);
248248
}
249249
if ((rv = xbps_alternatives_set(&xh, pkg, group)) == 0)

bin/xbps-checkvers/main.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ xstrdup(const char *src)
6666
{
6767
char *p;
6868
if (!(p = strdup(src))) {
69-
fprintf(stderr, "Error: %s\n", strerror(errno));
69+
xbps_error_printf("%s\n", strerror(errno));
7070
exit(1);
7171
}
7272
return p;
@@ -155,7 +155,7 @@ rcv_load_file(rcv_t *rcv, const char *fname)
155155

156156
if ((file = fopen(rcv->fname, "r")) == NULL) {
157157
if (!rcv->manual) {
158-
fprintf(stderr, "FileError: can't open '%s': %s\n",
158+
xbps_error_printf("FileError: can't open '%s': %s\n",
159159
rcv->fname, strerror(errno));
160160
}
161161
return false;
@@ -174,15 +174,15 @@ rcv_load_file(rcv_t *rcv, const char *fname)
174174
if (rcv->buf == NULL) {
175175
rcv->bufsz = rcv->len+1;
176176
if (!(rcv->buf = calloc(rcv->bufsz, sizeof(char)))) {
177-
fprintf(stderr, "MemError: can't allocate memory: %s\n",
177+
xbps_error_printf("MemError: can't allocate memory: %s\n",
178178
strerror(errno));
179179
fclose(file);
180180
return false;
181181
}
182182
} else if (rcv->bufsz <= rcv->len) {
183183
rcv->bufsz = rcv->len+1;
184184
if (!(rcv->buf = realloc(rcv->buf, rcv->bufsz))) {
185-
fprintf(stderr, "MemError: can't allocate memory: %s\n",
185+
xbps_error_printf("MemError: can't allocate memory: %s\n",
186186
strerror(errno));
187187
fclose(file);
188188
return false;
@@ -260,7 +260,7 @@ rcv_sh_substitute(rcv_t *rcv, const char *str, size_t len)
260260
}
261261
if (reflen) {
262262
if (reflen >= sizeof buf) {
263-
fprintf(stderr, "out of memory\n");
263+
xbps_error_printf("out of memory\n");
264264
exit(1);
265265
}
266266
strncpy(buf, ref, reflen);
@@ -283,10 +283,10 @@ rcv_sh_substitute(rcv_t *rcv, const char *str, size_t len)
283283
return ret;
284284

285285
err1:
286-
fprintf(stderr, "syntax error: in file '%s'\n", rcv->fname);
286+
xbps_error_printf("syntax error: in file '%s'\n", rcv->fname);
287287
exit(1);
288288
err2:
289-
fprintf(stderr,
289+
xbps_error_printf(
290290
"Shell cmd failed: '%s' for "
291291
"template '%s'",
292292
cmd, rcv->fname);
@@ -365,12 +365,11 @@ rcv_get_pkgver(rcv_t *rcv)
365365

366366
if (!xbps_dictionary_set(rcv->env, key,
367367
xbps_string_create_cstring(val))) {
368-
fprintf(stderr, "error: xbps_dictionary_set");
368+
xbps_error_printf("xbps_dictionary_set failed");
369369
exit(1);
370370
}
371371

372-
if (rcv->xhp.flags & XBPS_FLAG_DEBUG)
373-
fprintf(stderr, "%s: %s %s\n", rcv->fname, key, val);
372+
xbps_dbg_printf("%s: %s %s\n", rcv->fname, key, val);
374373

375374
free(key);
376375
free(val);
@@ -432,7 +431,7 @@ rcv_process_file(rcv_t *rcv, const char *fname, rcv_check_func check)
432431
if (!xbps_dictionary_get_cstring_nocopy(rcv->env, "pkgname", &pkgname) ||
433432
!xbps_dictionary_get_cstring_nocopy(rcv->env, "version", &version) ||
434433
!xbps_dictionary_get_cstring_nocopy(rcv->env, "revision", &revision)) {
435-
fprintf(stderr, "ERROR: '%s':"
434+
xbps_error_printf("'%s':"
436435
" missing required variable (pkgname, version or revision)!",
437436
fname);
438437
exit(1);
@@ -540,22 +539,22 @@ rcv_check_version(rcv_t *rcv)
540539
assert(rcv);
541540

542541
if ((rcv->have_vars & GOT_PKGNAME_VAR) == 0) {
543-
fprintf(stderr, "ERROR: '%s': missing pkgname variable!\n", rcv->fname);
542+
xbps_error_printf("'%s': missing pkgname variable!\n", rcv->fname);
544543
exit(EXIT_FAILURE);
545544
}
546545
if ((rcv->have_vars & GOT_VERSION_VAR) == 0) {
547-
fprintf(stderr, "ERROR: '%s': missing version variable!\n", rcv->fname);
546+
xbps_error_printf("'%s': missing version variable!\n", rcv->fname);
548547
exit(EXIT_FAILURE);
549548
}
550549
if ((rcv->have_vars & GOT_REVISION_VAR) == 0) {
551-
fprintf(stderr, "ERROR: '%s': missing revision variable!\n", rcv->fname);
550+
xbps_error_printf("'%s': missing revision variable!\n", rcv->fname);
552551
exit(EXIT_FAILURE);
553552
}
554553

555554
if (!xbps_dictionary_get_cstring_nocopy(rcv->env, "pkgname", &pkgname) ||
556555
!xbps_dictionary_get_cstring_nocopy(rcv->env, "version", &version) ||
557556
!xbps_dictionary_get_cstring_nocopy(rcv->env, "revision", &revision)) {
558-
fprintf(stderr, "error:\n");
557+
xbps_error_printf("couldn't get pkgname, version, and/or revision\n");
559558
exit(1);
560559
}
561560

@@ -646,7 +645,7 @@ rcv_process_dir(rcv_t *rcv, rcv_proc_func process)
646645
if ((closedir(dir)) != -1)
647646
return ret;
648647
error:
649-
fprintf(stderr, "Error: while processing dir '%s/srcpkgs': %s\n",
648+
xbps_error_printf("while processing dir '%s/srcpkgs': %s\n",
650649
rcv->distdir, strerror(errno));
651650
exit(1);
652651
}
@@ -779,7 +778,7 @@ main(int argc, char **argv)
779778
char *tmp = rcv.distdir;
780779
rcv.distdir = realpath(tmp, NULL);
781780
if (rcv.distdir == NULL) {
782-
fprintf(stderr, "Error: realpath(%s): %s\n", tmp, strerror(errno));
781+
xbps_error_printf("realpath(%s): %s\n", tmp, strerror(errno));
783782
exit(1);
784783
}
785784
free(tmp);
@@ -793,7 +792,7 @@ main(int argc, char **argv)
793792
rcv_init(&rcv, prog);
794793

795794
if (chdir(rcv.distdir) == -1 || chdir("srcpkgs") == -1) {
796-
fprintf(stderr, "Error: while changing directory to '%s/srcpkgs': %s\n",
795+
xbps_error_printf("while changing directory to '%s/srcpkgs': %s\n",
797796
rcv.distdir, strerror(errno));
798797
exit(1);
799798
}

bin/xbps-digest/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ main(int argc, char **argv)
8484

8585
if (mode && strcmp(mode, "sha256")) {
8686
/* sha256 is the only supported mode currently */
87-
fprintf(stderr, "%s: unsupported digest mode\n", progname);
87+
xbps_error_printf("%s: unsupported digest mode\n", progname);
8888
exit(EXIT_FAILURE);
8989
}
9090

@@ -96,7 +96,7 @@ main(int argc, char **argv)
9696
} else {
9797
for (int i = 0; i < argc; i++) {
9898
if (!xbps_file_sha256(sha256, sizeof sha256, argv[i])) {
99-
fprintf(stderr,
99+
xbps_error_printf(
100100
"%s: couldn't get hash for %s (%s)\n",
101101
progname, argv[i], strerror(errno));
102102
exit(EXIT_FAILURE);

bin/xbps-fbulk/main.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ runBuilds(const char *bpath)
371371
*/
372372
item->xcode = -98;
373373
fp = fopen(logpath, "a");
374-
fprintf(fp, "xbps-fbulk: unable to fork/exec xbps-src\n");
374+
xbps_error_printf("xbps-fbulk: unable to fork/exec xbps-src\n");
375375
fclose(fp);
376376
processCompletion(item);
377377
} else {
@@ -634,7 +634,7 @@ main(int argc, char **argv)
634634

635635
tmp = xbps_xasprintf("%s/masterdir/.xbps_chroot_init", bpath);
636636
if (access(tmp, R_OK) == -1) {
637-
fprintf(stderr, "ERROR: %s/masterdir wasn't initialized, "
637+
xbps_error_printf("%s/masterdir wasn't initialized, "
638638
"run binary-bootstrap first.\n", bpath);
639639
exit(EXIT_FAILURE);
640640
}
@@ -652,7 +652,7 @@ main(int argc, char **argv)
652652
tmp = strdup(LogDir);
653653
}
654654
if (xbps_mkpath(tmp, 0755) != 0) {
655-
fprintf(stderr, "ERROR: failed to create %s logdir: %s\n",
655+
xbps_error_printf("failed to create %s logdir: %s\n",
656656
tmp, strerror(errno));
657657
exit(EXIT_FAILURE);
658658
}
@@ -664,7 +664,7 @@ main(int argc, char **argv)
664664
const char *p = logdirs[i];
665665
tmp = xbps_xasprintf("%s/%s", LogDir, p);
666666
if (xbps_mkpath(tmp, 0755) != 0) {
667-
fprintf(stderr, "ERROR: failed to create %s logdir: %s\n",
667+
xbps_error_printf("failed to create %s logdir: %s\n",
668668
tmp, strerror(errno));
669669
exit(EXIT_FAILURE);
670670
}
@@ -678,13 +678,13 @@ main(int argc, char **argv)
678678
if (RebuildSystem) {
679679
rv = xbps_init(&xh);
680680
if (rv != 0) {
681-
fprintf(stderr, "ERROR: failed to initialize libxbps: %s", strerror(rv));
681+
xbps_error_printf("failed to initialize libxbps: %s", strerror(rv));
682682
exit(EXIT_FAILURE);
683683
}
684684
array = xbps_array_create();
685685
rv = xbps_pkgdb_foreach_cb_multi(&xh, pkgdb_get_pkgs_cb, &array);
686686
if (rv != 0) {
687-
fprintf(stderr, "ERROR: xbps_pkgdb_foreach_cb_multi: %s", strerror(rv));
687+
xbps_error_printf("xbps_pkgdb_foreach_cb_multi: %s", strerror(rv));
688688
exit(EXIT_FAILURE);
689689
}
690690
for (unsigned int i = 0; i < xbps_array_count(array); i++) {
@@ -704,7 +704,7 @@ main(int argc, char **argv)
704704
* many packages will be built.
705705
*/
706706
if (chdir(rpath) == -1) {
707-
fprintf(stderr, "ERROR: failed to chdir to %s: %s\n",
707+
xbps_error_printf("failed to chdir to %s: %s\n",
708708
rpath, strerror(errno));
709709
exit(EXIT_FAILURE);
710710
}

bin/xbps-fetch/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ main(int argc, char **argv)
167167
failure = true;
168168
continue;
169169
} else if (rv == 0) {
170-
fprintf(stderr, "%s: file is identical with remote.\n", argv[i]);
170+
xbps_warn_printf("%s: %s: file is identical with remote.\n", progname, argv[i]);
171171
if (shasum) {
172172
if (!xbps_file_sha256_raw(digest, sizeof digest, filename)) {
173173
xbps_error_printf("%s: failed to hash: %s: %s\n",

bin/xbps-install/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ repo_import_key_cb(struct xbps_repo *repo, void *arg UNUSED, bool *done UNUSED)
8787
int rv;
8888

8989
if ((rv = xbps_repo_key_import(repo)) != 0)
90-
fprintf(stderr, "Failed to import pubkey from %s: %s\n",
90+
xbps_error_printf("Failed to import pubkey from %s: %s\n",
9191
repo->uri, strerror(rv));
9292

9393
return rv;
@@ -245,7 +245,7 @@ main(int argc, char **argv)
245245

246246
if (!(xh.flags & XBPS_FLAG_DOWNLOAD_ONLY) && !drun) {
247247
if ((rv = xbps_pkgdb_lock(&xh)) != 0) {
248-
fprintf(stderr, "Failed to lock the pkgdb: %s\n", strerror(rv));
248+
xbps_error_printf("Failed to lock the pkgdb: %s\n", strerror(rv));
249249
exit(rv);
250250
}
251251
}

bin/xbps-install/transaction.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -257,22 +257,22 @@ dist_upgrade(struct xbps_handle *xhp, unsigned int cols, bool yes, bool drun)
257257

258258
rv = xbps_transaction_update_packages(xhp);
259259
if (rv == ENOENT) {
260-
printf("No packages currently registered.\n");
260+
xbps_error_printf("No packages currently registered.\n");
261261
return 0;
262262
} else if (rv == EBUSY) {
263263
if (drun) {
264264
rv = 0;
265265
} else {
266-
printf("The 'xbps' package must be updated, please run `xbps-install -u xbps`\n");
266+
xbps_error_printf("The 'xbps' package must be updated, please run `xbps-install -u xbps`\n");
267267
return rv;
268268
}
269269
} else if (rv == EEXIST) {
270270
return 0;
271271
} else if (rv == ENOTSUP) {
272-
fprintf(stderr, "No repositories currently registered!\n");
272+
xbps_error_printf("No repositories currently registered!\n");
273273
return rv;
274274
} else if (rv != 0) {
275-
fprintf(stderr, "Unexpected error %s\n", strerror(rv));
275+
xbps_error_printf("Unexpected error: %s\n", strerror(rv));
276276
return -1;
277277
}
278278

@@ -286,17 +286,17 @@ install_new_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
286286

287287
rv = xbps_transaction_install_pkg(xhp, pkg, force);
288288
if (rv == EEXIST)
289-
printf("Package `%s' already installed.\n", pkg);
289+
xbps_error_printf("Package `%s' already installed.\n", pkg);
290290
else if (rv == ENOENT)
291-
fprintf(stderr, "Package '%s' not found in repository pool.\n", pkg);
291+
xbps_error_printf("Package '%s' not found in repository pool.\n", pkg);
292292
else if (rv == ENOTSUP)
293-
fprintf(stderr, "No repositories currently registered!\n");
293+
xbps_error_printf("No repositories currently registered!\n");
294294
else if (rv == ENXIO)
295-
fprintf(stderr, "Package `%s' contains invalid dependencies, exiting.\n", pkg);
295+
xbps_error_printf("Package `%s' contains invalid dependencies, exiting.\n", pkg);
296296
else if (rv == EBUSY)
297-
fprintf(stderr, "The 'xbps' package must be updated, please run `xbps-install -u xbps`\n");
297+
xbps_error_printf("The 'xbps' package must be updated, please run `xbps-install -u xbps`\n");
298298
else if (rv != 0) {
299-
fprintf(stderr, "Unexpected error: %s\n", strerror(rv));
299+
xbps_error_printf("Unexpected error: %s\n", strerror(rv));
300300
rv = -1;
301301
}
302302
return rv;
@@ -311,17 +311,17 @@ update_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
311311
if (rv == EEXIST)
312312
printf("Package '%s' is up to date.\n", pkg);
313313
else if (rv == ENOENT)
314-
fprintf(stderr, "Package '%s' not found in repository pool.\n", pkg);
314+
xbps_error_printf("Package '%s' not found in repository pool.\n", pkg);
315315
else if (rv == ENODEV)
316-
fprintf(stderr, "Package '%s' not installed.\n", pkg);
316+
xbps_error_printf("Package '%s' not installed.\n", pkg);
317317
else if (rv == ENOTSUP)
318-
fprintf(stderr, "No repositories currently registered!\n");
318+
xbps_error_printf("No repositories currently registered!\n");
319319
else if (rv == ENXIO)
320-
fprintf(stderr, "Package `%s' contains invalid dependencies, exiting.\n", pkg);
320+
xbps_error_printf("Package `%s' contains invalid dependencies, exiting.\n", pkg);
321321
else if (rv == EBUSY)
322-
fprintf(stderr, "The 'xbps' package must be updated, please run `xbps-install -u xbps`\n");
322+
xbps_error_printf("The 'xbps' package must be updated, please run `xbps-install -u xbps`\n");
323323
else if (rv != 0) {
324-
fprintf(stderr, "Unexpected error: %s\n", strerror(rv));
324+
xbps_error_printf("Unexpected error: %s\n", strerror(rv));
325325
return -1;
326326
}
327327
return rv;
@@ -346,20 +346,20 @@ exec_transaction(struct xbps_handle *xhp, unsigned int maxcols, bool yes, bool d
346346
if (xbps_array_count(array)) {
347347
/* missing dependencies */
348348
print_array(array);
349-
fprintf(stderr, "Transaction aborted due to unresolved dependencies.\n");
349+
xbps_error_printf("Transaction aborted due to unresolved dependencies.\n");
350350
}
351351
} else if (rv == ENOEXEC) {
352352
array = xbps_dictionary_get(xhp->transd, "missing_shlibs");
353353
if (xbps_array_count(array)) {
354354
/* missing shlibs */
355355
print_array(array);
356-
fprintf(stderr, "Transaction aborted due to unresolved shlibs.\n");
356+
xbps_error_printf("Transaction aborted due to unresolved shlibs.\n");
357357
}
358358
} else if (rv == EAGAIN) {
359359
/* conflicts */
360360
array = xbps_dictionary_get(xhp->transd, "conflicts");
361361
print_array(array);
362-
fprintf(stderr, "Transaction aborted due to conflicting packages.\n");
362+
xbps_error_printf("Transaction aborted due to conflicting packages.\n");
363363
} else if (rv == ENOSPC) {
364364
/* not enough free space */
365365
xbps_dictionary_get_uint64(xhp->transd,
@@ -378,7 +378,7 @@ exec_transaction(struct xbps_handle *xhp, unsigned int maxcols, bool yes, bool d
378378
rv = -1;
379379
goto out;
380380
}
381-
fprintf(stderr, "Transaction aborted due to insufficient disk "
381+
xbps_error_printf("Transaction aborted due to insufficient disk "
382382
"space (need %s, got %s free).\n", instsize, freesize);
383383
if (drun) {
384384
goto proceed;
@@ -440,7 +440,7 @@ exec_transaction(struct xbps_handle *xhp, unsigned int maxcols, bool yes, bool d
440440
trans->rm_pkgcnt,
441441
trans->hold_pkgcnt);
442442
} else {
443-
fprintf(stderr, "Transaction failed! see above for errors.\n");
443+
xbps_error_printf("Transaction failed! see above for errors.\n");
444444
}
445445
out:
446446
if (trans->iter)

bin/xbps-pkgdb/check.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ check_pkg_integrity(struct xbps_handle *xhp,
9797
assert(buf);
9898
filesd = xbps_plist_dictionary_from_file(buf);
9999
if (filesd == NULL) {
100-
fprintf(stderr, "%s: cannot read %s, ignoring...\n",
100+
xbps_error_printf("%s: cannot read %s, ignoring...\n",
101101
pkgname, buf);
102102
free(buf);
103103
return -1;
@@ -106,11 +106,11 @@ check_pkg_integrity(struct xbps_handle *xhp,
106106
free(buf);
107107
if (rv == ENOENT) {
108108
xbps_dictionary_remove(opkgd, "metafile-sha256");
109-
fprintf(stderr, "%s: unexistent metafile, "
109+
xbps_error_printf("%s: unexistent metafile, "
110110
"updating pkgdb.\n", pkgname);
111111
} else if (rv == ERANGE) {
112112
xbps_object_release(filesd);
113-
fprintf(stderr, "%s: metadata file has been "
113+
xbps_error_printf("%s: metadata file has been "
114114
"modified!\n", pkgname);
115115
return 1;
116116
}

0 commit comments

Comments
 (0)