]>
sourceware.org Git - systemtap.git/blob - runtime/io.c
1483acfdaf60f70b4ad42524f93f10bfb8a68790
2 * I/O for printing warnings, errors and debug messages
3 * Copyright (C) 2005, 2006, 2007 Red Hat Inc.
5 * This file is part of systemtap, and is free software. You can
6 * redistribute it and/or modify it under the terms of the GNU General
7 * Public License (GPL); either version 2, or (at your option) any
14 #include "transport/transport.c"
16 void _stp_print_flush (void);
17 void _stp_string_cat_cstr (String str1
, const char *str2
);
20 * @brief I/O for printing warnings, errors and debug messages.
22 /** @addtogroup io I/O
26 #define WARN_STRING "WARNING: "
27 #define ERR_STRING "ERROR: "
28 enum code
{ INFO
=0, WARN
, ERROR
, DBUG
};
30 /** private buffer for _stp_log() */
31 #define STP_LOG_BUF_LEN 256
33 typedef char _stp_lbuf
[STP_LOG_BUF_LEN
];
34 void *Stp_lbuf
= NULL
;
36 static void _stp_vlog (enum code type
, const char *func
, int line
, const char *fmt
, va_list args
)
39 char *buf
= per_cpu_ptr(Stp_lbuf
, smp_processor_id());
43 start
= _stp_snprintf(buf
, STP_LOG_BUF_LEN
, "\033[36m%s:%d:\033[0m ", func
, line
);
44 } else if (type
== WARN
) {
45 strcpy (buf
, WARN_STRING
);
46 start
= sizeof(WARN_STRING
) - 1;
47 } else if (type
== ERROR
) {
48 strcpy (buf
, ERR_STRING
);
49 start
= sizeof(ERR_STRING
) - 1;
52 num
= _stp_vscnprintf (buf
+ start
, STP_LOG_BUF_LEN
- start
- 1, fmt
, args
);
54 if (buf
[num
+ start
- 1] != '\n') {
55 buf
[num
+ start
] = '\n';
57 buf
[num
+ start
] = '\0';
61 _stp_write(STP_OOB_DATA
, buf
, start
+ num
+ 1);
63 _stp_string_cat_cstr(_stp_stdout
,buf
);
70 * This function sends the message immediately to staprun. It
71 * will also be sent over the bulk transport (relayfs) if it is
72 * being used. If the last character is not a newline, then one
73 * is added. This function is not as efficient as _stp_printf()
74 * and should only be used for urgent messages. You probably want
75 * dbug(), or _stp_warn().
76 * @param fmt A variable number of args.
77 * @todo Evaluate if this function is necessary.
79 void _stp_log (const char *fmt
, ...)
83 _stp_vlog (INFO
, NULL
, 0, fmt
, args
);
88 * This function sends a warning message immediately to staprun. It
89 * will also be sent over the bulk transport (relayfs) if it is
90 * being used. If the last character is not a newline, then one
92 * @param fmt A variable number of args.
94 void _stp_warn (const char *fmt
, ...)
98 _stp_vlog (WARN
, NULL
, 0, fmt
, args
);
102 /** Exits and unloads the module.
103 * This function sends a signal to staprun to tell it to
104 * unload the module and exit. The module will not be
105 * unloaded until after the current probe returns.
106 * @note Be careful to not treat this like the Linux exit()
107 * call. You should probably call return immediately after
108 * calling _stp_exit().
110 void _stp_exit (void)
115 /** Prints error message and exits.
116 * This function sends an error message immediately to staprun. It
117 * will also be sent over the bulk transport (relayfs) if it is
118 * being used. If the last character is not a newline, then one
121 * After the error message is displayed, the module will be unloaded.
122 * @param fmt A variable number of args.
125 void _stp_error (const char *fmt
, ...)
129 _stp_vlog (ERROR
, NULL
, 0, fmt
, args
);
135 /** Prints error message.
136 * This function sends an error message immediately to staprun. It
137 * will also be sent over the bulk transport (relayfs) if it is
138 * being used. If the last character is not a newline, then one
141 * @param fmt A variable number of args.
144 void _stp_softerror (const char *fmt
, ...)
148 _stp_vlog (ERROR
, NULL
, 0, fmt
, args
);
153 static void _stp_dbug (const char *func
, int line
, const char *fmt
, ...)
157 _stp_vlog (DBUG
, func
, line
, fmt
, args
);
This page took 0.044685 seconds and 4 git commands to generate.