mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-10-05 10:44:04 +00:00

As Stephen Hemminger mentioned on the last submission the new_json_obj
function is always called with fp == stdout, so right now, there's no
need of this extra argument.
The background for the rework is the following:
The ip monitor didn't call `new_json_obj` (even for in non json context),
so the static FILE* _fp variable wasn't initialized, thus raising a
SIGSEGV in ipaddress.c. This patch should fix this issue for good, new
paths won't have to call `new_json_obj`.
How to reproduce:
$ ip -t mon label link
(gdb) bt
.#0 _IO_vfprintf_internal (s=s@entry=0x0, format=format@entry=0x45460d “%d: “, ap=ap@entry=0x7fffffff7f18) at vfprintf.c:1278
.#1 0x0000000000451310 in color_fprintf (fp=0x0, attr=<optimized out>, fmt=0x45460d “%d: “) at color.c:108
.#2 0x000000000044a856 in print_color_int (t=t@entry=PRINT_ANY, color=color@entry=4294967295, key=key@entry=0x4545fc “ifindex”,
fmt=fmt@entry=0x45460d “%d: “, value=<optimized out>) at ip_print.c:132
.#3 0x000000000040ccd2 in print_int (value=<optimized out>, fmt=0x45460d “%d: “, key=0x4545fc “ifindex”, t=PRINT_ANY) at ip_common.h:189
.#4 print_linkinfo (who=<optimized out>, n=0x7fffffffa380, arg=0x7ffff77a82a0 <_IO_2_1_stdout_>) at ipaddress.c:1107
.#5 0x0000000000422e13 in accept_msg (who=0x7fffffff8320, ctrl=0x7fffffff8310, n=0x7fffffffa380, arg=0x7ffff77a82a0 <_IO_2_1_stdout_>) at ipmonitor.c:89
.#6 0x000000000044c58f in rtnl_listen (rtnl=0x672160 <rth>, handler=handler@entry=0x422c70 <accept_msg>, jarg=0x7ffff77a82a0 <_IO_2_1_stdout_>)
at libnetlink.c:761
.#7 0x00000000004233db in do_ipmonitor (argc=<optimized out>, argv=0x7fffffffe5a0) at ipmonitor.c:310
.#8 0x0000000000408f74 in do_cmd (argv0=0x7fffffffe7f5 “mon”, argc=3, argv=0x7fffffffe588) at ip.c:116
.#9 0x0000000000408a94 in main (argc=4, argv=0x7fffffffe580) at ip.c:311
Fixes: 6377572f
("ip: ip_print: add new API to print JSON or regular format output")
Reported-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
70 lines
1.8 KiB
C
70 lines
1.8 KiB
C
/*
|
|
* json_print.h "print regular or json output, based on json_writer".
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version
|
|
* 2 of the License, or (at your option) any later version.
|
|
*
|
|
* Authors: Julien Fortin, <julien@cumulusnetworks.com>
|
|
*/
|
|
|
|
#ifndef _JSON_PRINT_H_
|
|
#define _JSON_PRINT_H_
|
|
|
|
#include "json_writer.h"
|
|
#include "color.h"
|
|
|
|
json_writer_t *get_json_writer(void);
|
|
|
|
/*
|
|
* use:
|
|
* - PRINT_ANY for context based output
|
|
* - PRINT_FP for non json specific output
|
|
* - PRINT_JSON for json specific output
|
|
*/
|
|
enum output_type {
|
|
PRINT_FP = 1,
|
|
PRINT_JSON = 2,
|
|
PRINT_ANY = 4,
|
|
};
|
|
|
|
void new_json_obj(int json);
|
|
void delete_json_obj(void);
|
|
|
|
bool is_json_context(void);
|
|
|
|
void fflush_fp(void);
|
|
|
|
void open_json_object(const char *str);
|
|
void close_json_object(void);
|
|
void open_json_array(enum output_type type, const char *delim);
|
|
void close_json_array(enum output_type type, const char *delim);
|
|
|
|
#define _PRINT_FUNC(type_name, type) \
|
|
void print_color_##type_name(enum output_type t, \
|
|
enum color_attr color, \
|
|
const char *key, \
|
|
const char *fmt, \
|
|
type value); \
|
|
\
|
|
static inline void print_##type_name(enum output_type t, \
|
|
const char *key, \
|
|
const char *fmt, \
|
|
type value) \
|
|
{ \
|
|
print_color_##type_name(t, -1, key, fmt, value); \
|
|
}
|
|
_PRINT_FUNC(int, int);
|
|
_PRINT_FUNC(bool, bool);
|
|
_PRINT_FUNC(null, const char*);
|
|
_PRINT_FUNC(string, const char*);
|
|
_PRINT_FUNC(uint, uint64_t);
|
|
_PRINT_FUNC(hu, unsigned short);
|
|
_PRINT_FUNC(hex, unsigned int);
|
|
_PRINT_FUNC(0xhex, unsigned int);
|
|
_PRINT_FUNC(lluint, unsigned long long int);
|
|
#undef _PRINT_FUNC
|
|
|
|
#endif /* _JSON_PRINT_H_ */
|