Linux chmod_()

Just starting out? Need help? Post your questions and find answers here.
Opcode
Enthusiast
Enthusiast
Posts: 138
Joined: Thu Jul 18, 2013 4:58 am

Linux chmod_()

Post by Opcode »

How would I properly use the Linux chmod_() function. I tried once and it completely destroyed my Linux install. :shock:

Code: Select all

chmod_("/etc/cron.daily/fstrim", 0755)
auser
Enthusiast
Enthusiast
Posts: 195
Joined: Wed Sep 06, 2006 6:59 am

Re: Linux chmod_()

Post by auser »

0755 is wrong. It would be 493 in that case. You could use strtol() to get your value:

Code: Select all

chmod_("/etc/cron.daily/fstrim",strtol_("0755",0,8))
Opcode
Enthusiast
Enthusiast
Posts: 138
Joined: Thu Jul 18, 2013 4:58 am

Re: Linux chmod_()

Post by Opcode »

auser wrote:0755 is wrong. It would be 493 in that case. You could use strtol() to get your value:

Code: Select all

chmod_("/etc/cron.daily/fstrim",strtol_("0755",0,8))
I just wanted to be sure of the parameters, seems like chmod_() is quite a fatal function if not used properly.
Opcode
Enthusiast
Enthusiast
Posts: 138
Joined: Thu Jul 18, 2013 4:58 am

Re: Linux chmod_()

Post by Opcode »

auser wrote:0755 is wrong. It would be 493 in that case. You could use strtol() to get your value:

Code: Select all

chmod_("/etc/cron.daily/fstrim",strtol_("0755",0,8))

Code: Select all

strtol_("0755", 0, 8)
Always returns 0. I tried chmod once again and like last time it bricked my Ubuntu install (had to reinstall, again...).
Opcode
Enthusiast
Enthusiast
Posts: 138
Joined: Thu Jul 18, 2013 4:58 am

Re: Linux chmod_()

Post by Opcode »

Opcode wrote:

Code: Select all

strtol_("0755", 0, 8)
Always returns 0. I tried chmod once again and like last time it bricked my Ubuntu install (had to reinstall, again...).
I think strtol() and strtoul() are both bugged. Both with normal and su privileges return 0 on Ubuntu 14.04.1 LTS.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Linux chmod_()

Post by luis »

Opcode wrote:How would I properly use the Linux chmod_() function. I tried once and it completely destroyed my Linux install. :shock:
...
I tried chmod once again and like last time it bricked my Ubuntu install (had to reinstall, again...)
If you think some code to test can be risky, consider using a virtual machine. At the touch of a button you can restore its previous state without reinstalling.

On a real OS, often another terminal already open with a root account or a sudo it's enough to repair most of the damage one can usually do.

In case that fails, it's a good idea to have a complete image made before. Restoring an image is quicker and less tedious than reinstalling the OS, configuring it , updating it and finally reinstalling all the required programs.

Opcode wrote: I think strtol() and strtoul() are both bugged. Both with normal and su privileges return 0 on Ubuntu 14.04.1 LTS.
Two of the most simple and widely used C library functions bugged.... do you think is likely ?

Or are you compiling with Unicode enabled ?

Code: Select all

long int strtol(const char *nptr, char **endptr, int base);
If that is the problem, you could try to override the PB import, or compile in ascii.

Code: Select all

ImportC ""
 strtol_(nptr.p-utf8, *endptr, base) As "strtol"
EndImport

Code: Select all

Debug  strtol_("0755", 0, 8)  ; 0 in unicode

Debug  strtol_("0755", 0, 8)  ; 493 in unicode with the fixed import
I hope when PB will drop ascii mode all the Linux imports will be fixed.
"Have you tried turning it off and on again ?"
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Linux chmod_()

Post by luis »

Were you able to check about this ? Was it due to unicode or something else ?
luis wrote:Two of the most simple and widely used C library functions bugged.... do you think is likely ?
Or are you compiling with Unicode enabled ?

EDIT: Well, you didn't answer to my question about Unicode, but it's nice to talk to myself. At least it is talking to someone I like. :wink:
"Have you tried turning it off and on again ?"
Post Reply