[syslinux] argv[0] doesn't contain module name and cat.c32 hangs with Syslinux 4.00-pre36
Gert Hulselmans
gerth at zytor.com
Thu Mar 18 11:49:31 PDT 2010
The program name of the module can't be retrieved with argv[0].
I tested it by running cat.c32 (com32/samples/cat.c32).
In Syslinux 3.85, argv[0] returns an empty string.
In Syslinux 4.00-pre36, argv[0] returns some garbage characters.
ISOLINUX 3.85 2010-02-20 ETCD Copyright (C) 1994-2010 H. Peter Anvin et al
argv = 0x00182c44
argv[0] = 0x07fbffc3 = ""
argv[1] = 0x00182c34 = "isolinux.cfg"
argv[2] = 0x00000000 = "(null)"
File = isolinux.cfg
DEFAULT cat_file
LABEL cat_file
COM32 cat.c32
APPEND isolinux.cfg
boot:
EXTLINUX 4.00 4.00-pre36 Copyright (C) 1994-2010 H. Peter Anvin et al
Press 1 to see the menu
Hello, World! from (hello.c)
argv = 0x001e1e48
argv[0] = 0x07fdffbf = "�"
argv[1] = 0x001e1e38 = "extlinux.conf"
argv[2] = 0x00000000 = "(null)"
File = extlinux.conf
DEFAULT cat_file
LABEL cat_file
COM32 cat.c32
APPEND extlinux.conf
boot:
On my PC, cat.c32 (com32/samples/cat.c32) of Syslinux 4.00-pre36 hangs when
you specify a file that doesn't exist (works fine in kvm).
It works fine with Syslinux 3.85.
Checking if the file exist, before trying to read its contents, fixes the
issue.
I also replace "exit(1)" by "return 1;" (suggestion of Shao Miller).
$ diff -up syslinux-4.00-pre36-original/com32/samples/cat.c
syslinux-4.00-pre36/com32/samples/cat.c
--- syslinux-4.00-pre36-original/com32/samples/cat.c 2010-03-07
00:13:36.000000000 +0100
+++ syslinux-4.00-pre36/com32/samples/cat.c 2010-03-18 18:02:58.499575668
+0100
@@ -15,13 +15,18 @@ int main(int argc, char *argv[])
printf("argv[%d] = %p = \"%s\"\n", i, argv[i], argv[i]);
if (argc < 2) {
- fprintf(stderr, "Missing file name!\n");
- exit(1);
+ fprintf(stderr, "Usage: cat.c32 filename\n");
+ return 1;
}
printf("File = %s\n", argv[1]);
f = fopen(argv[1], "r");
+ if (!f) {
+ fprintf(stderr, "File name \"%s\" does not exist.\n", argv[1]);
+ return 1;
+ }
+
while ((ch = getc(f)) != EOF)
putchar(ch);
Also a true cat.c32 module would be nice to have.
So a cat.c32 module that doesn't display this part:
===================================================
argv = 0x001e1e48
argv[0] = 0x07fdffbf = "�"
argv[1] = 0x001e1e38 = "extlinux.conf"
argv[2] = 0x00000000 = "(null)"
File = extlinux.conf
===================================================
Maybe replacing strange characters with "?" would even be better.
A more.c32 module would also be useful.
$ cat com32/modules/cat.c
#include <stdio.h>
#include <stdlib.h>
#include <console.h>
int main(int argc, char *argv[])
{
FILE *f;
int ch;
openconsole(&dev_stdcon_r, &dev_stdcon_w);
if (argc != 2) {
fprintf(stderr, "Usage: cat.c32 filename\n");
return 1;
}
f = fopen(argv[1], "r");
if (!f) {
fprintf(stderr, "File name \"%s\" does not exist.\n", argv[1]);
return 1;
}
while ((ch = getc(f)) != EOF)
putchar(ch);
fclose(f);
return 0;
}
- Gert Hulselmans
More information about the Syslinux
mailing list