|
Post by rikky on Dec 15, 2020 15:59:17 GMT 1
Somehow LOAD$ doesn't work in /proc Not /proc/cpuinfo nor /proc/cmdline or /proc/consoles etc. The rights for these files are -r--r--r--, owner:group root:root I'm not root, but cat works. And even if I turn myself in root, LOAD$ doesn't work. I tested on a testfile with only read rights for everybody, and owner:group root:root If this file is not in /proc, BaCon works. SUB SUDO
ALIAS getuid() TO GETUID
IF GETUID != 0 THEN SYSTEM "sudo " & ARGUMENT$ END RETVAL ELSE PRINT "you are now running as the root user " END IF
END SUB
IF GETUID != 0 THEN PRINT PRINT "cat works as a normal user:" PRINT "cat /proc/consoles => " & CHOP$(EXEC$("cat /proc/consoles")) PRINT PRINT "but not from BaCon:" PRINT "/proc/consoles => " & LOAD$("/proc/consoles") PRINT END IF
SUDO
IF GETUID == 0 THEN PRINT PRINT "Even root is powerless:" PRINT "/proc/consoles => " & LOAD$("/proc/consoles") PRINT END IF response: cat works as a normal user: cat /proc/consoles => tty0 -WU (EC p ) 4:7
but not from BaCon: /proc/consoles =>
you are now running as the root user
Even root is powerless: /proc/consoles => Rik.
|
|
|
Post by Pjot on Dec 15, 2020 19:23:07 GMT 1
Hi rikky, Believe it or not, this makes perfectly sense. The Linux "proc" files are special files and created by the kernel. They have 0 byte size. More details here: Linux Documentation ProjectThe BaCon function "LOAD$" uses the libc fread function. This function needs to specify how many bytes must be read from the disk. If the file is 0 bytes, then LOAD$ will load 0 bytes. Instead, you must use the READLN function. This is not a bug, it is the same as you are programming in C directly. This program works for me: OPEN "/proc/cpuinfo" FOR READING AS proc
WHILE NOT(ENDFILE(proc)) READLN txt$ FROM proc PRINT txt$ WEND
CLOSE FILE proc
HTH Peter
|
|
|
Post by rikky on Dec 15, 2020 21:43:38 GMT 1
Ow,,so.. Looking at your Linux documentation page the courage is sinking into my shoes. Am I ever going to learn even one tenth of this? Anyway, I adapted my bash4dummy's LOAD program, but now I'm bumping into the next error. The program has OPTION EXPLICIT activated, and this option wants to have a TYPE for proc This doesnt work: GLOBAL proc TYPE FILE OPEN argument$("1") FOR READING AS proc
How do you define a file? Rik.
|
|
|
Post by Pjot on Dec 15, 2020 21:55:20 GMT 1
Dear rikky,
You can use the C-type FILE* for this:
LOCAL proc TYPE FILE*
Regards, Peter
|
|