Skip to content

Commit 336d354

Browse files
committed
error: use GLib to remember the program name
Signed-off-by: Marc-André Lureau <[email protected]> Reviewed-by: Markus Armbruster <[email protected]>
1 parent 4529788 commit 336d354

File tree

6 files changed

+13
-29
lines changed

6 files changed

+13
-29
lines changed

include/qemu/error-report.h

-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ void error_init(const char *argv0);
7272
fmt, ##__VA_ARGS__); \
7373
})
7474

75-
const char *error_get_progname(void);
76-
7775
extern bool message_with_timestamp;
7876
extern bool error_with_guestname;
7977
extern const char *error_guest_name;

qemu-io.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ static char *get_prompt(void)
323323
static char prompt[FILENAME_MAX + 2 /*"> "*/ + 1 /*"\0"*/ ];
324324

325325
if (!prompt[0]) {
326-
snprintf(prompt, sizeof(prompt), "%s> ", error_get_progname());
326+
snprintf(prompt, sizeof(prompt), "%s> ", g_get_prgname());
327327
}
328328

329329
return prompt;
@@ -598,10 +598,10 @@ int main(int argc, char **argv)
598598
break;
599599
case 'V':
600600
printf("%s version " QEMU_FULL_VERSION "\n"
601-
QEMU_COPYRIGHT "\n", error_get_progname());
601+
QEMU_COPYRIGHT "\n", g_get_prgname());
602602
exit(0);
603603
case 'h':
604-
usage(error_get_progname());
604+
usage(g_get_prgname());
605605
exit(0);
606606
case 'U':
607607
force_share = true;
@@ -613,13 +613,13 @@ int main(int argc, char **argv)
613613
imageOpts = true;
614614
break;
615615
default:
616-
usage(error_get_progname());
616+
usage(g_get_prgname());
617617
exit(1);
618618
}
619619
}
620620

621621
if ((argc - optind) > 1) {
622-
usage(error_get_progname());
622+
usage(g_get_prgname());
623623
exit(1);
624624
}
625625

softmmu/vl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ static void help(int exitcode)
836836
version();
837837
printf("usage: %s [options] [disk_image]\n\n"
838838
"'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
839-
error_get_progname());
839+
g_get_prgname());
840840

841841
#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
842842
if ((arch_mask) & arch_type) \

storage-daemon/qemu-storage-daemon.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static void help(void)
141141
" --pidfile <path> write process ID to a file after startup\n"
142142
"\n"
143143
QEMU_HELP_BOTTOM "\n",
144-
error_get_progname());
144+
g_get_prgname());
145145
}
146146

147147
enum {

trace/control.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void trace_list_events(FILE *f)
161161
fprintf(f, "This list of names of trace points may be incomplete "
162162
"when using the DTrace/SystemTap backends.\n"
163163
"Run 'qemu-trace-stap list %s' to print the full list.\n",
164-
error_get_progname());
164+
g_get_prgname());
165165
#endif
166166
}
167167

util/qemu-error.c

+5-19
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,6 @@ void loc_set_file(const char *fname, int lno)
146146
}
147147
}
148148

149-
static const char *progname;
150-
151-
/*
152-
* Set the program name for error_print_loc().
153-
*/
154-
static void error_set_progname(const char *argv0)
155-
{
156-
const char *p = strrchr(argv0, '/');
157-
progname = p ? p + 1 : argv0;
158-
}
159-
160-
const char *error_get_progname(void)
161-
{
162-
return progname;
163-
}
164-
165149
/*
166150
* Print current location to current monitor if we have one, else to stderr.
167151
*/
@@ -171,8 +155,8 @@ static void print_loc(void)
171155
int i;
172156
const char *const *argp;
173157

174-
if (!monitor_cur() && progname) {
175-
fprintf(stderr, "%s:", progname);
158+
if (!monitor_cur() && g_get_prgname()) {
159+
fprintf(stderr, "%s:", g_get_prgname());
176160
sep = " ";
177161
}
178162
switch (cur_loc->kind) {
@@ -400,8 +384,10 @@ static void qemu_log_func(const gchar *log_domain,
400384

401385
void error_init(const char *argv0)
402386
{
387+
const char *p = strrchr(argv0, '/');
388+
403389
/* Set the program name for error_print_loc(). */
404-
error_set_progname(argv0);
390+
g_set_prgname(p ? p + 1 : argv0);
405391

406392
/*
407393
* This sets up glib logging so libraries using it also print their logs

0 commit comments

Comments
 (0)