mount: make progname static and remove external reference

The global variable 'progname' in mount_libmount.c and umount_libmount.c
triggers Sparse warnings because it is not declared in any header file.
However, exporting such a generic name in a shared header is undesirable
due to potential namespace pollution.

To resolve this, make 'progname' static in the definition files to limit
its scope.

In mount_attrs.c, which previously required access to 'progname' for
error reporting, replace the custom error() function with the standard
warnx() function.  This eliminates the need to reference the external
'progname' variable, allowing the extern declaration to be removed.

This resolves the following Sparse warnings:

mount_libmount.c:96:6: warning: symbol 'progname' was not declared. Should
 it be static?
umount_libmount.c:88:6: warning: symbol 'progname' was not declared. Should
 it be static?

Note:
Strictly speaking, replacing error() with warnx() removes the dependency
on the 'mount_quiet' global variable used for output suppression.
However, in the current libmount-based implementation, 'mount_quiet' is
never set and defaults to 0, rendering the legacy suppression logic
inactive.  Therefore, this change does not alter the actual behavior.
Proper verbosity control using the libmount context is left as a future
improvement.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
This commit is contained in:
Ryusuke Konishi 2026-01-10 21:54:26 +09:00
parent 13dbb30e13
commit b13f3764fb
3 changed files with 15 additions and 5 deletions

View File

@ -35,6 +35,10 @@
#include <stdlib.h>
#endif /* HAVE_STDLIB_H */
#if HAVE_ERR_H
#include <err.h>
#endif /* HAVE_ERR_H */
#if HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
@ -42,7 +46,6 @@
#include <libmount.h>
#include <stdarg.h>
#include <errno.h>
#include <assert.h>
#include "sundries.h"
@ -51,7 +54,6 @@
#include "cleaner_exec.h" /* PIDOPT_NAME */
#include "nls.h"
extern char *progname;
void nilfs_mount_attrs_init(struct nilfs_mount_attrs *mattrs)
{
@ -137,7 +139,15 @@ int nilfs_mount_attrs_parse(struct nilfs_mount_attrs *mattrs,
return 0;
out_inval:
error(_("%s: invalid options (%s)."), progname, optstr);
/*
* TODO: Implement proper verbosity control.
* Currently, warnx() is used unconditionally because the legacy
* 'mount_quiet' logic is inactive in the libmount version.
* Future cleanups should utilize the libmount context
* (e.g., mnt_context_get_mflags()) and remove dependencies on
* legacy sundries.c, etc.
*/
warnx(_("invalid options (%s)."), optstr);
res = -1;
failed:
if (rest) {

View File

@ -93,7 +93,7 @@ static char *mount_fstype;
/* global variables */
static const char fstype[] = NILFS2_FS_NAME;
char *progname = "mount." NILFS2_FS_NAME;
static char *progname = "mount." NILFS2_FS_NAME;
/* mount info */
struct nilfs_mount_info {

View File

@ -85,7 +85,7 @@ static int suid; /* reserved for non-root user mount/umount
/* global variables */
static const char fstype[] = NILFS2_FS_NAME;
char *progname = "umount." NILFS2_FS_NAME;
static char *progname = "umount." NILFS2_FS_NAME;
/* umount info */
struct nilfs_umount_info {