From b86aa869184f240182d3ae121dcfc8878d83e20d Mon Sep 17 00:00:00 2001 From: Michal Domonkos Date: Thu, 27 Nov 2025 13:40:00 +0100 Subject: [PATCH 1/2] Revert "Drop local implementation of xsetprogname/xgetprogname" Turns out some platforms (such as AIX) don't implement these. Don't compile it just yet, it needs some fixing up, which will be done in the next commit. Related: #4053 This reverts commit fa06b68ed7640c0e42a8a63dd9cb0bf8d4c73525. --- misc/rpmxprogname.c | 33 +++++++++++++++++++++++++++++++++ misc/rpmxprogname.h | 13 +++++++++++++ misc/system.h | 6 ++++-- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 misc/rpmxprogname.c create mode 100644 misc/rpmxprogname.h diff --git a/misc/rpmxprogname.c b/misc/rpmxprogname.c new file mode 100644 index 0000000000..f896006138 --- /dev/null +++ b/misc/rpmxprogname.c @@ -0,0 +1,33 @@ +/* Original author: Kamil Rytarowski + File: rpmxprogname.c + Date of creation: 2013-08-10 + License: the same as RPM itself */ + +#include "rpmxprogname.h" + +#include /* strrchr */ + +char *_rpmxprogname = NULL; + +char *_rpmxgetprogname(void) +{ + const char *empty = ""; + + if (_rpmxprognam != NULL) /* never return NULL string */ + return _rpmxprogname; + else + return empty; +} + +void _rpmxsetprogname(const char *pn) +{ + if (pn != NULL && _rpmxprogname == NULL /* set the value only once */) { + char *p = strrchr(pn, '/'); /* locate the last occurrence of '/' */ + if (p != NULL) + _rpmxprogname = p + 1 /* strip beginning '/' */; + else + _rpmxprogname = pn; + } +} + +#endif /* _RPMXPROGNAME_H */ diff --git a/misc/rpmxprogname.h b/misc/rpmxprogname.h new file mode 100644 index 0000000000..673c84aa25 --- /dev/null +++ b/misc/rpmxprogname.h @@ -0,0 +1,13 @@ +/* Original author: Kamil Rytarowski + File: rpmxprogname.c + Date of creation: 2013-08-10 + License: the same as RPM itself */ + +#ifndef _RPMXPROGNAME_H +#define _RPMXPROGNAME_H + +char *_rpmxgetprogname(void); +void _rpmxsetprogname(const char *pn); + +#endif /* _RPMXPROGNAME_H */ + diff --git a/misc/system.h b/misc/system.h index 36ea094cfa..1f110f8b9f 100644 --- a/misc/system.h +++ b/misc/system.h @@ -85,8 +85,10 @@ extern int fdatasync(int fildes); # define xsetprogname(pn) extern const char *__progname; # define xgetprogname(pn) __progname -#else -# error "Did not find any sutable implementation of xsetprogname/xgetprogname" +#else /* Reimplement setprogname and getprogname */ +# include "misc/rpmxprogname.h" +# define xsetprogname(pn) _rpmxsetprogname(pn) +# define xgetprogname() _rpmxgetprogname() #endif /* Take care of NLS matters. */ From 38848f89414ad603a7a5f4f2890e09058d2c555d Mon Sep 17 00:00:00 2001 From: Michal Domonkos Date: Thu, 27 Nov 2025 15:50:43 +0100 Subject: [PATCH 2/2] Adapt rpmxprogname fallback to current codebase Fix minor issues with the original code reverted in the previous commit that prevented it from compiling cleanly (mostly around the const usage) and actually enable it if no system implementation is available (such as on AIX). Note that this new source file is tiny so it's included in libmisc instead of a new target, and librpm is linked against it. Related: #4053 --- lib/CMakeLists.txt | 4 ++++ misc/CMakeLists.txt | 2 +- misc/rpmxprogname.c | 8 +++----- misc/rpmxprogname.h | 10 +++++++++- misc/system.h | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 79e5d10b51..f0c116f617 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -74,6 +74,10 @@ if(WITH_CAP) target_link_libraries(librpm PRIVATE PkgConfig::LIBCAP) endif() +if(NOT HAVE_SETPROGNAME AND NOT HAVE___PROGNAME) + target_link_libraries(librpm PRIVATE libmisc) +endif() + add_custom_command(OUTPUT tagtbl.inc COMMAND AWK=${AWK} ${CMAKE_CURRENT_SOURCE_DIR}/gentagtbl.sh ${CMAKE_SOURCE_DIR}/include/rpm/rpmtag.h > tagtbl.inc DEPENDS ${CMAKE_SOURCE_DIR}/include/rpm/rpmtag.h gentagtbl.sh diff --git a/misc/CMakeLists.txt b/misc/CMakeLists.txt index 925d2ea952..3dbda4c47d 100644 --- a/misc/CMakeLists.txt +++ b/misc/CMakeLists.txt @@ -1,2 +1,2 @@ -add_library(libmisc OBJECT fts.c rpmfts.h) +add_library(libmisc OBJECT fts.c rpmfts.h rpmxprogname.c rpmxprogname.h) target_include_directories(libmisc PRIVATE ${Intl_INCLUDE_DIRS}) diff --git a/misc/rpmxprogname.c b/misc/rpmxprogname.c index f896006138..edb7677f83 100644 --- a/misc/rpmxprogname.c +++ b/misc/rpmxprogname.c @@ -7,13 +7,13 @@ #include /* strrchr */ -char *_rpmxprogname = NULL; +const char *_rpmxprogname = NULL; -char *_rpmxgetprogname(void) +const char *_rpmxgetprogname(void) { const char *empty = ""; - if (_rpmxprognam != NULL) /* never return NULL string */ + if (_rpmxprogname != NULL) /* never return NULL string */ return _rpmxprogname; else return empty; @@ -29,5 +29,3 @@ void _rpmxsetprogname(const char *pn) _rpmxprogname = pn; } } - -#endif /* _RPMXPROGNAME_H */ diff --git a/misc/rpmxprogname.h b/misc/rpmxprogname.h index 673c84aa25..15c008634b 100644 --- a/misc/rpmxprogname.h +++ b/misc/rpmxprogname.h @@ -6,8 +6,16 @@ #ifndef _RPMXPROGNAME_H #define _RPMXPROGNAME_H -char *_rpmxgetprogname(void); +#ifdef __cplusplus +extern "C" { +#endif + +const char *_rpmxgetprogname(void); void _rpmxsetprogname(const char *pn); +#ifdef __cplusplus +} +#endif + #endif /* _RPMXPROGNAME_H */ diff --git a/misc/system.h b/misc/system.h index 1f110f8b9f..53b3242583 100644 --- a/misc/system.h +++ b/misc/system.h @@ -86,7 +86,7 @@ extern int fdatasync(int fildes); extern const char *__progname; # define xgetprogname(pn) __progname #else /* Reimplement setprogname and getprogname */ -# include "misc/rpmxprogname.h" +# include "rpmxprogname.h" # define xsetprogname(pn) _rpmxsetprogname(pn) # define xgetprogname() _rpmxgetprogname() #endif