This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: [patch] LINUX_REBOOT_MAGIC1 printed as UNKNOWN VALUE in argstr
On Thu, 2007-09-13 at 09:05 -0700, Mike Mason wrote:
> Why does aux_syscalls.stp use hard coded values instead of embedded C and the actual defines? They're all over the place. Something like below seems more proper to me.
I often write embedded C functions. Kevin from IBM wrote the first pass
of aux_syscalls and he did not use embedded C and much of that survives.
Also, for trivial functions where the values of the defines are not
arch-dependent or possibly going to change, it is a bit simpler to not
use C.
> switch (magic) {
> case LINUX_REBOOT_MAGIC1:
> strlcpy(THIS->__retvalue, "LINUX_REBOOT_MAGIC1", MAXSTRINGLEN);
> break;
> case LINUX_REBOOT_MAGIC2:
> strlcpy(THIS->__retvalue, "LINUX_REBOOT_MAGIC2", MAXSTRINGLEN);
> break;
> case LINUX_REBOOT_MAGIC2A:
> strlcpy(THIS->__retvalue, "LINUX_REBOOT_MAGIC2A", MAXSTRINGLEN);
> break;
> case LINUX_REBOOT_MAGIC2B:
> strlcpy(THIS->__retvalue, "LINUX_REBOOT_MAGIC2B", MAXSTRINGLEN);
> break;
> case LINUX_REBOOT_MAGIC2C:
> strlcpy(THIS->__retvalue, "LINUX_REBOOT_MAGIC2C", MAXSTRINGLEN);
> break;
> default:
> snprintf(THIS->__retvalue, MAXSTRINGLEN, "UNKNOWN VALUE: %d", magic);
> }
> %}
or maybe a bit cleaner:
char *res= 0;
switch (magic) {
case LINUX_REBOOT_MAGIC1:
res = "LINUX_REBOOT_MAGIC1";
break;
[...]
}
if (res)
strlcpy (THIS->__retvalue, res, MAXSTRINGLEN);
else
snprintf(THIS->__retvalue, MAXSTRINGLEN, "UNKNOWN VALUE: %d", magic);